#* --------------------------------------------------------------------*/
#*    Copyright (c) 1992-1998 by Manuel Serrano. All rights reserved.  */
#*                                                                     */
#*                                     ,--^,                           */
#*                               _ ___/ /|/                            */
#*                           ,;'( )__, ) '                             */
#*                          ;;  //   L__.                              */
#*                          '   \   /  '                               */
#*                               ^   ^                                 */
#*                                                                     */
#*                                                                     */
#*    This program is distributed in the hope that it will be useful.  */
#*    Use and copying of this software and preparation of derivative   */
#*    works based upon this software are permitted, so long as the     */
#*    following conditions are met:                                    */
#*           o credit to the authors is acknowledged following         */
#*             current academic behaviour                              */
#*           o no fees or compensation are charged for use, copies,    */
#*             or access to this software                              */
#*           o this copyright notice is included intact.               */
#*      This software is made available AS IS, and no warranty is made */
#*      about the software or its performance.                         */
#*                                                                     */
#*      Bug descriptions, use reports, comments or suggestions are     */
#*      welcome. Send them to                                          */
#*        Manuel Serrano -- Manuel.Serrano@unice.fr                    */
#*-------------------------------------------------------------------- */
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/comptime/Makefile                    */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Jan 14 08:29:03 1998                          */
#*    Last change :  Wed Mar  4 11:27:18 1998 (serrano)                */
#*    -------------------------------------------------------------    */
#*    The Makefile to build the compiler part of Bigloo (bootstrap).   */
#*    This Makefile can be process by Gnu make or Sun make.            */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    Compilers, Tools and Destinations                                */
#*---------------------------------------------------------------------*/
# which C compiler to be used
CC              = gcc               
# the directory to write executable
BIN             = ../bin
# the libraries directory
LIB		= ../lib
# the (sources) include directory
INCLUDE		= ../runtime/Include
# the basename of the produced compiler
BIGLOO		= bigloo
# the executable used to compile (used to bootstrap)
BIGLOO_CMP      = $(BIN)/$(BIGLOO)
# the .afile
AFILE           = .afile
# to warn when done
BEEP            = echo -n ""
# the shell to be used
SHELL           = /bin/sh
# the produced executable
BIGLOO_DEST	= $(BIN)/$(BIGLOO)
# another produced executable
NEW_SUFFIX	= new
# another target.
DEFAULT		= plain
# the current Bigloo version
VERSION		= `$(BIGLOO_CMP) -revision`
# how to clean
CLEAN		= clean

#*---------------------------------------------------------------------*/
#*    Backups and revisions                                            */
#*---------------------------------------------------------------------*/
TAR		= tar
TARCOPT         = cf
TARXOPT         = xfp
GZIP		= gzip
BACKUPDIR	= $$HOUSE/backup
BACKUPNAME	= comptime
RESTOREDIR	= ../lib

#*---------------------------------------------------------------------*/
#*    Bigloo compilation flags                                         */
#*---------------------------------------------------------------------*/
# Commmon flags
COMMONFLAGS	= -afile $(AFILE) \
                  -fsharing       \
                  -fno-reflection \
                  -finline-method \
                  -cc $(CC)       \
                  -unsafev
# Optimized _and_ debugged compilation
OGBFLAGS        = $(COMMONFLAGS)  \
                  -O2 -Wall -g3 -cg -O2 -cg
# Bootstrap flag
BFLAGS		= $(OGBFLAGS)       
# Distribution flag
DISTBFLAGS	= $(COMMONFLAGS) -O2 -rm -unsafe
# Link flag
LDFLAGS         = "-s"
# C compiler flag
CFLAGS		= -O2

#*---------------------------------------------------------------------*/
#*    Afile and Depend tools                                           */
#*---------------------------------------------------------------------*/
EXAMPLES	= $(BIN)/../examples
AFILE_DIR	= $(EXAMPLES)/Afile
AFILE_SCM	= $(AFILE_DIR)/afile.scm
AFILE_EXE	= $(BIN)/afile
DEPEND_DIR	= $(EXAMPLES)/Depend
DEPEND_SCM	= $(DEPEND_DIR)/depend.scm
DEPEND_EXE	= $(BIN)/depend

#*---------------------------------------------------------------------*/
#*    License                                                          */
#*---------------------------------------------------------------------*/
LICENSE		= ../LICENSE

#*---------------------------------------------------------------------*/
#*    Sources                                                          */
#*---------------------------------------------------------------------*/
#*--- init ------------------------------------------------------------*/
INIT_LESS_MAIN_FILE	= parse-args setrc extend
INIT_FILE		= $(INIT_LESS_MAIN_FILE) main

