# Generated automatically from Makefile.in by configure.
# Scheme 48 Makefile
# Last updated March 1994 by JAR
# Documentation in files INSTALL and doc/install.txt

srcdir = .
VPATH = .
CC = gcc
DEFS = -DHAVE_CONFIG_H
LIBS = 
CFLAGS = -O
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644

LDFLAGS =

prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
incdir = $(exec_prefix)/include
mandir = $(prefix)/man
manext = 1

# HP 9000 series, if you don't have gcc
#   CC = cc 
#   CFLAGS = -Aa -O +Obb1800
#   DEFS = -D_HPUX_SOURCE -Dhpux

# Ultrix
#   LDFLAGS = -N

.c.o:
	/usr/local/lib/gcc-cpp -undef -D__GNUC__ -Dapollo -Dunix -D__apollo__ -D__unix__ -D__HAVE_68881__ -Dmc68020 -D_APOLLO_SOURCE $(CPPFLAGS) $(DEFS) -I$(srcdir) -I/usr/local/include $< $*.i
	/usr/local/lib/gcc-cc1 $*.i -C $(CFLAGS) -quiet -dumpbase $< -o $*.s
	/usr/local/lib/gcc-as -C -mc68020 -o $*.o $*.s
	rm -f $*.i $*.s

# You might want to change RUNNABLE to "s48"
RUNNABLE = scheme48
MANPAGE = $(RUNNABLE).$(manext)
LIB = $(libdir)/$(RUNNABLE)

distdir = /users/ftp/pub/s48
#distdir = /net/mini-wheats/fs/admin/ftp/pub/s48

# If make barfs on this include line, just comment it out.  It's only
# really needed if you want to build the linker or rebuild initial.image.
include $(srcdir)/filenames.make
#
#NetBSD make wants to see this instead:
#.include "$(srcdir)/filenames.make"


# Static linker:
#
# You only need the linker if you're going to make changes to the
# things that go into the initial.image, which in general means the
# files in rts/.  If you decide you need to use the linker, then you
# gots your choice; it can run in just about any version of Scheme 48
# or Pseudoscheme.  (It has also been made to run in Scheme->C.)  It
# doesn't matter a whole lot which Scheme you use as long as it's not
# broken or unavailable.  The two best choices are:
# 1. As below: build the linker on the scheme48vm and scheme48.image
#    that are in the current directory.
# 2. LINKER_VM = $(RUNNABLE) $(BIG_HEAP)
#    LINKER_RUNNABLE = $(RUNNABLE)
#    These settings requires you to already have a $(RUNNABLE)
#    command.  This is desirable if you are making changes to the
#    system that might break scheme48vm and/or scheme48.image.  But it
#    requires you to have squirreled away a previous working version
#    of scheme48.

BIG_HEAP = -h 4000000
LINKER_VM = ./$(VM) $(BIG_HEAP)
LINKER_RUNNABLE = $(LINKER_VM) -i $(IMAGE)
LINKER_IMAGE = link/linker.image
LINKER = $(LINKER_VM) -i $(LINKER_IMAGE)
START_LINKER = echo ,batch; echo ,bench on;


# --------------------
# You shouldn't have to change anything below this point.

# Targets:

IMAGE = scheme48.image
INITIAL = $(srcdir)/initial.image
VM = scheme48vm
OBJS = unix.o dynload.o prescheme.o extension.o scheme48vm.o

# Sources:

CONFIG_FILES = interfaces.scm low-packages.scm rts-packages.scm \
	       comp-packages.scm

# Rules:

# The following is the first rule and therefore the "make" command's
# default target.
enough: $(VM) $(IMAGE) script $(MANPAGE)

# The developers are curious to know.  Don't be concerned if this fails.
.notify: minor-version-number
	touch .notify
	-echo Another 0.`cat $(srcdir)/minor-version-number` installation. \
	   | mail scheme-48-notifications@martigny.ai.mit.edu 

$(VM): main.o $(OBJS)
	$(CC) $(LDFLAGS) -o $@ main.o $(OBJS) $(LIBS)

