#!/usr/bin/make -f

export JAVA_HOME=/usr/lib/jvm/default-java

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export CPPFLAGS+=-gdwarf-4

%:
	dh $@

override_dh_auto_build-indep:
	dh_auto_build -- package -DskipTests -Pwith-native

override_dh_auto_build-arch:
	# Build the JNI bindings
	mkdir -p junixsocket-native/target
	# use clang because gcc does not seem to be well supported by upstream
	# and maintainer attempts to make it compile with gcc were unsuccessful
	clang $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
		-I$(CURDIR)/junixsocket-native/src/main/c/jni \
		-Wall -Wextra -Wstrict-prototypes -Wno-reserved-id-macro -Wno-undef -Wno-cast-qual \
		-Wno-disabled-macro-expansion -Wno-language-extension-token -Wno-gnu-auto-type \
		-Wno-c++11-extensions -Wno-c++98-compat -Wno-empty-translation-unit \-Wno-gnu-empty-initializer \
		-Werror-implicit-function-declaration -Wint-conversion -Wno-unused-command-line-argument \
		-Werror-implicit-function-declaration -Wno-long-long -Wpointer-arith -Wconversion \
		-finline-functions -fwrapv -fno-c++-static-destructors -fPIC -fvisibility=hidden -fno-common \
		-std=gnu11 -D_GNU_SOURCE -shared \
		junixsocket-native/src/main/c/*.c \
		-o junixsocket-native/target/libjunixsocket-native-system.so

override_dh_auto_test-arch:

override_dh_auto_install-indep:
	dh_auto_install -- -Pwith-native

override_dh_auto_install-arch:
	dh_install -plibjunixsocket-jni junixsocket-native/target/*.so usr/lib/$(DEB_HOST_MULTIARCH)/jni
