##
##    Values imported from the configure script
##
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
srcdir = @srcdir@
VPATH = @srcdir@
subdir = .

## do not edit these definitions ############################################

GMP_CPPFLAGS = @GMP_CPPFLAGS@
GMP_LIBS     = @GMP_LIBS@

BINDIR  = bin/@GAPARCH@
EXEEXT  = @EXEEXT@
EFILE   = $(BINDIR)/pq$(EXEEXT)
CC      = @CC@

#
# The following are valid compilation flags for the program.
#
#STANDARD_PCP -- if compiling version which permits construction of
#                standard presentation
#
#GAP_LINK  -- GAP is called by pq to perform insoluble stabiliser calculations 
#
#GAP -- if compiling version for incorporation in GAP
#
#DEBUG -- debugging information is generated by a number of procedures
#
# Change features of executable
#
#RUN_TIME -- supply maximum number of defining generators and class bound 
#             at run-time  (see README file for further details)
#
#TAILS_FILTER -- apply filter for exponent 4 and 5 and max occurrences
#
#CONSISTENCY_FILTER -- apply filter for exponent 4 and 5 and max occurrences
#
#
PQFLAGS = -DGAP_LINK_VIA_FILE -DGAP -I$(top_srcdir)/include -DSTANDARD_PCP -DGROUP -DANUPQ_GAP_EXEC='"$(GAP)"'


# FIXME: Add prototypes for all C functions and then remove -Wno-implicit.
# FIXME: Fix all -Wall warnings
#CFLAGS   += -O2 -Wall -Wno-implicit
CFLAGS   += -O2 -Wno-implicit
CPPFLAGS += $(GMP_CPPFLAGS) $(PQFLAGS)
LDLIBS    = $(GMP_LIBS) -lm
# FIXME: Deal with -lm in a more portable fashion (i.e. detect whether
# it is available and needed in configure)

## Command used to start up GAP4
GAP=gap

SRC=$(srcdir)/src
PKGNAME=anupq

all: $(EFILE) testPq

testPq: testPq.in tst/GAP
	sed "s/\@GAPARCH\@/@GAPARCH@/g" < $< > $@
	chmod +x $@

tst/GAP:
	echo $(GAP) > $@

## show makefile options ####################################################


## load list of object files ################################################
include Makefile.objs


## do the linking and put the executable in the right place #################
$(EFILE): $(OBJECTS)
	mkdir -p $(BINDIR)
	$(CC) -o $(EFILE) $(OBJECTS) $(LOPTS) $(LDLIBS) $(LDFLAGS)

## clean me up ##############################################################
clean:
	(rm -f $(OBJECTS) $(SRC)/core* $(EFILE); rm -rf $(BINDIR))

distclean: clean
	rm -f Makefile testPq tst/GAP standalone/bin/$(EFILE) $(top_builddir)/config.status


## regenerate Makefile etc. if necessary #####################################
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	cd $(top_builddir) && $(SHELL) ./config.status $@

$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
	$(SHELL) ./config.status --recheck

$(top_srcdir)/configure: $(top_srcdir)/configure.ac
	cd $(top_srcdir) && autoreconf

## move directories around to how GAP4 likes them ###########################
# FIXME: Do we still need this?
GAP4remapdirs:
	if test -d standalone-doc; then \
	echo "directories already remapped for GAP4?!?"; fi
	if test ! -d standalone-doc; then \
	mv README doc; mv doc standalone-doc; \
	mkdir -p -m 755 standalone/bin; mv TEST examples isom standalone; \
	(cd gap; mv README configure replace Makefile.in init.g read.g doc ..;\
	 mv examples tst lib ..;)\
	fi

## move directories from how GAP4 likes them to the generic layout ##########
# FIXME: Do we still need this?
restoredirs:
	if test -d gap/doc; then echo "directories already restored?!?"; fi
	if test ! -d gap/doc; then \
	$(MAKE) -f Makefile clean; \
	mkdir -p -m 755 gap; \
	mv examples tst lib gap; \
	mv README configure replace Makefile.in init.g read.g doc gap; \
	(cd standalone; mv examples isom TEST ..) \
	mv standalone-doc doc; mv doc/README .; \
	fi

## create object list for the Makefile ######################################
objectlist:
	@( ls -1 $(SRC)/*.c ) | \
	sed s/\\.c$$/\\.o/ | \
	( echo "OBJECTS=\\"; \
	  awk '{printf( "\t%-30s%s", $$0, "\\\n")}'; \
	  echo ""; echo "" ) > Makefile.objs

## create dependency list for the Makefile ##################################
depend:
	@echo Updating dependencies...
	@echo "# GENERATED FILE, DO NOT EDIT MANUALLY" > Makefile.deps
	@for i in $(OBJECTS) ; do \
	  j=`basename $$i .o` ; \
	  gcc -MM -MP -MQ $$i  $(CPPFLAGS) $(PQFLAGS) $(SRC)/$$j.c >> Makefile.deps ; \
	done
	@echo Done!

.PHONY: all clean distclean GAP4remapdirs restoredirs objectlist depend

## load dependency list for the Makefile ####################################
-include Makefile.deps
