#!/usr/bin/make -f

export DH_VERBOSE = 1
DESTDIR ?= $(abspath debian/libnewlib-ia16-elf)

%:
	exec dh $@ --parallel --builddirectory=build

override_dh_update_autotools_config:
	# Nope, do not touch config.sub or config.guess .

override_dh_auto_configure:
	CFLAGS_FOR_TARGET='-g -Os -mseparate-code-segment -D_IEEE_LIBM' \
	dh_auto_configure -O--parallel -- --target=ia16-elf \
	    --enable-newlib-elix-level=2 --disable-elks-libc \
	    --disable-newlib-wide-orient \
	    --enable-newlib-nano-malloc --disable-newlib-multithread \
	    --enable-newlib-global-atexit --enable-newlib-reent-small \
	    --disable-newlib-fseek-optimization \
	    --disable-newlib-unbuf-stream-opt --enable-target-optspace \
	    --enable-newlib-io-c99-formats --enable-newlib-mb \
	    --enable-newlib-iconv \
	    --enable-newlib-iconv-encodings=utf_8,utf_16,cp850,cp852,koi8_uni

override_dh_install:
	dh_install -O--parallel -O--builddirectory=build
	# See build.sh regarding .../sys-include/ .
	rm -rf $(DESTDIR)/usr/ia16-elf/sys-include
	mkdir -p $(DESTDIR)/usr/ia16-elf/sys-include
	ln -s ../include/limits.h $(DESTDIR)/usr/ia16-elf/sys-include/limits.h

override_dh_strip:
	# Not needed for now.  Note that stock GNU Binutils's strip(1) will
	# fail on the new (March 2019) Newlib libraries, as it does not
	# understand the IA16-specific segment relocations.