INIT_LESS_MAIN_OBJ 	= $(INIT_LESS_MAIN_FILE:%=Init/%.o)
INIT_OBJ		= $(INIT_FILE:%=Init/%.o)

#*--- tools -----------------------------------------------------------*/
TOOLS_FILE	= args file location progn trace speek error shape misc \
                  date dsssl license

TOOLS_OBJ	= $(TOOLS_FILE:%=Tools/%.o)

#*--- engine ----------------------------------------------------------*/
ENGINE_FILE	= compiler engine param interp link signals pass

ENGINE_OBJ	= $(ENGINE_FILE:%=Engine/%.o)

#*--- heap ------------------------------------------------------------*/
HEAP_FILE	= restore make

HEAP_OBJ	= $(HEAP_FILE:%=Heap/%.o)

#*--- write -----------------------------------------------------------*/
WRITE_FILE	= version expanded scheme ast

WRITE_OBJ	= $(WRITE_FILE:%=Write/%.o)

#*--- read ------------------------------------------------------------*/
READ_FILE	= access include src inline load

READ_OBJ	= $(READ_FILE:%=Read/%.o)

#*--- module ----------------------------------------------------------*/
MODULE_FILE	= foreign impuse main prototype with class include      \
                  module statexp eval load pragma type library checksum \
                  option

MODULE_OBJ	= $(MODULE_FILE:%=Module/%.o)

#*--- ast -------------------------------------------------------------*/
AST_FILE	= build venv glo-decl node unit dump glo-def pragma     \
                  var find-gdefs ident remove local sexp labels let     \
                  exit substitute alphatize occur app apply lvtype      \
                  shrinkify

AST_OBJ		= $(AST_FILE:%=Ast/%.o)

#*--- cc --------------------------------------------------------------*/
CC_FILE		= exec indent cc ld

CC_OBJ		= $(CC_FILE:%=Cc/%.o)

#*--- foreign ---------------------------------------------------------*/
FOREIGN_FILE	= access cenum cptr ctype calias cfun cstruct
 
FOREIGN_OBJ	= $(FOREIGN_FILE:%=Foreign/%.o)

#*--- Type ------------------------------------------------------------*/
TYPE_FILE	= cache tenv type coercion tools typeof pptype

TYPE_OBJ	= $(TYPE_FILE:%=Type/%.o)

#*--- expand ----------------------------------------------------------*/
EXPAND_FILE	= eps assert case define expander garith iarith farith  \
                  if initial lambda let map struct exit object syntax

EXPAND_OBJ	= $(EXPAND_FILE:%=Expand/%.o)

#*--- inline ----------------------------------------------------------*/
INLINE_FILE	= walk inline app size simple recursion variant loop


INLINE_OBJ	= $(INLINE_FILE:%=Inline/%.o)

#*--- coerce ----------------------------------------------------------*/
COERCE_FILE	= walk pproto coerce typeof app funcall apply convert

COERCE_OBJ	= $(COERCE_FILE:%=Coerce/%.o)

#*--- globalize -------------------------------------------------------*/
GLOBALIZE_FILE	= walk ginfo escape gn node free kapture integration    \
                  new-body loc2glo gloclo clocto globalize

GLOBALIZE_OBJ	= $(GLOBALIZE_FILE:%=Globalize/%.o)

#*--- cnst ------------------------------------------------------------*/
CNST_FILE	= walk cache alloc node initialize

CNST_OBJ	= $(CNST_FILE:%=Cnst/%.o)

#*--- cfa -------------------------------------------------------------*/
CFA_FILE	= app cinfo iterate set approx collect loose show walk  \
                  setup vector cfa funcall procedure struct stack type  \
                  closure tvector box specialize

CFA_OBJ		= $(CFA_FILE:%=Cfa/%.o)

#*--- Integrate -------------------------------------------------------*/
INTEGRATE_FILE	= walk definition iinfo a kk u g ctn cto kaptured       \
                  let-fun loc2glo node free

INTEGRATE_OBJ	= $(INTEGRATE_FILE:%=Integrate/%.o)

#*--- Cgen ------------------------------------------------------------*/
CGEN_FILE	= walk emit proto main init cop emit-cop cgen capp

CGEN_OBJ	= $(CGEN_FILE:%=Cgen/%.o)

#*--- Hgen ------------------------------------------------------------*/
HGEN_FILE	= walk

HGEN_OBJ	= $(HGEN_FILE:%=Hgen/%.o)

#*--- tvector ---------------------------------------------------------*/
TVECTOR_FILE	= tvector access cnst

TVECTOR_OBJ	= $(TVECTOR_FILE:%=Tvector/%.o)

#*--- trace -----------------------------------------------------------*/
TRACE_FILE	= walk

TRACE_OBJ	= $(TRACE_FILE:%=Trace/%.o)

