#*=====================================================================*/
#*    serrano/prgm/project/bigloo/api/fthread/Makefile                 */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Oct  3 05:37:54 2001                          */
#*    Last change :  Wed Aug 16 07:06:57 2006 (serrano)                */
#*    Copyright   :  2001-06 Manuel Serrano                            */
#*    -------------------------------------------------------------    */
#*    This Makefile *requires* GNU-Make.                               */
#*    -------------------------------------------------------------    */
#*    The Makefile for fthread                                         */
#*=====================================================================*/
include ../../Makefile.config

#*---------------------------------------------------------------------*/
#*    Directories where to find the files composing a revision         */
#*---------------------------------------------------------------------*/
POPDIR		= src examples recette semantics

POPULATION	= Makefile README

#*---------------------------------------------------------------------*/
#*    all                                                              */
#*---------------------------------------------------------------------*/
all: boot-c boot-jvm boot-dotnet
boot: boot-c boot-jvm boot-dotnet

boot-c:
	@ if [ "$(NATIVEBACKEND)" = "yes" ]; then \
	    if [ "$(PTHREADLIBS)" = "no" ]; then \
              echo "[0m[1;32m>>> No native support[0m"; \
            else \
	      if [ "$(CGCTHREADFLAGS)" = "no" ]; then \
                echo "[0m[1;32m>>> No native support[0m"; \
              else \
	        echo "[0m[1;32m>>> C[0m"; \
	        (cd src && $(MAKE) c) || exit 1; \
                if [ "$(GCCUSTOM)" = "yes" ]; then \
                  (cd ../../runtime && $(MAKE) gc_fth) \
                fi \
              fi \
            fi \
          fi

boot-jvm:
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
	    echo "[0m[1;31m>>> JVM[0m"; \
	    (cd src && $(MAKE) jvm) \
          fi

boot-dotnet:
	@ if [ "$(DOTNETBACKEND)" = "yes" ]; then \
	    echo "[0m[1;31m>>> .NET[0m"; \
	    (cd src && $(MAKE) dotnet) \
          fi

#*---------------------------------------------------------------------*/
#*    ude                                                              */
#*---------------------------------------------------------------------*/
ude:
	(cd src && $(MAKE) ude)

#*---------------------------------------------------------------------*/
#*    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:%=fthread/%)
	@ for d in $(POPDIR); do \
            (cd $$d && $(MAKE) -s pop) \
          done;

#*---------------------------------------------------------------------*/
#*    Clean                                                            */
#*---------------------------------------------------------------------*/
clean:
	(cd src && $(MAKE) clean)
	(cd recette && $(MAKE) clean)
	(cd examples && $(MAKE) clean)

distclean: clean
	(cd src && $(MAKE) distclean)
	(cd recette && $(MAKE) distclean)
	(cd examples && $(MAKE) distclean)

cleanall: distclean
	(cd src && $(MAKE) cleanall)
	$(RM) -f lib/*fth* >/dev/null 2>&1
	$(RM) -f *~ >/dev/null 2>&1

#*---------------------------------------------------------------------*/
#*    Installation                                                     */
#*---------------------------------------------------------------------*/
.PHONY: install install-c install-jvm uninstall

include ../../Makefile.misc

install: install-init
	@ if [ "$(NATIVEBACKEND)" = "yes" ]; then \
	    $(MAKE) install-c; \
          fi
	@ if [ "$(JVMBACKEND)" = "yes" ]; then \
            $(MAKE) install-jvm; \
          fi
	@ if [ "$(DOTNETBACKEND)" = "yes" ]; then \
            $(MAKE) install-dotnet; \
          fi

install-init:
	if [ -f $(BOOTLIBDIR)/fthread.init ]; then \
	  if [ $(DESTDIR)$(FILDIR) != $(BOOTLIBDIR) ]; then \
	    cp $(BOOTLIBDIR)/fthread.init $(DESTDIR)$(FILDIR)/fthread.init && \
	    chmod $(BMASK) $(DESTDIR)$(FILDIR)/fthread.init; \
          fi; \
        fi

