#*=====================================================================*/
#*    serrano/prgm/project/bigloo/Makefile                             */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Jan 14 13:40:15 1998                          */
#*    Last change :  Sat Oct  6 09:50:07 2001 (serrano)                */
#*    Copyright   :  1998-2001 Manuel Serrano, see LICENSE file        */
#*    -------------------------------------------------------------    */
#*    This Makefile *requires* GNU-Make.                               */
#*    -------------------------------------------------------------    */
#*    The main Bigloo Makefile. Here is a short description of the     */
#*    makefile entries.                                                */
#*                                                                     */
#*    Public entries:                                                  */
#*       boot.......... Compile Bigloo on a bare plateform.            */
#*       compile-bee... Compile BEE on a bare plateform.               */
#*                      The entry uses auxiliary public points.        */
#*       install....... Install a compiled Bigloo.                     */
#*       install-bee... Install a compiled Bigloo. This uses           */
#*                      install-xxx entry points).                     */
#*       uninstall..... Uninstall the bigloo system and Bee.           */
#*       uninstall-bee. Uninstall Bee. This uses uninstall-xxx points. */
#*       unconfigure... Unconfigure the bigloo system and Bee.         */
#*       test.......... Test a compiled Bigloo.                        */
#*       clean......... Cleaning.                                      */
#*       distclean..... Cleaning.                                      */
#*                                                                     */
#*    Private entries:                                                 */
#*       fullbootstrap. Bootstrap a development compiler (private)     */
#*       bigboot....... Compile Bigloo on already provided plateform.  */
#*                      This is not guarantee to work because it       */
#*                      requires a compatible installed Bigloo         */
#*                      compiler (public)                              */
#*       distrib....... Produces an official bigloo tarball file       */
#*                      (private). The tarball file is built from a    */
#*                      bootstrapped compiler that is freshly checked  */
#*                      out from the revision system. Uses (true-      */
#*                      distrib, bigloo.tar.gz, bigloo.tar).           */
#*       distrib-jvm... Produces an official bigloo zip file with      */
#*                      default back-end set to jvm (for Windows and   */
#*                      MacIntosh boxes).                              */
#*       zip........... aka for distrib-jvm                            */
#*       rpm........... Produces an rpm file for Bigloo.               */   
#*       newrevision... Changes the development Bigloo revision.       */
#*       pop........... The population that composes Bigloo.           */
#*       popfilelist... The sort file list of the Bigloo population.   */
#*       revision...... commit a revision (uses prcs-revision and      */
#*                      cvs-revision).                                 */
#*       checkout...... commit a checkout (uses prcs-checkout and      */
#*                      cvs-checkout).                                 */
#*       checkgmake.... Check that make is gmake.                      */
#*=====================================================================*/
 
#*---------------------------------------------------------------------*/
#*    The default configuration                                        */
#*---------------------------------------------------------------------*/
include Makefile.config

#*---------------------------------------------------------------------*/
#*    Compilers, Tools and Destinations                                */
#*---------------------------------------------------------------------*/
# the executable used to bootstrap
BIGLOO          = $(BOOTBINDIR)/bigloo
# the shell to be used
SHELL           = /bin/sh
# The directory where to build and install a distribution
DISTRIBTMPDIR	= /tmp
DISTRIBDIR	= $$HOME/prgm/distrib
# The Bigloo html page directory
HTMLPAGEDIR	= $$HOME/public_html/bigloo
# The ftp host and location where to store Bigloo
FTPHOSTNAME	= tahoe
FTPHOST		= $(FTPHOSTNAME).unice.fr
FTPDIR		= $$HOME/public_ftp
# The library to be installed on the ftp server
FTP_LIBRARIES	= contrib/srfi-1.tar.gz \
                  contrib/format.tar.gz \
                  contrib/lib-example.tar.gz
# the libc we are testing for version
LIBC		= /usr/lib/libc.so
# the library C version
LIBCVERSION	= 6
# the rpm architecture (for now only i386 is supported)
RPMARCH		= i686
# the root directory where to remove directory after the rpm contruction
RPMBASEDIR	= /usr/src/RPM
RPMSOURCEDIR	= $(RPMBASEDIR)/SOURCES
RPMBUILDDIR	= $(RPMBASEDIR)/BUILD
# The rpm source directory
RPMSOURCESDIR	= $(RPMBASEDIR)/SOURCES
RPMRPMDIR	= $(RPMBASEDIR)/RPMS
# The JVM standard installation directory
JVMBASEDIR	= "C:\\\\Bgl`echo $(RELEASE) | sed -e 's/[.]//'`"
# gzip
GZIP		= gzip -9
# zip
ZIP		= zip
# The revision system
REVISIONSYSTEM	= prcs# either prcs or cvs
# The message to log the revision
LOGMSG		= ""
# Sudo command
SUDO		= sudo

