#!/usr/bin/make -f
# debian/rules for adacontrol.
# Copyright (c) 2006, 2012 Ludovic Brenta <lbrenta@debian.org>
# Copyright (c) 2014-2014 Nicolas Boulenguez <nicolas@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# The full text of the GNU General Public License is in the file
# /usr/share/common-licenses/GPL on Debian systems.

include /usr/share/dpkg/default.mk
include /usr/share/ada/debian_packaging.mk

ADAFLAGS += -gnatwa

POLICY_TARGETS := binary binary-arch binary-indep build build-arch \
  build-indep clean
.PHONY: $(POLICY_TARGETS)
$(POLICY_TARGETS):
	dh $@

# No upstream build system.
.PHONY: $(addprefix override_dh_auto_,configure build clean install)

override_dh_auto_build: project $(foreach s,pm ug,$(foreach f,html info pdf txt,doc/obj/adacontrol_$(s).$(f)))

.PHONY: project
project: | src/exe src/obj
	gnatmake $(BUILDER_OPTIONS) -Psrc/build.gpr -cargs $(ADAFLAGS) -largs $(LDFLAGS)

doc/obj/%.html: doc/%.texi | doc/obj
	texi2any --html --no-split $< --output=$@
doc/obj/%.info: doc/%.texi | doc/obj
	texi2any --info --no-split $< --output=$@
doc/obj/%.pdf : doc/%.texi | doc/obj
	cd doc/obj; texi2any --pdf --no-iftex --Xopt --quiet ../$*.texi --output=$*.pdf
doc/obj/%.txt : doc/%.texi | doc/obj
	texi2any --plaintext $< --output=$@

doc/obj src/exe src/obj:
	mkdir $@
override_dh_auto_clean:
	rm -fr doc/obj src/exe src/obj

override_dh_install:
	dh_install
	dh_install $(filter-out GPS/adacontrol.xml,$(wildcard GPS/*)) \
	   /usr/share/gps/plug-ins

# Adactl cannot open compressed rules.
# PDF files are already internally compressed.
.PHONY: override_dh_compress
override_dh_compress:
	dh_compress --exclude=.aru --exclude=.pdf

# This file exists in upstream archive, do not remove it.
.PHONY: override_dh_clean
override_dh_clean:
	dh_clean --exclude=test/ref/t_allocators.txt.bak
