#*---------------------------------------------------------------------*/
#*   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/out/bigloo1.9e/cigloo/Makefile                           */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Jan 14 14:46:31 1998                          */
#*    Last change :  Fri Jan 15 09:38:44 1999 (serrano)                */
#*    -------------------------------------------------------------    */
#*    The Makefile to build Cigloo. This makefile has to be processed  */
#*    either 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 executable used to bootstrap
BIGLOO          = $(BIN)/bigloo     
# the .afile
AFILE           = .afile
# to warn when done
BEEP            = echo -n ""
# the shell to be used
SHELL           = /bin/sh
# the produced executable
CIGLOO_DEST	= $(BIN)/cigloo
# how to clean
CLEAN		= clean

#*---------------------------------------------------------------------*/
#*    Afile and Depend tools                                           */
#*---------------------------------------------------------------------*/
AFILE_EXE	= $(BIN)/afile
DEPEND_EXE	= $(BIN)/bdepend

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

#*---------------------------------------------------------------------*/
#*    Compilation flags                                                */
#*---------------------------------------------------------------------*/
BDBGFLAGS	= -afile $(AFILE) -g2 -cg -O +rm -fsharing
BOPTFLAGS	= -afile $(AFILE) -O2 -rm -fsharing -unsafe
BFLAGS		= $(BDBGFLAGS)
CFLAGS          = 

#*---------------------------------------------------------------------*/
#*    Les sources                                                      */
#*---------------------------------------------------------------------*/
#*--- init ------------------------------------------------------------*/
INIT_FILE	= main setrc parse-args

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

#*--- engine ----------------------------------------------------------*/
ENGINE_FILE	= engine param translate

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

#*--- translate -------------------------------------------------------*/
TRANSLATE_FILE	= function declaration type decl tspec expr eval

TRANSLATE_OBJ	= $(TRANSLATE_FILE:%=Translate/%.o)


#*--- tools -----------------------------------------------------------*/
TOOLS_FILE	= date speek error file

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

#*--- write -----------------------------------------------------------*/
WRITE_FILE	= version

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

#*--- parser ---------------------------------------------------------*/
PARSER_FILE	= parser lexer tools cpp

PARSER_OBJ	= $(PARSER_FILE:%=Parser/%.o)

#*---------------------------------------------------------------------*/
#*    Tout le code ...                                                 */
#*---------------------------------------------------------------------*/
O_OBJECTS       = $(INIT_OBJ) $(ENGINE_OBJ) $(PARSE_OBJ) $(TOOLS_OBJ)   \
                  $(WRITE_OBJ) $(PARSER_OBJ) $(TRANSLATE_OBJ)

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

POPULATION	= $(SOURCE_FILES)           \
                  Makefile                  \
                  Init/args.sch             \
                  Parser/coord.sch          \
                  Translate/ast.sch         \
                  Translate/type.sch        \
                  Translate/function.sch    \
                  Tools/union.sch           \
                  Example/Makefile          \
	 	  Example/b-file.scm        \
	          Example/c-file.h          \
	          Example/c-file.c          \
                  .afile

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

#*---------------------------------------------------------------------*/
#*    L'executable `cigloo'                                            */
#*---------------------------------------------------------------------*/
cigloo: Tools/date.scm
	@ $(MAKE) $(CIGLOO_DEST)

#*---------------------------------------------------------------------*/
#*    $(CIGLOO_DEST)                                                   */
#*---------------------------------------------------------------------*/
$(CIGLOO_DEST): $(O_OBJECTS)
	@ echo "Linking:"
	@ $(BIGLOO) $(BFLAGS) $(O_OBJECTS) -o $(CIGLOO_DEST)
	@ strip $(CIGLOO_DEST) 2> /dev/null
	@ echo "Cigloo Done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    afile                                                            */
