# @configure_input@
include ../../include/config.Makefile
# we (may) want to ignore the --datarootdir setting, whatever that means, so here we we mention it: datarootdir
VPATH = @srcdir@
TIDY = yes
PKG = @PACKAGE_TARNAME@-@PACKAGE_VERSION@-@ARCH@-@OS@-@ISSUE@.tbz
packinglist: .prepared packages-used
	echo @name @PACKAGE_TARNAME@-@PACKAGE_VERSION@ >$@
	echo @srcdir @abs_builddir@/files >>$@
	(cd files && find * -type f ) >>$@
	echo @comment >>$@
	echo @unexec rm -f %D/@tail_mandir@/man1/M2.1 %D/@tail_mandir@/man1/M2.1.gz >>$@
	(cd files/@tail_infodir@; for i in *.info ; do \
		echo   @exec install-info          --quiet --info-dir="%D/@tail_infodir@" "%D/@tail_infodir@/$$i" ; \
		echo @unexec install-info --remove --quiet --info-dir="%D/@tail_infodir@" "%D/@tail_infodir@/$$i" ; \
	     done ) >>$@
	(cd files && @FIND@ @tail_docdir@ @tail_packagesdir@ @tail_libm2dir@ -depth -type d | sed 's/^/@dirrm /') >>$@
all: chk-opts ../../$(PKG)
chk-opts: check-prefix-is-slash-usr-slash-local check-debug-disabled check-optimize-enabled check-strip-enabled
check-prefix-is-slash-usr-slash-local:; [ "${prefix}" = /usr/local ]
check-debug-disabled:; [ @DEBUG@ = no ]
check-optimize-enabled:; [ @OPTIMIZE@ = yes ]
check-strip-enabled:; [ @ENABLE_STRIP@ = yes ]
../../$(PKG): .prepared packinglist
	chmod a+x post-install post-deinstall
	pkg_create \
		-c -"a software system for algebraic geometry research" \
		-d @srcdir@/description \
		-f packinglist \
		-I post-install \
		-K post-deinstall \
		-p /usr/local \
		-P "`cat packages-used`" \
		../../$(PKG)

view : ../../$(PKG)
	@TAR@ tvjf $^ | head -20
	@ echo +CONTENTS:
	@ @TAR@ xvjf $^ +CONTENTS
	@ head -20 +CONTENTS
	@ echo .
	@ echo .
	@ echo .
	@ tail -20 +CONTENTS
	@ rm -f +CONTENTS

T=@TAR@ --create --mode=a+rX,og-ws --exclude-from=@srcdir@/../tar-exclusions --file=-
.prepared : always
	rm -rf files
	$(MKDIR_P) files
	$(T) -C @pre_exec_prefix@ . | @TAR@ xfp - -C files
	$(T) -C @pre_prefix@      . | @TAR@ xfp - -C files
	cd files/@tail_mandir@ && gzip */*.1
	cd files && find * -type d -empty -exec touch {}/.empty ';'
	touch $@

libraries-used : files/bin/M2@EXE@
	ldd files/bin/M2@EXE@ | sed -e 's/.* => //' -e 's/^	//' -e 's/ .*//' | egrep '^/' >$@ || true
files-used: Makefile
	for i in @FILE_PREREQS@ ; do echo $i ; done >$@
packages-used : libraries-used files-used
	cat $^ | while read x ; do pkg_info -W "$$x" | sed -e 's=.* was installed by package =='; done >$@

ifeq ($(TIDY),yes)
maybe-tidy: tidy_after
else
maybe-tidy:
endif
tidy tidy_after:; rm -f .prepared libraries-used packages-used +CONTENTS files packinglist
clean:tidy; rm -f ../../$(PKG)
distclean: clean; rm -f Makefile
% : %.in; cd ../..; ./config.status distributions/freebsd/$@

# Local Variables:
# compile-command: "make -C $M2BUILDDIR/distributions/freebsd "
# End:
.NOTPARALLEL:
