#* --------------------------------------------------------------------*/
#*    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/recette/Makefile                     */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Mon Nov  2 17:38:43 1992                          */
#*    Last change :  Thu Mar 12 07:22:06 1998 (serrano)                */
#*    -------------------------------------------------------------    */
#*    The Makefile to build the recette                                */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    Compilers, Tools and Destinations                                */
#*---------------------------------------------------------------------*/
# which C compiler to be used
CC              = gcc
# the directory to write executable
BIN             = ../bin
# the executable used to bootstrap
BIGLOO          = $(BIN)/bigloo
# to warn when done
BEEP            = echo -n ""
# the shell to be used
SHELL           = /bin/sh
# lint
LINT		= lint

#*---------------------------------------------------------------------*/
#*    Backups and revisions                                            */
#*---------------------------------------------------------------------*/
BACKUPDIR	= $$HOUSE/backup
BACKUPNAME	= recette

#*---------------------------------------------------------------------*/
#*    Compiler flags                                                   */
#*---------------------------------------------------------------------*/
# C compiler
CFLAGS      	= $(INCLUDE) -O -g
# lint options
LINTFLAGS	= -u -v $(INCLUDE)

#*---------------------------------------------------------------------*/
#*  !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!  WARNING !!!   */
#*    -------------------------------------------------------------    */
#*  The recette can't be compiled in `-unsafe' mode (due to try forms) */
#*    -------------------------------------------------------------    */
#*  The recette can't be compiled with the `-fsharing' option          */
#*---------------------------------------------------------------------*/
VERBOSE		= 
BG_FLAGS        = $(VERBOSE) -cg -rm -g -O3 -cc $(CC) -q \
                  -eval "(set! *indent* (= 1 2))" -copt ""

#*---------------------------------------------------------------------*/
#*    Les objects destinations                                         */
#*---------------------------------------------------------------------*/
OBJECTS		= vital.o bool.o list.o vector.o struct.o print.o       \
                  string.o kwote.o case.o bexit.o vararity.o apply.o    \
                  globalis.o filtre.o rgc-trap.o rgc-jm.o port.o        \
                  read.o callcc.o fringe.o tail.o foreign.o big-file.o  \
                  sqic.o eval.o inline.o match.o letrec.o macro.o       \
                  flonum.o number.o char.o define.o error.o cse.o       \
                  kapture.o include.o 0cfa.o alias.o alias-aux.o main.o \
                  rgc-eval.o rgc.o hash.o module.o import1.o import2.o  \
                  object.o cfa2.o cell.o hygien.o wind.o

OBJECT_C_FOREIGN= c-file.o

LN_OBJECTS	= $(OBJECTS:%.o=%.ln)

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

SOURCE_FILES	= $(OBJECTS:%.o=%.scm) c-file.c

POPULATION	= $(SOURCE_FILES)           \
                  Makefile                  \
                  test.sch                  \
                  c-file.h                  \
		  include.sch               \
		  include2.sch              \
		  misc

#*---------------------------------------------------------------------*/
#*    recette                                                          */
#*---------------------------------------------------------------------*/
recette: $(OBJECTS) $(OBJECT_C_FOREIGN) 
	$(BIGLOO) $(BG_FLAGS) -o recette $(OBJECT_C_FOREIGN) $(OBJECTS)
	@ echo "Recette Done..."
	@ $(BEEP)
	@ echo "-------------------------------"

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

#*---------------------------------------------------------------------*/
#*    backup                                                           */
#*---------------------------------------------------------------------*/
backup:
	@ echo "Backuping $(BACKUPNAME) in $(BACKUPDIR)"
	@ (\rm -f $(BACKUPDIR)/$(BACKUPNAME).tar.gz;                   \
	   cleanup;                                                    \
           tar cf $(BACKUPDIR)/$(BACKUPNAME).tar $(POPULATION);        \
           gzip $(BACKUPDIR)/$(BACKUPNAME).tar)
	@ echo "done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    restore ...                                                      */
#*---------------------------------------------------------------------*/
restore:
	@ echo "Restoring $(BACKUPNAME) from $(BACKUPDIR)"
	@ (gzip -d --to-stdout $(BACKUPDIR)/$(BACKUPNAME).tar.gz | tar xfp -)
	@ echo "done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    pop                                                              */
#*---------------------------------------------------------------------*/
pop:
	@ echo $(POPULATION:%=recette/%)

#*---------------------------------------------------------------------*/
#*     Les suffixes ...                                                */
#*---------------------------------------------------------------------*/
.SUFFIXES:
.SUFFIXES: .o .scm .c .ln

#*---------------------------------------------------------------------*/
#*    .scm.o                                                           */
#*---------------------------------------------------------------------*/
.scm.o:
	$(BIGLOO) $(BG_FLAGS) -c $*.scm

