# Top-level Makefile for KLIC system
# Copyright 1993 Institute for New Generation Computer Technology
# Read COPYRIGHT for detailed information

########################################
# Directory Names
########################################

# Directory name prefix for all the KLIC system files
DIRPREFIX = /usr/local

# Include file directory
KLICINCLUDE = $(DIRPREFIX)/include

# Library directory
KLICLIB = $(DIRPREFIX)/lib

# Executable directory
KLICBIN = $(DIRPREFIX)/bin

########################################
# System-dependent switches
########################################

# If you are using Prolog systems different from SICStus Prolog,
# you need to modify the following line.
PROLOG = sicstus

# If you are not using gcc, change the following.
CC = gcc -pipe
LD = gcc -pipe

# Optimization flags for compiling the runtime system.
OPTFLAGS = -O2 -fomit-frame-pointer
DEBUGFLAGS = -g

# Optimization flags to be passed to cc along with -O
# specified optimization on compilation of user programs.
UOPTFLAGS = -fomit-frame-pointer

# If you are using System V, uncomment the following.
#SYSV = -DSYSV

# If your system doesn't have lockf feature, comment the following
LOCKF = -DUSELOCKF

RANLIB = ranlib
# If your system doesn't have ranlib, uncomment the following.
#RANLIB = true

# If you are using non-standard make, change the following.
MAKE = make

INSTALL = install
INSTDIR = install -d
# If you do not have "install" command, uncomment the following two.
#INSTALL = cp -p
#INSTDIR = mkdir -p

INSTALLHDR = cp -p

########################################
# DO NOT TOUCH WHAT FOLLOWS
########################################

UCFLAGS = -DCSUSPS $(GCC) $(SYSV)
CFLAGS = $(UCFLAGS) $(OPTFLAGS) $(DEBUGFLAGS)

all:	compilerdir runtimedir

runtimedir: compilerdir
	cd runtime; $(MAKE) CFLAGS="$(CFLAGS)" CC="$(CC)" LD="$(LD)" \
		RANLIB=$(RANLIB)

compilerdir:
	cd compiler; $(MAKE) PROLOG="$(PROLOG)" CFLAGS="$(CFLAGS)" \
		CC="$(CC)" LD="$(LD)" KLICINCLUDE="$(KLICINCLUDE)" \
		KLICLIB="$(KLICLIB)" KLICBIN="$(KLICBIN)" \
		UOPTFLAGS="$(UOPTFLAGS)" \
		UCFLAGS="$(UCFLAGS)"

tests:	compilerdir runtimedir
	cd test; $(MAKE) distclean tests

install: all install-compiler install-runtime install-include

install-compiler: compilerdir
	cd compiler; \
	$(MAKE) install INSTALL="$(INSTALL)" INSTDIR="$(INSTDIR)" \
		KLICLIB="$(KLICLIB)" KLICBIN="$(KLICBIN)" \
		KLICINCLUDE="$(KLICINCLUDE)"

install-runtime: runtimedir
	cd runtime; \
	$(MAKE) install INSTALL="$(INSTALL)" INSTDIR="$(INSTDIR)" \
		KLICLIB="$(KLICLIB)" KLICBIN="$(KLICBIN)" \
		KLICINCLUDE="$(KLICINCLUDE)" RANLIB="$(RANLIB)"

install-include:
	cd include; \
	$(MAKE) install INSTALL="$(INSTALL)" INSTDIR="$(INSTDIR)" \
		INSTALLHDR="$(INSTALLHDR)" \
		KLICLIB="$(KLICLIB)" KLICBIN="$(KLICBIN)" \
		KLICINCLUDE="$(KLICINCLUDE)"

depend:
	cd runtime; \
	$(MAKE) depend PROLOG="$(PROLOG)" CFLAGS="$(CFLAGS)" \
		CC="$(CC)" LD="$(LD)" KLICINCLUDE="$(KLICINCLUDE)" \
		KLICLIB="$(KLICLIB)" KLICBIN="$(KLICBIN)" \
		UOPTFLAGS="$(UOPTFLAGS)" \
		UCFLAGS="$(UCFLAGS)"
	cd compiler; \
	$(MAKE) depend PROLOG="$(PROLOG)" CFLAGS="$(CFLAGS)" \
		CC="$(CC)" LD="$(LD)" KLICINCLUDE="$(KLICINCLUDE)" \
		KLICLIB="$(KLICLIB)" KLICBIN="$(KLICBIN)" \
		UOPTFLAGS="$(UOPTFLAGS)" \
		UCFLAGS="$(UCFLAGS)"

clean:
	cd compiler; $(MAKE) clean
	cd include; $(MAKE) clean
	cd runtime; $(MAKE) clean
	cd test; $(MAKE) clean

distclean:
	cd compiler; $(MAKE) distclean
	cd include; $(MAKE) distclean
	cd runtime; $(MAKE) distclean
	cd test; $(MAKE) distclean
	/bin/rm -f *~
