#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+all optimize=-lto
export qe := $(CURDIR)
export saclib := $(CURDIR)
export SPECLFLAGS := $(LDFLAGS)
FLAGS := "$(CPPFLAGS) $(shell pkg-config saclib --cflags) $(CXXFLAGS)"

%:
	dh $@

override_dh_auto_build:
# statically link against saclib because qepcad re-defines several
# saclib functions (e.g., CREAD) that are called by other saclib functions,
# so dynamic linking won't work
	mkdir -p lib
	ln -s /usr/lib/$(DEB_HOST_MULTIARCH)/libsaclib.a lib/saclibo.a
	$(MAKE) opt FLAGSo=$(FLAGS)
	$(MAKE) -C cad2d opt FLAGSo=$(FLAGS)
	$(MAKE) -C plot2d INCD="$(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS)"
	rm -rf lib