#*---------------------------------------------------------------------*/
#*    The directory that compose a version                             */
#*---------------------------------------------------------------------*/
DIRECTORIES	= cigloo \
                  jigloo \
                  bench \
	          autoconf \
                  etc \
                  examples \
                  gc-forward \
                  recette \
                  tools \
                  xlib \
                  runtime \
	          comptime \
		  bdb \
                  bde \
                  bmacs \
                  manuals \
		  win32 \
                  www

#*---------------------------------------------------------------------*/
#*    The file that have to be removed when building a distrib.        */
#*---------------------------------------------------------------------*/
NO_DIST_FILES	= .bigloo.prcs_aux bigloo.lsm www

#*---------------------------------------------------------------------*/
#*    boot ...                                                         */
#*    -------------------------------------------------------------    */
#*    Boot a new Bigloo system on a new host. This boot makes use      */
#*    of the pre-compiled C files.                                     */
#*---------------------------------------------------------------------*/
boot: checkgmake
	@ (cd runtime; $(MAKE) boot JVMLN="$(JVMLN)")
	@ (cd comptime; $(MAKE) boot)
	@ (cd runtime; $(MAKE) heap JVMLN="$(JVMLN)")
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
             (cd runtime; \
              $(MAKE) boot-jvm \
                      JVMLN="$(JVMLN)" \
                      JVMCPATH='$(JVMCPATH)'); \
          fi
	@ (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
           LD_LIBRARY_PATH=$(BOOTLIBDIR); export LD_LIBRARY_PATH; \
           cd bde; $(MAKE) boot)
	@ echo "Boot Done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    manuals                                                          */
#*---------------------------------------------------------------------*/
manuals:
	-@ (cd manuals; $(MAKE) html ps)
	-@ (cd manuals; $(MAKE) compile-bee)

#*---------------------------------------------------------------------*/
#*    manual-pdf                                                       */
#*---------------------------------------------------------------------*/
manual-pdf:
	@ (cd manuals; $(MAKE) bigloo.pdf)

#*---------------------------------------------------------------------*/
#*    bigboot ...                                                      */
#*    -------------------------------------------------------------    */
#*    Boot a new Bigloo system on a an host. This boot uses an already */
#*    installed Bigloo on that hosts. That is, it recompiles, all the  */
#*    Scheme source files.                                             */
#*    -------------------------------------------------------------    */
#*    To use this entry:                                               */
#*      1- configure the system:                                       */
#*          ./configure --bootconfig                                   */
#*      2- type something like:                                        */
#*          make bigboot BIGLOO=/usr/local/bin/bigloo                  */
#*---------------------------------------------------------------------*/
bigboot: 
	@ mkdir -p bin
	@ mkdir -p lib/$(RELEASE)
	@ (cd runtime; $(MAKE) bigboot BIGLOO=$(BIGLOO))
	@ (cd comptime; $(MAKE) bigboot BIGLOO=$(BIGLOO))
	@ (cd comptime; $(MAKE))
	@ (cd runtime; $(MAKE) clean heap libs)
	@ echo "Boot Done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    compile-bee                                                      */
#*    -------------------------------------------------------------    */
#*    Once the system is booted. It is now possible to compile the     */
#*    Bee. This is the role of this entry.                             */
#*    Compile bee on an bootstrapped plateform                         */
#*---------------------------------------------------------------------*/
compile-bee: 
	@ (cd cigloo; $(MAKE))
	@ if [ "$(JVMBACKEND) " = "yes" ]; then \
            (cd jigloo; $(MAKE)) \
          fi
	@ (LD_LIBRARY_PATH=$(BOOTLIBDIR); export LD_LIBRARY_PATH; \
           cd bdb; $(MAKE))
	@ (cd runtime; $(MAKE) compile-bee)
	@ if [ "$(EMACSDIR) " != " " ]; then \
            (cd bmacs; $(MAKE) compile-bee) \
          fi

