DESTFILES=synth_server.bin synth_exec ref singen play singennl gpd silence mididump midisend
#synth_perf 
SYNTHOBJS=synth_impl.o synth.o synthmodule.o utils.o modules.o midisupport.o midibus.o sound-$(SOUND).o ioevent.o
INCLUDES=
CFLAGS=-O2
#-g -DHAVE_MINI_STL -finline-functions
DISTFILE=ksynth-`date +%y%m%d`.tgz
MICOLDFLAGS=-lmico2.0.8 -ldl
CXX=g++
CC=gcc
CXXLD=g++

default:
	@echo "   No architecture given, trying `uname -s | tr A-Z a-z`"
	@echo "-------------------------------------------------------------------------------"
	@echo "possible choices would be:"
	@echo   
	@echo "   - make linux"
	@echo
	@$(MAKE) all SOUND="`uname -s | tr A-Z a-z`"

linux:
	@$(MAKE) all SOUND=linux

all: $(DESTFILES)

play: play.o sound-$(SOUND).o utils.o
	$(CC) -o play play.o sound-$(SOUND).o utils.o

singen: singen.o
	$(CC) -o singen singen.o -lm

singennl: singennl.o
	$(CC) -o singennl singennl.o -lm

synth_exec: synth_exec.o synth.o
	$(CXXLD) -o synth_exec synth_exec.o synth.o $(MICOLDFLAGS)

midisend: midisend.o midibus.o utils.o
	$(CXXLD) -o midisend midibus.o midisend.o utils.o $(MICOLDFLAGS)

synth_perf: synth_perf.o synth.o
	$(CXXLD) -o synth_perf synth_perf.o synth.o $(MICOLDFLAGS)

synth_server.bin: $(SYNTHOBJS) synth_server.o
	$(CXXLD) -o synth_server.bin synth_server.o $(SYNTHOBJS) $(MICOLDFLAGS)

clean:
	rm -f $(DESTFILES) synth.cc synth.h midibus.cc midibus.h *.o core ksynth-*.tgz

synth_impl.o: synth_impl.h synth_impl.cc synth.h moduleserver.h
	$(CXX) $(CFLAGS) -c synth_impl.cc $(INCLUDES)

synth_exec.o: synth.h synth_exec.cc
	$(CXX) $(CFLAGS) -c synth_exec.cc $(INCLUDES)

midisend.o: midibus.h midisend.cc utils.h
	$(CXX) $(CFLAGS) -c midisend.cc $(INCLUDES)

synth_perf.o: synth.h synth_perf.cc
	$(CXX) $(CFLAGS) -c synth_perf.cc $(INCLUDES)

synth_server.o: synth_impl.h synth_server.cc
	$(CXX) $(CFLAGS) -c synth_server.cc $(INCLUDES)

synth.o: synth.cc synth.h
	$(CXX) $(CFLAGS) -c synth.cc $(INCLUDES)

midibus.o: midibus.cc midibus.h
	$(CXX) $(CFLAGS) -c midibus.cc $(INCLUDES)

synthmodule.o: synthmodule.cc moduleserver.h
	$(CXX) $(CFLAGS) -c synthmodule.cc $(INCLUDES)

midisupport.o: midisupport.cc moduleserver.h midibus.h
	$(CXX) $(CFLAGS) -c midisupport.cc $(INCLUDES)

ioevent.o: ioevent.cc ioevent.h
	$(CXX) $(CFLAGS) -c $*.cc $(INCLUDES)

modules.o: modules.cc moduleserver.h
	$(CXX) $(CFLAGS) -c modules.cc $(INCLUDES)

synth.cc: synth.h
synth.h: synth.idl
	idl synth.idl

midibus.cc: midibus.h
midibus.h: midibus.idl
	idl $*.idl

distrib:
	$(MAKE) clean
	cd gui/ksbuild
	$(MAKE) clean
	cd ../..
	tar -cf - `find . -type f -print |grep -v CVS |grep -v old` | gzip -9 >$(DISTFILE)
	@echo "--------------------------------------------------------"
	@echo "  everything important is now in $(DISTFILE)"
	@echo "--------------------------------------------------------"