#*--- fail ------------------------------------------------------------*/
FAIL_FILE	= walk

FAIL_OBJ	= $(FAIL_FILE:%=Fail/%.o)

#*--- callcc ----------------------------------------------------------*/
CALLCC_FILE	= walk

CALLCC_OBJ	= $(CALLCC_FILE:%=Callcc/%.o)

#*--- reduce ----------------------------------------------------------*/
REDUCE_FILE	= walk cond typec copy cse same 1occ

REDUCE_OBJ	= $(REDUCE_FILE:%=Reduce/%.o)

#*--- effect ----------------------------------------------------------*/
EFFECT_FILE	= effect walk cgraph spread

EFFECT_OBJ	= $(EFFECT_FILE:%=Effect/%.o)

#*--- object ----------------------------------------------------------*/
OBJECT_FILE	= class generic method access struct slots tools inline

OBJECT_OBJ	= $(OBJECT_FILE:%=Object/%.o)

#*--- user ------------------------------------------------------------*/
USER_FILE	= user

USER_OBJ	= $(USER_FILE:%=User/%.o)

#*---------------------------------------------------------------------*/
#*    The object files                                                 */
#*---------------------------------------------------------------------*/
O_OBJECTS       = $(INIT_OBJ) $(ENGINE_OBJ) $(WRITE_OBJ)                \
                  $(READ_OBJ) $(AST_OBJ) $(CC_OBJ) $(FOREIGN_OBJ)       \
                  $(HEAP_OBJ) $(MODULE_OBJ) $(TYPE_OBJ) $(EXPAND_OBJ)   \
                  $(INLINE_OBJ) $(BIVALUE_OBJ) $(USER_OBJ) $(HGEN_OBJ)  \
                  $(COERCE_OBJ) $(GLOBALIZE_OBJ) $(CNST_OBJ) $(CFA_OBJ) \
		  $(INTEGRATE_OBJ) $(CGEN_OBJ) $(TVECTOR_OBJ)           \
                  $(TSTRUCT_OBJ) $(TRACE_OBJ) $(CALLCC_OBJ) $(EVAL_OBJ) \
                  $(LIFEXT_OBJ) $(FAIL_OBJ) $(REDUCE_OBJ) $(EFFECT_OBJ) \
                  $(OBJECT_OBJ) $(TOOLS_OBJ)

# This entry is used by QNC, for building bigloo++. Mainly Christian
# defines is own main entry point. This list does not contains the
# init/main.o file
O_LESS_MAIN_OBJECTS=$(INIT_LESS_MAIN_OBJ) $(ENGINE_OBJ) $(WRITE_OBJ)    \
                  $(READ_OBJ) $(AST_OBJ) $(CC_OBJ) $(FOREIGN_OBJ)       \
                  $(HEAP_OBJ) $(MODULE_OBJ) $(TYPE_OBJ) $(EXPAND_OBJ)   \
                  $(INLINE_OBJ) $(BIVALUE_OBJ) $(USER_OBJ) $(HGEN_OBJ)  \
                  $(COERCE_OBJ) $(GLOBALIZE_OBJ) $(CNST_OBJ) $(CFA_OBJ) \
		  $(INTEGRATE_OBJ) $(CGEN_OBJ) $(TVECTOR_OBJ)           \
                  $(TSTRUCT_OBJ) $(TRACE_OBJ) $(CALLCC_OBJ) $(EVAL_OBJ) \
                  $(LIFEXT_OBJ) $(FAIL_OBJ) $(REDUCE_OBJ) $(EFFECT_OBJ) \
                  $(OBJECT_OBJ) $(TOOLS_OBJ) 

C_OBJECTS	= $(O_OBJECTS:%.o=%.c)

SOURCE_FILES	= $(O_OBJECTS:%.o=%.scm)

POPULATION	= $(SOURCE_FILES)                                       \
		  Ast/node.sch                                          \
		  Ast/unit.sch                                          \
		  Engine/pass.sch                                       \
		  Expand/expander.sch                                   \
		  Init/args.sch                                         \
		  Object/class.sch                                      \
		  Tools/location.sch                                    \
		  Tools/trace.sch                                       \
		  Tvector/tvector.sch                                   \
		  Type/coercer.sch                                      \
                  Makefile

#*---------------------------------------------------------------------*/
#*    Suffixes                                                         */
#*---------------------------------------------------------------------*/
.SUFFIXES:
.SUFFIXES: .scm .c .o

#*---------------------------------------------------------------------*/
#*    Bootstrap (one round) the compiler                               */
#*---------------------------------------------------------------------*/
bigloo:
	@ $(MAKE) bigloo.$(DEFAULT)

