#*---------------------------------------------------------------------*/
#*   A pratical implementation for the Scheme programming language     */
#*                                                                     */
#*                                    ,--^,                            */
#*                              _ ___/ /|/                             */
#*                          ,;'( )__, ) '                              */
#*                         ;;  //   L__.                               */
#*                         '   \\   /  '                               */
#*                              ^   ^                                  */
#*                                                                     */
#*   Copyright (c) 1992-1999 Manuel Serrano                            */
#*                                                                     */
#*     Bug descriptions, use reports, comments or suggestions are      */
#*     welcome. Send them to                                           */
#*       bigloo-request@kaolin.unice.fr                                */
#*       http://kaolin.unice.fr/bigloo                                 */
#*                                                                     */
#*   This program is free software; you can redistribute it            */
#*   and/or modify it under the terms of the GNU General Public        */
#*   License as published by the Free Software Foundation; either      */
#*   version 2 of the License, or (at your option) any later version.  */
#*                                                                     */
#*   This program is distributed in the hope that it will be useful,   */
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of    */
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     */
#*   GNU General Public License for more details.                      */
#*                                                                     */
#*   You should have received a copy of the GNU General Public         */
#*   License along with this program; if not, write to the Free        */
#*   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,   */
#*   MA 02111-1307, USA.                                               */
#*---------------------------------------------------------------------*/
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/recette/Makefile                     */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Mon Nov  2 17:38:43 1992                          */
#*    Last change :  Sun Jun 28 16:04:24 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		= 
BFLAGS          = $(VERBOSE) -cg -rm -g -O3 -cc $(CC) -q -Wall \
                  -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 object1.o object2.o cfa2.o cell.o hygien.o   \
                  wind.o dsssl.o sua.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) $(BFLAGS) -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) $(BFLAGS) -c $*.scm

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

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

wind.o: wind.scm
	$(BIGLOO) $(BFLAGS) -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 BFLAGS=$(BFLAGS) >> $@
	@ 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) $(BFLAGS) -o recette $$(OBJECTS)' >> $@
	@ echo "" >> $@
	@ echo "clean:" >> $@
	@ echo '	@- rm -f $$(OBJECTS)' >> $@
	@ echo "" >> $@
	@ echo ".scm.o:" >> $@
	@ echo '	$$(BIGLOO) $$(BFLAGS) -c $$*.scm' >> $@
	@ echo "" >> $@
	@ echo ".c.o:" >> $@
	@ echo '	@ echo $$*.c:' >> $@
	@ echo '	@ $$(CC) $$(CFLAGS) -c -o $$*.o $$*.c' >> $@
	@ echo "" >> $@
	@ echo "callcc.o: callcc.scm" >> $@
	@ echo '	$$(BIGLOO) $$(BFLAGS) -c -call/cc callcc.scm' >> $@
	@ echo "" >> $@
	@ echo "fringe.o: fringe.scm" >> $@
	@ echo '	$$(BIGLOO) $$(BFLAGS) -c -call/cc fringe.scm' >> $@
