#*=====================================================================*/
#*    serrano/prgm/project/bigloo/pnet2ms/Makefile                     */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Jan 14 14:46:31 1998                          */
#*    Last change :  Wed Aug 16 07:03:28 2006 (serrano)                */
#*    Copyright   :  1998-2006 Manuel Serrano, see LICENSE file        */
#*    -------------------------------------------------------------    */
#*    The Makefile to build pnet2ms.                                   */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    Default configuration                                            */
#*---------------------------------------------------------------------*/
include ../Makefile.config

#*---------------------------------------------------------------------*/
#*    Compilers, Tools and Destinations                                */
#*---------------------------------------------------------------------*/
# the executable used to bootstrap
BIGLOO=        $(BOOTBINDIR)/bigloo     
# the .afile
AFILE=         .afile
# the shell to be used
SHELL=         /bin/sh
# the produced executable
PNET2MS_DEST=  $(BOOTBINDIR)/pnet2ms$(EXE_SUFFIX)

#*---------------------------------------------------------------------*/
#*    Afile tool                                                       */
#*---------------------------------------------------------------------*/
AFILE_BIN=     $(BOOTBINDIR)/$(AFILE_EXE)

#*---------------------------------------------------------------------*/
#*    Compilation flags                                                */
#*---------------------------------------------------------------------*/
BFLAGS=        -rm -afile $(AFILE) -O2 -fsharing -unsafe $(SHRD_BDE_OPT)

#*---------------------------------------------------------------------*/
#*    Object files                                                     */
#*---------------------------------------------------------------------*/
OBJECTS=       pnet2ms.o win32-base.o win32-registry.o win32-helpers.o

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

POPULATION=    $(SOURCE_FILES) Makefile bigloo.dotnetkey

#*---------------------------------------------------------------------*/
#*     Suffixes ...                                                    */
#*---------------------------------------------------------------------*/
.SUFFIXES:
.SUFFIXES: .scm .c .o

#*---------------------------------------------------------------------*/
#*    The `pnet2ms' binary                                             */
#*---------------------------------------------------------------------*/
pnet2ms: $(SOURCE_FILES) afile
	@ $(MAKE) $(PNET2MS_DEST)

#*---------------------------------------------------------------------*/
#*    $(PNET2MS_DEST)                                                  */
#*---------------------------------------------------------------------*/
$(PNET2MS_DEST): $(OBJECTS)
	@ echo "Linking:"
	@ $(BIGLOO) $(BFLAGS) $(OBJECTS) -o $(PNET2MS_DEST)
	@- $(STRIP) $(PNET2MS_DEST)
	@ echo "pnet2ms done..."
	@ echo "-------------------------------"

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

install:
	if [ $(BINDIR) != $(BOOTBINDIR) ]; then \
	   cp $(BOOTBINDIR)/pnet2ms$(EXE_SUFFIX) $(DESTDIR)$(BINDIR); \
	   chmod $(BMASK) $(DESTDIR)$(BINDIR)/pnet2ms$(EXE_SUFFIX); \
        fi

uninstall:
	- $(RM) -f $(DESTDIR)$(BINDIR)/pnet2ms$(EXE_SUFFIX)

#*---------------------------------------------------------------------*/
#*    afile                                                            */
#*---------------------------------------------------------------------*/
afile: $(SOURCE_FILES)
	@ echo "   - " $ $(AFILE)
	@ $(AFILE_BIN) -o $(AFILE) $(SOURCE_FILES)

#*---------------------------------------------------------------------*/
#*    distrib                                                          */
#*    -------------------------------------------------------------    */
#*    We prepare the compiler for a distribution                       */
#*---------------------------------------------------------------------*/
distrib: 
	@ if [ `pwd` = $(BOODIR)/pnet2ms ]; then \
             echo "*** ERROR:Illegal dir to make a distrib `pwd`"; \
             exit 1; \
          fi
	@ $(MAKE) cleanall
	@ $(MAKE) afile

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

clean:
	@- $(RM) -f $(OBJECTS)
	@- $(RM) -f $(OBJECTS:%.o=%.c)
	@- $(RM) -f $(AFILE)
	@ find . \( -name '*[~%]' \
                       -o -name '.??*[~%]' \
                       -o -name '#*#' \
                       -o -name '?*#' \
                       -o -name \*core \) \
                     -type f -exec rm {} \;   
	@ echo "cleanup done..."
	@ echo "-------------------------------"

cleanall: clean
	@- $(RM) -f $(PNET2MS_DEST)

distclean: cleanall

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

#*---------------------------------------------------------------------*/
#*    link ...                                                         */
#*---------------------------------------------------------------------*/
link:
	@ echo "Linking:"
	@ $(BIGLOO) $(BFLAGS) -o $(PNET2MS_DEST) $(OBJECTS) -lm
	@ echo "link done..."
	@ echo "-------------------------------"

#*---------------------------------------------------------------------*/
#*    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:%=pnet2ms/%)

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

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