#### Makefile for Linux ####

# improve! #fold00
ifeq (${HOSTNAME},solar.tscc)
SYSTEM=redhat
else
SYSTEM=suse
endif

# General #fold00
PREFIX=/opt/vocoder/
BINDIR=$(PREFIX)bin/
LIBDIR=$(PREFIX)lib/

ifeq ($(SYSTEM),redhat)
# RedHat
BUILDENV=/usr/src/redhat/
else
# SuSE
BUILDENV=/usr/src/packages/
endif


VERSION=`grep " VERSION " common.h | cut -d \" -f2`
TARGETS = vocoder
VOCODER_OBJECTS = main.o sampleio.o fileio.o io.o vocoder.o \
	wind_main.o wind_common.o wind_about.o wind_setbands.o

# various compiler and linker options #fold00
#  add -DFAST_CONVERT_LOOPS for 1-2% more performance
CC = gcc
CFLAGS = -O2 -fno-strength-reduce -Wall -W -g -DLINUX -DUSEGTK
CFLAGS += `gtk-config --cflags`
LIBCFLAGS = -fPIC
LFLAGS = -lm
LFLAGS += `gtk-config --libs`

.SUFFIXES:	.c

.c.o:
	$(CC) -c $(CFLAGS) $<

#######################################################################
# standard destinations #fold00
all:	$(TARGETS)

vocoder:    	$(VOCODER_OBJECTS)
	$(CC) -o vocoder $(LFLAGS) $(LIBCFLAGS) $(VOCODER_OBJECTS)
        
install:	vocoder
	install -d $(BINDIR)
	install -m 755 -s vocoder $(BINDIR)vocoder

uninstall:
	rm -f $(BINDIR)vocoder
        
#######################################################################
# various tool-destinations #fold00
run:	vocoder
	vocoder out.raw
	make out2wav

benchmark:	vocoder
	@echo "starting..."
	@typeset -i i ; i=0 ; while [ $$i -lt 7 ] ; do \
        time vocoder --nogui out.raw ;\
        i=$$i+1; \
        done

out2wav:
	sox -t .raw -c1 -r 50000 -b -s out.raw -u -b -c1 out.wav

raw2wav:
	for i in *.raw ; do \
	if ! [ $$i = 'out.raw' ] ; then \
	sox -s -b -c1 -r50000 $$i -s -w `echo $$i | sed -e "s/\.raw/\.wav/"` ; \
	fi ;\
	done


showfreqs:
	rm -f showfreqs
	make -C stuff/showfreqs showfreqs && ln -s stuff/showfreqs/showfreqs .

getcoeffs:
	get_coeffs.pl
        

# other tools #fold00
clean:
	rm -f *~ *.bak *.o vocoder out.raw out.wav stuff/*~ stuff/*.bak
	rm -f showfreqs
	rm -f specfile
	test -d stuff/showfreqs/ || exit 0 ; make -C stuff/showfreqs/ clean
	test -d stuff/frg/ || exit 0 ; make -C stuff/frg/ clean

tar:	clean
	(cd ../ ; tar czf vocoder.tgz vocoder/ )

disk:	tar
	mcopy -o ../vocoder.tgz a:
	rm ../vocoder.tgz

distrib:	clean
	mkdir ../vocoder-${VERSION}/
	cp -a `cat files.in | grep -v '%dir' | sed -e 's/^%.* //'` ../vocoder-${VERSION}/
#	cp -ar *.c *.h carrier?.raw formant.raw COPYRIGHT Makefile rules.txt imgs/ ../vocoder-${VERSION}/
	tar czf ../vocoder-${VERSION}.tgz -C../ vocoder-${VERSION}/
	rm -r ../vocoder-${VERSION}

specfile:	clean
	(cat specfile.in ; echo "$(BINDIR)vocoder" ) | sed -e s/\<VERSION\>/${VERSION}/ | sed -e s/\<PACKAGER\>/${USER}@${HOSTNAME}/ >specfile
	
rpm:	specfile distrib
	cp specfile $(BUILDENV)/SPECS/vocoder-$(VERSION).spec
	mv ../vocoder-$(VERSION).tgz $(BUILDENV)/SOURCES/
	cd $(BUILDENV) && rpm -v -ba $(BUILDENV)/SPECS/vocoder-*.spec
	mv $(BUILDENV)RPMS/i386/vocoder*.rpm ../
        
depend:
	@makedepend -Y -- $(CFLAGS) -- *.c 2>/dev/null

dep:	depend

backup:	tar
	mv ../vocoder.tgz ../backup/vocoder_`date +%y%m%d`.tgz

desktop:
	cp fte-desktop $(HOME)/.fte-desktop

# make depend stuff #fold00
# DO NOT DELETE THIS LINE -- make depend depends on it.

fileio.o: common.h fileio.h
io.o: common.h io.h sampleio.h fileio.h
main.o: common.h vocoder.h io.h wind_common.h wind_main.h
sampleio.o: common.h sampleio.h
vocoder.o: common.h vocoder.h
wind_about.o: wind_about.h common.h wind_common.h imgs/vocoder.xpm
wind_about.o: imgs/icon.xpm
wind_common.o: wind_common.h common.h
wind_main.o: io.h common.h wind_main.h vocoder.h wind_about.h wind_setbands.h
wind_main.o: wind_common.h imgs/icon.xpm imgs/vocoder.xpm imgs/exit.xpm
wind_main.o: imgs/start.xpm imgs/pause.xpm imgs/stop.xpm imgs/mute.xpm
wind_main.o: imgs/unmute.xpm
wind_setbands.o: wind_setbands.h common.h wind_common.h imgs/icon.xpm
