#!/usr/bin/make -f
# -*- makefile -*-

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# This is not supported by the gcc being built.
export DEB_CPPFLAGS_MAINT_STRIP=-Wdate-time

package = gcc-h8300-hms
target = h8300-hitachi-coff
configure_flags = \
	--enable-languages=c,c++ \
	--disable-libssp \
	--enable-target-optspace \
	--disable-multilib \
	--target=$(target) \
	--with-gnu-as \
	--with-gnu-ld

build_dir=build

%:
	dh $@ -B$(build_dir)

execute_after_dh_auto_clean:
	# Too old, autoreconf will install up to date versions.
	rm ltcf-*.sh ltconfig ltmain.sh
	# Generated using gperf.
	rm -f gcc/cp/cfns.h


override_dh_autoreconf:
	dh_autoreconf autoreconf -- -f -i -Wno-obsolete \
		. gcc intl libiberty

override_dh_auto_configure:
	dh_auto_configure -B$(build_dir) -- $(configure_flags)
	# Make sure they are rebuilt.
	touch */*.[yl] */*/*.[yl]

override_dh_auto_build:
	# No hardening for target libraries.
	echo 'blhc: ignore-line-regexp: .*/xgcc .*'
	# There is something wrong in dependencies, disable parallel.
	dh_auto_build -B$(build_dir) --no-parallel

override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install -B$(build_dir)
	cd debian/$(package) && rm -r \
		usr/share/locale \
		usr/lib/*/libiberty.a \
		usr/bin/$(target)-gccbug \
		usr/bin/$(target)-gcov
	# Empty dirs.
	cd debian/$(package) && rmdir \
		usr/h8300-hitachi-coff/lib \
		usr/h8300-hitachi-coff \
		usr/include \
		usr/share/info \
		usr/share/man/man1 \
		usr/share/man/man7 \
		usr/share/man
	# Backward compat.
	cd debian/$(package) && \
		ln -s $(target)-c++ usr/bin/h8300-hms-c++ && \
		ln -s $(target)-cpp usr/bin/h8300-hms-cpp && \
		ln -s $(target)-g++ usr/bin/h8300-hms-g++ && \
		ln -s $(target)-gcc usr/bin/h8300-hms-gcc && \
		ln -s $(target)-gcc-3.4.6 usr/bin/h8300-hms-gcc-3.4.6

override_dh_strip:
	# Not ELF files, those are target COFF.
	dh_strip -X.a