#*---------------------------------------------------------------------*/
afile: Tools/date.scm
	@ echo "   - .afile"
	@ $(AFILE_EXE) -o $(AFILE) $(SOURCE_FILES)
	@ echo "   - dep"
	@ $(MAKE) dep
	@ echo "   - .etags"
	@ $(MAKE) tags

#*---------------------------------------------------------------------*/
#*    tags                                                             */
#*---------------------------------------------------------------------*/
tags:
	@ etags -o .etags $(SOURCE_FILES) 

#*---------------------------------------------------------------------*/
#*    dep                                                              */
#*---------------------------------------------------------------------*/
dep:
	@(num=`grep -n '^#bdepend start' Makefile | awk -F: '{ print $$1}' -`;\
          head -`expr $$num - 1` Makefile > /tmp/Makefile.aux)
	@ $(DEPEND_EXE) $(SOURCE_FILES) >> /tmp/Makefile.aux
	@ mv /tmp/Makefile.aux Makefile

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

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

clean: fast-clean

Clean: clean
	@- rm -f $(CIGLOO_DEST)

Dclean: clean
DClean: Clean

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

#*---------------------------------------------------------------------*/
#*    link ...                                                         */
#*---------------------------------------------------------------------*/
link:
	@ echo "Linking:"
	@ $(BIGLOO) $(BFLAGS) -o $(CIGLOO_DEST) Init/main.o $(O_OBJECTS) -lm
	@ echo "link done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    distrib                                                          */
#*    -------------------------------------------------------------    */
#*    Prepare Cigloo for a distribution                                */
#*---------------------------------------------------------------------*/
distrib:
	@ if [ `pwd` = $$HOME/prgm/project/bigloo/cigloo ]; then     \
             echo "*** ERROR:Illegal dir to make a distrib `pwd`";   \
             exit 1;                                                 \
          fi
	@ $(MAKE) $(CLEAN)
	@ $(MAKE) afile
	@ $(MAKE) Dmakefile
	@ $(BIN)/copyright $(POPULATION)

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

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

#*---------------------------------------------------------------------*/
#*    Dmakefile                                                        */
#*    -------------------------------------------------------------    */
#*    This entry build the Dmakefile file that is used to boot         */
#*    Cigloo 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 $@
	@ echo "# !!! This is a generated file, don't edit !!!" > $@
	@ echo "CIGLOO_DEST=cigloo" >> $@
	@ echo "BIGLOO=bigloo" >> $@
	@ echo "BFLAGS=-unsafe -O4 -afile .afile" >> $@
	@ echo "shell=sh" >> $@
	@ echo "" >> $@
	@ echo "OBJECTS=$(O_OBJECTS)" >> $@
	@ echo "" >> $@
	@ echo "../bin/$$""(CIGLOO_DEST): $$""(OBJECTS)" >> $@
	@ echo "	$$""(BIGLOO) $$""(BFLAGS) -o ../bin/$$""(CIGLOO_DEST) $$""(OBJECTS)" >> $@
	@ echo "	-strip ../bin/$$""(CIGLOO_DEST)" >> $@
	@ echo "	@ echo \"cigloo done...\"" >> $@
	@ echo "" >> $@
	@ echo "clean:" >> $@
	@ echo '	@- rm -f $$(OBJECTS)' >> $@
	@ echo '	@- rm -f $$(CIGLOO_DEST)' >> $@
	@ echo "" >> $@
	@ echo "%.o: %.scm" >> $@
	@ echo '	$$(BIGLOO) -c $$(BFLAGS) $$*.scm -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:
	@ echo $(POPULATION:%=$(BACKUPNAME)/%)

#*---------------------------------------------------------------------*/
#*    date.scm                                                         */
#*---------------------------------------------------------------------*/
Tools/date.scm:
	@- rm -f $@
	@ echo ";; Automatically generated file (don't edit)" > $@
	@ echo "(module tools_date (export (cigloo-date)))" >> $@
	@ echo "" >> $@
	@ echo "(define (cigloo-date) " \" `date` \"")" >> $@

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

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

