# Makefile to build Static version of ProTcl
# (c) Gertjan van Noord

# this only has linux and hpux as possibilities, but it should not
# be difficult to add other systems. In order to add an operating system
# you have to provide the LDFLAGS (cf. the Sicstus Makefile) and the
# OOS and OOSLIST variables. The latter two define the object files
# that you want to include. The first variable is an ordinary sequence
# of o files, the second variable is Prolog notation..

###############################
## Edit the following lines: ##
###############################

# directory containing ProTcl sources
PROTCL=$(HOME)/src/ProTcl

# directory in which protcl will be installed upon make install
BINDIR=$(HOME)/bin

# command that starts sicstus
SICSTUS=sicstus


#########################################################
# You might not need to edit anything beyond this point #
#########################################################

default:
	@echo Usage: make linux ;\
         echo    or: make hpux


include $(PROTCL)/Makefile

# sicstus source directory
SICSTUS_DIR=$(PROLOG_INCLUDE)

TKO = $(PROTCL)/tk.o
CHARSIOO = $(SICSTUS_DIR)/library/charsio.o

# copy from Sicstus' Makefile:
# HPUX:   LDFLAGS= -Wl,-a,archive -n
# Linux:  LDFLAGS= 

linux:
	make OOS=$(TKO) OOSLIST="'$(TKO)'" target

hpux:
	make OOS="$$(TKO) $$(CHARSIOO)" OOSLIST="'$$(TKO)','$$(CHARSIOO)'" \
        LDFLAGS="-Wl,-a,archive -n" target

LIBFLAGS=-L/usr/local/lib -L$(HOME)/lib -L$(PROTCL) -L$(TCL_LIBRARY)\
         -L$(TK_LIBRARY) $(XLIBSW) -linit -ltkXAccess -lBLT -ltk -ltcl -lX11 -lm

install: target
	rm -f $(BINDIR)/protcl
	ln -s `pwd`/target $(BINDIR)/protcl

target: $(OOS) def.pl
	( echo "assertz(charsio_path('$(CHARSIOO)')).";\
          echo "assertz(tk_path('$(TKO)')).";\
          echo "reconsult(def),"; \
          echo "prepare_foreign_files([$(OOSLIST)]). " ) | $(SICSTUS) -f
	$(CC) -c -O flinkage.c
	$(CC) $(SICSTUS_DIR)/Emulator/sp.o flinkage.o \
              $(OOS) $(LDFLAGS) $(LIBFLAGS) -o sp
	echo "assertz(library_directory('$(SICSTUS_DIR)/library')),\
              save_program('target')." | ./sp -b $(SICSTUS_DIR)/Library/boot.ql -f

clean:
	rm -f flinkage.* sp target

