#
# Makefile -- dependency description for ``make''
#
# (C) m.b (Matthias Blume); 1992, HUB; Mar 1993 PU/CS
#         Humboldt-University of Berlin
#         Princeton University, Dept. of Computer Science
#
# This is the Makefile for the Scheme implementation ``vscm'' by
# Matthias Blume.  It requires the existence of an ANSI-C-System.
# Use the make-variables below to adapt to your local needs.
#

# Use a Bourne-Shell-like shell:

                        SHELL = /bin/sh

# The ``delete'' command:

                       DELETE = rm
                  FORCEDELETE = $(DELETE) -f

# The librarian ``ar'':
                           AR = ar

# The next section describes your local C system.
# CC is the name of your C-Compiler.  Use gcc, if available.  You MUST
#       use an ANSI-C-Compiler.
# OPTFLAGS (e.g. ``-O'', ``-O2'', ``-DNDEBUG'')
#	instruct the compiler to produce optimized code.
#       With gcc (at least v2.1) NEVER use plain ``-O'' (there is a bug...)!
# WARNFLAGS (e.g. ``-Wall'') are used to select the warn level.
# DEBUGFLAGS (e.g. ``-g'', ``-DDEBUG'')
#	instruct the compiler to include debugging information and/or code.
# EXTRACFLAGS (e.g. ``-Iincldir'') are extra flags passed to the compile phase.
# EXTRALDFLAGS (e.g. ``-Llibdir'') are extra flags passed to the link phase.
# EXTRALIBS (e.g. ``-lcposix'') are extra libraries, which might be necessary.
# RANLIB is the library randomizer (normally ``ranlib'') or a null command
#	if ranlib is not necessary (e.g. ``:'')

# Note: The flags defined in this section should be specific to your
# local C system.  They do not include generally applicable things like
# ``-DNDEBUG'' etc.


                           CC = gcc
                     OPTFLAGS = -O2
                    WARNFLAGS = -Wall -Wmissing-prototypes
                   DEBUGFLAGS = -g
                  EXTRACFLAGS = -DADJUSTABLE_SFIXNUM_RANGE -DVSCM_POSIX
                 EXTRALDFLAGS =
                    EXTRALIBS =
                       RANLIB = ranlib


# The next section gives examples for systems, where I know, how it works:
# 1. DECstation (ULTRIX) using gcc (v2.1, v2.3, v2.4):
##                           CC = gcc
##                     OPTFLAGS = -O2 -mcpu=r3000
##                    WARNFLAGS = -Wall -Wmissing-prototypes
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = ranlib
#
# 2. HP series 800 or 700, HP-UX:  (it is NOT working currently!!)
##                           CC = cc -Aa
##                     OPTFLAGS = -O -DNDEBUG
##                    WARNFLAGS =
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = ranlib
#
# 3. ISC 3.2 using gcc (v2.2.2)
##                           CC = gcc
##                     OPTFLAGS = -O2
##                    WARNFLAGS = -Wall -Wmissing-prototypes
##                   DEBUGFLAGS =
##                  EXTRACFLAGS = -Dsig_atomic_t=int
##                 EXTRALDFLAGS =
##                    EXTRALIBS = -lcposix
##                       RANLIB = :
#
# 4. experimental (lcc)
##                           CC = lcc
##                     OPTFLAGS =
##                    WARNFLAGS =
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = ranlib
#
# 5. experimental (DEC Alpha, OSF/1, cc (complains about volatile functions))
##                           CC = cc
##                     OPTFLAGS = -O2
##                    WARNFLAGS =
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = :
#
# 6. SGI (IRIX) using gcc:
##                           CC = gcc
##                     OPTFLAGS = -O2 -mcpu=r3000
##                    WARNFLAGS = -Wall -Wmissing-prototypes
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = :
#
# 7. NeXT using gcc:
##                           CC = gcc
##                     OPTFLAGS = -O2
##                    WARNFLAGS = -Wall -Wmissing-prototypes
##                   DEBUGFLAGS =
##                  EXTRACFLAGS = -DCLOCKS_PER_SEC=60
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = ranlib
# 8. IBM RS/6000 workstation:
##                           CC = xlc
##                     OPTFLAGS = -O
##                    WARNFLAGS =
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = ranlib
# 9. HP 9000 series 700 (tested on a 750), HP-UX, using gcc (!)
##                           CC = gcc
##                     OPTFLAGS = -O2
##                    WARNFLAGS = -Wall -Wmissing-prototypes
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = ranlib
# 10. DEC Alpha using GCC
##                           CC = gcc
##                     OPTFLAGS = -O2
##                    WARNFLAGS = -Wall -Wmissing-prototypes
##                   DEBUGFLAGS =
##                  EXTRACFLAGS =
##                 EXTRALDFLAGS =
##                    EXTRALIBS =
##                       RANLIB = :

