# Makefile for three SAS/C 6.51 versions of Gofer 2.30a for Amiga:
#
#   The 16 bit small version and the 32 bit regular one.
#   I haven't tried to build the 32 bit large version, but
#   the rules are in here to do it.
# 
# It will probably also work with earlier versions of SAS/C 6,
# but you may have to drop some of the optimizer options(?)
#
# Torsten Poulin (torsten@diku.dk)
# 20-Sep-94
#
# IMPORTANT: make sure that you use the same compiler to build gofc
# executables (often by setting an appropriate value in the gofcc script)
# as you use to build the file runtime.o.

.SUFFIXES:	.y .c .h .o

# Choose the setup you want. Note that I use different names for the
# executables and runtime library based on the setup, because I use
# both the small and the regular version on my system.
# Remember to select the correct setup in prelude.h, i.e.,
# S_AMISAS, R_AMISAS, or L_AMISAS.

# Small 16 bit Gofer and Gofer->C.
#CSIZE   = sint
#LDSIZE  = sint
#GOFER   = s-gofer
#GOFC    = s-gofc
#RUNTIME = s-runtime.o

# Regular 32 bit Gofer and Gofer->C
CSIZE   =
LDSIZE  =
GOFER   = r-gofer
GOFC    = r-gofc
RUNTIME = r-runtime.o

# Large 32 bit Gofer and Gofer->C
#CSIZE   =
#LDSIZE  =
#GOFER   = l-gofer
#GOFC    = l-gofc
#RUNTIME = l-runtime.o


# The file amiga.c contains a custem version of the stdlib.h function
# system(). The one present in the SAS/C 6.51 library ignores the users
# choice of default shell. Thus people using (for example) WShell loose
# access to their aliases etc.
#
# The custom version is just a wrapper around the dos.library V36+
# function System() with the flag SYS_UserShell set to true. If Gofer is
# run on on a pre-V36 system, dos.library/Execute() is used instead.
#
# In addition it contains a function, amigaIsTrueConsole(), that
# is used in machdep.c to find out if we are running in a real
# shell window, in which case we can determine the width of the
# console.
#
# system() isn't used by gofc, but it only adds a few hundred bytes
# to a 200k+ executable so who cares :-)

OBJECTS  = storage.o input.o static.o type.o compiler.o
IOBJECTS = gofer.o builtin.o  machine.o output.o $(OBJECTS) amiga.o
COBJECTS = gofc.o cbuiltin.o cmachine.o $(OBJECTS) amiga.o

CFLAGS   = ign=161,104 math=standard data=far code=far minc nostkchk nover
LDFLAGS  = math=standard stripdbg chkabort nover $(LDSIZE)

OPTFLAGS = opt opttime
OPT1     = opt nooptglobal optpeep noautoreg

.c.o:
	sc $(CFLAGS) $(OPTFLAGS) $(CSIZE) strmer $*.c

all: $(GOFER) $(GOFC) $(RUNTIME)

$(GOFER): $(IOBJECTS)
	sc link $(IOBJECTS) pname $(GOFER) $(LDFLAGS)

$(GOFC): $(COBJECTS)
	sc link $(COBJECTS) pname $(GOFC) $(LDFLAGS)


# The runtime library must be compiled using 32 bit integers.
# If we use 16 bit, the machine crashes when the apps are run...
# If anybody figures out why, I would appreciate if they
# dropped me a note describing how to solve the problem.
#
#   - Torsten

$(RUNTIME):	prelude.h gofc.h machdep.c markscan.c twospace.c
	sc $(OPTFLAGS) $(CFLAGS) runtime.c objname $(RUNTIME)


clean:
	-delete \#?.(o|lnk)

# I haven't been able to find a yacc for Amiga that doesn't break things

#parser.c: parser.y
#	yacc parser.y
#	rename y.tab.c parser.c

#doparser.c: parser.y
#	yacc doparser.y
#	rename y.tab.c doparser.c

# Important! Don't use the SAS/C 6.51 global optimizer on
# gofer.c and gofc.c. It breaks the signal handling code.
# I would really like to know why...
gofer.o:	prelude.h storage.h connect.h errors.h \
		command.h machdep.c commonui.c
	sc $(CFLAGS) $(CSIZE) strmer gofer.c
gofc.o:		prelude.h storage.h connect.h errors.h \
		command.h machdep.c commonui.c output.c
	sc $(CFLAGS) $(CSIZE) strmer gofc.c

storage.o:	prelude.h storage.h connect.h errors.h
input.o:	prelude.h storage.h connect.h errors.h doparser.c command.h
static.o:	prelude.h storage.h connect.h errors.h scc.c
type.o:		prelude.h storage.h connect.h errors.h preds.c \
		kind.c subst.c
	sc $(CFLAGS) $(OPTFLAGS) $(CSIZE) type.c
output.o:	prelude.h storage.h connect.h errors.h
compiler.o:	prelude.h storage.h connect.h errors.h
	sc $(OPT1) $(CFLAGS) $(CSIZE) compiler.c
machine.o:	prelude.h storage.h connect.h errors.h
cmachine.o:	prelude.h storage.h connect.h errors.h
builtin.o:	prelude.h storage.h connect.h errors.h prims.c
cbuiltin.o:	prelude.h storage.h connect.h errors.h prims.c
amiga.o:	amiga.c