#*---------------------------------------------------------------------*/
#*    fullbootstrap ...                                                */
#*    -------------------------------------------------------------    */
#*    Bootstrap the compiler. This is a development entry point. It    */
#*    should be used only when testing a new unstable compiler.        */
#*---------------------------------------------------------------------*/
fullbootstrap:
	@ (dt=`date '+%d%b%y'`; \
           /bin/rm -f $(BIGLOO).???????.gz > /dev/null 2>&1; \
           /bin/rm -f $(BIGLOO).????????.gz > /dev/null 2>&1; \
           /bin/rm -f $(BIGLOO).?????????.gz > /dev/null 2>&1; \
           cp $(BIGLOO) $(BIGLOO).$$dt; \
           echo "$(BIGLOO).$$dt.gz:"; \
           $(GZIP) $(BIGLOO).$$dt)
	@ (cd comptime; $(MAKE) -i touchall; $(MAKE))
	@ (cd runtime; $(MAKE) -i touchall; $(MAKE) heap libs-c gcs)
	@ (cd comptime; $(MAKE) -i touchall; $(MAKE))
	@ (cd comptime; $(MAKE) -i touchall; $(MAKE))
	@ (cd runtime; $(MAKE) heap-jvm lib-jvm_u lib-jvm)
	@ (cd recette; $(MAKE) -i touchall; $(MAKE) recette; ./recette)
	@ $(MAKE) -s revision LOGMSG="Full Bootstrap succeeded at `date '+%d%b%y'`"
	@ echo "Bigloo full bootstrap Done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    newrevision ...                                                  */
#*    -------------------------------------------------------------    */
#*    Change the development Bigloo version number.                    */
#*---------------------------------------------------------------------*/
newrevision:
	(cd runtime; make includes)
	(mkdir lib/$(RELEASE))
	(cd comptime; make)
	(cd runtime; make touchall; make all)
	(cd comptime; make touchall; make)
	@ $(MAKE) $(REVISIONSYSTEM)-branch

#*---------------------------------------------------------------------*/
#*    distrib                                                          */
#*    -------------------------------------------------------------    */
#*    This entry build a distribution (biglooXXX.tar.gz file).         */
#*    This rule uses dependencies that cannot be satisfied by this     */
#*    current makefile. The dependencies are here present just to      */
#*    check that everything is ready for a distribution.               */
#*---------------------------------------------------------------------*/
.PHONY: distrib prcs-distrib cvs-distrib

distrib: $(REVISIONSYSTEM)-distrib

prcs-distrib:
	@ (cd $(DISTRIBTMPDIR); \
	   rm -rf bigloo; \
	   rm -rf bigloo$(RELEASE); \
           rm -rf bigloo; mkdir bigloo; cd bigloo; \
           $(MAKE) -I $(BOOTDIR) -f $(BOOTDIR)/Makefile checkout; \
           cp $(BOOTDIR)/Makefile.config Makefile.config; \
           $(MAKE) true-distrib)

cvs-distrib:
	@ (cd $(DISTRIBTMPDIR); \
	   rm -rf bigloo; \
	   rm -rf bigloo$(RELEASE); \
           rm -rf bigloo; \
           $(MAKE) -I $(BOOTDIR) -f $(BOOTDIR)/Makefile checkout; \
           cd bigloo; \
           cp $(BOOTDIR)/Makefile.config Makefile.config; \
           $(MAKE) true-distrib)

true-distrib: $(DISTRIBDIR)/bigloo$(RELEASE).tar.gz

$(DISTRIBDIR)/bigloo$(RELEASE).tar.gz: $(DISTRIBDIR)/bigloo.tar
	@ /bin/rm -f $(DISTRIBDIR)/bigloo$(RELEASE).tar.gz
	@ $(GZIP) $(DISTRIBDIR)/bigloo$(RELEASE).tar
	@ echo "$(DISTRIBDIR)/bigloo$(RELEASE).tar.gz Done..."
	@ echo "-------------------------------"

$(DISTRIBDIR)/bigloo.tar:
	@ for p in $(NO_DIST_FILES); do \
             rm -rf $$p; \
          done
	@ for d in $(DIRECTORIES); do \
             if [ -d $$d ]; then \
               echo "distribution $$d ..."; \
	       (cd $$d; $(MAKE) distrib) || exit 1; \
             fi \
          done
	@ /bin/rm -f Makefile.config;
	@ echo "bigloo.tar"
	@ (cd ..; \
           mv bigloo bigloo$(RELEASE); \
           tar cf $(DISTRIBDIR)/bigloo$(RELEASE).tar bigloo$(RELEASE))
	@ echo "$(DISTRIBDIR)/bigloo$(RELEASE).tar Done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    distrib-jvm                                                      */
#*---------------------------------------------------------------------*/
.PHONY: zip distrib-jvm prcs-distrib-jvm cvs-distrib-jvm

zip: distrib-jvm
distrib-jvm: $(REVISIONSYSTEM)-distrib-jvm

