#!/usr/bin/make -f
# Copyright 2018 Bill Allombert <ballombe@debian.org>

export SOURCE_DATE_EPOCH = $(shell date -d "$$(dpkg-parsechangelog -SDate)" +%s)
export FORCE_SOURCE_DATE = 1
export LC_ALL = C

build-indep-stamp:
	mkdir -p debian/gaproot/pkg
	ln -s ../../.. debian/gaproot/pkg/SmallGrp
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	gap -q -l 'debian/gaproot;/usr/share/gap' < tst/testall.g | tee debian/gap.tst
	! grep "^########" debian/gap.tst
endif
	env SOURCE_DATE_EPOCH=`env TZ=C date -d "2022/11/04" +"%s"` \
	echo 'PushOptions(rec(relativePath:=true)); Read("makedoc.g");' \
	| gap -q -l 'debian/gaproot;/usr/share/gap' && touch build-indep-stamp
build-indep: build-indep-stamp
build-arch:
build: build-indep

clean:
	dh_testdir
	dh_testroot
	make -C doc clean
	rm -f build-indep-stamp
	rm -rf debian/gaproot
	rm -f debian/gap.tst
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	dh_install -p gap-smallgrp  gap *.g id2 small2 usr/share/gap/pkg/SmallGrp
	dh_install -p gap-smallgrp-extra id[13-9]* small[13-9] usr/share/gap/pkg/SmallGrp
	find debian/gap-smallgrp/usr/share/gap/pkg/SmallGrp/small* -type f -exec gunzip --no-name '{}' \;
	find debian/gap-smallgrp/usr/share/gap/pkg/SmallGrp/small* -type f -exec sh -c 'gzip --no-name --best -c {} > {}.gz && rm {}' \;
	find debian/gap-smallgrp/usr/share/gap/pkg/SmallGrp/id* -type f -exec gunzip --no-name '{}' \;
	find debian/gap-smallgrp/usr/share/gap/pkg/SmallGrp/id* -type f -exec sh -c 'gzip --no-name --best -c {} > {}.gz && rm {}' \;
	find debian/gap-smallgrp-extra/usr/share/gap/pkg/SmallGrp/small* -type f -exec gunzip --no-name '{}' \;
	find debian/gap-smallgrp-extra/usr/share/gap/pkg/SmallGrp/small* -type f -exec sh -c 'gzip --no-name --best -c {} > {}.gz && rm {}' \;
	find debian/gap-smallgrp-extra/usr/share/gap/pkg/SmallGrp/id* -type f -exec gunzip --no-name '{}' \;
	find debian/gap-smallgrp-extra/usr/share/gap/pkg/SmallGrp/id* -type f -exec sh -c 'gzip --no-name --best -c {} > {}.gz && rm {}' \;
	make -C doc install DESTDIR=../debian/gap-smallgrp
binary-arch: build-arch
binary-indep: build-indep install
	dh_testdir
	dh_testroot
	dh_installdocs README README.md
	dh_installexamples
	dh_installchangelogs CHANGES.md
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
