#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

egdir = debian/libreadline-java-doc/usr/share/doc/libreadline-java-doc/examples
export JAVA_HOME:=/usr/lib/jvm/default-java

# GCC >= 14 promotes -Wincompatible-pointer-types to a hard error.  The JNI
# wrapper (org_gnu_readline_Readline.c) deliberately takes the address of
# readline globals whose types were changed in readline 8.x (rl_readline_state
# became unsigned long, rl_library_version & friends became const char*).
# Downgrade the diagnostic to a warning to keep the previous build behaviour.
export CFLAGS := $(CFLAGS) -Wno-error=incompatible-pointer-types

%:
	dh $@ --no-parallel --with javahelper

override_dh_auto_build:
	dh_auto_build -- JAVAC=$(JAVA_HOME)/bin/javac JC_FLAGS="-source 1.8 -target 1.8 -h native" CC=gcc \
	  JAVAINCLUDE=$(JAVA_HOME)/include \
	  JAVANATINC=$(JAVA_HOME)/include \
	  T_LIBS="JavaReadline JavaEditline" jar build-native

override_dh_auto_install:
	# Skip auto-install - it causes a rebuild and we do not need it.

override_dh_auto_test:
	# Skip tests - they dont work.

override_dh_installexamples:
	dh_installexamples
	# Tidy up the examples directory.
	test ! -d $(egdir) || rm $(egdir)/test/Makefile
	test ! -d $(egdir) || mv $(egdir)/libreadline-java-doc.README.test $(egdir)/README.test