#*---------------------------------------------------------------------*/
#*    Parser/parser.o:                                                 */
#*---------------------------------------------------------------------*/
Parser/parser.o: Parser/parser.scm 
	@ $(BIGLOO) $(BOPTFLAGS) $(BFLAGS) -c $*.scm -o $*.o

#*---------------------------------------------------------------------*/
#*    Parser/cpp.o:                                                    */
#*---------------------------------------------------------------------*/
Parser/cpp.o: Parser/cpp.scm 
	@ $(BIGLOO) $(BOPTFLAGS) $(BFLAGS) -c $*.scm -o $*.o

#*---------------------------------------------------------------------*/
#*    Parser/lexer.o:                                                  */
#*---------------------------------------------------------------------*/
Parser/lexer.o: Parser/lexer.scm 
	@ $(BIGLOO) $(BOPTFLAGS) $(BFLAGS) -c $*.scm -o $*.o

#bdepend start (don't edit)
#*---------------------------------------------------------------------*/
#*    Dependencies ...                                                 */
#*---------------------------------------------------------------------*/
Init/main.o: Engine/engine.mco Init/parse-args.mco Init/setrc.mco 
Engine/translate.o: Tools/error.mco Tools/speek.mco Translate/type.mco   \
      Translate/declaration.mco Translate/function.mco Parser/lexer.mco  \
      Parser/parser.mco Engine/param.mco Parser/coord.sch                \
      Translate/ast.sch 
Translate/declaration.o: Tools/speek.mco Engine/param.mco                \
      Translate/type.mco Translate/tspec.mco Translate/function.mco      \
      Translate/decl.mco Translate/ast.sch Translate/type.sch 
Engine/param.o: Tools/date.mco 
Translate/type.o: Translate/expr.mco Translate/tspec.mco Tools/speek.mco \
      Tools/error.mco Engine/param.mco Translate/ast.sch                 \
      Translate/type.sch 
Write/version.o: Tools/speek.mco Engine/param.mco 
Parser/parser.o: Translate/decl.mco Parser/lexer.mco Engine/param.mco    \
      Translate/declaration.mco Translate/ast.sch 
Translate/function.o: Tools/error.mco Tools/speek.mco Translate/eval.mco \
      Translate/tspec.mco Translate/decl.mco Translate/type.mco          \
      Engine/param.mco Parser/coord.sch Translate/ast.sch                \
      Translate/type.sch Translate/function.sch 
Parser/lexer.o: Engine/param.mco Parser/cpp.mco Parser/tools.mco 
Translate/ast.o: Tools/union.sch 
Tools/error.o: Translate/ast.sch Parser/coord.sch 
Parser/tools.o: Parser/coord.sch 
Translate/eval.o: Tools/speek.mco Engine/param.mco 
Engine/engine.o: Parser/lexer.mco Translate/eval.mco                     \
      Engine/translate.mco Engine/param.mco Tools/file.mco               \
      Tools/speek.mco 
Parser/cpp.o: Parser/tools.mco Engine/engine.mco Engine/param.mco        \
      Parser/coord.sch 
Init/parse-args.o: Write/version.mco Parser/lexer.mco Engine/param.mco   \
      Init/args.sch 
Init/setrc.o: Engine/param.mco 
Translate/tspec.o: Tools/speek.mco Tools/error.mco Translate/decl.mco    \
      Translate/type.mco Engine/param.mco Translate/ast.sch              \
      Translate/type.sch 
Translate/expr.o: Translate/decl.mco Translate/tspec.mco                 \
      Translate/type.mco Translate/ast.sch Translate/type.sch 
Translate/decl.o: Tools/speek.mco Engine/param.mco Translate/tspec.mco   \
      Translate/type.mco Translate/function.mco Parser/coord.sch         \
      Translate/ast.sch Translate/type.sch 
Tools/speek.o: Engine/param.mco 

#bdepend stop