#main.o: main.c
#	$(CC) -c -DDEFAULT_IMAGE_NAME=\"$(LIB)/$(IMAGE)\" $(CPPFLAGS) $(CFLAGS) $(srcdir)/main.c

scheme48vm.o: scheme48vm.c prescheme.h
extension.o: extension.c sysdep.h scheme48.h
unix.o: unix.c sysdep.h
dynload.o: dynload.c sysdep.h scheme48.h

# --------------------
# Make scheme48.image from initial.image and library .scm files.
#
# In the following, "make" passes $$USER to the shell as $USER, which
# the shell sees as an environment variable reference.
#
# For bootstrap reasons, initial.image is *not* listed as a source,
# even though it really is.

$(IMAGE): $(VM) env/init-defpackage.scm more-interfaces.scm link-packages.scm \
	   more-packages.scm $(usual-files) initial.debug build-usual-image
	sh $(srcdir)/build-usual-image "$(srcdir)" "$(LIB)" "$(IMAGE)" \
	   "$(VM)" "$(INITIAL)"

# Unix man page...

$(MANPAGE): scheme48.man Makefile
	sed 's=LBIN=$(bindir)=g' $(srcdir)/scheme48.man \
	 | sed 's=LLIB=$(LIB)=g' \
	 | sed 's=LS48=$(RUNNABLE)=g' >$@
	chmod +r $@

