#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/makefile.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/utils.mk
export CCACHE=none
## Complete autoreconf, only for our own git snapshot
#DEB_AUTO_UPDATE_AUTOCONF = 2.68
#DEB_AUTO_UPDATE_AUTOMAKE = 1.11
#DEB_AUTO_UPDATE_LIBTOOL = yes
#DEB_AUTO_UPDATE_ACLOCAL = 1.11

## Upstream ChangeLog generated via 'git log > ChangeLog'.
#DEB_INSTALL_CHANGELOGS_ALL := debian/ChangeLog

# Also build PDF and HTML documentation.
DEB_MAKE_BUILD_TARGET := all pdf html

# Don't strip/compress certain files.
DEB_STRIP_EXCLUDE := .elf .bin examples
DEB_COMPRESS_EXCLUDE := .elf .bin examples

# TODO: Use --enable-oocd_trace later, right now it's just a proof-of-concept.
DEB_CONFIGURE_EXTRA_FLAGS := \
	--enable-maintainer-mode \
	--disable-werror \
	--enable-ft2232_libftdi \
	--enable-ep93xx \
	--enable-at91rm9200 \
	--enable-usbprog \
	--enable-presto_libftdi \
	--enable-jlink \
	--enable-vsllink \
	--enable-rlink \
	--enable-arm-jtag-ew \
	--enable-dummy \
	--enable-buspirate \
	--enable-ulink \
	--enable-presto_libftdi \
	--enable-usb_blaster_libftdi \
	--enable-ft2232_libftdi

configure_flags_parport := \
	--enable-parport \
	--enable-parport_ppdev

ifeq ($(DEB_HOST_ARCH_OS),linux)
# Parport drivers only work on Linux and kFreeBSD, conditionally add them here
DEB_CONFIGURE_EXTRA_FLAGS += $(configure_flags_parport)
# Add --enable-gw16012 and --enable-amtjtagaccel only for Linux,
# as they're currently supported there only.
DEB_CONFIGURE_EXTRA_FLAGS += --enable-gw16012 --enable-amtjtagaccel
endif
   
ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
# Parport drivers only work on Linux and kFreeBSD, conditionally add them here
DEB_CONFIGURE_EXTRA_FLAGS += $(configure_flags_parport)
endif

### # We must first call ./bootstrap to generate the autotools stuff.
### post-patches:: debian/stamp-autothings-update
### debian/stamp-autothings-update:
### 	./bootstrap
### 	touch $@

post-patches::
	@### @# Make autotools scripts executable.
	@### chmod 755 depcomp install-sh missing configure
	@### chmod 755 config.guess config.sub doc/mdate-sh
	@# Copy udev rules file into debian/ so that dh_installudev finds it.
	cp contrib/openocd.udev debian/openocd.udev

binary-post-install/openocd::
	@# Don't ship openocd.udev in /usr/share, dh_installudev handles it.
	rm -f debian/openocd/usr/share/openocd/contrib/openocd.udev
	@# Strip the RPATH of the binary.
	chrpath -d debian/openocd/usr/bin/openocd
	@# Drop /usr/share/info/dir, it's generated at runtime.
	rm -f debian/openocd/usr/share/info/dir
	@# Drop .la files
	rm -f `find debian/openocd -name '*.la'`

clean::
	@### rm -f debian/stamp-autothings-update
	@# Clean copied udev file.
	rm -f debian/openocd.udev
	@### @# Delete generated files, we don't want them in the diff.
	@### rm -f config.guess aclocal.m4 config.h.in config.sub Makefile.in
	@### rm -f install-sh missing depcomp configure src/Makefile.in
	@### rm -f src/helper/Makefile.in src/pld/Makefile.in src/jtag/Makefile.in
	@### rm -f src/server/Makefile.in src/target/Makefile.in
	@### rm -f src/xsvf/Makefile.in src/flash/Makefile.in doc/mdate-sh
	@### rm -f doc/texinfo.tex doc/Makefile.in doc/version.texi
	@### rm -f doc/stamp-vti doc/openocd.info src/svf/Makefile.in
	@### rm -f ltmain.sh compile

# For /usr/share/cdbs/1/rules/utils.mk sanity check.
common-binary-post-install-arch:: list-missing

