## Define the version number of this release.  Do not change this.

VERSION = 4.7

## Define where the final targets are installed. If you wish to put the final
## pieces in different places, you should change these macros before you create
## the configuration file and before you build the package because these
## variables are used to hardcode addresses in some of the package modules.
## These macros are copied into the configuration file and used by the
## individual modules that comprise the entire system.

.IF ${INSTALLPREFIX} == ${NULL}
	INSTALLPREFIX = $(shell pwd)
.END
.IF ${INSTALLBINDIR} == ${NULL}
	INSTALLBINDIR = ${INSTALLPREFIX}/bin
.END
.IF ${INSTALLLIBDIR} == ${NULL}
	INSTALLLIBDIR = ${INSTALLPREFIX}/lib
.END
.IF ${INSTALLINCDIR} == ${NULL}
	INSTALLINCDIR = ${INSTALLPREFIX}/inc
.END
.IF ${INSTALLMANDIR} == ${NULL}
	INSTALLMANDIR = ${INSTALLPREFIX}/man
.END
.IF ${INSTALLDOCDIR} == ${NULL}
	INSTALLDOCDIR = ${INSTALLPREFIX}/doc
.END

## Define where temporary files are created during compilation and execution.

.IF ${TMPDIR} == ${NULL}
	TMPDIR = /usr/tmp
.END


########################### END OF THINGS TO CHANGE ###########################


## Define the directory that contains the package as the current directory.

PACKAGE = $(shell pwd)

## Define where the configuration file lives.

CONFIG = ${PACKAGE}/CONFIG

## Ensure the correct shell is used

SHELL !:= /bin/sh
GROUPSHELL !:= /bin/sh

## Define the major recipes.

all \
depend \
clean \
install :
@[
	## If the configuration file is not yet built, instruct
	## the user how to create one.

	if [ ! -f ${CONFIG} ] ; then
		echo ""
		echo "The file ${CONFIG} was not found."
		echo "Create file ${CONFIG} with one of the following commands..."
		echo ""
#		echo "	${MAKECMD} sequent-i386-ptx"
		echo "	${MAKECMD} sun-sparc-sunos"
		echo "	${MAKECMD} sun-sparc-svr4"
		echo "	${MAKECMD} sun-m68k-sunos"
#		echo "	${MAKECMD} sun-i386-svr4"
		echo "	${MAKECMD} dec-ultrix-mips"
		echo "	${MAKECMD} dec-alpha"
		echo "	${MAKECMD} sgi-mips-r4000"
		echo "	${MAKECMD} sgi-mips-r3000"
		echo "	${MAKECMD} ibm-rs6000"
		echo "	${MAKECMD} hp-hppa"
		echo "	${MAKECMD} pc-i386-linux"
		echo "	${MAKECMD} gizmo"
		echo ""
		exit 1
	fi

	## Build each of the modules in the system. It is important that the modules be
	## built in this order. Each successive module is built using previous modules.

	for module in doc/man src/translator src/collection src/kernel src/profiler src/library src/trace src/usertrace src/debugger ; do
		( set -x; cd ${PACKAGE}/$${module}; ${MAKECMD} ${MAKETARGETS} ${MFLAGS} )
	done
]

