#*=====================================================================*/
#*    serrano/prgm/project/bigloo/Makefile                             */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Jan 14 13:40:15 1998                          */
#*    Last change :  Thu Oct  7 10:37:27 2004 (serrano)                */
#*    Copyright   :  1998-2004 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.            */
#*       boot-thread... Compile Bigloo thread library.                 */
#*       compile-bee0..                                                */
#*       compile-bee... Compile BEE on a bare plateform.               */
#*                      The entry uses auxiliary public points.        */
#*       install....... Install a compiled Bigloo.                     */
#*       install-bee0..                                                */
#*       install-bee... Install a compiled Bigloo. This uses           */
#*                      install-xxx entry points).                     */
#*       install-thread Install Bigloo thread library.                 */
#*       uninstall..... Uninstall the bigloo system and Bee.           */
#*       uninstall-bee0                                                */
#*       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 \
                  doc \
                  win32 \
                  www \
                  fthread \
                  srfi \
                  bdl \
		  pnet2ms

#*---------------------------------------------------------------------*/
#*    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)
	@ (cd comptime && $(MAKE) boot)
	@ (cd runtime && $(MAKE) heap)
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
             (PATH=$(BOOTBINDIR):$$PATH; export PATH; \
              cd runtime && \
              $(MAKE) boot-jvm JVMCPATH='$(JVMCPATH)'); \
          fi
	@ if [ "$(DOTNETBACKEND)" = "yes" ]; then \
             (PATH=$(BOOTBINDIR):$$PATH; export PATH; \
              cd runtime && \
              $(MAKE) boot-dotnet); \
          fi
	@ (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
           LD_LIBRARY_PATH=$(BOOTLIBDIR):$$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; \
           PATH=$(BOOTBINDIR):$$PATH; export PATH; \
           cd bde && $(MAKE) boot)
	@ (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
           LD_LIBRARY_PATH=$(BOOTLIBDIR):$$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; \
           PATH=$(BOOTBINDIR):$$PATH; export PATH; \
           $(MAKE) boot-thread)
	@ echo "Boot Done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    boot-thread                                                      */
#*---------------------------------------------------------------------*/
boot-thread:
	@ if [ "$(PTHREADLIBS)" != "no" ]; then \
             if [ "$(CGCTHREADFLAGS)" != "no" ]; then \
               (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
                cd fthread && \
                $(MAKE) boot-c) || exit 1; \
	       if [ "$(GCCUSTOM)" = "yes" ]; then \
                  (cd runtime && $(MAKE) gc_fth); \
               fi; \
             fi \
          fi
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
             (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
              cd fthread && \
              $(MAKE) boot-jvm JVMCPATH='$(JVMCPATH)') || exit 1; \
          fi
	@ if [ "$(DOTNETBACKEND)" = "yes" ]; then \
             (BIGLOOLIB=$(BOOTLIBDIR); export BIGLOOLIB; \
              cd fthread && \
              $(MAKE) boot-dotnet) || exit 1; \
          fi

#*---------------------------------------------------------------------*/
#*    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=$(BIGLOOBOOT))
	@ (cd comptime && $(MAKE) bigboot BIGLOO=$(BIGLOOBOOT))
	@ (cd comptime && $(MAKE))
	@ (cd runtime && $(MAKE) clean heap libs)
	@ echo "Big 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-bee0: 
	@ (LD_LIBRARY_PATH=$(BOOTLIBDIR):$$LD_LIBRARY_PATH && \
           export LD_LIBRARY_PATH && \
           (cd bdl && $(MAKE)) && \
	   (cd cigloo && $(MAKE)) && \
	   if [ "$(JVMBACKEND) " = "yes" ]; then \
              (cd jigloo && $(MAKE)) \
           fi)
	@ if [ "$(EMACSDIR) " != " " ]; then \
            (cd bmacs && $(MAKE) compile-bee) \
          fi

compile-bee1:
	@ (LD_LIBRARY_PATH=$(BOOTLIBDIR):$$LD_LIBRARY_PATH && \
           export LD_LIBRARY_PATH && \
           (cd bdb && $(MAKE)))
	@ (cd runtime && $(MAKE) compile-bee)

