#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -fPIC
export DEB_CXXFLAGS_MAINT_APPEND = -fPIC
export DEB_LDFLAGS_MAINT_APPEND = -fPIC

ifneq (, $(shell which clang))
  export CC=clang
  export CXX=clang++
endif

%:
	dh $@

# Since this depends on golang-go, not gccgo, so let's update manually
# Depends: golang-go
update-sources-mk:
	dpkg-source --before-build .
	python3 src/util/generate_build_files.py eureka
	cp eureka.mk debian/sources.mk

override_dh_auto_build:
	dh_auto_build --buildsystem=makefile -- -f debian/compiler_test.mk
	LD_LIBRARY_PATH=debian/out debian/out/compiler_test
	dh_auto_build --buildsystem=makefile -- -f debian/libcrypto.mk
	dh_auto_build --buildsystem=makefile -- -f debian/libssl.mk

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	dh_auto_build --buildsystem=makefile -- -f debian/crypto_test.mk
	dh_auto_build --buildsystem=makefile -- -f debian/ssl_test.mk
	LD_LIBRARY_PATH=debian/out debian/out/crypto_test
	LD_LIBRARY_PATH=debian/out debian/out/ssl_test
endif
