#Copyright (C) The University of Melbourne 1993
#All Rights Reserved

#Permission to use, copy, modify, and distribute this software and
#its documentation for any purpose and without fee is hereby
#granted, provided that the above copyright notice appear in all
#copies and that both that the copyright notice and this
#permission notice and warranty disclaimer appear in supporting
#documentation, and that the name of The University of Melbourne 
#or any of its entities not be used in advertising or publicity
#pertaining to distribution of the software without specific,
#written prior permission.

#THE UNIVERSITY OF MELBOURNE DISCLAIMS ALL WARRANTIES WITH REGARD
#TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
#MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL THE UNIVERSITY
#OF MELBOURNE OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
#SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
#IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
#ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
#THIS SOFTWARE.

#AUTHORS : Jason Lee (jasonl@cs.mu.oz.au)
#	   Andrew Davison (ad@cs.mu.oz.au)

#*******************************************************************
# MACROS TO CHANGE TO REFLECT THE CONFIGURATION OF YOUR LOCAL
# MACHINE PLEASE HAVE A READ AND EDIT

# The shell to use, shouldn't need to be changed, but here just in case
SHELL= /bin/sh

# The NU-Prolog compiler is needed and we assume it
# is in your path. If not change this to the absolute
# path name, this is very important!!!!.
NC= nc

# The install directory, where to place the system once
# created (NOTE : REMEMBER THIS, FOR EDITING THE BP FILE 
# DURING INSTALLATION, READ THE README FILE FOR MORE DETAILS)
INSTALLDIR="you_have_not_set_installdir_as_yet_in_the_Makefile"

# The directory to place the man pages
# This should be set to a local man directory
MANDIR="you_have_not_set_mandir_as_yet_in_the_Makefile"

# The editor to invoke to force the changing of the bp
# shell file to reflect the final placement (SEE THE README
# FILE FOR MORE DETAILS)
VI= vi

# Yacc flags to set
YFLAGS= "-vdtl"

# The location of lex and yacc commands, assume there in 
# your path
LEX= lex
YACC= yacc

# Libraries to include
# -lc_s = C shared library
# -ll = lex library
# -ly = yacc library
LIBS= "-lc_s -ll -ly"

# Warnings to set while compiling
# There are two different sets, see below for more details
GCCWARN=  -Wall -Wshadow -Wid-clash-20 -Wpointer-arith -Wcast-qual \
		-Wwrite-strings
GCC2WARN=  -Wall -Wshadow -Wid-clash-20 -Wpointer-arith -Wcast-qual
CCWARN=

# Change this if you which to use functions instead
# of the defined macros, have a look at compiler/bebop.h
# NOTE: if using functions then define USE_FUNCTIONS
# Only if you really want too, the macros are fine...
DEF= -DDYYDEBUG
#DEF= -DDYYDEBUG -DUSE_FUNCTIONS

# If sprintf doesn't return int then set macro SPRT
# This may be the case if you aren't fully ANSI C
# yet
SPRT=
#SPRT=          -DSPRT

# Optimise
GCCOP= -O
CCOP= -O2 -Olimit 2000

# Debugging level
DEB=

#Actual flags that are set, a combination of the above
GCCFLAGS=       $(GCCOP) $(DEB) $(SPRT) $(GCCWARN) $(DEF)
GCC2FLAGS=      $(GCCOP) $(DEB) $(SPRT) $(GCC2WARN) $(DEF)
CCFLAGS=        $(CCOP) $(DEB) $(SPRT) $(CCWARN) $(DEF)
CFLAGS=

# Which compiler to use cc or gcc
# NOTE : Unless you know for sure that lex output will compile
#        ok with cc stick with gcc. I noted that cc didn't like
#        the code produced and would hang, gcc however worked
#        fine (gcc version 1.40). The fix was later found
#        you must have -signed to indicate signed chars i.e EOF
#        is (-1) in lex and the new macro input uses it
#        Also some library files in lex and yacc use traditional
#	 C compilation and others are full ANSI, so
#	 uncomment/comment all of the below
#        depending on the compiler.
TRADCC=         "gcc $(GCC2FLAGS)"
CC2=            "gcc -ansi $(GCC2FLAGS)"
CC=             "gcc -ansi $(GCCFLAGS)"
#If you use CC use theses
#CC=            "cc -ansi $(CCFLAGS)"
#CC2=           "$(CC)"
#TRADCC=        "cc -signed $(CCFLAGS)"


#*********DO NOT EDIT/CHANGE ANYTHING PASSED THIS POINT ******
bebop :
	@/bin/echo ""
	@/bin/echo "Changing to bp directory." 
	@/bin/echo "Creating the bp interpreter, hold on a minute...."
	@/bin/echo ""
	@/bin/echo ""
#	This is so the user can see and read the above message
	@sleep 3
	@(cd bp;\
	make SHELL=$(SHELL) NC=$(NC))
	@/bin/echo ""
	@/bin/echo "Changing to compiler directory."
	@/bin/echo "Creating the bebop compiler, hold on a minute....."
	@/bin/echo ""
	@/bin/echo ""
#	This is so the user can see and read the above message
	@sleep 3
	@(cd compiler;\
	 /bin/echo "";\
	 /bin/echo "PLEASE EDIT THIS FILE, I WILL INVOKE THE EDITOR FOR YOU";\
	 sleep 3;\
	 $(VI) +47 bebop.h;\
	 /bin/echo "";\
	 /bin/echo "";\
	 /bin/echo "THANK YOU FOR EDITING THE HEADER FILE, NOW COMPILING";\
	 make SHELL=$(SHELL)  YFLAGS=$(YFLAGS) \
	      LEX=$(LEX) YACC=$(YACC) LIBS=$(LIBS) CFLAGS=$(CFLAGS) \
	      TRADCC=$(TRADCC) CC2=$(CC2) CC=$(CC);)
	@/bin/echo ""
	@/bin/echo " Changing to pnp directory. Making the pnp processor"
	@/bin/echo ""
	@/bin/echo ""
#	This is so the user can see and read the above message
	@sleep 3
	@(cd pnp;\
	  make SHELL=$(SHELL) NC=$(NC);)

install :
#	If there isn't any INSTALLDIR or MANDIR then stop
	@if [ ! -d $(INSTALLDIR) -o ! -d $(MANDIR) ]; then \
		/bin/echo "Have you set the INSTALLDIR macro correctly ??";\
		/bin/echo "Have you set the MANDIR macro correctly ??";\
		/bin/echo "There doesn't seem to be any directory called";\
		/bin/echo $(INSTALLDIR) for the install dir;\
		/bin/echo "There doesn't seem to be any directory called";\
		/bin/echo $(INSTALLDIR) for the man dir;\
	else \
	(cd bp; make install INSTALLDIR=$(INSTALLDIR) VI=$(VI));\
	(cd compiler; make install INSTALLDIR=$(INSTALLDIR));\
	(cd pnp; make install INSTALLDIR=$(INSTALLDIR) VI=$(VI));\
	/bin/cp man/* $(MANDIR);\
	fi
	
clean :
	(cd bp; make clean;)
	(cd compiler; make clean;)
	(cd pnp; make clean;)

clobber :
	(cd bp; make clobber;)
	(cd compiler; make clobber;)
	(cd pnp; make clobber;)