# A specification of the default prefix string that is written into the
# first line of memory dump files:
# (only GNU make can handle this line properly)

DDP = -DDEFAULT_DUMP_PREFIX='"\#!/home/blume/bin/scheme -b"' -DDEFAULT_BOOTFILE='"/home/blume/lib/.scheme-boot"'

# The following section can be used to define flags which change the
# configuration of the system.  In general it will be necessary to have
# some knowledge about the internal consequences of those settings.
# Don't change them if you are not familiar with them!
#
# WARNINGS: NEVER MAKE CHANGES TO THESE SETTINGS BEFORE BUILDING THE
# SYSTEM FOR THE FIRST TIME!
#
# Note: whenever you make changes to the system which will result in
# changes to the ``dump file'' format you must ``touch(1)'' the file
# ``format.time'' before recompilation.

# useful -D? options: TRACE_VM_EXECUTION VM_INSTRUCTION_COUNTING DEBUG TICKING


                   A_OPTFLAGS = $(OPTFLAGS)	-DNDEBUG
                  A_WARNFLAGS = $(WARNFLAGS)
                 A_DEBUGFLAGS = $(DEBUGFLAGS)
                A_EXTRACFLAGS = $(EXTRACFLAGS)	-DTICKING
               A_EXTRALDFLAGS = $(EXTRALDFLAGS)
                  A_EXTRALIBS = $(EXTRALIBS)

# Don't fool around with stuff below this line...

.DEFAULT:
	@echo I hope, making $< is not necessary...

CFLAGS  = $(A_OPTFLAGS) $(A_WARNFLAGS) $(A_DEBUGFLAGS) $(A_EXTRACFLAGS) $(DDP)
LDFLAGS = $(A_OPTFLAGS) $(A_DEBUGFLAGS) $(A_EXTRALDFLAGS)
CLFLAGS = $(CFLAGS) $(A_EXTRALDFLAGS)
LIBS    = -lm $(A_EXTRALIBS)

OBJECTS =	\
	storage.o storext.o identifier.o reader.o keyword.o io.o Boolean.o \
	Symbol.o Cont.o Primitive.o Code.o Port.o Corout.o Numeric.o \
	Cell.o Character.o Cons.o Vector.o String.o Procedure.o Promise.o \
	Module.o except.o main.o list-prim.o misc-prim.o bool-prim.o \
	equiv-prim.o sym-prim.o num-prim.o vect-prim.o contr-prim.o \
	sc-prim.o cr-prim.o tmpstring.o gcstat.o posix.o

TMPLIBS = non-ansi-lib

.PRECIOUS:	$(TMPLIBS)

.SUFFIXES:	.tab

all:	scheme .scheme-boot

#
# Dependencies:
#

$(OBJECTS) mkalign.o mkpvtab.o:	rcs.h

Boolean.o:	Boolean.c storext.h numops.tab Boolean.h storage.h align.h \
		type.h identifier.h ident.tab except.h noreturn.h
Cell.o:	Cell.c storext.h numops.tab Cell.h storage.h align.h identifier.h \
		ident.tab type.h
Character.o:	Character.c storext.h numops.tab Character.h storage.h \
		align.h type.h identifier.h ident.tab except.h noreturn.h
Code.o:		Code.c storext.h numops.tab Code.h storage.h align.h \
		Vector.h noreturn.h Cont.h identifier.h ident.tab type.h \
		except.h speccont.h mode.h keyword.h Cons.h Procedure.h \
		Promise.h Boolean.h Cell.h Symbol.h Primitive.h String.h \
		Numeric.h Module.h realloc.h vbis.sort