prcs-distrib-jvm:
	@ (cd $(DISTRIBTMPDIR); \
	   rm -rf bigloo; \
	   rm -rf bigloo$(RELEASE); \
           rm -rf bigloo; mkdir bigloo; cd bigloo; \
           $(MAKE) -I $(BOOTDIR) -f $(BOOTDIR)/Makefile checkout; \
           cp $(BOOTDIR)/Makefile.config Makefile.config; \
           $(MAKE) true-distrib-jvm)

cvs-distrib-jvm:
	@ (cd $(DISTRIBTMPDIR); \
	   rm -rf bigloo; \
	   rm -rf bigloo$(RELEASE); \
           rm -rf bigloo; \
           $(MAKE) -I $(BOOTDIR) -f $(BOOTDIR)/Makefile checkout; \
           cd bigloo; \
           cp $(BOOTDIR)/Makefile.config Makefile.config; \
           $(MAKE) true-distrib-jvm)

true-distrib-jvm: $(DISTRIBDIR)/bigloo$(RELEASE).zip

$(DISTRIBDIR)/bigloo$(RELEASE).zip: manual-pdf
	@ mkdir -p lib/$(REALEASE)
	@ mkdir -p bin
	@ mkdir -p bigloo$(RELEASE)/lib/$(RELEASE)
	@ mkdir -p bigloo$(RELEASE)/bin
	@ (ver=`echo $(RELEASE) | sed -e 's/[.]//'`; \
           cat win32/install.bat | sed -e "s/THE-VERSION/$$ver/g" > bigloo$(RELEASE)/install.bat; \
           cat win32/uninstall.bat | sed -e "s/THE-VERSION/$$ver/g" > bigloo$(RELEASE)/uninstall.bat)
	@ (cp $(BIGLOO) bin/bigloo)
	@ (cp $(BOOTBINDIR)/afile bin/afile)
	@ (cp $(BOOTBINDIR)/jfile bin/jfile)
	@ (cp $(BOOTBINDIR)/bdepend bin/bdepend)
	@ (./configure --os-win32 \
                       --jvm-default-backend \
                       --prefix="$(JVMBASEDIR)" \
                       --javashell=msdos --java=java \
                       --javac=javac --jvm=force \
                       --a.bat=a.bat --a.out=a.exe)
	(cd runtime; $(MAKE) obj all-jvm)
	@ $(MAKE) -f $(DISTRIBTMPDIR)/bigloo/Makefile true-comptime-jvm
	@ (cd bde; $(MAKE) jvm)
	@ (cd jigloo; $(MAKE) jvm)
	@ mkdir bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/bigloo.jheap bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/bigloo.zip bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/bigloo_u.zip bigloo$(RELEASE)/lib/BGL-TMP
	@ mkdir bigloo$(RELEASE)/lib/bigloo
	@ mv bigloo$(RELEASE)/lib/BGL-TMP bigloo$(RELEASE)/lib/bigloo/`echo $(RELEASE) | sed -e 's/[.]//'`
	@ cp bin/bigloo.jar bigloo$(RELEASE)/bin/bigloo.jar
	@ cat bin/bigloo.jvm | sed -e "s/\/tmp\/bigloo\/bin\//$(JVMBASEDIR)\\\\bin\\\\/" > bigloo$(RELEASE)/bin/bigloo.bat
	@ cp bde/afile.class bigloo$(RELEASE)/bin
	@ cp bde/jfile.class bigloo$(RELEASE)/bin
	@ cp jigloo/jigloo.class bigloo$(RELEASE)/bin
	@ cp INSTALL.jvm bigloo$(RELEASE)/INSTALL
	@ cp README.jvm bigloo$(RELEASE)/README
	@ cp manuals/bigloo.pdf bigloo$(RELEASE)/bigloo.pdf
	@ (mkdir bigloo$(RELEASE)/demo; \
           mkdir bigloo$(RELEASE)/demo/awt; \
           mkdir bigloo$(RELEASE)/demo/maze; \
           cp examples/Jawt/README.jvm bigloo$(RELEASE)/demo/awt/README; \
           cp examples/Jawt/Utils.java bigloo$(RELEASE)/demo/awt/Utils.java; \
           cp examples/Jawt/awt.scm bigloo$(RELEASE)/demo/awt/awt.scm; \
           cp examples/Maze/README.jvm bigloo$(RELEASE)/demo/maze/README; \
           cp examples/Maze/maze.scm bigloo$(RELEASE)/demo/maze/maze.scm)
	@ /bin/rm -r bigloo$(RELEASE)/lib/$(RELEASE)
	@ mv bigloo$(RELEASE) bgl`echo $(RELEASE) | sed -e 's/[.]//'`
	@ /bin/rm -f $(DISTRIBDIR)/bigloo`echo $(RELEASE) | sed -e 's/[.]//'`.zip
	@ $(ZIP) -r $(DISTRIBDIR)/bigloo`echo $(RELEASE) | sed -e 's/[.]//'`.zip bgl`echo $(RELEASE) | sed -e 's/[.]//'`
	@ echo "$(DISTRIBDIR)/bigloo$(RELEASE).zip Done..."
	@ echo "-------------------------------"

