MCFLAGS = --infer-all

BUILD=development

# uncomment this for the final version:
# BUILD=production

-include Mmake.params
include Mmake.curs

ifeq "$(BUILD)" "development"
# For the development version, we want fast compile times, hence dynamic
# linking
MCFLAGS += -O0
MGNUCFLAGS += --pic-reg
MLFLAGS += --shared
endif

# For the production version, we want to enable optimization, and
# the executable that we ship as our final entry should be statically linked
ifeq "$(BUILD)" "production"
MCFLAGS += -O6 --intermodule-optimization
CFLAGS += -DML_OMIT_MATH_DOMAIN_CHECKS
MLFLAGS += --static
endif

MAIN_TARGET = main test_protocol test_influence_map

# needed for fdopen()
MGNUCFLAGS-protocol = --no-ansi

depend : main.depend test_protocol.depend test_influence_map.depend

tags: *.m
	mtags *.m

check: test_protocol.res

%.out: % %.inp
	./$* < $*.inp > $@ 2>&1

%.res: %.out %.exp
	diff -u $*.exp $*.out > $@ || cat $@

.PHONY: tar
tar: submission.tar.gz

ifeq "$(BUILD)" "production"
submission.tar.gz: main buildme runme README COPYING NOTES *.m *.inp *.exp Mmakefile Mmake.curs
	-[ -d source ] || mkdir source
	cp -a *.m *.inp *.exp Mmakefile Mmake.curs source
	tar --exclude=CVS -cf - buildme runme main README COPYING NOTES source \
		| gzip -9 > submission.tar.gz
else
submission.tar.gz:
	@echo "Set BUILD=production, and do mmake clean, before shipping"
	exit 1
endif

info: submission.tar.gz
	ls -l submission.tar.gz
	echo "md5sum: `md5sum submission.tar.gz | awk '{print $$1;}'`"

###
### uncomment this and run `mmake email-submission' to submit the final entry
### Don't forget to set MLFLAGS = --static
###
#email-submission: tar info.txt
#	./submit.sh info.txt submission.tar.gz
