#
# makefile for the Gauss package                             Mohamed Barakat
#                                                              Simon Görtzen
#                                                            Max Neunhoeffer
#
#  This file is free software, see license information at the end.
#

# Inspired  by the makefile prototype for the EDIM package of Frank Lübeck

CONFIGNAME=
GAPPATH=/build/gap/src/gap-4.11.1
GAPARCH=aarch64-unknown-linux-gnu-default64-kv7

PKGROOT=$(shell pwd)

GAP=$(PKGROOT)/../../bin/gap-$(CONFIGNAME).sh

.PHONY: default static doc clean distclean docclean test

default: bin/aarch64-unknown-linux-gnu-default64-kv7/gauss.so

static:
	mkdir -p bin/aarch64-unknown-linux-gnu-default64-kv7
	(cd $(GAPPATH)/bin/aarch64-unknown-linux-gnu-default64-kv7; \
	./gac -o gap-static -p "-DGAUSSSTATIC" -P "-static" \
	../../pkg/Gauss/src/gauss.c)

bin/aarch64-unknown-linux-gnu-default64-kv7/gauss.so: src/gauss.c
	mkdir -p bin/aarch64-unknown-linux-gnu-default64-kv7
	$(GAPPATH)/bin/aarch64-unknown-linux-gnu-default64-kv7/gac -d -o bin/aarch64-unknown-linux-gnu-default64-kv7/gauss.so src/gauss.c

doc: doc/manual.six

doc/manual.six:	makedoc.g \
		PackageInfo.g \
		gap/*.gd gap/*.gi
		gap makedoc.g

clean:
	rm -rf bin/aarch64-unknown-linux-gnu-default64-kv7 Makefile Makefile-$(CONFIGNAME) *~

distclean:
	rm -rf bin Makefile Makefile-*

docclean:
	(cd doc; ./clean)

test: doc
	gap -b maketest.g

test-with-coverage:	doc
	OUTPUT=$$(/usr/bin/time --quiet --format="%U %S\n%e" --output=performance.out gap --banner --quitonbreak --cover stats maketest.g 2>&1); \
	echo "$$OUTPUT"; \
	! echo "$$OUTPUT" | sed "s/\r//" | grep -v "Running list" | grep -v "^#I  " | grep "" > /dev/null
	echo 'LoadPackage("profiling"); OutputJsonCoverage("stats", "coverage.json");' | gap

ci-test:	test-with-coverage

##
##  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.
##
##  You should have received a copy of the GNU General Public License
##  along with this program; if not, write to the Free Software
##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