#*---------------------------------------------------------------------*/
#*    distrib                                                          */
#*    -------------------------------------------------------------    */
#*    We prepare the compiler for a distribution                       */
#*---------------------------------------------------------------------*/
distrib: 
	@ if [ `pwd` = $$HOME/prgm/project/bigloo/comptime ]; then   \
             echo "*** ERROR:Illegal dir to make a distrib `pwd`";   \
             exit 1;                                                 \
          fi
	@ $(MAKE) $(CLEAN)
	@ $(MAKE) afile
	@ $(MAKE) dist-bigloo.exe BFLAGS="$(DISTBFLAGS)"
	@ $(MAKE) Dmakefile
	@ $(BIN)/copyright $(POPULATION)

#*---------------------------------------------------------------------*/
#*    bigloo.plain                                                     */
#*    -------------------------------------------------------------    */
#*    Because some OS does not support executable to be changed while  */
#*    running we cannot directly override the file used to compile.    */
#*    That is, if we are compiling Bigloo with a file called           */
#*    bin/bigloo we cannot directly produce a new version called       */
#*    bin/bigloo. Instead, we generate a file called bin/bigloo.plain  */
#*    and then, we rename this file into bin/bigloo.                   */
#*    -------------------------------------------------------------    */
#*    On a bootstrap, we _always_ change the compiler date. That's     */
#*    why, Tools/date.scm is erased and rebuild.                       */
#*---------------------------------------------------------------------*/
.PHONY: plain
plain: bigloo.plain
bigloo.plain: Tools/license.scm
	@- \rm -f Tools/date.scm
	@ $(MAKE) Tools/date.scm
	@ $(MAKE) $(BIGLOO_DEST)

#*---------------------------------------------------------------------*/
#*    bigloo.new                                                       */
#*---------------------------------------------------------------------*/
.PHONY: new
new: bigloo.new
bigloo.new:
	@ $(MAKE) $(BIGLOO_DEST).$(NEW_SUFFIX)
renew:
	@ \rm -f $(BIGLOO_DEST).$(NEW_SUFFIX)
	@ $(MAKE) new

#*---------------------------------------------------------------------*/
#*    bigloo                                                           */
#*---------------------------------------------------------------------*/
$(BIGLOO_DEST): $(O_OBJECTS)
	@ echo "Linking..."
	@ $(BIGLOO_CMP) $(BFLAGS) -static-bigloo -o $(BIGLOO_DEST).aux \
          $(O_OBJECTS) -ldopt $(LDBOOTFLAGS) $(LDFLAGS)
	@ mv $(BIGLOO_DEST).aux $(BIGLOO_DEST)
	@ echo "$(BIGLOO_DEST) done..."
	@ $(BEEP)
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    bigloo.new                                                       */
#*---------------------------------------------------------------------*/
$(BIGLOO_DEST).$(NEW_SUFFIX): $(O_OBJECTS)
	@ echo "Linking..."
	@ $(BIGLOO_CMP) $(BFLAGS) -o $(BIGLOO_DEST).$(NEW_SUFFIX)      \
                        $(O_OBJECTS) -static-bigloo -ldopt $(LDFLAGS)
	@ echo "$(BIGLOO_DEST).$(NEW_SUFFIX) done..."
	@ $(BEEP)
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    handlink                                                         */
#*    -------------------------------------------------------------    */
#*    This entry point links Bigloo manualy (just using CC).           */
#*    -------------------------------------------------------------    */
#*    If this target fails because of the VERSION variable that        */
#*    require Bigloo, you may invoke make with a value for VERSION     */
#*    (such as `make VERSION=1.9c handlink').                          */
#*---------------------------------------------------------------------*/
.PHONY: handlink handstrip
handlink: $(O_OBJECTS)
	@ echo "Hand linking:"
	$(CC) -o $(BIGLOO_DEST) $(O_OBJECTS) -L$(LIB) -lgc -lbigloo$(VERSION) -lm
	@ echo "$(BIGLOO_DEST) done."
	@ $(BEEP)
	@ echo "-------------------------------"

handstrip:
	strip $(BIGLOO_DEST)

#*---------------------------------------------------------------------*/
#*    mainnewo (for Bigloo++ regeneration)                             */
#*---------------------------------------------------------------------*/
mainnewo: $(O_LESS_MAIN_OBJECTS_OBJECTS)
	@ $(BIGLOO_CMP) $(BFLAGS) -o $(BIGLOO_DEST) $(ADDITIONAL_BFLAGS) \
	    $(INIT_MAIN_SCM) $(O_LESS_MAIN_OBJECTS) $(ADDITIONAL_LIBRARIES)