#*---------------------------------------------------------------------*/
#*    Certains fichiers doivent etre compiles avec des flags           */
#*    supplementaires. On les rajoute maintenant                       */
#*---------------------------------------------------------------------*/
callcc.o: callcc.scm
	$(BIGLOO) $(BG_FLAGS) -c -call/cc $*.scm

fringe.o: fringe.scm
	$(BIGLOO) $(BG_FLAGS) -c -call/cc $*.scm

wind.o: wind.scm
	$(BIGLOO) $(BG_FLAGS) -c -call/cc $*.scm

#*---------------------------------------------------------------------*/
#*    .c.o                                                             */
#*---------------------------------------------------------------------*/
.c.o:
	@ echo "$*.c:"
	@ $(CC) $(CFLAGS) -c -o $*.o $*.c

#*---------------------------------------------------------------------*/
#*    .c.ln                                                            */
#*---------------------------------------------------------------------*/
.c.ln:
	@ echo "$*.c:"
	@ $(LINT) $(LINTFLAGS) $*.c > $*.ln

#*---------------------------------------------------------------------*/
#*     touchall ...                                                    */
#*---------------------------------------------------------------------*/
touchall:
	@ touch *.scm c-file.c
	@ echo "touch done..."
	@ $(BEEP)
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    clean                                                            */
#*---------------------------------------------------------------------*/
clean: cleanlint
	@- \rm -f $(OBJECTS)
	@- \rm -f $(C_OBJECTS)
	@- \rm -f $(OBJECT_C_FOREIGN)
	@- \rm -f recette
	@- \rm -f recette.log
	@- \rm -f *.tree
	@- \rm -f *.ast
	@- \rm -f *.escm
	@- \rm -f Dmakefile
	@ find . \( -name '*[~%]'                   \
                       -o -name '.??*[~%]'          \
                       -o -name '#*#'               \
                       -o -name '?*#'               \
                       -o -name '*.BAK'             \
                       -o -name \*core \)           \
                     -type f -exec rm {} \;   
	@ echo "Clean up done..."
	@ $(BEEP)
	@ echo "-------------------------------"

Dclean: clean

#*---------------------------------------------------------------------*/
#*    wc                                                               */
#*---------------------------------------------------------------------*/
wc:
	@ wc *.scm
	@ echo "wc done..."
	@ $(BEEP)
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    lint                                                             */
#*---------------------------------------------------------------------*/
lint: all.lint
	@ echo "lint done..."
	@ $(BEEP)
	@ echo "-------------------------------"

all.lint: $(LN_OBJECTS)
	@- \rm -f all.lint
	@- touch all.lint
	@ ( for p in *.ln;                 \
            do echo "   " $$p >> all.lint; \
            cat $$p >> all.lint;           \
            done )

#*---------------------------------------------------------------------*/
#*    cleanlint                                                        */
#*---------------------------------------------------------------------*/
cleanlint:
	@- \rm -f $(LN_OBJECTS)
	@- \rm -f all.lint

#*---------------------------------------------------------------------*/
#*    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 BG_FLAGS=$(BG_FLAGS) >> $@
	@ echo "BIN=../bin" >> $@
	@ echo 'BIGLOO=$$(BIN)/bigloo' >> $@
	@ echo "" >> $@
	@ echo "OBJECTS=$(OBJECTS) $(OBJECT_C_FOREIGN)" >> $@
	@ echo "" >> $@
	@ echo ".SUFFIXES:" >> $@
	@ echo ".SUFFIXES: .scm .c .o" >> $@
	@ echo "" >> $@
	@ echo "recette: $(OBJECTS)" >> $@
	@ echo '	$$(BIGLOO) $(BG_FLAGS) -o recette $$(OBJECTS)' >> $@
	@ echo "" >> $@
	@ echo "clean:" >> $@
	@ echo '	@- rm -f $$(OBJECTS)' >> $@
	@ echo "" >> $@
	@ echo ".scm.o:" >> $@
	@ echo '	$$(BIGLOO) $$(BG_FLAGS) -c $$*.scm' >> $@
	@ echo "" >> $@
	@ echo ".c.o:" >> $@
	@ echo '	@ echo $$*.c:' >> $@
	@ echo '	@ $$(CC) $$(CFLAGS) -c -o $$*.o $$*.c' >> $@
	@ echo "" >> $@
	@ echo "callcc.o: callcc.scm" >> $@
	@ echo '	$$(BIGLOO) $$(BG_FLAGS) -c -call/cc callcc.scm' >> $@
	@ echo "" >> $@
	@ echo "fringe.o: fringe.scm" >> $@
	@ echo '	$$(BIGLOO) $$(BG_FLAGS) -c -call/cc fringe.scm' >> $@
