PREFIX = /usr/local

CC = g++
OPTS = -O6 -ffast-math -funroll-loops -Wall -fPIC -DPIC
# users of later iterations of the x86 architecture may want to add these:
# OPTS = -msse2 -mfpmath=sse -pipe -ftracer

CFLAGS = $(OPTS)

PLUG = caps
VERSION = 0.3.0

SOURCES = $(wildcard *.cc)
OBJECTS	= $(SOURCES:.cc=.o) 
HEADERS = $(wildcard *.h) $(wildcard dsp/*.h) $(wildcard util/*.h)

PDF = caps-$(VERSION).pdf

DEST = $(PREFIX)/lib/ladspa
RDFDEST = $(PREFIX)/share/ladspa/rdf

-include defines.make

# all systems go ##############################################################

all: depend $(PLUG).so tags
	@cat README.dist

run: all
	#sudo python -i test.py
	#python -i offline.py
	#python tools/test-denormals.py
	#sudo python ../scripts/caps-test.py
	#sudo python tools/caps-test.py scape.rack
	sudo python tools/caps-test.py ../ampiii.rack

pdf: all tools/make-ps.py
	VERSION=$(VERSION) python tools/make-ps.py | ps2pdf - $(PDF)
	xpdf $(PDF) &

$(PLUG).so: $(OBJECTS)
	$(CC) -nostartfiles $(CFLAGS) -shared -o $@ $(OBJECTS)

.cc.s: 
	$(CC) $(CFLAGS) -S $<

.cc.o:
	$(CC) $(CFLAGS) -I/usr/local/include -c $<

tags: $(SOURCES) $(HEADERS)
	@echo making tags
	@-if [ -x /usr/bin/ctags ]; then ctags $(SOURCES) $(HEADERS) ; fi

install: all
	strip $(PLUG).so
	install -d $(DEST)
	install -m 644 $(PLUG).so $(DEST)

alt-install: all
	strip $(PLUG).so
	install -d $(DEST)
	install -m 644 $(PLUG).so $(DEST)/$(PLUG)-ng.so

fake-install: all
	-rm $(DEST)/$(PLUG).so
	ln -s $(PWD)/$(PLUG).so $(DEST)/$(PLUG).so

rdf-install:
	install -d $(RDFDEST)
	install -m 644 $(PLUG).rdf $(RDFDEST)

uninstall:
	-rm $(DEST)/$(PLUG).so
	-rm $(DEST)/$(PLUG)-ng.so

clean:
	rm -f *.o *.so *.s depend

dist: all pdf
	cp $(PDF) /www/quitte/dsp/
	touch /www/quitte/dsp/caps_$(VERSION).tar.gz
	tools/make-dist.py caps $(VERSION) $(CFLAGS)
	@rm /www/quitte/dsp/caps*.tar.gz
	@cp caps_$(VERSION).tar.gz /www/quitte/dsp

depend: $(SOURCES) $(HEADERS)
	$(CC) -MM $(DEFINES) $(SOURCES) > depend

-include depend
