# Faustine top-level Makefile.

EXEC = faustine
SRC_DIR = interpreter
PREPROCESSOR_DIR = $(SRC_DIR)/preprocessor/faust-0.9.47mr3
EXAMPLES_DIR = examples
SINWAVE_DIR = $(EXAMPLES_DIR)/sinwave

DESTDIR ?= 
PREFIX ?= /usr/local
prefix := $(DESTDIR)$(PREFIX)
lib    := $(wildcard lib/*.*)

all: $(EXEC)

faustine:
	$(MAKE) -C $(SRC_DIR) opt    # using ocamlopt compiler (optimized)

.PHONY: clean mrproper test help install uninstall

help :
	@echo "make or make all : compiler the faustine interpreter"
	@echo "make clean : remove all object files"
	@echo "make doc : generate the documentation using ocamldoc (TODO)"
	@echo "make install : install the interpreter and the library files in $(prefix)/bin $(prefix)/lib/faustine"
	@echo "make uninstall : undo what install did"
	@echo "make dist : make a tar.gz file ready for distribution (TODO)"

clean:
	@($(MAKE) -C $(SRC_DIR) clean)
	@(rm -f *~)

mrproper: clean
	@($(MAKE) -C $(SRC_DIR) mrproper)
	@($(MAKE) -C $(PREPROCESSOR_DIR) clean)
	@($(MAKE) -C $(EXAMPLES_DIR) clean)

test:
	@$(MAKE) -C $(SINWAVE_DIR) clean
	@$(MAKE) -C $(SINWAVE_DIR)

	@echo "    You might want to check the output file with either:"
	@echo "audacity $(SINWAVE_DIR)/sin.wav"
	@echo "open $(SINWAVE_DIR)/sin.wav"
	@echo "octave -q --eval 'plot(wavread(\"$(SINWAVE_DIR)/sin.wav\")); pause'"

examples::
	@($(MAKE) -C $(EXAMPLES_DIR))

install :
	mkdir -p $(prefix)/lib/faustine/
	mkdir -p $(prefix)/bin/
	install $(SRC_DIR)/faustine $(prefix)/bin/
	install -m 0644 $(lib) $(prefix)/lib/faustine/

uninstall :
	rm -rf $(prefix)/lib/faustine/
	rm -f $(prefix)/bin/faustine