#
# Copyright (c) by Jaroslav Kysela (Perex soft)
# This library can be compiled only on ELF systems
#

.EXPORT_ALL_VARIABLES:

ifndef ARCH_COPTS
ARCH_COPTS = -O2 -g
endif
FLAGS	=
ifndef FINAL_VERSION
FLAGS	:= $(FLAGS) -DDEBUG
endif

TARGET  = libgus.so
TARGETX = libgus.so.`cat version` 
TARGETO = libgus.so.`cat version | cut -d . -f 1`
CC	= gcc
INCLUDE	= -I/usr/src/linux/include
CFLAGS	= -DLINUX -D__GUS_PATH_LIB__ $(FLAGS)
#CFLAGS	+= -g
COPTS	= -Wall -Wstrict-prototypes $(ARCH_COPTS) -fomit-frame-pointer -pipe -fPIC

SUBDIRS =

OBJECTS = debug.o \
	  access.o \
	  synth.o \
          instr.o iwffff.o patch.o \
          mixer.o pcm.o \
          convert.o spline.o \
          midi.o mididinfo.o midiplay.o \
	  iweffects.o

.c.o:
	$(CC) $(COPTS) $(CFLAGS) $(INCLUDE) -c -o $*.o $<

all: .depend $(TARGET)
	@ls -l $(TARGETX)

$(TARGET): $(OBJECTS) icfg/libigus.a
	gcc -shared -Wl,-soname,$(TARGETO) -Licfg -licfg -o $(TARGETX) $(OBJECTS)

icfg/libigus.a:
	$(MAKE) -C icfg

install: all
	rm -rf /usr/local/lib/libgus.so*
	install -m 755 -o root -g root $(TARGETX) /usr/local/lib
	install -m 644 -o root -g root libgus.h /usr/local/include
	ln -s /usr/local/lib/$(TARGETX) /usr/local/lib/libgus.so
	ln -s /usr/local/lib/$(TARGETX) /usr/local/lib/libgus.so.4
	ldconfig

gcompile: all

clean:
	- rm -f .depend *.o *~ $(TARGET) $(TARGETX) out.txt libgus.a
	$(MAKE) -C icfg clean
	$(MAKE) -C conf clean

.depend:
	$(CPP) $(CFLAGS) $(INCLUDE) -M *.c > .depend

dep:	.depend

dummy:

#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
