#########################################################################
#   IC-Prolog ][							#
#									#
#   Makefile for building IC-Prolog ][ system				#
#									#
#   Created by Yannis Cosmadopoulos					#
#   25 November, 1992							#
#########################################################################



#########################################################################
#
#                   start of user configurable section
#
#########################################################################

######################################
# Specify the installation directories
######################################

# INSTALLDIR - where the run time system will be installed.
# Using the default (`pwd`/runtime) will avoid multiple copies being created.
# space requirement: up to 2.8M (allow extra 1.5M if installing for
# both Sun-3 and Sun-4 architectures).
# WARNING: Do not use this default if you use an automounting system.  You
# must give a full path name.
INSTALLDIR	= `pwd`/runtime

# BINDIR - where the executables will be installed.
# space requirement = 2K
BINDIR		= /usr/local/bin

# INFODIR - directory for on-line manual using info nodes.
# If you use an automounting system, you must use a hard-wired path.
# space requirement = 350K
INFODIR		= /usr/local/emacs/info
# If not using on-line manual, uncomment the following line
#INFODIR		=

##############################
# Specify choice of C compiler
##############################

# (the choice is irrelevant if you do not have the C sources)

# ----------- GNU cc ---------------------
CC      	= gcc
# If you want optimised code, you can set CFLAGS to '-O2' with
# gcc version 2.  Under version 1, the optimisation flag is '-O'.
# Optimised code gives a significant performance improvement.
# Note that -O2 will only work with version 2, and will give
# errors when used with version 1.
# Use "gcc -v" to find out which version you have.
#CFLAGS  	= -g
CFLAGS  	= -O2
LDFLAGS 	= -static

# ----------- Sun cc ---------------------
#CC      	= cc
#CFLAGS  	= -w -O
#LDFLAGS 	= -Bstatic

############################
# options (more to be added)
############################

# By default, the Parlog TCP primitives must be explicitly loaded
# using the Parlog foreign language interface facilities.  The core
# system is thus kept small, and the primitives are only loaded when
# needed.  However, using the foreign language interface implies a
# short delay while the primitives are loaded.  If you intend to use
# the Parlog TCP features regularly, you might prefer to load those
# primitives as part of the core system.  The core system will be
# slightly larger as a result.  If you prefer to do this AND you have
# access to the C sources, uncomment the following line.
#
#PARLOG_CPP1	= -DPARLOGTCP
#
# If you make any change to the above line (either commenting or
# uncommenting) after building the system for the first time, you
# must manually issue the commands
#
#	touch src/parlog/initial.c
#	rm -f sun[34]/parlog/libparlog.a
#
# and regenerate the makefiles using
#
#	make makefiles
#

#########################################################################
#           The default values in the next section are fine.
#                    Edit only if really necessary.
#########################################################################

###################
# names of programs
###################

ICP		= icp
MBX_SERVER	= mbx_server

############################
# size of each prolog thread
# (use default values initially and adjust later if necessary)
############################

# default heap size is 48K cells
HEAPSIZE	= 0xc000L

# default stack size is 16K cells
STACKSIZE	= 0x4000L

#######################################
# Unix commands to be used in makefiles
#######################################

RM		= /usr/bin/rm -f
RM_CMD		= $(RM) core .make* .nse_depinfo
M4		= /usr/bin/m4
SED		= /usr/bin/sed
CUT		= /usr/bin/cut
CHMOD		= /usr/bin/chmod
INSTALL		= /usr/bin/install
INSTBINFLAGS	= -m 0775
INSTLIBFLAGS	= -m 0664
LN		= /usr/bin/ln
TAR		= /usr/bin/tar
AR_CMD		= /usr/bin/ar ruv
RANLIB		= /usr/bin/ranlib
MAKEDEPEND	= /usr/bin/X11/makedepend

#############################################
# commands needed for producing documentation
#############################################
TEX		= tex
LATEX		= latex
TEXINDEX	= texindex
MAKEINFO	= makeinfo

#####################################
# commands used in this makefile only
#####################################
MKDIRH		= install/mkdirhier
FIND		= /usr/bin/find
PERL		= /usr/local/bin/perl
PWD		= /usr/bin/pwd

#########################################################################
#                    end of user configurable section
#                  DO NOT EDIT ANYTHING BELOW THIS LINE
#########################################################################
CURRENT_DIR	= .
COMPDIR		= .
MAKEFILE	= Makefile