script:
	(echo '#!/bin/sh'; \
	 echo exec '$(LIB)/$(VM)' -o '$(LIB)/$(VM)' -i '$(LIB)/$(IMAGE)' \"\$$\@\") \
	   > script
	chmod +x script

### Fake targets:  all clean install man dist

install: script install-vm install-image install-misc install-man install-inc
	$(INSTALL_PROGRAM) script $(bindir)/$(RUNNABLE)

install-vm: $(VM)
	$(INSTALL_PROGRAM) $(VM) $(LIB)/

install-image: $(IMAGE)
	$(INSTALL_DATA) $(IMAGE) $(LIB)/

install-man: $(MANPAGE)
	if test -d $(mandir)/man$(manext);  \
	  then $(INSTALL_DATA) $(MANPAGE) $(mandir)/man$(manext); \
          else echo "No man directory, not installing man page"; fi

install-inc: scheme48.h
	$(INSTALL_DATA) $(srcdir)/scheme48.h $(incdir)/

install-misc: $(LIB)/rts $(LIB)/env $(LIB)/big $(LIB)/opt \
	      $(LIB)/misc $(LIB)/link
	for f in $(srcdir)/rts/*num.scm; \
	    do $(INSTALL_DATA) $$f $(LIB)/rts/; done
	for f in $(srcdir)/env/*.scm; do $(INSTALL_DATA) $$f $(LIB)/env/; done
	for f in $(srcdir)/big/*.scm; do $(INSTALL_DATA) $$f $(LIB)/big/; done
	for f in $(srcdir)/opt/*.scm; do $(INSTALL_DATA) $$f $(LIB)/opt/; done
	for f in $(srcdir)/misc/*.scm; \
	    do $(INSTALL_DATA) $$f $(LIB)/misc/; done
	for f in $(srcdir)/link/*.scm; \
	    do $(INSTALL_DATA) $$f $(LIB)/link/; done
	$(INSTALL_DATA) $(srcdir)/rts/jar-defrecord.scm $(LIB)/rts/
#  -p: Intermediate directories are created as necessary.
$(LIB)/rts:
	mkdir -p $(LIB)/rts
$(LIB)/env:
	mkdir -p $(LIB)/env
$(LIB)/opt:
	mkdir -p $(LIB)/opt
$(LIB)/big:
	mkdir -p $(LIB)/big
$(LIB)/misc:
	mkdir -p $(LIB)/misc
$(LIB)/link:
	mkdir -p $(LIB)/link

configure: configure.in
	cd $(srcdir); autoconf

clean:
	-rm -f $(VM) *.o TAGS $(IMAGE) *.tmp script $(MANPAGE) \
	    link/*.image debug/*.image debug/*.debug mini mini-heap.c

distclean: clean
	rm -f Makefile sysdep.h config.status
     
man:	$(MANPAGE)

check:	$(VM) $(IMAGE) debug/check.scm
	(echo ,translate =scheme48/ $(srcdir)/; \
 	 echo ,config ,load $(srcdir)/debug/test.scm; \
	 echo ,exec ,load $(srcdir)/debug/check.scm; echo ,exec "(done)") \
	| ./$(VM) -i $(IMAGE) -a batch

# --------------------
# Rules from here on down are not essential for the basic installation
# procedure, and are not expected to work when srcdir is not the
# distribution directory.

all: vm linker
	$(MAKE) image
vm: $(VM)
linker: $(LINKER_IMAGE)
image: $(INITIAL)
	$(MAKE) $(IMAGE)

tags:
	etags rts/*.scm bcomp/*.scm *.scm env/*.scm big/*.scm \
	  link/*.scm opt/*.scm debug/*.scm misc/*.scm

# --------------------
# Distribution...

# DISTFILES should include all sources.  In order to avoid circular
# dependencies (as reflected in file creation dates), the following
# ordering constraints should be met:
#  - filenames.make should appear after *.scm.
#  - initial.image should appear after *.scm and */*.scm.
#  - scheme48.h should appear after vm/*.scm and link/*.scm.

DISTFILES = COPYING README INSTALL NEWS TODO \
	    configure configure.in Makefile.in sysdep.h.in \
	    build-usual-image scheme48.man doc/*.txt doc/*.tex doc/*.ps \
	    *.scm filenames.make \
	    rts/*.scm bcomp/*.scm opt/*.scm env/*.scm big/*.scm misc/*.scm \
	    link/*.scm vm/*.scm alt/*.scm debug/*.scm infix/*.scm \
	    *.[ch] \
	    initial.image initial.debug \
	    link/*.lisp link/*.exec \
	    emacs/*.el .gdbinit *-version-number \
	    */README

distfile = $(RUNNABLE)-0.`cat minor-version-number`.tar.gz

dist: initial.image
	tar cf - $(DISTFILES) | gzip -c >$(distdir)/$(distfile)
	rm -f $(distdir)/$(RUNNABLE).tar.gz
	dist=$(distfile); cd $(distdir); ln -s $$dist $(RUNNABLE).tar.gz
#	$(MAKE) inc

# Increment the minor version number
inc:
	(cat minor-version-number; echo 1+p) | dc >minor-version-number.tmp
	mv minor-version-number.tmp minor-version-number
	echo \(define version-info \"0.`cat minor-version-number`\"\) \
	  >env/version-info.scm


# --------------------
# Generate filenames.make from *packages.scm
#
# This hack traces the module dependencies described in the
# various configuration files and converts them into dependency lists
# that "make" can use for its purposes.
#
# Since the distribution comes with a filenames.make, this rule
# shouldn't be invoked for simple installations.  But it will be used
# if you change any of the *-packages.scm files.
#
# You can actually the forms in filenames.scm to any Scheme
# implementation that has syntax-rules and explicit-renaming low-level
# macros (e.g., most versions of Scheme 48 and Pseudoscheme).
# If there are errors running this script, and you need to debug,
# don't use the initial.image, use something that has a reasonable
# environment.
#
# If this fails and you don't feel like debugging or fixing the problem,
# try "touch filenames.make" and hope for the best.

PACKAGES=packages.scm rts-packages.scm alt-packages.scm \
		comp-packages.scm initial-packages.scm link-packages.scm \
		more-packages.scm filenames.scm

filenames.make: $(PACKAGES)
	$(MAKE) $(VM) PACKAGES=
	./$(VM) -i $(INITIAL) -a batch <filenames.scm
# or:	$(RUNNABLE) -a batch <filenames.scm

# --------------------
# Static linker
#
# The linker is capable of rebuilding an image from sources, even
# across an incompatible change in VM data representations.

link/linker.image: $(linker-files) alt/init-defpackage.scm
	(echo ,batch; echo ,bench on;                  \
	 echo ,open signals handle features;           \
	 echo ,open bitwise ascii code-vectors record; \
	 echo ,load $(linker-files);		       \
	 echo ,load alt/init-defpackage.scm;	       \
	 echo ,dump link/linker.image)		       \
	| $(LINKER_RUNNABLE)

# Or, to bootstrap from Lucid Common Lisp: (last tested with
# Pseudoscheme 2.9 and Scheme 48 version 0.19)

PSEUDODIR = ../pseudo

link/linker-in-lucid: link/lucid-script.lisp $(linker-files) \
	    alt/pseudoscheme-features.scm alt/pseudoscheme-record.scm
	(echo \(defvar pseudoscheme-directory \"$(PSEUDODIR)/\"\); \
	 cat link/lucid-script.lisp; \
	 echo \(dump-linker\) \(lcl:quit\)) \
	| lisp

# --------------------
# Initial image
#
# The initial.image is built by the static linker.  The image contains
# Scheme, the byte-code compiler, and a minimal command processor, but
# no debugging environment to speak of.

$(INITIAL): $(LINKER_IMAGE) $(CONFIG_FILES) initial.scm $(initial-files)
	($(START_LINKER)               \
	 echo \(load-configuration \"interfaces.scm\"\); \
	 echo \(load-configuration \"packages.scm\"\); \
	 echo \(flatload initial-structures\); \
	 echo \(load \"initial.scm\"\);  \
	 echo \(link-initial-system\))   \
	| $(LINKER)

# --------------------
# Various small images for debugging low-level changes

LOAD_DEBUG = \
	 $(START_LINKER) \
	 echo \(load-configuration \"interfaces.scm\"\); \
	 echo \(load-configuration \"packages.scm\"\); \
	 echo \(flatload debug-structures\)

debug/tiny.image: $(LINKER_IMAGE) debug/tiny-packages.scm debug/tiny.scm
	($(START_LINKER) \
	 echo \(load-configuration \"debug/tiny-packages.scm\"\); \
	 echo \(link-simple-system \'\(debug tiny\) \'start tiny-system\)) \
	| $(LINKER)

debug/little.image: $(LINKER_IMAGE) $(CONFIG_FILES) debug-packages.scm
	($(LOAD_DEBUG); echo \(link-little-system\)) \
	| time $(LINKER)

debug/mini.image: $(LINKER_IMAGE) $(CONFIG_FILES)
	($(LOAD_DEBUG); echo \(link-mini-system\)) \
	| $(LINKER)

debug/medium.image: $(LINKER_IMAGE) $(CONFIG_FILES)
	($(LOAD_DEBUG); echo \(flatload compiler-structures\); \
	 echo \(link-medium-system\)) \
	| $(LINKER)

smain.o: main.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -DSTATIC_AREAS -o $@ $(srcdir)/main.c

mini: mini-heap.o smain.o
	$(CC) $(LDFLAGS) -o $@ smain.o mini-heap.o $(OBJS) $(LIBS)
mini-heap.o: mini-heap.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $(srcdir)/mini-heap.c
mini-heap.c: debug/mini1.image
	(echo ,exec ,load misc/load-static.scm; \
	 echo \(do-it 150000 \"$(srcdir)/debug/mini1.image\" \"$@\"\)) \
	| $(RUNNABLE) -h 3000000 -a batch
debug/mini1.image: $(VM) debug/mini.image
	echo "(write-image \"debug/mini1.image\" \
			   (usual-resumer (lambda (args) \
					    (command-processor #f args))) \
			   \"foo\")" \
	| ./$(VM) -i debug/mini.image -a batch


# --------------------
# Generate scheme48.h from VM sources

scheme48.h: vm/arch.scm vm/data.scm link/generate-c-header.scm
	(echo ,bench; \
	 echo ,load-package big-scheme; echo ,open big-scheme; \
	 echo ,load link/generate-c-header.scm; \
	 echo \(make-c-header-file \"$@\" \
				   \"$(srcdir)/vm/arch.scm\" \"$(srcdir)/vm/data.scm\"\)) \
	| $(RUNNABLE) -a batch

#scheme48vm.c: $(vm-files)
#	prescheme $(srcdir)/vm/compile-vm
