# $Header: /a/coll/disk/home/coll/rjg/Ml/fam.src/UPTODATE/RCS/Makefile,v 4.4 90/07/04 11:09:33 rjg Exp $
# $Log: Makefile,v $
# Revision 4.4  90/07/04  11:09:33  rjg
# Readline version 4.1.00
# New bytecode OpPrompt 
# 
# Revision 4.0  89/09/20  13:28:00  rjg
# incorporated RCS
# 
# Revision 4.0  89/09/20  13:12:53  rjg
# incorporated RCS
# 
# Modified by as@uk.ac.ed.aipna for GNU make on Acorn Archimedes
# machines: suffixes become prefixes, manually patch round use of
# sed,... 
#
#       Add a new type of suffix so that we can build object code from
#       headers directly and avoid the pain of keeping two different
#       files in synchronization.
#
# NICK: The magic suffix is now ".END", which is more obvious than ".tp".
#       All the temporary files created during a make have names beginning
#       with "_", which is more obvious than nothing at all.
#

.PREFIXES: c. h. o.

#
#       Here is where we set all of the flags to the $(CC) compiler to
#       control the defaults for compilation.  Note that this is
#       useful as we run recursive makes (c.f. debug and profile).
#
#       The GNU Readline library (distributed with bash) may be used to 
#       allow line editing.  If you have this software available, 
#       add -DREADLINE to CFLAGS and add the appropriate pathnames to 
#       CFLAGS and LIBFLAGS (and LDFLAGS)
#       See the man pag for details on features available with Readline lib.
#

LIBFLAGS = 
LDFLAGS = 
CFLAGS = -pcc -DRISC_OS -DARM
EQ = "="
#       NICK: never use an optimiser, if you expect your code to work
#       afterwards.
#
#       Making this a parameter allows the test target to be invoked
#       for different versions of the program.
#
VERSION = fam
#
#       Specify optional parameters for the ML interpreter itself.
#
MLPARMS = -h 2000 ml.new
#
#       Here is the rule for how to build an object module which holds
#       the storage allocation for all the external variables in a
#       header file.  The caveat with this particular rule is that you
#       should never have a header file and a C source file with the
#       same name.
#
#       Note that this allows the user to create header files which
#       contain all of the external declarations for external typing
#       and will allow external storage allocation to be done
#       automatically.  The form of the header files is as follows:
#
#       extern int      var /*/ = 0 /*/ ;
#
#       Note the very special form of comment markers, i.e. /*/, which
#       allows a distinctive form for removal.
#


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


o.%: h.%
        sed -e "s?extern?/* ext */?" -e "s?\/\*\/?/* */?g" < $< > c.$(basename $<) 
        $(CC) -c $(CFLAGS) c.$(basename $<) 
        delete c.$(basename $<)

#
#       Define the list of all the primary targets which this makefile
#       creates.  This is most useful when it is used by clobber.
#
ALL = debug profile fam 
OTHER = c._dumpcode c._debug c._version

all:    $(ALL)

#
#       Clean all extraneous files from this directory.
#
clean:
        delete -f o.*
#
#       Clean all generated files from this directory.
#
clobber:        clean
        delete -f $(ALL) $(OTHER)
#
#       How to retrieve the function which is used to call the
#       makefile with a test target.  This file will specify which
#       version of the interpreter to run and what parameters to
#       provide it with.
#
#       List all of the object modules needed to build the ML
#       interpreter.
#
FAM = o.fam o.interp o.io o.store o.system o._dumpcode o._debug o._version

# ARCHY
# If I lack a working sed the above would be replaced with
# FAM = o.fam o.interp o.io o.store o.system o.dumpcode o.debug o.version
#  c.dumpcode c.debug and c.version would have to be created by
# appropriate hand-editing of the h. files of the same name OR
# (lazier but probably o.k.) copying the files in the hc directory.

 
#
#       How to build the ML interpreter.
#

fam:    $(FAM)
        $(CC) -o fam $(CFLAGS) $(LDFLAGS) $(FAM) $(LIBFLAGS)


# ARCHY
# The following sed wizardy probably won't work without a
# little tweaking.

o._version: c._version
        $(CC) -c $(CFLAGS) c._version
        delete  c._version

c._version: c.* h.*
        egrep "\$$Header" c.* h.* > _1
        sed "s/.*\/\([^\/]*\),v \([^ \t]*\).*/\"\1 \2\",/" < _1 > _2
        uecho "char VersionId[][80]" $(EQ) "{" > c._version
        print _2 { >> c._version }
        uecho "\"@(\#)CFLAGS = $(CFLAGS)\","  >> c._version 
        uecho "\"@(\#)LDFLAGS = $(LDFLAGS)\","  >> c._version 
        uecho "\"\"" } ;  >> c._version 
        delete _1 _2


#
#       Create the routine which will print a profile of the FAM
#       opcodes.  Note that this routine is built automatically from
#       the master list of opcodes.
#
o._debug: c._debug
        $(CC) -c $(CFLAGS) c._debug

c._debug: h.debug
        sed -e "s/extern//" -e "s/\/\*\///g" < h.debug > c._debug

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

c._dumpcode:    END.dumpcode h.bcodes
        uecho "\#ifdef DEBUGinterp" > c._dumpcode
        uecho "char opstrings[][40] = {" >> c._dumpcode
        sed -n "s/^\#[\t ]*define[\t ]*\(Op[^\t ]*\)[\t ]*\(.*\)/\"\1\",/p" < h.bcodes >> c._dumpcode
        uecho "\"INVALID_OPCODE\"} ;"  >> c._dumpcode 
        uecho "int opcode[] = {" >> c._dumpcode
        sed -n "s/^\#[\t ]*define[\t ]*\(Op[^\t ]*\)[\t ]*\(.*\)/\2,/p" < h.bcodes >> c._dumpcode
        uecho "-1 } ;" >> c._dumpcode
        print END.dumpcode { >> c._dumpcode }