#*---------------------------------------------------------------------*/
#*    dist-bigloo.exe                                                  */
#*---------------------------------------------------------------------*/
dist-bigloo.exe: $(C_OBJECTS)
	@ echo "Comptime (distribution) done..."
	@ $(BEEP)
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    Tools/date.scm                                                   */
#*    -------------------------------------------------------------    */
#*    We produce a legal Scheme file, that implements a function,      */
#*    returning the date of the compiler bootstrap.                    */
#*---------------------------------------------------------------------*/
Tools/date.scm:
	@- rm -f $@
	@ echo ";; Automatically generated file (don't edit)" > $@
	@ echo "(module tools_date (export (bigloo-date)))" >> $@
	@ echo "" >> $@
	@ echo "(define (bigloo-date) " \" `date` \"")" >> $@

#*---------------------------------------------------------------------*/
#*    Tools/license.scm                                                */
#*    -------------------------------------------------------------    */
#*    We produce the license module from the official Bigloo license.  */
#*---------------------------------------------------------------------*/
Tools/license.scm: $(LICENSE)
	@- rm -f $@
	@ echo ";; Automatically generated file (don't edit)" > $@
	@ echo "(module tools_license (export (bigloo-license)))" >> $@
	@ echo "" >> $@
	@ echo "(define (bigloo-license)" >> $@
	@ echo " \" `cat ../LICENSE` \")" >> $@

#*---------------------------------------------------------------------*/
#*    afile                                                            */
#*    -------------------------------------------------------------    */
#*    This entry point produce the .afile file, the .etags file for    */
#*    emacs and update the Makefile for dependences.                   */
#*---------------------------------------------------------------------*/
.PHONY: afile
afile: $(AFILE_EXE) Tools/date.scm Tools/license.scm
	@ echo "   - .afile"
	@ $(AFILE_EXE) -o $(AFILE) $(SOURCE_FILES)
	@ echo "   - dep"
	@ $(MAKE) dep
	@ echo "   - .etags"
	@ $(MAKE) tags

#*---------------------------------------------------------------------*/
#*    tags                                                             */
#*    -------------------------------------------------------------    */
#*    The emacs .etags file                                            */
#*---------------------------------------------------------------------*/
.PHONY: tags
tags:
	@ etags -o .etags $(SOURCE_FILES)

#*---------------------------------------------------------------------*/
#*    qnctags                                                          */
#*---------------------------------------------------------------------*/
.PHONY: qnctags
qnctags:
	@ etags `find . -name '*.scm' -print -o -name '*.[ch]' -print`

#*---------------------------------------------------------------------*/
#*    dep                                                              */
#*---------------------------------------------------------------------*/
.PHONY: dep
dep: $(DEPEND_EXE) Tools/date.scm Tools/license.scm
	@ - head -`grep -n \^#depend Makefile | awk -F: '{ print $$1}' -` Makefile > /tmp/Makefile.aux
	@ $(DEPEND_EXE) $(SOURCE_FILES) >> /tmp/Makefile.aux
	@ mv /tmp/Makefile.aux Makefile

#*---------------------------------------------------------------------*/
#*    AFILE_EXE                                                        */
#*    -------------------------------------------------------------    */
#*    The entry that build the afile executable                        */
#*---------------------------------------------------------------------*/
$(AFILE_EXE): $(AFILE_SCM)
	(cd $(AFILE_DIR);                \
         $(MAKE) BIGLOO=../$(BIGLOO_CMP) \
                 BFLAGS="-O2 -unsafe"    \
                 DEST=../$(AFILE_EXE))

#*---------------------------------------------------------------------*/
#*    depend                                                           */
#*    -------------------------------------------------------------    */
#*    The entry that build the depend tool                             */
#*---------------------------------------------------------------------*/
$(DEPEND_EXE): $(DEPEND_SCM)
	(cd $(DEPEND_DIR);               \
         $(MAKE) BIGLOO=../$(BIGLOO_CMP) \
                 BFLAGS="-O2 -unsafe"    \
                 DEST=../$(DEPEND_EXE))

#*---------------------------------------------------------------------*/
#*     clean ...                                                       */
#*---------------------------------------------------------------------*/
.PHONY: Clean clean fast-clean

fast-clean:
	@- rm -f $(O_OBJECTS)
	@- rm -f $(AFILE)
	@- rm -f .etags
	@ find . \( -name '*[~%]'                   \
                       -o -name '.??*[~%]'          \
                       -o -name '#*#'               \
                       -o -name '?*#'               \
                       -o -name \*core \)           \
                     -type f -exec rm {} \;   
	@ echo "cleanup done..."
	@ $(BEEP)
	@ echo "-------------------------------"

clean: fast-clean
	@- rm -f Dmakefile
	@- rm -f $(C_OBJECTS)

