#############################################################################
##
#A  Makefile			GAP source		     Martin Schoenert
##
#H  @(#)$Id: Makefile,v 1.12 1999/11/22 11:34:01 sal Exp $
##
#Y  Copyright (C)  1994,  Lehrstuhl D fuer Mathematik,	RWTH Aachen,  Germany
##
##  This file contains the definitions and actions to compile and  link	 GAP.
##
##  To compile and link GAP you simply enter
##
##	make
##
##  for a list of targets  of the form	'<vendor>-<cpu>-<system>-<compiler>',
##  such as 'sun-sparc-sunos-gcc2',  which is the target for a Sun 4  machine
##  running the SunOS operating system with the GNU C compiler version 2.
##
##  Choose the best matching target and enter
##
##	make  <target>
##
##  e.g., enter 'make sun-sparc-sunos-gcc2',  to compile all the source files
##  and produce an executable file 'gap'.
##
##  Note  that	the  targets  are  listed  according  to   preference,	e.g.,
##  'sun-sparc-sunos-gcc2' is listed before 'sun-sparc-sunos-cc' because  the
##  GNU	 C compiler produces faster code on Sun 4 machines than native 'cc'.
##
##  If no target matches precisely, use 'bsd' (if  your UNIX is more Berkely)
##  or 'usg' (if your UNIX is more  System  V).	  If compilation  of the file
##  'system.c'	fails or  the command line editing does not work,  remove the
##  file 'system.o' and try the other target.
##
##  To specify additional compiler and linker options enter
##
##	make  <target>	COPTS=<compiler-options>  LOPTS=<linker-options>
##
##  e.g., enter 'make sun-sparc-sunos-gcc2 COPTS=-g LOPTS=-g' to compile  GAP
##  with debugging information.
##
##  To compile	GAP on a  DOS machine you need DJGPP version 1.11m5 or higher
##  (available from	'ftp.informatik.rwth-aachen.de').    DJGPP    must be
##  installed in  the directory '\DJGPP\',  because the	 linkage script looks
##  for the DOS extender 'GO32.EXE' in	'\DJGPP\BIN\'.	If you have installed
##  DJGPP differently you have to change this below.
##
#H  $Log: Makefile,v $
#H  Revision 2016/03/11 Christian Stump
#H  Autouse Linux/Darvin and 32bit/64bit.
#H
#H  Revision 2014/08/22 Jean Michel
#H  remove obsolete targets. Add 64bit target.
#H
#H  Revision 1.12  1999/11/22 11:34:01  sal
#H  Split obsolete targets from main list. Changed gcc2 to simply gcc.	SL
#H
#H  Revision 1.11  1999/10/11 15:51:57	werner
#H  Adjust the compile flags for Debian Linux.	Hope they work for other
#H  Linux distributions, too.  If not we should make a new target.
#H
#H  Revision 1.10  1997/10/10 15:00:46	gap
#H  Added info to ignore overflow warnings on sun-cc. AH
#H
#H  Revision 1.7  1997/09/11 10:57:06  gap
#H  Changes O2 to O1 for the DOS version. AH
#H
#H  Revision 1.6  1997/05/07 16:31:59  gap
#H  Added Solaris-Gcc support AH
#H
#H  Revision 1.5  1997/04/25 14:32:55  ahulpke
#H  added djppcross
#H
#H  Revision 1.1.1.1  1996/12/11 12:43:50  werner
#H  Preparing 3.4.4 for release
#H
#H  Revision 3.16  1994/06/09  20:55:51	 mschoene
#H  added coding theory package
#H
#H  Revision 3.15  1994/06/03  12:02:32	 mschoene
#H  updated 'x86-dos-djgpp' entry for DJGPP 1.11m5
#H
#H  Revision 3.14  1994/01/17  12:11:34	 fceller
#H  added options for 'sun-sparc-sunos-gcc2'
#H
#H  Revision 3.10  1993/10/28  18:24:46	 martin
#H  fixed the compilation flags for 'x86-linux-gcc2'
#H
#H  Revision 3.9  1993/10/18  12:43:17	martin
#H  changed to use <vendor>-<cpu>-<system>-<compiler> and only one system file
#H
#H  Revision 3.7  1993/02/25  16:45:59	fceller
#H  added 'SYS_HAS_SIG_T' for 'SYS_IS_USG'
#H
#H  Revision 3.6  1993/02/04  10:51:10	martin
#H  added 'plist' and 'vecffe' and cleaned up
#H
#H  Revision 3.4  1993/01/27  12:17:29	martin
#H  fixed 'ibmpc-msdos-djgpp'
#H
#H  Revision 3.3  1993/01/12  13:23:53	fceller
#H  changed 'ibmpc-386bsd-gcc' to 'ibmpc-386bsd-cc'
#H
#H  Revision 3.1  1992/11/16  18:49:03	martin
#H  initial revision under RCS (of the new Makefile)
##
SHELL = /bin/sh

ARCH = $(shell getconf LONG_BIT)
UNAME_S = $(shell uname -s)

unknown:
	@echo "###########################################################"
	@echo "#  Building GAP3 for '$(UNAME_S)' and '$(ARCH) bit'"
	@echo "###########################################################"

ifeq ($(UNAME_S),Linux)
    ifeq ($(ARCH),64)
		@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS) -O -DSYS_IS_64_BIT -DSYS_IS_USG -DSYS_HAS_TIME_PROTO -DSYS_HAS_SIGNAL_PROTO -DSYS_HAS_IOCTL_PROTO"
		@$(MAKE) gap CC=gcc CFLAGS="$(COPTS) -O -DSYS_IS_64_BIT " SYS_FILE=system.o LOPTS="$(LOPTS) -static"
		strip gap
		mv gap ../bin/gap3
    endif
    ifeq ($(ARCH),32)
		@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS) -m32 -O2 -DSYS_IS_USG -DSYS_HAS_TIME_PROTO -DSYS_HAS_SIGNAL_PROTO -DSYS_HAS_IOCTL_PROTO"
		@$(MAKE) gap CC=gcc CFLAGS="$(COPTS) -m32 -O " SYS_FILE=system.o LOPTS="$(LOPTS) -m32 -static"
		strip gap
		mv gap ../bin/gap3
    endif