# This entry as to be isolated from the general bigloo.zip rule
# Because, it is mandatory here, not to use the Makefile.config of
# of the Bigloo used to bootstrap the distribution. We have to use
# the locally configured Bigloo
true-comptime-jvm:
	 (cd comptime; \
           $(MAKE) afile jfile jvm \
                   JARPATH=`echo '$(BINDIR)' | sed -e 's/\\\\/\\\\\\\\/g'`\
                   CLASSPATH=`echo '$(LIBDIR)' | sed -e 's/\\\\/\\\\\\\\/g'`\
                   LIBDIR=`echo '$(BOOTLIBDIR)' | sed -e 's/\\\\/\\\\\\\\/g'`)

#*---------------------------------------------------------------------*/
#*    rpm                                                              */
#*---------------------------------------------------------------------*/
rpm: bigloo$(RELEASE).spec bigloo$(RELEASE).$(RPMARCH).rpm

bigloo$(RELEASE).$(RPMARCH).rpm: $(RPMSOURCESDIR)/bigloo.tar.gz
	@ $(SUDO) rpm -bb --rmsource bigloo$(RELEASE).spec
	@ $(SUDO) cp $(RPMRPMDIR)/$(RPMARCH)/bigloo-$(RELEASE)-$(LIBCVERSION).$(RPMARCH).rpm $(DISTRIBDIR)
	@ $(SUDO) chown $$LOGNAME $(DISTRIBDIR)/bigloo-$(RELEASE)-$(LIBCVERSION).$(RPMARCH).rpm
	@ $(SUDO) rm $(RPMRPMDIR)/$(RPMARCH)/bigloo-$(RELEASE)-$(LIBCVERSION).$(RPMARCH).rpm
	@ echo "Removing $(RPMBUILDDIR)/bigloo$(RELEASE)"
	@ $(SUDO) /bin/rm -rf $(RPMBUILDDIR)/bigloo$(RELEASE)
	@ echo "Removing $(RPMSOURCEDIR)/bigloo$(RELEASE).tar.gz"
	@ $(SUDO) /bin/rm -rf $(RPMSOURCEDIR)/bigloo$(RELEASE).tar.gz
	@ /bin/rm -f bigloo$(RELEASE).spec

.PHONY: $(RPMSOURCESDIR)/bigloo$(RELEASE).tar.gz

$(RPMSOURCESDIR)/bigloo.tar.gz:
	@ echo "building bigloo.spec for libc version: $(LIBCVERSION)"
	@ echo "Copying bigloo.tar.gz into $(RPMSOURCESDIR)/bigloo.tar.gz"
	@ $(SUDO) cp $(DISTRIBDIR)/bigloo$(RELEASE).tar.gz $(RPMSOURCESDIR)/bigloo.tar.gz

#*---------------------------------------------------------------------*/
#*    bigloo$(RELEASE).spec                                            */
#*---------------------------------------------------------------------*/
bigloo$(RELEASE).spec: bigloo.spec configure
	@ cat bigloo.spec | sed -e s/@RELEASE@/$(RELEASE)/g > bigloo$(RELEASE).spec

#*---------------------------------------------------------------------*/
#*    ftplibrary                                                       */
#*    -------------------------------------------------------------    */
#*    This entry creates and fill an library directory. That directory */
#*    must be installed in the ftp server with the name library.       */
#*---------------------------------------------------------------------*/
ftplibrary:
	@ rm -rf library
	@ mkdir library
	@ for d in $(FTP_LIBRARIES); do \
              echo "copying $$d..."; \
              cp $$d library; \
          done
	@ chmod a+r -R library
	@ chmod a+x library

#*---------------------------------------------------------------------*/
#*    ftp                                                              */
#*    -------------------------------------------------------------    */
#*    Set up the ftp file for the Bigloo distribution                  */
#*---------------------------------------------------------------------*/
ftp:
	@ rcp $(DISTRIBDIR)/bigloo-$(RELEASE)-$(LIBCVERSION).$(RPMARCH).rpm \
              $(FTPHOSTNAME):$(FTPDIR)/bigloo-$(RELEASE)-$(LIBCVERSION).$(RPMARCH).rpm
	@ rcp $(DISTRIBDIR)/bigloo$(RELEASE).tar.gz         \
              $(FTPHOSTNAME):$(FTPDIR)/bigloo$(RELEASE).tar.gz
	@ (rsh $(FTPHOSTNAME) chmod a+rx -R $(FTPDIR))