Clean: clean
	@- rm -f Tools/date.scm Tools/license.scm
	@- rm -f $(BIGLOO_DEST)
	@- rm -f $(AFILE_EXE) 
	@- rm -f $(DEPEND_EXE)

Dclean: 
	@- rm -f $(O_OBJECTS)

DClean:
	@- rm -f Tools/date.scm Tools/license.scm
	@- rm -f $(BIGLOO_DEST)
	@- rm -f $(AFILE_EXE) 
	@- rm -f $(DEPEND_EXE)

#*---------------------------------------------------------------------*/
#*     touchall ...                                                    */
#*---------------------------------------------------------------------*/
.PHONY: touchall
touchall:
	@ touch $(SOURCE_FILES)
	@ echo "touchall done..."
	@ $(BEEP)
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*     .scm --> .o                                                     */
#*---------------------------------------------------------------------*/
.scm.o:
	@ $(BIGLOO_CMP) $(BFLAGS) -c $*.scm -o $*.o

#*---------------------------------------------------------------------*/
#*     .scm --> .c                                                     */
#*---------------------------------------------------------------------*/
.scm.c:
	$(BIGLOO_CMP) $(BFLAGS) -indent $*.scm

#*---------------------------------------------------------------------*/
#*    Dmakefile                                                        */
#*    -------------------------------------------------------------    */
#*    This entry build the Dmakefile file that is used to boot         */
#*    Bigloo (from .c file) on a new host.                             */
#*    -------------------------------------------------------------    */
#*    This entry can be used only on a platform that has bootstrapped  */
#*    Bigloo. That is, this makefile cannot be generated on a          */
#*    platform that wants to install Bigloo.                           */
#*---------------------------------------------------------------------*/
Dmakefile: Makefile
	@- rm -f Dmakefile
	@ echo "# !!! This is a generated file, don't edit !!!" > $@
	@ echo "CC=$(CC)" >> $@
	@ echo "CFLAGS=$(CFLAGS)" >> $@
	@ echo "VERSION=$(VERSION)" >> $@
	@ echo "BIGLOO_DEST=bigloo$$""(VERSION)" >> $@
	@ echo "LIBS=$(LIB)/lib$$""(LIBRARYNAME)$$""(VERSION).a $(LIB)/libgc.a" >> $@
	@ echo "shell=sh" >> $@
	@ echo "" >> $@
	@ echo "OBJECTS=$(O_OBJECTS)" >> $@
	@ echo "" >> $@
	@ echo "../bin/bigloo: ../bin/$$""(BIGLOO_DEST)" >> $@
	@ echo "	(cd ../bin; ln -s $$""(BIGLOO_DEST) bigloo)" >> $@
	@ echo "" >> $@
	@ echo "../bin/$$""(BIGLOO_DEST): $$""(OBJECTS)" >> $@
	@ echo "	$$""(CC) $$""(CFLAGS) -o ../bin/$$""(BIGLOO_DEST) $$""(OBJECTS) $$""(LIBS) -lm" >> $@
	@ echo "	@ echo \"bigloo$$""(VERSION) done...\"" >> $@
	@ echo "" >> $@
	@ echo "clean:" >> $@
	@ echo '	@- rm -f $$(OBJECTS)' >> $@
	@ echo '	@- rm -f $$(BIGLOO_DEST)' >> $@
	@ echo "" >> $@
	@ echo "%.o: %.c" >> $@
	@ echo '	$$(CC) -I$(LIB) $$(CFLAGS) $$*.c -c && mv `basename $$*.o` $$*.o' >> $@

#*---------------------------------------------------------------------*/
#*    pop                                                              */
#*    -------------------------------------------------------------    */
#*    This entry is used by the bigloo/Makefile (the main Bigloo       */
#*    makefile) to get the list of file that populate a revision.      */
#*---------------------------------------------------------------------*/
.PHONY: pop
pop: Tools/date.scm Tools/license.scm
	@ echo $(POPULATION:%=$(BACKUPNAME)/%)

#*---------------------------------------------------------------------*/
#*    backup                                                           */
#*---------------------------------------------------------------------*/
.PHONY: backup
backup:
	@ echo "Backuping $(BACKUPNAME) in $(BACKUPDIR)"
	@ $(MAKE) backup-lib-dir
	@ (\rm -f $(BACKUPDIR)/$(BACKUPNAME).tar.gz;                 \
	   cleanup;                                                  \
           $(TAR) $(TARCOPT) $(BACKUPDIR)/$(BACKUPNAME).tar          \
                             $(POPULATION);                          \
           $(GZIP) $(BACKUPDIR)/$(BACKUPNAME).tar)
	@ $(MAKE) restore-lib-dir
	@ echo "done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    restore ...                                                      */