scratch :
	rm -rf ${INSTALLMANDIR}/* ${INSTALLBINDIR}/* ${INSTALLLIBDIR}/* ${INSTALLINCDIR}/*


# These recipe recursively invoke this file again with all configuration variables set.

sequent-i386-ptx : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sequent OS=svr4 CPU=i386 TVENDOR=sequent TOS=svr4 TCPU=i386 MULTI=TRUE TRACE=FALSE

sun-sparc-sunos : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sun OS=sunos CPU=sparc TVENDOR=sun TOS=sunos TCPU=sparc MULTI=TRUE TRACE=TRUE

sun-sparc-svr4 : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sun OS=svr4 CPU=sparc TVENDOR=sun TOS=svr4 TCPU=sparc MULTI=TRUE TRACE=TRUE

sun-m68k-sunos : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sun OS=sunos CPU=m68k TVENDOR=sun TOS=sunos TCPU=m68k MULTI=TRUE TRACE=FALSE

#sun-i386-svr4 : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sun OS=svr4 CPU=i386 TVENDOR=sun TOS=svr4 TCPU=i386 MULTI=TRUE TRACE=FALSE

dec-ultrix-mips : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=dec OS=ultrix CPU=mips TVENDOR=dec TOS=ultrix TCPU=mips MULTI=FALSE TRACE=FALSE

dec-alpha : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=dec OS=svr4 CPU=alpha TVENDOR=dec TOS=svr4 TCPU=alpha MULTI=TRUE TRACE=FALSE

sgi-mips-r4000 : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sgi OS=svr4 CPU=mips TVENDOR=sgi TOS=svr4 TCPU=mips MULTI=TRUE TRACE=FALSE

sgi-mips-r3000 : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sgi OS=svr4 CPU=mips TVENDOR=sgi TOS=svr4 TCPU=mips MULTI=FALSE TRACE=FALSE

ibm-rs6000 : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=ibm OS=aix CPU=rs6000 TVENDOR=ibm TOS=aix TCPU=rs6000 MULTI=FALSE TRACE=TRUE

hp-hppa : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=hp OS=hpux CPU=hppa TVENDOR=hp TOS=hpux TCPU=hppa MULTI=FALSE TRACE=FALSE

pc-i386-linux : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=pc OS=linux CPU=i386 TVENDOR=pc TOS=linux TCPU=i386 MULTI=TRUE TRACE=FALSE

gizmo : ; @${MAKECMD} ${MAKEMACROS} ${MFLAGS} configure VENDOR=sun OS=svr4 CPU=sparc TVENDOR=gizmo TOS=bsd TCPU=m68k MULTI=FALSE TRACE=FALSE


configure :
@[
	echo "Configuring u++-${VERSION} for ${VENDOR} host running ${OS} on a ${CPU} for ${TVENDOR} target running ${TOS} on a ${TCPU}."

	echo "##" > ${CONFIG}
	echo "## Don't edit this file directly.  Edit the make" >> ${CONFIG}
	echo "## file instead, and then make a new config file." >> ${CONFIG}
	echo "##" >> ${CONFIG}
	echo "VERSION = ${VERSION}" >> ${CONFIG}
	echo "VENDOR = ${VENDOR}" >> ${CONFIG}
	echo "OS != ${OS}" >> ${CONFIG}
	echo "CPU = ${CPU}" >> ${CONFIG}
	echo "TVENDOR = ${TVENDOR}" >> ${CONFIG}
	echo "TOS = ${TOS}" >> ${CONFIG}
	echo "TCPU = ${TCPU}" >> ${CONFIG}
	echo "INSTALLBINDIR = ${INSTALLBINDIR}" >> ${CONFIG}
	echo "INSTALLLIBDIR = ${INSTALLLIBDIR}" >> ${CONFIG}
	echo "INSTALLINCDIR = ${INSTALLINCDIR}" >> ${CONFIG}
	echo "INSTALLMANDIR = ${INSTALLMANDIR}" >> ${CONFIG}
	echo "INSTALLDOCDIR = ${INSTALLDOCDIR}" >> ${CONFIG}
	echo "TMPDIR = ${TMPDIR}" >> ${CONFIG}
	echo "MULTI = ${MULTI}" >> ${CONFIG}
	echo "TRACE = ${TRACE}" >> ${CONFIG}
	echo "SHELL !:= /bin/sh" >> ${CONFIG}

	for file in `find doc src -type f -name Makefile -print` ; do
		sed 's^VERSION = .*^VERSION = '${VERSION}'^' $$file > /tmp/t$$$$
		if cmp -s $$file /tmp/t$$$$ ; then
			rm /tmp/t$$$$
		else
			echo "Setting hard coded variables in file $$file"
			mv /tmp/t$$$$ $$file
		fi
		sed 's^PACKAGE = .*^PACKAGE = '${PACKAGE}'^' $$file > /tmp/t$$$$
		if cmp -s $$file /tmp/t$$$$ ; then
			rm /tmp/t$$$$
		else
			echo "Setting hard coded variables in file $$file"
			mv /tmp/t$$$$ $$file
		fi
	done

	if [ ${TVENDOR} = gizmo ] ; then	# TEMPORARY, printf does not support %p
		echo "Adjusting for printf format difference"
		for file in `find . -type f \( -name '*.cc' -o -name '*.h' \) -print` ; do
			sed 's/0x%p/0x%x/g' $$file > /tmp/t$$$$
			if cmp -s $$file /tmp/t$$$$ ; then
				rm /tmp/t$$$$
			else
				mv /tmp/t$$$$ $$file
			fi
		done
	fi
	if [ ${TOS} = linux ] ; then		# TEMPORARY, printf adds "0x" for %p
		echo "Adjusting for printf format difference"
		for file in `find . -type f \( -name '*.cc' -o -name '*.h' \) -print` ; do
			sed 's/0x%p/%p/g' $$file > /tmp/t$$$$
			if cmp -s $$file /tmp/t$$$$ ; then
				rm /tmp/t$$$$
			else
				mv /tmp/t$$$$ $$file
			fi
		done
	fi

	echo "Finished configuration, just type ${MAKECMD} install."
]

## Local Variables: ##
## compile-command: "dmake" ##
## End: ##