Cons.o:		Cons.c storext.h numops.tab Cons.h storage.h align.h \
		identifier.h ident.tab keyword.h Boolean.h type.h
Cont.o:		Cont.c storext.h numops.tab Cont.h storage.h align.h \
		Vector.h Code.h noreturn.h identifier.h ident.tab stack-t.h \
		type.h except.h speccont.h mode.h
Corout.o:	Corout.c storext.h numops.tab Corout.h storage.h align.h \
		Cont.h Vector.h Code.h noreturn.h speccont.h identifier.h \
		ident.tab type.h
Numeric.o:	Numeric.c Numeric.h storage.h align.h storext.h numops.tab \
		except.h noreturn.h identifier.h ident.tab type.h numops.h \
		realloc.h
Port.o:		Port.c storext.h numops.tab Port.h storage.h align.h \
		identifier.h ident.tab except.h noreturn.h type.h Boolean.h \
		Character.h Cont.h Vector.h Code.h io.h reader.h realloc.h
Primitive.o:	Primitive.c storext.h numops.tab Primitive.h storage.h \
		align.h identifier.h ident.tab type.h except.h noreturn.h \
		builtins.tab speccont.h
Procedure.o:	Procedure.c storext.h numops.tab Procedure.h storage.h \
		align.h identifier.h ident.tab
Promise.o:	Promise.c storext.h numops.tab Promise.h storage.h align.h \
		identifier.h ident.tab
String.o:	String.c storext.h numops.tab String.h storage.h align.h \
		identifier.h ident.tab type.h except.h noreturn.h
Symbol.o:	Symbol.c storext.h numops.tab Symbol.h storage.h align.h \
		Primitive.h identifier.h ident.tab type.h except.h noreturn.h
Vector.o:	Vector.c storext.h numops.tab Vector.h storage.h align.h \
		identifier.h ident.tab type.h except.h noreturn.h
Module.o:	Module.c storext.h numops.tab Module.h storage.h align.h \
		identifier.h ident.tab type.h
bool-prim.o:	bool-prim.c Boolean.h storage.h align.h storext.h numops.tab \
		Cont.h Vector.h Code.h noreturn.h builtins.tab speccont.h
contr-prim.o:	contr-prim.c Cont.h storage.h align.h storext.h numops.tab \
		Vector.h Code.h noreturn.h Procedure.h Primitive.h Promise.h \
		Boolean.h Cons.h except.h type.h builtins.tab speccont.h
cr-prim.o:	cr-prim.c storage.h align.h storext.h numops.tab Corout.h \
		Cont.h Vector.h Code.h noreturn.h Procedure.h except.h \
		type.h builtins.tab speccont.h
equiv-prim.o:	equiv-prim.c Cont.h storage.h align.h storext.h numops.tab \
		Vector.h Code.h noreturn.h Boolean.h builtins.tab speccont.h
except.o:	except.c Cont.h storage.h align.h storext.h numops.tab \
		Vector.h Code.h noreturn.h String.h except.h m-except.h \
		io.h type.h mode.h tmpstring.h
fileno.o:	fileno.c
gcstat.o:	gcstat.c storage.h align.h storext.h numops.tab Cont.h \
		Vector.h Code.h noreturn.h Numeric.h Boolean.h speccont.h \
		mode.h except.h
identifier.o:	identifier.c storage.h align.h storext.h numops.tab \
		identifier.h ident.tab type.h Boolean.h Character.h Cons.h \
		Cell.h Procedure.h Promise.h String.h Symbol.h Vector.h \
		Cont.h Code.h noreturn.h Primitive.h Port.h Numeric.h \
		Corout.h Module.h 
io.o:		io.c io.h Port.h storage.h align.h storext.h numops.tab \
		Boolean.h Cont.h Vector.h Code.h noreturn.h String.h \
		Numeric.h mode.h type.h tmpstring.h except.h reader.h \
		builtins.tab speccont.h realloc.h
keyword.o:	keyword.c keyword.h storage.h align.h storext.h numops.tab \
		Symbol.h
list-prim.o:	list-prim.c Cont.h storage.h align.h storext.h numops.tab \
		Vector.h Code.h noreturn.h Boolean.h Cons.h Numeric.h \
		type.h except.h builtins.tab speccont.h
