##############################################################################
#
# Makefile
#
# Make program to build a scheme image for the AXIOM-XL runtime
#
# Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
#
##############################################################################
#
# Targets: all, junk, clean, quick
#
#    make all	-- make the basic library for the AXIOM-XL compiler
#    make junk	-- list files which are not part of the AXIOM-XL compiler
#    make clean -- remove generated files  (e.g. foo.c~)
#
# Parameters:  ALDORROOT
#
#    To override defaults do, e.g.,
#	 make -e ALDORROOT=/spad/local/aldor/rs all
#    or
#	 setenv ALDORROOT /spad/local/aldor/rs; setenv MAKEFLAGS e; make all
#
##############################################################################
#
#  2006/Dec/22
#
#  On Solaris, the value of PWD does not change when make is invoked
#  recursively.  Consequently, it is necessary to explicitly set it
#  at the start of the makefile.
#
PWD = $(shell pwd)

# Environment

IncDir	= $(ALDORROOT)/include
LibDir	= $(ALDORROOT)/lib
LispDir = $(ALDORROOT)/lib
TestDir = ../../../test

AXIOMXL  = $(ALDORROOT)/bin/aldor

# file listing
FILELIST = `ar t $(LibDir)/libaxllib.al`

OKFILES = Makefile axllib.scm

# top level rules

all: $(LibDir)/axllib.boot

junk::
	@ ls -d $(OKFILES) * | sort | grep -v CVS | uniq -u

clean::
	@ rm -f *~ *.lsp core

test: $(LibDir)/mandel.out

# This is tacky:
#   Building scheme depends on the existence of a file 
#   scheme.build: The dependency simply ensures that the scheme
#   stuff is not built by default.

$(LibDir)/axllib.boot: $(LibDir)/scheme.test $(LibDir)/scheme.build $(AXIOMXL) $(LibDir)/libaxllib.al \
		      $(LibDir)/axllib.scm
	(cd $(LibDir) ; \
	for i in $(FILELIST); do ar x $(LibDir)/libaxllib.al $$i ; aldor -Flsp $$i ; done;\
	echo '(load "axllib.scm")(axllib:dump "axllib.boot")' | scheme;\
	for i in $(FILELIST); do ar x $(LibDir)/libaxllib.al $$i ; rm $$i ; done)

$(LibDir)/axllib.scm: $(LibDir)/libaxllib.al axllib.scm ../foam_s.scm
	cp axllib.scm $(LibDir)
	for i in $(FILELIST); do echo "(defmacro:load" \"`basename $$i .ao`.lsp\"\) >> $(LibDir)/axllib.scm; done

$(LibDir)/scheme.test:
	scheme < /dev/null

$(LibDir)/mandel.out: $(TestDir)/mandel.as $(LibDir)/axllib.boot
	aldor -R/tmp -Flsp $(TestDir)/mandel.as; \
	echo '(defmacro:load "/tmp/mandel.lsp")(call |G-mandel|)' | \
	            scheme -b $(LibDir)/axllib.boot > $(LibDir)/mandel.out
	rm /tmp/mandel.lsp	
