#
#  Le Makefile du systeme Le_Lisp [macaux] #
#
SYSTEM=macaux
SIZEF31= -float 0
SIZEF= $(SIZEF31)
COMMON=commonmacaux

# Pour executer le makefile en shell
SHELL=/bin/sh

# On change all en camlisp:
all:    camlisp

FOREIGN=-DFOREIGN
# On ajoute la taille de Caml
SZCAML= -stack 24 -code 1000 -heap 1000 -number 0 \
	-vector 30 -string 40 -symbol 6  -cons 15  $(SIZEF)
# Caml avec une giigaanntesque zone de code
SZBIGCAML= -stack 24 -code 1500 -heap 1000 -number 0 \
	-vector 30 -string 40 -symbol 6  -cons 15  $(SIZEF)

SIZE=$(SZCAML)

# Entry to create 3 standard memory images
#all: lelisp cmplc lelispX11

# Entry to create standard binaries
tout: lelispbin leX11bin 

#
# Les tailles par de'faut des zones de donne'es
#

#SIZE=  -stack 6 -code 600 -heap 256 -number 0 -float 0 \
#        -vector 4 -string 6 -symbol 5 -cons 4

#SIZEX=  -stack 6 -code 800 -heap 256 -number 0 -float 0 \
#        -vector 5 -string 5 -symbol 4 -cons 5

#SIZE-=  -stack 3 -code 1 -heap 90 -number 0 -float 0 \
#        -vector 2 -string 2 -symbol 2 -cons 3

#SIZEH= -stack 8 -code 800 -heap 512 -number 0 -float 0 \
#       -vector 8 -string 12 -symbol 11 -cons 8

# For debugging use -g
CDEBUG= 
# For optimization use -O
COPT= -O
PAGESIZE=4096
LLINCLUDE=`pwd`/../$(COMMON)

CFLAGS= $(CDEBUG) $(COPT) -DPAGESIZE=$(PAGESIZE) \
	-DMACAUX -DNBSYST=38 -DS5 -Dx11r2 -DTIMEUNIT=60. \
	-I$(LLINCLUDE) $(FOREIGN)\
        -DFILEINI=\"../llib15.23/startup.ll\" 

# Empty string to keep local symbols in the executable. -x to save space.
LDFLAGS= 

LDLIBS= -lm -lc

XLDLIBS= -lX11 $(LDLIBS)

cobj= o/llmain.o o/caml.o o/camlstdio.o o/llfloat.o

xobj= o/x11.o o/cstruct.o $(cobj)

testextobj= o/testext.o o/cstruct.o $(cobj)

camlispbin: lefpu31bin
	@rm -f camlispbin
	ln lefpu31bin camlispbin

lefpu31bin: lefpu31bin.o $(cobj)
	cc $(LDFLAGS)  lefpu31bin.o $(cobj) $(LDLIBS) -o lefpu31bin
#	/bin/ld -z -x -o lefpu31bin /lib/crt0.o lefpu31bin.o $(cobj) -lm -lc /usr/lib/shared.ld

lefpu64bin: lefpu64bin.o $(cobj)
	cc $(CFLAGS) lefpu64bin.o $(cobj) $(LDLIBS) $(LDFLAGS) -o lefpu64bin

# une entre'e ge'ne'riques pour les utilisateurs exigents
# tous les fichiers etant parametre's, on peut refaire son propre binaire
# (on peut meme redifinir le compilo: ex: CC=/bin/f77
# ex: 
# % make monlelispbin USERBIN=monlelispbin USERO="foo.o bar.o"
# pour eventuellement changer de mode flottants
USERBINO=lefpu31bin.o
# pour le nom du binaire 
USERBIN=monlelispbin
# les fichiers *.o utilisateurs
USERO=
# pour avoir des flags supplementaires
USERFLAGS=

$(USERBIN): $(cobj) $(USERBINO) $(USERO)
	$(CC) $(CFLAGS) $(LDFLAGS) $(cobj) $(USERBINO) $(USERO) \
	$(LDLIBS) $(USERFLAGS) -o $(USERBIN)
	
######################################################################
BITMAP=X11
leX11bin: $(xobj) lefpu31bin.o
	cc $(CFLAGS) $(LDFLAGS) -I../virbitmap/X11 lefpu31bin.o $(xobj) \
		$(XLDLIBS) -o leX11bin

letestextbin: $(testextobj) lefpu31bin.o
	cc $(CFLAGS) lefpu31bin.o $(testextobj) $(LDLIBS) $(LDFLAGS) \
		-o letestextbin

o/llmain.o: ../$(COMMON)/llmain.c
	cc $(CFLAGS) -c ../$(COMMON)/llmain.c
	mv llmain.o o

o/caml.o:  ../$(COMMON)/caml.c
	cc $(CFLAGS) -c ../$(COMMON)/caml.c
	mv caml.o o

o/camlstdio.o:  ../$(COMMON)/llstdio.c
	cc $(CFLAGS) -DMAXCHAR=1024 -c ../$(COMMON)/llstdio.c
	mv llstdio.o o/camlstdio.o

o/llfloat.o:  ../$(COMMON)/llfloat.c
	cc $(CFLAGS) -c ../$(COMMON)/llfloat.c
	mv llfloat.o o

o/llnumb.o:  c/llnumb.c
	cc $(CFLAGS) -c ../$?
	mv llnumb.o o

o/cstruct.o: ../$(COMMON)/cstruct.c
	cc $(CFLAGS) -c ../$(COMMON)/cstruct.c
	mv cstruct.o o/cstruct.o

o/x11.o: ../virbitmap/X11/x11.c
	cc $(CFLAGS) $(XLDFLAGS) -c ../virbitmap/X11/x11.c
	mv x11.o o
#	(CFLAGS="$(CFLAGS)"; \
#	cd ../virbitmap/X11 ; \
#	$(MAKE) ../../$(SYSTEM)/o/x11.o SYSTEM=$(SYSTEM) CFLAGS="$$CFLAGS")

o/testext.o:  ../lltest/testext.c
	cc $(CFLAGS) -c ../lltest/testext.c
	mv testext.o o


#
# Le point d'entre'e permettant de faire le syste`me
# 

camlisp: makefile conf/camlispconf.ll  camlispbin
	../system/config camlisp camlispbin camlispconf.ll macaux $(SIZE)

lelisp-: makefile conf/lelisp-conf.ll  lelispbin
	../system/config lelisp- lelispbin lelisp-conf.ll macaux $(SIZE)

lelisp++: makefile conf/lelispconf.ll  lelispbin
	../system/config lelisp++ lelispbin lelispconf.ll macaux $(SIZEH)

cmplc: makefile conf/cmplcconf.ll  lelispbin
	../system/config cmplc lelispbin cmplcconf.ll macaux $(SIZE)

cmplc++: makefile conf/cmplcconf.ll  lelispbin
	../system/config cmplc++ lelispbin cmplcconf.ll macaux $(SIZEH)

lelispX11: makefile conf/leX11conf.ll  leX11bin
	../system/config  lelispX11 leX11bin leX11conf.ll macaux $(SIZEX)

lefpu64: makefile conf/lelispconf.ll  lefpu64bin
	../system/config lefpu64 lefpu64bin lelispconf.ll macaux $(SIZE)

letest: conf/lelispconf.ll letestextbin
	../system/config letest letestextbin lelispconf.ll macaux $(SIZE)

# make target that removes all the files that can be regenerated by the
# user.
clean:
	rm -f $(cobj) $(xobj) lelisp cmplc lelispX11 le*bin

