#!/usr/bin/make -f
# debian/rules for gxemul.
include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

ifeq ($(origin CC),default)
CC := $(DEB_HOST_GNU_TYPE)-gcc
endif

override_dh_auto_configure:
	CFLAGS="${CFLAGS}" PREFIX="/usr" DESTDIR=$(shell pwd)/debian/tmp ./configure
	sed -e 's/#define VERSION.*/#define VERSION \"$(DEB_VERSION_UPSTREAM)\"/g' \
	    -e 's/#define COMPILE_DATE.*/#define COMPILE_DATE "compiled by Debian"/' \
	    -i config.h
	sed -e 's/-Wl,-rpath,[^\w]*//g' -i Makefile
	touch configure-stamp

override_dh_auto_build:
	make -C src/include
	make -C src/devices/fonts Xconv_raw_to_c
	make -C src/cpus generate_head generate_tail $(shell awk '/^CPU_TOOLS/{$$1="";print}' src/cpus/Makefile)
	dh_auto_build -- CC="${CC}"

override_dh_install:
	dh_install
	rm -rf debian/gxemul/usr/share/doc/gxemul/*

override_dh_installdocs:
	dh_installdocs
	rm -f debian/gxemul-doc/usr/share/doc/gxemul/machines/*.SKEL
	rm -f debian/gxemul-doc/usr/share/doc/gxemul/RELEASE.html
	rm -f debian/gxemul-doc/usr/share/doc/gxemul/TODO.html

override_dh_installchangelogs:
	dh_installchangelogs HISTORY

override_dh_clean:
	dh_clean
	if [ -f Makefile ]; then make clean_all; fi

override_dh_auto_test:

%:
	dh $@