PGMS = EladRemote pa_devs
INCL = struct.h
LIBS = -lglut -lGL -lGLU -lftgl -lm -ldl -lfreetype
LIBS1 = -lpthread -Llssl -lcrypto -lm `pkg-config --libs glib-2.0` -lportaudio -lopus -lpng -lrt
LIBS2 = libConfig.so libDrawings.so libActions.so libTMATE2.so
LIBS3 = libWsocket.a
OBJS = wsocket.o th_audio.o serial.o keyer.o time.o png.o oscillator.o locale.o tmateset.o audioFFT.o
OBJS2 = drawings.o config.o actions.o TMATE2.o
LIBS_USB  = `pkg-config libusb-1.0 --libs` -lrt -lpthread
IMGS = button.png encoder1.png encoder2.png encoder3.png encoder4.png meter.png smeter.png wmeter.png wsmeter.png 
TXTS = langue-Default.txt langue-English.txt langue-Francoise.txt langue-Italiano.txt setup.txt 
FONTS = FreeSansBold.ttf FreeSans.ttf LiberationSerif-BoldItalic.ttf LiberationSerif-Bold.ttf LiberationSerif-Italic.ttf LiberationSerif-Regular.ttf Ni7seg.ttf
INSTDIR = /opt/EladRemote

all:	$(LIBS3) $(LIBS2) $(OBJS) $(PGMS)

EladRemote: EladRemote.c $(INCL) $(OBJS)
	gcc -g -o EladRemote EladRemote.c $(LIBS3) ${LIBS} $(LIBS1) -I/usr/include/opus/ -I/usr/include/freetype2 -rdynamic
	chmod 06775 EladRemote

pa_devs: pa_devs.c
	gcc -o pa_devs pa_devs.c -lportaudio -ldl
	chmod 06775 pa_devs

.c.o: $(INCL)
	gcc -g `pkg-config libusb-1.0 --cflags` `pkg-config --cflags glib-2.0` -Wall -fPIC -I/usr/include/opus/ -I/usr/include/freetype2 -c $<

libWsocket.a: $(OBJS) $(INCL)
	ar -rv libWsocket.a $(OBJS)

libConfig.so: config.o struct.h $(INCL)
	gcc -g -shared -Wl,-soname,libConfig.so -o libConfig.so config.o $(LIBS3) $(LIBS)

libDrawings.so: drawings.o struct.h $(INCL)
	gcc -g -shared -Wl,-soname,libDrawings.so -Wl,--unresolved-symbols=report-all -o libDrawings.so drawings.o $(LIBS3) $(LIBS) $(LIBS1)

libTMATE2.so: TMATE2.o TMATE2.h
	gcc -g -shared -Wl,-soname,libDrawings.so -Wl,--unresolved-symbols=report-all -o libTMATE2.so TMATE2.o $(LIBS_USB)

libActions.so: actions.o struct.h $(INCL)
	gcc -g -shared -Wl,-soname,libActions.so -o libActions.so actions.o $(LIBS3) $(LIBS1)

clean:
	@rm -f $(LIBS2) $(PGMS) $(OBJS) $(OBJS2) $(LIBS3)

install:
	mkdir -p $(INSTDIR)
	cp EladRemote.sh $(LIBS2) $(PGMS) $(IMGS) $(TXTS) $(FONTS) $(INSTDIR)
	chmod 06775 $(INSTDIR)/EladRemote
	chmod 06775 $(INSTDIR)/pa_devs

cleaninstall:
	cd $(INSTDIR) && rm -f EladRemote.sh  $(LIBS2) $(PGMS) $(IMGS) $(TXTS) $(FONTS)
	rmdir $(INSTDIR)
