#!/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

lib%.so: debian/lib%.mk
	dh_auto_build --buildsystem=makefile -- --file=$<

compiler_test: debian/compiler_test.mk
	dh_auto_build --buildsystem=makefile -- --file=$<
	LD_LIBRARY_PATH=debian/out debian/out/$@

%_test: debian/%_test.mk libtest_support.so libcrypto.so libssl.so
	dh_auto_build --buildsystem=makefile -- --file=$<

override_dh_auto_build: compiler_test tool_test
	dh_auto_build $@

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test: crypto_test ssl_test
	LD_LIBRARY_PATH=debian/out debian/out/bssl-tool|:
ifneq ($(DEB_HOST_ARCH), mips64el)
	LD_LIBRARY_PATH=debian/out debian/out/crypto_test
else
	# TODO: mips64el fails this test currently
	LD_LIBRARY_PATH=debian/out debian/out/crypto_test | :
endif
	LD_LIBRARY_PATH=debian/out debian/out/ssl_test
endif