default:
	@echo
	@echo "                   IC-PROLOG ]["
	@echo "                   ============"
	@echo
	@echo "This is the procedure for installing the IC-Prolog ]["
	@echo "system on Sun-3 or Sun-4 machines running SunOS 4.x."
	@echo
	@echo "STEP 1:"
	@echo "Before installing, please check the user configurable"
	@echo "section at the top of the makefile, and configure the"
	@echo "variables if necessary.  Then issue the command"
	@echo
	@echo "        make makefiles"
	@echo
	@echo "STEP 2: (Optional)"
	@echo "If you have the makedepend program, you can enhance the"
	@echo "the makefiles you have just built by adding dependency"
	@echo "lists.  To do this, type"
	@echo
	@echo "        make depend"
	@echo
	@echo "STEP 3:"
	@echo "Now you are ready to build the system, issue the command"
	@echo
	@echo "        make all >& make.log"
	@echo
	@echo "STEP 4: (Optional)"
	@echo "If you do not have the ready-made .dvi and .info*"
	@echo "documentation and on-line manual (check the doc/parlog"
	@echo "and doc/prolog directories), you will need to generate"
	@echo "them from the texinfo files.  For this, you will need the"
	@echo "texinfo package version 2.88 or later.  If you have an"
	@echo "earlier version, please copy texinfo.tex (version 2.88)"
	@echo "included in the doc directory to your local tex macros"
	@echo "directory before generating the documentation.  To generate"
	@echo "the documentation and on-line manual, type"
	@echo
	@echo "        make doc"
	@echo
	@echo "STEP 5:"
	@echo "The run-time system will be built initially in ./runtime."
	@echo "To install IC-PROLOG ][ in the final destination, you will"
	@echo "need write permission for"
	@echo
	@echo "        \$$INSTALLDIR ($(INSTALLDIR))"
	@echo "        \$$INFODIR    ($(INFODIR))"
	@echo "        \$$BINDIR     ($(BINDIR))"
	@echo
	@echo "If you are satisfied with these values, now type"
	@echo
	@echo "        make install"
	@echo
	@echo
	@echo "NOTES :"
	@echo "Do not use the -k option of make unless you are sure"
	@echo "all the values for the variables are valid."
	@echo
	@echo "Do not edit the Makefiles in the subdirectories.  To make"
	@echo "changes, modify the top level makefile and then reissue"
	@echo
	@echo "        make makefiles"
	@echo
	@echo "If more changes are required and you feel confident about"
	@echo "what you are doing, try modifying install/Makefile.sed,"
	@echo "install/Makefile.subdir and the Makefile.m4 files in"
	@echo "subdirectories."
	@echo
	@echo "Hardcopies of the manuals may be printed from the dvi"
	@echo "files in doc/*."
	@echo

makefiles ::
	@echo "making makefiles in ."
	@if [ -d src/xpce ]; then xpce=yes; else xpce=no; fi; \
	if [ "$(PARLOG_CPP1)" ]; then parlogtcp=yes; else parlogtcp=no; fi; \
	$(SED) \
		-e "s:@m4cc@:`basename $(CC)`:" \
		-e "s:@m4arch@:`/bin/arch`:" \
		-e "s:@m4xpce@:$$xpce:" \
		-e "s:@m4parlogtcp@:$$parlogtcp:" \
		-e "s:@CC@:$(CC):" \
		-e "s:@CFLAGS@:\`$(CFLAGS)\':" \
		-e "s:@LDFLAGS@:$(LDFLAGS):" \
		-e "s:@PARLOG_CPP1@:$(PARLOG_CPP1):" \
		-e "s:@HEAPSIZE@:$(HEAPSIZE):" \
		-e "s:@STACKSIZE@:$(STACKSIZE):" \
		-e "s:@RM@:$(RM):" \
		-e "s:@RM_CMD@:$(RM_CMD):" \
		-e "s:@M4@:$(M4):" \
		-e "s:@SED@:$(SED):" \
		-e "s:@CUT@:$(CUT):" \
		-e "s:@CHMOD@:$(CHMOD):" \
		-e "s:@INSTALL@:$(INSTALL):" \
		-e "s:@INSTBINFLAGS@:$(INSTBINFLAGS):" \
		-e "s:@INSTLIBFLAGS@:$(INSTLIBFLAGS):" \
		-e "s:@LN@:$(LN):" \
		-e "s:@TAR@:$(TAR):" \
		-e "s:@AR_CMD@:$(AR_CMD):" \
		-e "s:@RANLIB@:$(RANLIB):" \
		-e "s:@MAKEDEPEND@:$(MAKEDEPEND):" \
		-e "s:@TEX@:$(TEX):" \
		-e "s:@LATEX@:$(LATEX):" \
		-e "s:@TEXINDEX@:$(TEXINDEX):" \
		-e "s:@MAKEINFO@:$(MAKEINFO):" \
		-e "s:@TOPDIR@:`pwd`:" \
		-e "s:@COMPDIR@:`cd $(COMPDIR); pwd`:" \
		install/$(MAKEFILE).sed > install/$(MAKEFILE).incl
	$(M4) $(MAKEFILE).m4 > $(MAKEFILE)