#*---------------------------------------------------------------------*/
.PHONY: restore
restore:
	@ echo "Restoring $(BACKUPNAME) from $(BACKUPDIR)"
	@ ($(GZIP) -d --to-stdout $(BACKUPDIR)/$(BACKUPNAME).tar.gz | \
          $(TAR) $(TARXOPT) -)
	@ $(MAKE) restore-lib-dir
	@ echo "done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    backup-lib-dir                                                   */
#*---------------------------------------------------------------------*/
backup-lib-dir:
	@ echo "unsetting default lib dir [$(RESTOREDIR)] in Engine/param.scm"
	@ cat Engine/param.scm | sed -e s,"$(RESTOREDIR)","the-default-lib-dir", > Engine/param.new
	@ mv Engine/param.new Engine/param.scm

#*---------------------------------------------------------------------*/
#*    restore-lib-dir                                                  */
#*---------------------------------------------------------------------*/
restore-lib-dir: Engine/param.scm
	@ echo "setting default lib dir [$(RESTOREDIR)] in Engine/param.scm"
	@ cat Engine/param.scm | sed -e s,"the-default-lib-dir","$(RESTOREDIR)", > Engine/param.new
	@ mv Engine/param.new Engine/param.scm

#*---------------------------------------------------------------------*/
#*    Dependences                                                      */
#*---------------------------------------------------------------------*/
Engine/param.o: $(INCLUDE)/bigloo_cfg.h
#depend
Tools/shape.o: Ast/node.sch Tvector/tvector.sch
Tools/error.o: Tools/location.sch Ast/node.sch
Tools/location.o: Tools/location.sch
Object/inline.o: Tools/trace.sch
Object/tools.o: Object/class.sch
Object/slots.o: Object/class.sch
Object/struct.o: Object/class.sch
Object/access.o: Object/class.sch
Object/class.o: Object/class.sch
Effect/spread.o: Ast/node.sch
Effect/cgraph.o: Ast/node.sch Tools/trace.sch
Effect/walk.o: Engine/pass.sch Tools/trace.sch
Effect/effect.o: Ast/node.sch
Reduce/1occ.o: Tools/trace.sch
Reduce/same.o: Tools/trace.sch
Reduce/cse.o: Tools/trace.sch
Reduce/copy.o: Tools/trace.sch
Reduce/typec.o: Tools/trace.sch
Reduce/cond.o: Tools/trace.sch
Reduce/walk.o: Engine/pass.sch
Fail/walk.o: Engine/pass.sch Tools/location.sch Ast/node.sch
Callcc/walk.o: Engine/pass.sch Ast/node.sch
Trace/walk.o: Engine/pass.sch Ast/node.sch
Tvector/cnst.o: Tvector/tvector.sch
Cgen/capp.o: Tools/trace.sch
Cgen/cgen.o: Tools/trace.sch
Cgen/proto.o: Tvector/tvector.sch
Cgen/walk.o: Engine/pass.sch Ast/unit.sch Tools/trace.sch
Integrate/free.o: Tools/trace.sch
Integrate/node.o: Tools/trace.sch
Integrate/loc2glo.o: Tools/trace.sch
Integrate/let-fun.o: Tools/trace.sch
Integrate/kaptured.o: Tools/trace.sch
Integrate/cto.o: Tools/trace.sch
Integrate/ctn.o: Tools/trace.sch
Integrate/g.o: Tools/trace.sch
Integrate/u.o: Tools/trace.sch
Integrate/kk.o: Tools/trace.sch
Integrate/a.o: Tools/trace.sch
Integrate/definition.o: Tools/trace.sch
Integrate/walk.o: Engine/pass.sch
Cfa/specialize.o: Tools/trace.sch
Cfa/box.o: Tools/trace.sch
Cfa/tvector.o: Tools/trace.sch Ast/unit.sch Tvector/tvector.sch
Cfa/closure.o: Tools/trace.sch
Cfa/stack.o: Tools/trace.sch
Cfa/struct.o: Tools/trace.sch
Cfa/procedure.o: Tools/trace.sch
Cfa/funcall.o: Tools/trace.sch
Cfa/cfa.o: Tools/trace.sch
Cfa/vector.o: Tools/trace.sch
Cfa/setup.o: Tools/trace.sch
Cfa/walk.o: Engine/pass.sch
Cfa/show.o: Tools/trace.sch
Cfa/loose.o: Tools/trace.sch
Cfa/collect.o: Tools/trace.sch
Cfa/iterate.o: Tools/trace.sch
Cfa/app.o: Tools/trace.sch
Cnst/initialize.o: Tools/trace.sch Ast/unit.sch
Cnst/node.o: Tools/trace.sch Tvector/tvector.sch
Cnst/alloc.o: Tvector/tvector.sch
Cnst/walk.o: Engine/pass.sch
Globalize/globalize.o: Tools/trace.sch
Globalize/clocto.o: Tools/trace.sch
Globalize/gloclo.o: Tools/trace.sch
Globalize/loc2glo.o: Tools/trace.sch
Globalize/new-body.o: Tools/trace.sch
Globalize/integration.o: Tools/trace.sch
Globalize/kapture.o: Tools/trace.sch
Globalize/free.o: Tools/trace.sch
Globalize/node.o: Tools/trace.sch
Globalize/gn.o: Tools/trace.sch
Globalize/ginfo.o: Ast/node.sch
Globalize/walk.o: Engine/pass.sch Ast/node.sch
Coerce/convert.o: Tools/trace.sch Tools/location.sch Type/coercer.sch
Coerce/apply.o: Tools/trace.sch Tools/location.sch
Coerce/funcall.o: Tools/trace.sch Tools/location.sch
Coerce/app.o: Tools/trace.sch
Coerce/coerce.o: Tools/trace.sch
Coerce/walk.o: Engine/pass.sch
Hgen/walk.o: Engine/pass.sch
User/user.o: Engine/pass.sch Ast/unit.sch
Inline/loop.o: Tools/trace.sch
Inline/variant.o: Tools/trace.sch
Inline/recursion.o: Tools/trace.sch
Inline/simple.o: Tools/trace.sch
Inline/size.o: Ast/node.sch
Inline/app.o: Tools/trace.sch
Inline/inline.o: Ast/node.sch Tools/trace.sch
Inline/walk.o: Engine/pass.sch Tools/trace.sch Ast/node.sch
Expand/syntax.o: Tools/trace.sch Engine/pass.sch Ast/unit.sch
Expand/object.o: Object/class.sch
Expand/exit.o: Expand/expander.sch Tools/trace.sch
Expand/if.o: Tools/trace.sch
Expand/expander.o: Expand/expander.sch
Expand/define.o: Expand/expander.sch Tools/trace.sch
Expand/case.o: Tools/trace.sch
Expand/assert.o: Tools/location.sch
Expand/eps.o: Expand/expander.sch Tools/trace.sch Engine/pass.sch Ast/unit.sch
Type/typeof.o: Tvector/tvector.sch
Type/coercion.o: Type/coercer.sch
Type/tenv.o: Tools/trace.sch
Module/option.o: Ast/unit.sch
Module/checksum.o: Ast/unit.sch Engine/pass.sch
Module/library.o: Ast/unit.sch
Module/type.o: Ast/unit.sch Tools/trace.sch
Module/eval.o: Ast/unit.sch Ast/node.sch
Module/statexp.o: Ast/unit.sch
Module/module.o: Ast/unit.sch Engine/pass.sch
Module/include.o: Ast/unit.sch
Module/class.o: Ast/unit.sch Object/class.sch Tools/trace.sch
Module/impuse.o: Ast/unit.sch Tools/trace.sch
Module/foreign.o: Ast/unit.sch Tools/trace.sch
Heap/make.o: Engine/pass.sch
Heap/restore.o: Engine/pass.sch
Foreign/cstruct.o: Tools/trace.sch
Foreign/calias.o: Tools/trace.sch
Foreign/ctype.o: Tools/trace.sch
Foreign/cptr.o: Tools/trace.sch
Cc/exec.o: Tools/trace.sch
Ast/apply.o: Ast/node.sch
Ast/app.o: Ast/node.sch
Ast/occur.o: Ast/node.sch
Ast/alphatize.o: Ast/node.sch Tools/location.sch
Ast/substitute.o: Tools/trace.sch
Ast/exit.o: Ast/node.sch Tools/trace.sch
Ast/let.o: Ast/node.sch Tools/trace.sch
Ast/labels.o: Ast/node.sch Tools/trace.sch
Ast/sexp.o: Tools/trace.sch
Ast/remove.o: Ast/node.sch
Ast/find-gdefs.o: Ast/node.sch
Ast/pragma.o: Ast/node.sch
Ast/glo-def.o: Tools/trace.sch
Ast/dump.o: Tvector/tvector.sch Ast/node.sch
Ast/unit.o: Ast/unit.sch Ast/node.sch Tools/trace.sch
Ast/glo-decl.o: Tools/trace.sch
Ast/build.o: Engine/pass.sch Ast/node.sch
Read/load.o: Tools/trace.sch
Read/inline.o: Tools/trace.sch Ast/unit.sch
Write/ast.o: Engine/pass.sch Ast/node.sch
Write/expanded.o: Ast/unit.sch
Engine/compiler.o: Ast/unit.sch Engine/pass.sch
Init/parse-args.o: Init/args.sch Tools/trace.sch