compile-bee: compile-bee0
	@ if [ "$(INSTALLBEE)" = "full" ]; then \
            $(MAKE) compile-bee1; \
          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'`; \
           $(RM) -f $(BIGLOO).???????.gz > /dev/null 2>&1; \
           $(RM) -f $(BIGLOO).????????.gz > /dev/null 2>&1; \
           $(RM) -f $(BIGLOO).?????????.gz > /dev/null 2>&1; \
           cp $(BIGLOO)$(EXE_SUFFIX) $(BIGLOO).$$dt$(EXE_SUFFIX); \
           echo "$(BIGLOO).$$dt.gz:"; \
           $(GZIP) $(BIGLOO).$$dt$(EXE_SUFFIX))
	@ ./configure --bootconfig
	@ (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_s)
	@ (cd runtime && $(MAKE) lib-dotnet_u lib-dotnet_s)
	@ (cd fthread && $(MAKE) -i clean; $(MAKE) boot-c boot-jvm boot-dotnet)
	@ (cd cigloo && $(MAKE) -i clean; $(MAKE))
	@ (cd recette && $(MAKE) -i touchall; \
           $(MAKE) recette && ./recette$(EXE_SUFFIX) && \
           $(MAKE) recette-jvm && ./recette-jvm$(SCRIPTEXTENSION) && $(MAKE) clean)
	@ $(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$(RELEASE) && \
           $(RM) -rf bigloo && mkdir bigloo && cd bigloo && \
           $(MAKE) -I $(BOOTDIR) -f $(BOOTDIR)/Makefile checkout && \
           cp $(BOOTDIR)/Makefile.config Makefile.config && \
           $(MAKE) true-distrib)
	@ $(RM) -rf $(DISTRIBTMPDIR)/bigloo$(RELEASE)

cvs-distrib:
	@ (cd $(DISTRIBTMPDIR) && \
	   $(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 && \
           $(RM) -rf bigloo$(RELEASE))

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

$(DISTRIBDIR)/bigloo$(RELEASE).tar.gz: $(DISTRIBDIR)/bigloo.tar
	@ $(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
	@ $(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)
	@ $(RM) -rf $(DISTRIBTMPDIR)/bigloo
	@ $(RM) -rf $(DISTRIBTMPDIR)/bigloo$(RELEASE)

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)/btags bin/btags)
	@ (cp $(BOOTBINDIR)/bdepend bin/bdepend)
	@ (./configure --os-win32 \
                       --jvm-default-backend \
                       --prefix="$(JVMBASEDIR)" \
                       --fildir="$(JVMBASEDIR)"/lib \
                       --zipdir="$(JVMBASEDIR)"/lib \
                       --javashell=msdos --java=java \
                       --javac=javac --jvm=force \
                       --a.bat=a.bat --a.out=a.exe)
	(cd runtime && $(MAKE) obj all-jvm)
	(cd fthread && $(MAKE) boot-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_s.zip bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/bigloo_u.zip bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/fthread.jheap bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/fthread.init bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/fthread_s.zip bigloo$(RELEASE)/lib/BGL-TMP
	@ cp lib/$(RELEASE)/fthread_s.zip bigloo$(RELEASE)/lib/BGL-TMP/fthread_u.zip
	@ 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 doc/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)
	@ $(RM) -r bigloo$(RELEASE)/lib/$(RELEASE)
	@ mv bigloo$(RELEASE) bgl`echo $(RELEASE) | sed -e 's/[.]//'`
	@ $(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_s.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$(RELEASE).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) $(RM) -rf $(RPMBUILDDIR)/bigloo$(RELEASE)
	@ echo "Removing $(RPMSOURCEDIR)/bigloo$(RELEASE).tar.gz"
	@ $(SUDO) $(RM) -rf $(RPMSOURCEDIR)/bigloo$(RELEASE).tar.gz
	@ $(RM) -f bigloo$(RELEASE).spec

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

$(RPMSOURCESDIR)/bigloo$(RELEASE).tar.gz:
	@ echo "building bigloo.spec for libc version: $(LIBCVERSION)"
	@ echo "Copying bigloo.tar.gz into $(RPMSOURCESDIR)/bigloo$(RELEASE).tar.gz"
	@ $(SUDO) cp $(DISTRIBDIR)/bigloo$(RELEASE).tar.gz $(RPMSOURCESDIR)/bigloo$(RELEASE).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):$(LD_LIBRARY_PATH); export LD_LIBRARY_PATH; \
             cd recette && $(MAKE) static-recette && ./recette.static $(RECETTEFLAGS)) \
          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-bigloo-classpath $(CYGWINPREFIX)$(BOOTLIBDIR)" JVMCPATH='$(CYGWINJVMPATH)' && \
            ./recette-jvm$(SCRIPTEXTENSION) $(RECETTEFLAGS)) \
          fi

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

install: install-progs install-docs