#*---------------------------------------------------------------------*/
#*    test                                                             */
#*---------------------------------------------------------------------*/
.PHONY: test c-test jvm-test

test: 
	(PATH=`pwd`/bin:$$PWD/bin:$$PATH; export PATH; $(MAKE) c-test)
	(PATH=`pwd`/bin:$$PWD/bin:$$PATH; export PATH; \
         LD_LIBRARY_PATH=`pwd`/lib/$(RELEASE):$$PWD/lib/$(RELEASE):$$LD_LIBRARY_PATH; \
         $(MAKE) jvm-test)

c-test: 
	@ if [ "$(NATIVEBACKEND)" = "yes" ]; then \
            (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
             LD_LIBRARY_PATH=$(BOOTLIBDIR); export LD_LIBRARY_PATH; \
             cd recette; $(MAKE) recette ; ./recette) \
          fi

jvm-test:
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
           (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
            BIGLOOCLASSPATH=$(BOOTLIBDIR); export BIGLOOCLASSPATH;\
            LD_LIBRARY_PATH=`pwd`/lib/$(RELEASE):$$PWD/lib/$(RELEASE):$$LD_LIBRARY_PATH; \
            export LD_LIBRARY_PATH; \
            cd recette; \
            $(MAKE) clean; \
            $(MAKE) jvm JVMCLASSPATH="-jvm-classpath $(CYGWINPREFIX)$(BOOTLIBDIR)" JVMCPATH='$(CYGWINJVMPATH)';\
            ./$(RECETTEJVM)) \
          fi

#*---------------------------------------------------------------------*/
#*    install & uninstall                                              */
#*---------------------------------------------------------------------*/
.PHONY: install uninstall

install: 
	(cd comptime; $(MAKE) install)
	(cd runtime; $(MAKE) install)
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
             (cd runtime; $(MAKE) install-jvm); \
          fi
	-(cd manuals; $(MAKE) install)
	(cp Makefile.config $(LIBDIR)/Makefile.config; \
         chmod $(BMASK) $(LIBDIR)/Makefile.config)
	(cd bde; $(MAKE) install)

install-bee:
	(cd cigloo; $(MAKE) install)
	@ if [ "$(JVMBACKEND) " = "yes" ]; then \
            (cd jigloo; $(MAKE) install) \
          fi
	(cd bdb; $(MAKE) install)
	(cd runtime; $(MAKE) install-bee)
	-(cd manuals; $(MAKE) install-bee)
	-(cd bmacs; $(MAKE) install)

uninstall: uninstall-bee
	(cd bde; $(MAKE) uninstall)
	(cd comptime; $(MAKE) uninstall)
	(cd runtime; $(MAKE) uninstall)
	-(cd manuals; $(MAKE) uninstall)
	rm -f $(LIBDIR)/Makefile.config

uninstall-bee:
	(cd cigloo; $(MAKE) uninstall)
	(cd jigloo; $(MAKE) uninstall)
	(cd bdb; $(MAKE) uninstall)
	(cd runtime; $(MAKE) uninstall-bee)
	-(cd manuals; $(MAKE) uninstall-bee)
	-(cd bmacs; $(MAKE) uninstall)

#*---------------------------------------------------------------------*/
#*    unconfigure                                                      */
#*---------------------------------------------------------------------*/
.PHONY: unconfigure

unconfigure: 
	@ if [ `pwd` = $$HOME/prgm/project/bigloo ]; then \
             echo "*** ERROR:Illegal dir to make an unconfigure `pwd`"; \
             exit 1; \
          fi
	rm -f lib/$(RELEASE)/bigloo_config.h
	rm -f Makefile.config
	rm -f configure.log

#*---------------------------------------------------------------------*/
#*    clean                                                            */
#*---------------------------------------------------------------------*/
.PHONY: clean cleanall distclean 

clean:
	@ if [ `pwd` = $$HOME/prgm/project/bigloo ]; then \
             echo "*** ERROR:Illegal dir to make a clean `pwd`"; \
             exit 1; \
          fi
	/bin/rm -f configure.log
	(cd comptime; $(MAKE) clean)
	(cd runtime; $(MAKE) clean)
	(cd manuals; $(MAKE) clean)
	(cd cigloo; $(MAKE) clean)
	(cd jigloo; $(MAKE) clean)
	(cd bmacs; $(MAKE) clean)
	(cd bde; $(MAKE) clean)
	(cd bdb; $(MAKE) clean)
	(cd recette; $(MAKE) clean)