install-c:
	if [ "$(PTHREADLIBS)" != "no" ]; then \
	  if [ "$(CGCTHREADFLAGS)" != "no" ]; then \
	    (cd ../../runtime && $(MAKE) install-thread); \
	    if [ $(DESTDIR)$(FILDIR) != $(BOOTLIBDIR) ]; then \
	      cp $(BOOTLIBDIR)/fthread.heap $(DESTDIR)$(FILDIR)/fthread.heap && \
	      chmod $(BMASK) $(DESTDIR)$(FILDIR)/fthread.heap; \
            fi; \
	    $(MAKE) install-lib LIB=libbigloofth_s-$(RELEASE); \
	    $(MAKE) install-shared-lib LIB=libbigloofth_e-$(RELEASE); \
	    $(MAKE) install-lnlib LIB=libbigloofth_s-$(RELEASE) LN=libbigloofth_u-$(RELEASE); \
         fi; \
       fi

install-jvm:
	if [ $(DESTDIR)$(FILDIR) != $(BOOTLIBDIR) ]; then \
	  cp $(BOOTLIBDIR)/fthread.jheap $(DESTDIR)$(FILDIR)/fthread.jheap && \
	  chmod $(BMASK) $(DESTDIR)$(FILDIR)/fthread.jheap && \
	  cp $(BOOTLIBDIR)/bigloofth_s-$(RELEASE).zip $(DESTDIR)$(FILDIR)/bigloofth_s-$(RELEASE).zip && \
	  chmod $(BMASK) $(DESTDIR)$(FILDIR)/bigloofth_s-$(RELEASE).zip && \
	  (cd $(DESTDIR)$(FILDIR) && \
           $(RM) -f bigloofth_u-$(RELEASE).zip && \
           ln bigloofth_s-$(RELEASE).zip bigloofth_u-$(RELEASE).zip); \
	  (cd $(DESTDIR)$(FILDIR) && \
           $(RM) -f bigloofth_e-$(RELEASE).zip && \
           ln bigloofth_s-$(RELEASE).zip bigloofth_e-$(RELEASE).zip); \
        fi

install-dotnet:
	if [ $(DESTDIR)$(FILDIR) != $(BOOTLIBDIR) ]; then \
	  cp $(BOOTLIBDIR)/fthread.jheap $(DESTDIR)$(FILDIR)/fthread.jheap && \
	  chmod $(BMASK) $(DESTDIR)$(FILDIR)/fthread.jheap && \
	  cp $(BOOTLIBDIR)/bigloofth_s-$(RELEASE).dll $(DESTDIR)$(FILDIR)/bigloofth_s-$(RELEASE).dll && \
	  chmod $(BMASK) $(DESTDIR)$(FILDIR)/bigloofth_s-$(RELEASE).dll && \
	  cp $(BOOTLIBDIR)/bigloofth_u-$(RELEASE).dll $(DESTDIR)$(FILDIR)/bigloofth_u-$(RELEASE).dll && \
	  chmod $(BMASK) $(DESTDIR)$(FILDIR)/bigloofth_u-$(RELEASE).dll ; \
	  cp $(BOOTLIBDIR)/bigloofth_e-$(RELEASE).dll $(DESTDIR)$(FILDIR)/bigloofth_e-$(RELEASE).dll && \
	  chmod $(BMASK) $(DESTDIR)$(FILDIR)/bigloofth_e-$(RELEASE).dll ; \
        fi

uninstall:
	-$(RM) -f $(DESTDIR)$(FILDIR)/fthread.init
	-$(RM) -f $(DESTDIR)$(FILDIR)/fthread.heap
	-$(MAKE) uninstall-lib LIB=libbigloofth_s-$(RELEASE)
	-$(MAKE) uninstall-lib LIB=libbigloofth_u-$(RELEASE)
	-$(MAKE) uninstall-lib LIB=libbigloofth_e-$(RELEASE)
	-$(RM) -f $(DESTDIR)$(FILDIR)/fthread.jheap
	-$(RM) -f $(DESTDIR)$(FILDIR)/bigloofth_s-$(RELEASE).zip
	-$(RM) -f $(DESTDIR)$(FILDIR)/bigloofth_e-$(RELEASE).zip
	-$(RM) -f $(DESTDIR)$(FILDIR)/bigloofth_u-$(RELEASE).zip
	-$(RM) -f $(DESTDIR)$(FILDIR)/bigloofth_s-$(RELEASE).dll
	-$(RM) -f $(DESTDIR)$(FILDIR)/bigloofth_u-$(RELEASE).dll
	-$(RM) -f $(DESTDIR)$(FILDIR)/bigloofth_e-$(RELEASE).dll

#*---------------------------------------------------------------------*/
#*    distrib                                                          */
#*---------------------------------------------------------------------*/
distrib:
	(cd src && $(MAKE) ude)