install-progs:
	(cd comptime && $(MAKE) install)
	(cd runtime && $(MAKE) install)
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
             (cd runtime && $(MAKE) install-jvm) && \
             (cd fthread && $(MAKE) install-jvm); \
          fi
	@ if [ "$(DOTNETBACKEND)" = "yes" ]; then \
             (cd runtime && $(MAKE) install-dotnet) && \
             (cd fthread && $(MAKE) install-dotnet); \
          fi
	(cp Makefile.config $(DESTDIR)$(FILDIR)/Makefile.config && \
         chmod $(BMASK) $(DESTDIR)$(FILDIR)/Makefile.config)
	(cp Makefile.misc $(DESTDIR)$(FILDIR)/Makefile.misc && \
         chmod $(BMASK) $(DESTDIR)$(FILDIR)/Makefile.misc)
	(cp srfi/Makefile.srfi $(DESTDIR)$(FILDIR)/Makefile.srfi && \
         chmod $(BMASK) $(DESTDIR)$(FILDIR)/Makefile.srfi)
	(cd bde && $(MAKE) install)
	@ if [ "$(PTHREADLIBS)" != "no" ]; then \
            (cd fthread && $(MAKE) install-init); \
            if [ "$(CGCTHREADFLAGS)" != "no" ]; then \
              (cd runtime && $(MAKE) install-thread); \
              (cd fthread && $(MAKE) install-c); \
            fi \
          fi

install-docs:
	(cd manuals && $(MAKE) install)

install-bee0:
	(cd cigloo && $(MAKE) install)
	(cd bdl && $(MAKE) install)
	@ if [ "$(JVMBACKEND) " = "yes" ]; then \
            (cd jigloo && $(MAKE) install) \
          fi
	-(cd bmacs && $(MAKE) install)

install-bee1:
	(cd bdb && $(MAKE) install)
	(cd runtime && $(MAKE) install-bee)

install-bee: install-bee0
	@ if [ "$(INSTALLBEE)" = "full" ]; then \
            $(MAKE) install-bee1; \
          fi

install-thread:
	(cd fthread && $(MAKE) install)
	(cd runtime && $(MAKE) install-thread)

uninstall: uninstall-bee
	(cd bde && $(MAKE) uninstall)
	(cd comptime && $(MAKE) uninstall)
	(cd runtime && $(MAKE) uninstall uninstall-thread)
	-(cd manuals && $(MAKE) uninstall)
	(cd fthread && $(MAKE) uninstall)
	$(RM) -f $(LIBDIR)/Makefile.config

uninstall-bee0:
	(cd cigloo && $(MAKE) uninstall)
	(cd jigloo && $(MAKE) uninstall)
	(if [ -d bdb ]; then cd bdb && $(MAKE) uninstall; fi)
	(cd runtime && $(MAKE) uninstall-bee)
	-(cd manuals && $(MAKE) uninstall-bee)
	-(cd bmacs && $(MAKE) uninstall)

uninstall-bee: uninstall-bee0

#*---------------------------------------------------------------------*/
#*    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
	$(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)
	if [ -d bdb ]; then \
	   (cd bdb && $(MAKE) clean); \
	fi
	(cd recette && $(MAKE) clean)
	(cd fthread && $(MAKE) clean)
	(cd bdl && $(MAKE) clean)
	(cd pnet2ms && $(MAKE) clean)

cleanall: 
	@ if [ "`pwd`" = "$$HOME/prgm/project/bigloo" ]; then \
             echo "*** ERROR:Illegal dir to make a cleanall `pwd`"; \
             exit 1; \
          fi
	$(RM) -f 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)
	if [ -d bdb ]; then \
	   (cd bdb && $(MAKE) cleanall); \
        fi
	(cd fthread && $(MAKE) cleanall)
	(cd bdl && $(MAKE) cleanall)
	(cd pnet2ms && $(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; $(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)
	if [ -d bdb ]; then \
	   (cd bdb && $(MAKE) distclean); \
	fi
	(cd fthread && $(MAKE) distclean)
	(cd bdl && $(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 \
               Makefile Makefile.misc 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

checkpop:
	@ for f in `$(MAKE) -s popfilelist`; do \
	    if [ ! -e $$f ]; then \
	      echo "Missing file: " $$f; \
	    fi; \
	  done

#*---------------------------------------------------------------------*/
#*    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
	prcs populate bigloo `$(MAKE) popfilelist`
#* 	@ 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 README.icc \                */
#*              Makefile configure bigloo.lsm bigloo.spec \            */
#*              tutorial                                               */

prcs-checkin:
	prcs checkin -r$(RELEASE).@ bigloo
	@ (revision=`prcs info -r $(RELEASE).@ | awk '{ print $$2 }'` && \
           $(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 && \
	   $(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,"[.]","-",`