endif
ifeq ($(UNAME_S),Darwin)
	@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS) -m32 -DSYS_IS_MACOSX -DARCH_INCLUDE -DSYS_HAS_IOCTL_PROTO"
	@$(MAKE) gap	    CC=gcc  CFLAGS="$(COPTS) -m32 -O2"  SYS_FILE=system.o  LOPTS="$(LOPTS) -m32"
	mv gap ../bin/gap3
endif

	@echo "###########################################################"
	@echo "#  Building complete, you can run GAP3 from './../bin/gap3'"
	@echo "###########################################################"

#############################################################################
##
#T  Linkage . . . . . . . . . . . . . . . . . . . . . .	 commands to link GAP
##
##  Following are the commands to link GAP.  The targets below should not  be
##  used directly, they should only be addressed by the	 recursive  calls  of
##  'make' from above.
##
##  After linking for DOS we prepend the DOS extender 'GO32.EXE' to the file,
##  so that we get an executable that works without further run-time support.
##
OBJBASC = gap.o $(SYS_FILE) gasman.o scanner.o idents.o read.o eval.o
OBJFLDS = integer.o rational.o cyclotom.o unknown.o finfield.o polynom.o
OBJGRPS = permutat.o word.o costab.o tietze.o agcollec.o aggroup.o pcpresen.o
OBJLIST = list.o plist.o set.o vector.o vecffe.o range.o blister.o string.o
OBJLANG = record.o statemen.o function.o coding.o
OBJECTS = $(OBJBASC) $(OBJFLDS) $(OBJGRPS) $(OBJLIST) $(OBJLANG)

gap	  : $(OBJECTS)
	$(CC) $(LOPTS) -o gap $(OBJECTS)

gapdjg.exe: $(OBJECTS)
	$(CC) $(LOPTS) -o gapdjg.out $(OBJECTS) -lpc
	copy /b \djgpp\bin\go32.exe+gapdjg.out gapdjg.exe

gap.ttp	  : $(OBJECTS)
	$(CC) $(LOPTS) -o gap.ttp $(OBJECTS)


#############################################################################
##
#T  Dependencies  . . . . . . . . .  dependencies between the packages of GAP
##
##  Following are the dependencies between the various packages of GAP.	 Note
##  that the dependencies '<package>.o: <package>.c' are  not  given,  'make'
##  adds them automagically.
##
INCBASC = system.h gasman.h scanner.h idents.h eval.h integer.h
INCFLDS = rational.h cyclotom.h unknown.h finfield.h polynom.h
INCGRPS = permutat.h word.h costab.h tietze.h agcollec.h aggroup.h pcpresen.h
INCLIST = list.h plist.h set.h vector.h vecffe.h range.h blister.h string.h
INCLANG = record.h statemen.h function.h coding.h

gap.o	  :	       $(INCBASC) list.h plist.h string.h read.h $(INCLANG)
system.o  : system.h
gasman.o  : gasman.h   system.h
scanner.o : scanner.h  system.h
idents.o  : idents.h   system.h gasman.h
read.o	  : read.h     $(INCBASC)
eval.o	  : eval.h     $(INCBASC) $(INCFLDS) $(INCGRPS) $(INCLIST) $(INCLANG)
integer.o : integer.h  $(INCBASC)
rational.o: rational.h $(INCBASC)
cyclotom.o: cyclotom.h $(INCBASC) list.h
unknown.o : unknown.h  $(INCBASC)
finfield.o: finfield.h $(INCBASC)
polynom.o : polynom.h  $(INCBASC) list.h plist.h vector.h vecffe.h finfield.h
permutat.o: permutat.h $(INCBASC) list.h
word.o	  : word.h     $(INCBASC) list.h agcollec.h
costab.o  : costab.h   $(INCBASC) list.h
tietze.o  : tietze.h   $(INCBASC) list.h word.h agcollec.h
agcollec.o: agcollec.h $(INCBASC) list.h word.h aggroup.h
aggroup.o : aggroup.h  $(INCBASC) list.h plist.h word.h agcollec.h finfield.h
pcpresen.o: pcpresen.h $(INCBASC) list.h plist.h word.h agcollec.h aggroup.h
list.o	  : list.h     $(INCBASC) set.h permutat.h record.h
plist.o	  : plist.h    $(INCBASC) list.h range.h record.h
set.o	  : set.h      $(INCBASC) list.h plist.h range.h
vector.o  : vector.h   $(INCBASC) list.h plist.h range.h
vecffe.o  : vecffe.h   $(INCBASC) list.h plist.h range.h
range.o	  : range.h    $(INCBASC) list.h plist.h
blister.o : blister.h  $(INCBASC) list.h plist.h range.h set.h
string.o  : string.h   $(INCBASC) list.h plist.h range.h
record.o  : record.h   $(INCBASC) plist.h string.h
statemen.o: statemen.h $(INCBASC) list.h
function.o: function.h $(INCBASC) plist.h record.h statemen.h
coding.o  : coding.h   $(INCBASC) list.h plist.h blister.h finfield.h vecffe.h

#############################################################################
##
#T  Miscellaneous  . . . . . . . . . . . . . . . . . targets to clean up, etc.
##
clean:
	rm -f *.o gap gapdjg.exe gap.ttp objects