diffs makefiles all depend doc clean ::
	$(MAKE) $(MFLAGS) -f $(MAKEFILE) $@ CURRENT_DIR=$(CURRENT_DIR)

makefiles::
	@echo
	@echo "make makefiles completed."
	@echo
	@echo "The next step is optional.  If you have the makedepend"
	@echo "program ($(MAKEDEPEND)), now is the time to do"
	@echo
	@echo "        make depend"
	@echo

depend::
	@echo
	@echo "make depend completed."
	@echo

makefiles depend::
	@echo "The next step is to build the system.  Type"
	@echo
	@echo "        make all >& make.log"
	@echo

all::
	@echo
	@echo "make all completed."
	@echo
	@echo "The next step is optional.  If you use info files as"
	@echo "on-line manuals, you can generate an on-line manual"
	@echo "for IC-Prolog ][ by typing"
	@echo
	@echo "        make doc"
	@echo

doc::
	@echo
	@echo "make doc completed."
	@echo

all doc::
	@echo "The next step is to install the system.  First check"
	@echo "that the following directories are writeable by you"
	@echo
	@echo "        \$$INSTALLDIR ($(INSTALLDIR))"
	@echo "        \$$INFODIR    ($(INFODIR))"
	@echo "        \$$BINDIR     ($(BINDIR))"
	@echo
	@echo "and then type"
	@echo
	@echo "        make install"
	@echo

# this builds the makefile in runtime and installs
install install.bin::
	$(MKDIRH) $(INSTALLDIR) $(BINDIR) $(INFODIR)
	(	echo "    INSTALLDIR = $(INSTALLDIR)"; \
		echo "        BINDIR = $(BINDIR)"; \
		echo "       INFODIR = $(INFODIR)"; \
		echo "# To disable the installation of the on-line"; \
		echo "# manual, leave INFODIR blank in the line above."; \
		echo ""; \
		echo "# Names of programs to be installed"; \
		echo "#"; \
		echo "           ICP = $(ICP)"; \
		echo "    MBX_SERVER = $(MBX_SERVER)"; \
		echo ""; \
		echo "# pathname of perl if you have it"; \
		echo "#"; \
		echo "          PERL = $(PERL)"; \
		echo ""; \
		echo "# unlikely to need modification below this line"; \
		echo "#"; \
		echo "  INSTBINFLAGS = $(INSTBINFLAGS)"; \
		echo "  INSTLIBFLAGS = $(INSTLIBFLAGS)"; \
		echo "        MKDIRH = install/mkdirhier"; \
		echo "           PWD = $(PWD)"; \
		echo "           SED = $(SED)"; \
		echo "            M4 = $(M4)"; \
		echo "           TAR = $(TAR)"; \
		echo "       INSTALL = $(INSTALL)"; \
		cat install/Makefile.install \
	) | $(M4) - > runtime/$(MAKEFILE)
	(cd runtime; $(MAKE) $(MFLAGS) -f $(MAKEFILE) $@)

clean::
	$(RM) -r runtime
	$(FIND) . -name $(MAKEFILE) -exec $(RM) {} \;

#
#  This is only used when building ICP in a mixed environment
#
sun3::
	(cd ./sun3; $(MAKE) $(MFLAGS) -f $(MAKEFILE) all)

sun4::
	(cd ./sun4; $(MAKE) $(MFLAGS) -f $(MAKEFILE) all)

sun3 sun4:: install.bin

#
#  To add new lines to /etc/services
#
services:
	(cd ./install; $(PERL) inst-services.perl)
