#!/usr/bin/make -f

CXXFLAGS = -g -Wall
LDFLAGS = -g -Wall

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -O0
	ADA_OPT = -O0
else
	CXXFLAGS += -O2
	LDFLAGS += -O2
	ADA_OPT = -O2 -fdata-sections -ffunction-sections
	ADA_LINK = -Wl,--gc-sections
endif

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	SPARKCPUS = $(NUMJOBS)
else
	SPARKCPUS = 1
endif

export CXXFLAGS LDFLAGS ADA_OPT ADA_LINK SPARKCPUS

%:
	dh $@ --with swi_prolog

override_dh_auto_clean:
	$(MAKE) reallycleanall

override_dh_auto_build:
	# create empty directories that can be destroyed by git
	mkdir -p victor/vct/bin
	mkdir -p bin
	mkdir -p share/spark

	dh_auto_build CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)"

override_dh_auto_install:
	# nothing

override_dh_auto_test:
	# nothing

override_dh_install:
	dh_install
	rm -r debian/spark/usr/lib/spark/current/spark_
