#############################################################################
##
#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-solaris-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-solaris-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-solaris-gcc2'   is   listed   before  'sun-sparc-solaris-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-solaris-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 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-solaris-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

#############################################################################
##
#T  Targets . . . . .  targets of the form <vendor>-<cpu>-<system>-<compiler>
##
##  Following are the targets that the	user can specify.  Each target	calls
##  'make' recursively twice.
##
##  The first time it calls
##
##	@$(MAKE) <system-file>.o  CFLAGS="$(COPTS) <copts>"
##
##  where <system-file> is either 'system' or the name of another system file
##  and where <copts> are the options to  pass to  pass	 to  the  C compiler,
##  e.g., 'SYS_IS_BSD' or 'SYS_IS_MSDOS'.
##
##  The second time it calls
##
##	@$(MAKE) gap  CC=<c-compiler> CFLAGS="$(COPTS) <opts>" \
##		      SYS_FILE=<system-file>.o LOPTS="$(LOPTS)"
##
##  where <system-file> is the same file as above, <c-compiler> is  the	 name
##  of the C compiler to use ($(CC) is used if this is not present),  <copts>
##  are	 the options to pass ot	 the  C compiler, e.g., '-O2'.
##
unknown:
	@echo "usage: 'make <target>' where target is one of"
	@echo "'x86linux-gcc64'   for x86linux with gcc"
	@echo "'x86linux-gcc'     for x86linux with gcc in 32bit mode"
	@echo "'macosx-gcc'       for mac os x with gcc"
	@echo "'x86bsd-gcc'       for x86BSD with gcc"
	@echo "'sun-sparc-solaris-gcc' for SUN under Solaris with GNU cc"
	@echo "'sun-sparc-solaris-cc'  for SUN under Solaris with cc"
	@echo "'bsd'		       for others under Berkeley UNIX with cc"
	@echo "	"
	@echo "	  additional C compiler and linker flags can be passed with"
	@echo "	  'make <target> COPTS=<compiler-opts> LOPTS=<linker-opts>',"
	@echo "	  i.e., 'make x86linux-gcc COPTS=-g LOPTS=-g for debug'"

x86linux-gcc:
	@$(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/gap.x86linux

x86linux-gccd:
	@$(MAKE) system.o   CC=gcc  CFLAGS="-g -m32 -O2 -DSYS_IS_USG -DSYS_HAS_TIME_PROTO -DSYS_HAS_SIGNAL_PROTO -DSYS_HAS_IOCTL_PROTO"
	@$(MAKE) gap CC=gcc CFLAGS="-g -m32 -O " SYS_FILE=system.o LOPTS="-g -m32 -static"

x86linux-gcc64:
	@$(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/gap.x86linux64

x86-dos-djgpp:
	@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS) -DSYS_IS_MSDOS_DJGPP -DSYS_HAS_MISC_PROTO"
	@$(MAKE) gapdjg.exe CC=gcc  CFLAGS="$(COPTS) -O1"  SYS_FILE=system.o  LOPTS="$(LOPTS)"

x86-dos-djgppcross:
	@$(MAKE) system.o   CC=dos-gcc	CFLAGS="$(COPTS) -DSYS_IS_MSDOS_DJGPP -DSYS_HAS_MISC_PROTO"
	@$(MAKE) gapdjg.exe CC=dos-gcc	CFLAGS="$(COPTS) -O1"  SYS_FILE=system.o  LOPTS="$(LOPTS)"

# sbrk doesn't work in macosx so we need to use vm_allocate
macosx-gcc:
	@$(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"

# sbrk doesn't work in macosx so we need to use vm_allocate
# This is using Frank Luebeck's optimized compile....but it doesn't
# change the GAPstones for the files in ../tst
macosx-gcc-686-optimized:
	@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS) -m32 -fomit-frame-pointer -pipe -fno-strength-reduce -march=i686 -falign-loops=2 -falign-jumps=2 -falign-functions=2 -DCPU=686 -g -O2 -DSYS_IS_MACOSX -DARCH_INCLUDE -DSYS_HAS_IOCTL_PROTO"
	@$(MAKE) gap	    CC=gcc  CFLAGS="$(COPTS) -m32 -fomit-frame-pointer -pipe -fno-strength-reduce -march=i686 -falign-loops=2 -falign-jumps=2 -falign-functions=2 -DCPU=686 -g -O3"  SYS_FILE=system.o  LOPTS="$(LOPTS) -m32"

sun-sparc-solaris-cc:
	@$(MAKE) system.o   CC=cc  CFLAGS="$(COPTS) -O -DSYS_IS_USG -DSYS_HAS_TIME_PROTO -DSOLARIS2"
	@echo "Don't worry about 'out of range' and 'overflow' warnings"
	@echo "(29 in total)"
	@$(MAKE) gap	    CC=cc  CFLAGS="$(COPTS) -O2"  SYS_FILE=system.o  LOPTS="$(LOPTS)"

sun-sparc-solaris-gcc2:						   
	@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS)  -O6 -DSYS_IS_USG -DSYS_HAS_TIME_PROTO -DSOLARIS2"						       
	@$(MAKE) gap	    CC=gcc  CFLAGS="$(COPTS)  -O6"  SYS_FILE=system.o LOPTS="$(LOPTS)"								     

# 'sys/times.h' claims 'times' returns 'clock_t' (how shall it return -1?)
sun-sparc-sunos-gcc:
	@$(MAKE) system.o   CC=gcc  CFLAGS="$(COPTS) -DSYS_IS_USG -DSYS_HAS_TIME_PROTO -DSYS_HAS_SIGNAL_PROTO"
	@$(MAKE) gap	    CC=gcc  CFLAGS="$(COPTS) -O2"  SYS_FILE=system.o  LOPTS="$(LOPTS)"

# 'sys/times.h' claims 'times' returns 'clock_t' (how shall it return -1?)
sun-sparc-sunos-cc:
	@$(MAKE) system.o   CFLAGS="$(COPTS) -DSYS_IS_USG -DSYS_HAS_TIME_PROTO"
	@$(MAKE) gap	    CFLAGS="$(COPTS) -O"  SYS_FILE=system.o  LOPTS="$(LOPTS)"

bsd:
	@$(MAKE) system.o   CC=$(CC)  CFLAGS="$(COPTS) -DSYS_IS_BSD"
	@$(MAKE) gap	    CC=$(CC)  CFLAGS="$(COPTS) -O"  SYS_FILE=system.o  LOPTS="$(LOPTS)"

#############################################################################
##
#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