cleanall: 
	@ if [ `pwd` = $$HOME/prgm/project/bigloo ]; then \
             echo "*** ERROR:Illegal dir to make a cleanall `pwd`"; \
             exit 1; \
          fi
	/bin/rm configure.log
	(cd comptime; $(MAKE) cleanall)
	(cd runtime; $(MAKE) cleanall)
	(cd manuals; $(MAKE) cleanall)
	(cd cigloo; $(MAKE) cleanall)
	(cd jigloo; $(MAKE) cleanall)
	(cd bmacs; $(MAKE) cleanall)
	(cd bde; $(MAKE) cleanall)
	(cd bdb; $(MAKE) cleanall)

distclean: 
	@ if [ `pwd` = $$HOME/prgm/project/bigloo ]; then \
             echo "*** ERROR:Illegal dir to make a distclean `pwd`"; \
             exit 1; \
          fi
	touch configure.log; /bin/rm configure.log
	(cd comptime; $(MAKE) distclean)
	(cd runtime; $(MAKE) distclean)
	(cd manuals; $(MAKE) distclean)
	(cd cigloo; $(MAKE) distclean)
	(cd jigloo; $(MAKE) distclean)
	(cd bmacs; $(MAKE) distclean)
	(cd bde; $(MAKE) distclean)
	(cd bdb; $(MAKE) distclean)
	$(MAKE) unconfigure

#*---------------------------------------------------------------------*/
#*    population                                                       */
#*    -------------------------------------------------------------    */
#*    The list of all files that have to be placed inside the          */
#*    repository for revision.                                         */
#*---------------------------------------------------------------------*/
pop:
	@ echo gc-boehm \
               LICENSE COPYING ChangeLog \
               INSTALL INSTALL.jvm README \
               README.ppc README.sgi \
               README.alpha README.openbsd \
               README.finalizer README.fp \
               README.win32 README.jvm \
               README.athlon README.pentium \
               Makefile configure \
               bigloo.lsm bigloo.spec \
               tutorial
	@ $(MAKE) revision-pop
	@ for d in $(DIRECTORIES); do \
             (cd $$d; $(MAKE) -s pop); \
          done;

popfilelist:
	@ (for p in `$(MAKE) -s pop`; do \
            echo $$p; \
           done) | sort

#*---------------------------------------------------------------------*/
#*    checkgmake                                                       */
#*---------------------------------------------------------------------*/
.PHONY: checkgmake

checkgmake:
	@ autoconf/gmaketest --make=$(MAKE) || \
          (echo "GNU-Make is required to install Bigloo. Aborting."; exit 1)

#*---------------------------------------------------------------------*/
#*    revision                                                         */
#*    -------------------------------------------------------------    */
#*    Generic revision entry point.                                    */
#*---------------------------------------------------------------------*/
.PHONY: revision checkout populate revision-pop

revision: $(REVISIONSYSTEM)-revision
checkout: $(REVISIONSYSTEM)-checkout
populate: $(REVISIONSYSTEM)-populate
branch: $(REVISIONSYSTEM)-branch
revision-pop: $(REVISIONSYSTEM)-pop

#*---------------------------------------------------------------------*/
#*    PRCS revisions ...                                               */
#*---------------------------------------------------------------------*/
.PHONY: prcs-branch prcs-revision prcs-populate bigloo.prcs-new prcs-pop bigloo.prj

prcs-branch:

prcs-revision: prcs-populate prcs-checkin

prcs-populate: bigloo.prj
	@ for d in $(DIRECTORIES); do \
             echo "populating from $$d ..."; \
             prcs populate bigloo `cd $$d; $(MAKE) -s pop`; \
          done;
	prcs populate bigloo gc-boehm \
             LICENSE COPYING ChangeLog \
             INSTALL README \
             INSTALL.jvm README.jvm \
             README.ppc README.sgi \
             README.alpha README.openbsd \
             README.finalizer README.fp \
             Makefile configure bigloo.lsm bigloo.spec \
             tutorial

prcs-checkin:
	prcs checkin -r$(RELEASE).@ bigloo
	@ (revision=`prcs info -r $(RELEASE).@ | awk '{ print $$2 }'`; \
           /bin/rm -f $(BIGLOO).$(RELEASE).*.gz > /dev/null 2>&1; \
           cp $(BOOTBINDIR)/bigloo $(BOOTBINDIR)/"bigloo.$$revision"; \
           echo "$(BOOTBINDIR)/bigloo.$$revision.gz:"; \
           $(GZIP) "$(BOOTBINDIR)/bigloo.$$revision")

prcs-checkout:
	@ prcs checkout -r$(RELEASE).@ bigloo

