################################################################
# Makefile for preparing/moving/installing the binary distribution of
# SWI-Prolog and/or XPCE
#
# Author: Jan Wielemaker, SWI, University of Amsterdam
# E-mail: jan@swi.psy.uva.nl
#
# Targets
#	make		(Re)makes SWI-Prolog startup file and XPCE
#			precompiled Prolog files (QLF-files).  The
#			latter is only possible if you can open a
#			connection to the X-server
#
#	make [prefix=path] [PWD=path-to-here] [PL=pl] [XPCE=xpce] install
#			Install public binaries and manual pages for
#			pl, xpce, chpl and pl-bite.  The binaries are
#			installed in $prefix/bin and the manuals in
#			$prefix/man/man$(mansec)
#
#			The default prefix is /usr/local, the default
#			path-to-here is the result if `pwd`.
#
#			The variables $PL and $XPCE may be used to
#			modify the name of the executable
################################################################


prefix=/usr/local
bindir=$(prefix)/bin
mansec=1
mandir=$(prefix)/man/man$(mansec)

MAKE=gmake
PLNAME=pl
PL=bin/i486-linux/$(PLNAME)
XPCE=xpce
CLIENT=xpce-client
PLARCH=i486-linux

BPL=		bin/$(PLARCH)/$(PLNAME)
PWD=`pwd`

# Make this boot64 for 64-bit processors

STARTUP=	boot32.prc
BOOTPLS=	boot/apply.pl boot/autoload.pl \
		boot/bags.pl boot/dwim.pl \
		boot/history.pl boot/init.pl \
		boot/load.pl boot/parms.pl \
		boot/qlf.pl boot/syspred.pl boot/toplevel.pl \
		boot/topvars.pl boot/writef.pl

all:		$(STARTUP) xpce-qlfs

$(STARTUP):	$(BOOTPLS)
		$(BPL) -O -o $@ -b boot/init.pl

xpce-qlfs:	
		@PLBASE=$(PWD); \
		if [ -d xpce ]; then \
		   echo $(MAKE) PL=$$PLBASE/$(BPL); \
                   (cd xpce/prolog/lib; $(MAKE) PL=$$PLBASE/$(BPL)); \
		fi

install:	all
		PLBASE=$(PWD); \
		for f in plrc plld; do \
		    (cd $(bindir); rm -f $$f; ln -s $$PLBASE/bin/$(PLARCH)/$$f .); \
		done ; \
		(cd $(bindir); rm -f $(PLNAME); ln -s $$PLBASE/bin/$(PLARCH)/$(PLNAME) $(PLNAME)) ; \
		if [ -d xpce ]; then \
		  (cd $(bindir);rm -f $(XPCE);ln -s $$PLBASE/$(BPL) $(XPCE));\
		  (cd $(bindir);rm -f $(CLIENT);ln -s $$PLBASE/xpce/bin/$(PLARCH)/xpce-client $(CLIENT)); \
		fi
		-for f in $(PLNAME) plld; do \
		    cp man/$$f.1 $(mandir)/$$f.$(mansec); \
		done
		-if [ -d xpce ]; then \
		    for f in xpce xpce-client; do \
		        cp xpce/man/$$f.1 $(mandir)/$$f.$(mansec); \
		    done; \
		fi

		
clean:
		rm -f `find xpce/prolog -name '*.qlf' -print`