main.o:		main.c main.h storage.h align.h storext.h numops.tab \
		keyword.h reader.h except.h noreturn.h Cont.h Vector.h \
		Code.h Boolean.h Symbol.h Cons.h String.h Corout.h \
		Numeric.h io.h m-except.h speccont.h type.h mainloop.h
misc-prim.o:	misc-prim.c storage.h align.h storext.h numops.tab Cont.h \
		Vector.h Code.h noreturn.h Numeric.h String.h Boolean.h \
		Primitive.h Procedure.h Symbol.h Cons.h type.h tmpstring.h \
		mode.h except.h builtins.tab speccont.h m-except.h mainloop.h
mkalign.o:	mkalign.c
num-prim.o:	num-prim.c Cont.h storage.h align.h storext.h numops.tab \
		Vector.h Code.h noreturn.h Numeric.h Boolean.h Cons.h \
		String.h type.h except.h reader.h builtins.tab speccont.h
reader.o:	reader.c reader.h keyword.h type.h Cons.h storage.h align.h \
		storext.h numops.tab Cont.h Vector.h Code.h noreturn.h \
		Character.h String.h Symbol.h Boolean.h Numeric.h except.h \
		realloc.h
realloc.o:	realloc.c realloc.h
sc-prim.o:	sc-prim.c String.h storage.h align.h storext.h numops.tab \
		Character.h Boolean.h Cont.h Vector.h Code.h noreturn.h \
		Numeric.h Cons.h type.h except.h builtins.tab speccont.h
storage.o:	storage.c align.h storage.h storage-t.h except.h noreturn.h \
		realloc.h
storext.o:	storext.c storage.h align.h storext.h numops.tab numops.h \
		except.h noreturn.h
strerr.o:	strerr.c
sym-prim.o:	sym-prim.c storage.h align.h storext.h numops.tab Cont.h \
		Vector.h Code.h noreturn.h Symbol.h String.h Boolean.h \
		type.h except.h tmpstring.h builtins.tab speccont.h
tmpstring.o:	tmpstring.c realloc.h tmpstring.h except.h noreturn.h
vect-prim.o:	vect-prim.c Code.h storage.h align.h storext.h numops.tab \
		Vector.h noreturn.h Cont.h Boolean.h Numeric.h Cons.h \
		type.h except.h builtins.tab speccont.h
posix.o:	posix.c Boolean.h storage.h align.h storext.h numops.tab \
		String.h Cons.h Cont.h Vector.h Code.h noreturn.h type.h \
		except.h tmpstring.h builtins.tab speccont.h
mkpvtab.o:	mkpvtab.c builtins.tab speccont.h

#
# Rules:
#

objects: $(OBJECTS)

align.h: mkalign
	./mkalign >align.h

vbis.sort:	vbis.tab
	sed -e '1,/^--FILE_STARTS_HERE--$$/d' <vbis.tab | \
	awk -F\" '{print $$2, $$0}' | sort | \
	sed -e 's/^[^ ]*//' >vbis.sort

.c.o:
	$(CC) $(CFLAGS) -c $<

.c:
	$(CC) -o $* $(CLFLAGS) $< $(LIBS)

non-ansi-lib:	\
	non-ansi-lib(fileno.o) \
	non-ansi-lib(realloc.o) \
	non-ansi-lib(strerr.o)
	$(RANLIB) non-ansi-lib
	@echo non-ansi-lib is now up to date

.c.a:
	$(CC) $(CFLAGS) -c $<
	$(AR) rv $@ $*.o
	$(FORCEDELETE) $*.o

scheme:	$(OBJECTS) $(TMPLIBS)
	$(CC) -o scheme $(LDFLAGS) $(OBJECTS) $(LIBS) -lc $(TMPLIBS)

.scheme-boot: compiler/O/repl.scb
	cp compiler/O/repl.scb .scheme-boot

compiler/O/repl.scb: mkpvtab
	(cd compiler; ./build $(MAKE))

# The following section contains stuff related to ULTRIX's
# profiling system (pixie):

scheme.pixie: scheme
	pixie -o scheme.pixie scheme

prof: scheme.pixie .scheme-boot
	./scheme.pixie
	prof -pixie scheme | more
