# Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021 Kevin Ryde

# This file 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 3, or (at your option) any later
# version.
#
# This file 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.
#
# You should have received a copy of the GNU General Public License along
# with this file.  If not, see <http://www.gnu.org/licenses/>.

VERSION = 15
DISTNAME = recurrence-guess
DISTVNAME = recurrence-guess-$(VERSION)

GP = gp

default:
	@echo 'nothing to make, but try "make test" for self-tests'

test: test-symbols.txt
	$(GP) -f --quiet <test.gp
	$(GP) -f --quiet <test-print.gp >/dev/null
test-symbols.txt: recurrence-guess.gp
	tools/my-gp-symbols.pl \
	  --exclude-prefix recurrence_guess \
	  --exclude-prefix pol_partial_fractions \
	  recurrence-guess.gp >test-symbols.txt

clean:

#------------------------------------------------------------------------------
# development

test-all: test test-maint
test-maint:
	tools/my-check-gp.pl --verbose recurrence-guess.gp

# No good, various 'x 'n 'cannot_factorize symbols used come out as
# fetch_user_var()
fetch-user-var:
	# want no "fetch_user_var()" of global variables
	if gp2c -S recurrence-guess.gp \
	  | grep fetch_user_var |grep -v '"x"'; \
	  then exit 1; else exit 0; fi

# without iferr trapping
test-noerr:
	$(GP) recurrence-guess.gp test.gp </dev/null

version:
	@echo $(VERSION)

DIST_FILES = \
  COPYING \
  Makefile \
  *.gp \
  test-symbols.txt \
  examples/*.gp \
  devel/*.gp \
  tools/*.pl
DIST_GENERATED_FILES = \
  test-symbols.txt

dist: $(DISTVNAME).tar.gz
	ls -l $(DISTVNAME).tar.gz

$(DISTVNAME).tar.gz: $(DIST_FILES) $(DIST_GENERATED_FILES)
	$(MAKE) -$(MAKEFLAGS) distdir
	tar cf $(DISTVNAME).tar --sort=name $(DISTVNAME)
	gzip -9 --force $(DISTVNAME).tar
	rm -rf $(DISTVNAME)

distdir:
	rm -rf $(DISTVNAME)
	mkdir $(DISTVNAME)
	mkdir $(DISTVNAME)/examples
	mkdir $(DISTVNAME)/devel
	mkdir $(DISTVNAME)/tools
	cp -p --parents $(DIST_FILES) $(DISTVNAME)

diff-tux:
	diff -u $(HOME)/tux/data/pari/recurrence-guess.gp recurrence-guess.gp |less

#------------------------------------------------------------------------------
.PHONY: all clean dist distdir test test-maint test-all version