bigloo.prj:
	@ cat bigloo.prj | sed -e s,"(Populate-Ignore ())","(Populate-Ignore (\"\\\\\\\\\\.o\\$$\" \"\\\\\\\\\\~$$\" \"\\\\\\\\\\.log\\$$\" \"\\\\\\\\\\.ps\\$$\" \"\\\\\\\\\\.aux\\$$\" \"\\\\\\\\\\.date_of_backup\\$$\" \"\\\\\\\\\\.so\\$$\" \"\\\\\\\\\\.a\\$$\" \"if_not_there\\$$\" \"if_mach\\$$\" \"threadlibs\\$$\"))", > bigloo.dprj; rm -f bigloo.prj; mv bigloo.dprj bigloo.prj

#*---------------------------------------------------------------------*/
#*    CVS revisions ...                                                */
#*---------------------------------------------------------------------*/
.PHONY: cvs-branch cvs-revision cvs-populate cvs-pop bigloo.cvs-new

# Create a new branch in the CVS repository. This is used when a new Bigloo
# release number has been allocated
cvs-branch:
	(cvsrelease=`echo bigloo-$(RELEASE) | sed -e s,"[.]","-",`; \
         cvs tag -b $$cvsrelease; \
         cvs update -r $$cvsrelease; \
         cvs commit -m "Creation of branch $$cvsrelease")

cvs-revision: 
	@ (cd bde; $(MAKE) clean)
	@ (cd recette; $(MAKE) clean)
	@ (cd examples; $(MAKE) clean)
	@ (cd bmacs; $(MAKE) clean)
	@ (cd bench; $(MAKE) clean)
	@ (cd xlib; $(MAKE) clean)
	@ $(MAKE) -s cvs-populate cvs-checkin

# remove all the now delete files and add the new ones
cvs-populate: bigloo.cvs-new
	for p in `$(BOOTBINDIR)/bigloo -i tools/diff.scm bigloo.cvs bigloo.cvs-new`; do \
           (d=`dirname $$p`; b=`basename $$p`; cd $$d; cvs remove $$b) \
        done
	if [ -f bigloo.cvs ]; then \
	  for p in `$(BOOTBINDIR)/bigloo -i tools/diff.scm bigloo.cvs-new bigloo.cvs`; do \
	   (d=`dirname $$p`; b=`basename $$p`; cd $$d; cvs add $$b) \
          done \
        else \
	  for p in `cat bigloo.cvs-new`; do \
           (d=`dirname $$p`; b=`basename $$p`; cd $$d; cvs add $$b) \
          done; \
	  mv bigloo.cvs-new bigloo.cvs; \
          cvs add bigloo.cvs; \
        fi
	rm -f bigloo.cvs-new

cvs-checkin:
	if [ -d private ]; then \
	   if [ ! -f private/ChangeLog ]; then \
              if [ "$(LOGMSG) " = " " ]; then \
                 touch private/ChangeLog; \
              else \
                 echo $(LOGMSG) > private/ChangeLog; \
              fi; \
           fi; \
	   cp ChangeLog ChangeLog.old; \
           cp private/ChangeLog ChangeLog; \
           cat ChangeLog.old >> ChangeLog; \
           cvs commit -F private/ChangeLog; \
	   /bin/rm private/ChangeLog; \
        else \
           (cvsrelease=`echo bigloo-$(RELEASE) | sed -e s,"[.]","-",`; \
            cvs commit -r $$cvsrelease -m $(LOGMSG)); \
        fi

cvs-checkout:
	(cvsrelease=`echo bigloo-$(RELEASE) | sed -e s,"[.]","-",`; \
         cvs checkout -r $$cvsrelease bigloo)

bigloo.cvs-new: 	
	@ $(MAKE) -s popfilelist > bigloo.cvs-new

cvs-pop:
	echo bigloo.cvs

# Create a revision of Bigloo into a CVS repository
cvs-create: 
	@ echo "*** To create a Bigloo version for a CVS repository type-in: "
	@ echo cvs import -I bigloo.prj -I .bigloo.prcs_aux -I "'"gc-boehm*.*"'" -I "'"gc-boehm_*"'" -I "'"*~"'" -I "'"*.mco"'" -I "'"*.o"'" -I "'"*.ps"'" -I "'"*.info*"'" -I "'"*.dvi"'" -I "'"*.log"'" -I RUN -I contrib -I objs -I "'"*.Olib*"'" -I Makefile.config -I bin -I lib -I private -I public -I work -I bigloo.html -I bdb.html -m "\"Bigloo development tree\"" bigloo bigloo `echo bigloo-2.2a | sed -e s,"[.]","-",`
