
# $Source: /usr/local/kcs/sys.DAVIS_800/mongoose/RCS/Makefile,v $
# $Revision: 1.6.98.10 $
# $State: Exp $
# $Date: 96/05/24 16:11:11 $

INCLUDE_DIR   = include_dir

# NOTE: Some defines are grouped here instead of in alphabetical
#       order.  This is to make it easy to change them as a group.

# NOTE: These defines build boot using the standard Compiler.

ST_CCINCS     =
ST_CC	      = cc
ST_LD	      = ld
ST_LINT       = lint

# NOTE: These defines build boot using the kernel Build Environment.

BE_CCINCS     = -I $(INCLUDE_DIR)
BE_CC	      = ../bld_tools/be_cc
BE_LD	      = ../bld_tools/be_ld
BE_LINT	      = ../bld_tools/be_lint


# NOTE: These defines build a version of the boot that can be
#       debugged as a user command.

XDB_CCDEFS    = -DXDB
XDB_CCOPTS    = -g +DS1.0 +DA1.0 -Ae +ESrel
XDB_LDFLAGS   = -Wl,-a,archive -g -z srt0.o 
XDB_LINK      = $(M_BE_ST_CC)

# NOTE: Uncomment these two lines if using profile instead of debug.
# XDB_CCOPTS    = -p +DS1.0 +DA1.0 -Ae +ESrel
# XDB_LDFLAGS   = -Wl,-a,archive -p -z srt0.o 

# NOTE: These defines build a normal version of the boot.

STD_CCDEFS    = -DRELOCATABLE_MONGOOSE
STD_CCOPTS    = -O +DS1.0 +DA1.0 -Ae +ESrel
STD_LDFLAGS   = -HF -t -k mongoose_ld -aarchive -N -Q -e _start srt0.o
STD_LINK      = $(M_BE_ST_LD)

CCINCS	      = $(M_BE_ST_CCINCS)


CFLAGS	      = $(M_STD_XDB_CCDEFS) $(M_STD_XDB_CCOPTS) $(CCINCS)

CC	      = $(M_BE_ST_CC)


LD	      = $(M_STD_XDB_LINK)

LDFLAGS	      = $(M_STD_XDB_LDFLAGS)

LINT	      = $(M_BE_ST_LINT)

DEST	      = .

EXTHDRS	      =

HDRS	      = bcache.h \
		conf.h \
		defines.h \
		exec.h \
		gputil.h \
		kdep.h \
		lifio.h \
		machdep.h \
		partition.h \
		saio.h \
		syscall.h \
		tftp.h \
		xdbconf.h

INSTALL	      = /usr/sbin/install

LIBS	      = libutl.a libkdep.a libmach.a libxdb.a

LIB_libkdep.a = \
		btcons.o \
		btdisc.o \
		btlan.o \
		btmem.o \
		bttape.o \
		call.o \
		env.o \
		error.o \
		exec.o \
		iob.o \
		kdep.o \
		ldvm.o \
		lfsm.o \
		lifio.o \
		lvol.o \
		malloc.o \
		nfs.o \
		nullfs.o \
		partition.o \
		peek.o \
		pif.o \
		prf.o \
		reboot.o \
		rmp.o \
		sys.o \
		tftp.o

LIB_libmach.a = \
		bcache.o \
		driver.o \
		elf64.o \
		iodc_util.o \
		machdep.o \
		reloc_it.o \
		som.o \
		srt0.o

LIB_libutl.a  = \
		btboot.o \
		cat.o \
		cvtutl.o \
		dd.o \
		flags.o \
		gputil.o \
		interact.o \
		lifcmds.o \
		listenv.o \
		ls.o \
		memutl.o \
		parse.o \
		show.o \
		strutl.o \
		uif.o

LIB_libxdb.a = \
		xdbconf.o \
		xdbio.o \
		xdbpdc.o \
		xdbrmp_iodc.o \
		xdbstd_iodc.o \
		xdbtftp_iodc.o

MAKEFILE      = Makefile

OBJECTS      = \
		boot.o \
		conf.o \
		hpux_rel.o

OBJS	      = \
		${LIB_libutl.a} \
		${LIB_libmach.a} \
		${LIB_libkdep.a} \
		${LIB_libxdb.a} \
		${OBJECTS}

PRINT	      = pr

PROGRAM       = boot

SHELL	      = /usr/bin/sh

SRCS	      = bcache.c \
		boot.c \
		btboot.c \
		btcons.c \
		btdisc.c \
		btlan.c \
		btmem.c \
		bttape.c \
		call.c \
		cat.c \
		conf.c \
		cvtutl.c \
		dd.c \
		driver.s \
		elf64.c \
		env.c \
		error.c \
		exec.c \
		flags.c \
		gputil.c \
		hpux_rel.c \
		interact.c \
		iob.c \
		iodc_util.c \
		kdep.c \
		ldvm.c \
		lfsm.c \
		lifcmds.c \
		lifio.c \
		listenv.c \
		ls.c \
		lvol.c \
		machdep.c \
		malloc.c \
		memutl.c \
		nfs.c \
		nullfs.c \
		parse.c \
		partition.c \
		peek.c \
		pif.c \
		prf.c \
		reboot.c \
		reloc_it.c \
		rmp.c \
		show.c \
		som.c \
		srt0.s \
		strutl.c \
		sys.c \
		tftp.c \
		uif.c \
		xdbconf.c \
		xdbio.c \
		xdbpdc.c \
		xdbrmp_iodc.c \
		xdbstd_iodc.c \
		xdbtftp_iodc.c

SYSHDRS	      =

UNDEFS	      = -DINET_COSE -DIVT_INTERCEPT -DLOCAL_SWITCH -DMULTIPLE_LOGICAL_HOSTS -DRSVP_ISI -DMROUTING -DMULTICAST -DAPPLETALK -DFDDI_VM -DSPARSE_PDIR -DAUDIT -DACLS -DPGPROF -DKI -DMP -DLWSYSCALL -DICA_ON -DNEW_RDB -DRDB -D_LVMROOT -D_HPUX -D_LVM -DCONVERGED_IO -USEMAPHORE_DEBUG -UMPDEBUG -UOSDEBUG -DXDB

# UNDEFS=`(cd ../S800;make -f makefile Prod_ident)`


# REMOVE_START_USAGE
error:
		@echo "First you need to make a make file:"
		@echo "     make -f Makefile makefile"
		@echo "then:"
		@echo "     make -f makefile boot REV=????"
# REMOVE_END_USAGE

all:		$(PROGRAM)

rebuild_reloc_it:
		rm -f reloc_it.c.org
		mv reloc_it.c reloc_it.c.org
		odump -fixups boot > temp1
		grep "addr=" temp1 > temp2
		sed -e "s/.*=/          /" -e "s/).*/,/" \
			temp2 > temp3
		sed \
			-e "/REPLACE FROM HERE/p" \
			-e "/TO HERE/p" \
			-e "/REPLACE FROM HERE/,/TO HERE/D" \
			reloc_it.c.org > temp4
		sed -e "/REPLACE FROM HERE/r temp3" \
			temp4 > reloc_it.c

build:		$(OBJECTS) $(LIBS)
		$(LD) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(PROGRAM) \
						1>ld.out 2>ld.error

$(PROGRAM):	include_dir mk_tools $(OBJECTS) $(LIBS)
# REMOVE_START_XDB
		@echo "BUILD: Determining the number of pointers to relocate"
		touch reloc_it.c
		$(MAKE) build
		$(MAKE) rebuild_reloc_it
		@echo "BUILD: Determining the addresses of the pointers"
		touch reloc_it.c
		$(MAKE) build
		$(MAKE) rebuild_reloc_it
		$(MAKE) $(LIBS)
		touch reloc_it.c
# REMOVE_END_XDB
		@echo "BUILD: Final linking of $(PROGRAM) ..."
		$(LD) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(PROGRAM) \
						1>ld.out 2>ld.error
		
		if [ -x $(PROGRAM) ]; then \
			chmod 777 $(PROGRAM); \
			size $(PROGRAM); \
		fi

# REMOVE_START_XDB
		sed \
			-e "/^#/D" \
			 ld.check1 > ld.check.2
		sed -e \
			"s/^.*://" \
			-e "/This option will not be supported/D" \
			ld.error > ld.error.2
		-cmp -s ld.error.2 ld.check.2; \
		if [ $$? -ne 0 ]; then \
			echo "WARNING: The ld Warnings do not match."; \
		fi

		sed \
			-e "/libutl.a/D" \
			-e "/libkdep.a/D" \
			-e "/libmach.a/D" \
			-e "/milli.a/D" \
				ld.out > ld.out.2
		-egrep "\.a" ld.out.2; \
		if [ $$? -ne 1 ]; then \
			echo "WARNING: Unexpected libraries were used in the linking process."; \
		fi
		
# REMOVE_END_XDB
		@echo "done"


profile:        $(OBJECTS) $(LIBS)
		@echo "Linking $(PROGRAM) ..."
		$(LD) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(PROGRAM)
		if [ -x $(PROGRAM) ]; then \
			chmod 777 $(PROGRAM); \
			size $(PROGRAM); \
		fi
		@echo "done"

libkdep.a: ${LIB_libkdep.a}
	rm -f libkdep.a
	ar cur libkdep.a ${LIB_libkdep.a}

libmach.a: ${LIB_libmach.a}
	rm -f libmach.a
	ar cru libmach.a ${LIB_libmach.a}

libutl.a: ${LIB_libutl.a}
	rm -f libutl.a
	ar cru libutl.a ${LIB_libutl.a}

libxdb.a: ${LIB_libxdb.a}
	rm -f libxdb.a
	ar cru libxdb.a ${LIB_libxdb.a}

hpux_rel.o:
		$(CC) $(CFLAGS) -c -DREVISION='"${REV}"' $<

.s.o:
		$(CC) $(CFLAGS) -c $<

.c.o:
		$(CC) $(CFLAGS) -c $<

clean:;		rm -f $(OBJS) $(LIBS) core

clobber:;	rm -rf $(OBJS) $(LIBS) $(PROGRAM) $(INCLUDE_DIR) \
			ld.out ld.error ld.out.1 ld.error.1 core tags \
			ld.error ld.error.2 ld.check.2 \
			ld.out ld.out.2 \
			temp1 temp2 temp3 temp4

depend:;	mkmf -f $(MAKEFILE) ROOT=$(ROOT)

echo:;		@echo $(HDRS) $(SRCS)

index:;		ctags -wx $(HDRS) $(SRCS)

install:	$(PROGRAM)
		@echo Installing $(PROGRAM) in $(DEST)
		-strip $(PROGRAM)
		if [ $(DEST) != . ]; then \
		(rm -f $(DEST)/$(PROGRAM); $(INSTALL) -f $(DEST) $(PROGRAM)); fi

print:;		$(PRINT) $(HDRS) $(SRCS)

tags:           $(HDRS) $(SRCS); ctags $(HDRS) $(SRCS)

update:		$(DEST)/$(PROGRAM)

lint:;		$(LINT) $(CCINCS) -Ae $(SRCS)

kcsdiffit:
		kcsdiff $(SRCS) $(HDRS) Makefile buildit mongoose_ld \
			ld.check1 blds.shar incs.shar

rcsdiffit:
		rcsdiff $(SRCS) $(HDRS) Makefile buildit mongoose_ld \
			ld.check1 blds.shar incs.shar

mk_blds:
		chmod 555	../bld_tools/Makefile
		chmod 555	../bld_tools/be_env
		chmod 555	../bld_tools/be_root
		tar cvf blds	../bld_tools/Makefile \
				../bld_tools/be_env \
				../bld_tools/be_root
		shar -cCs blds > blds.shar
		rm -f blds

un_blds:
		sh blds.shar
		tar xvf blds
		rm -f blds

mk_incs:
		tar cvf incs include_dir
		shar -cCs incs > incs.shar
		rm -f incs

include_dir: incs.shar
		sh incs.shar
		tar xvf incs
		rm -f incs

../bld_tools:
	if [[ ! -d ../bld_tools ]] \
	then \
		sh blds.shar; \
		tar xvf blds; \
	fi

../bld_tools/Makefile:
	if [[ ! -f ../bld_tools/Makefile ]] \
	then \
		sh blds.shar; \
		tar xvf blds; \
	fi

../bld_tools/be_env:
	if [[ ! -f ../bld_tools/be_env ]] \
	then \
		sh blds.shar; \
		tar xvf blds; \
	fi

../bld_tools/be_root:
	if [[ ! -f ../bld_tools/be_root ]] \
	then \
		sh blds.shar; \
		tar xvf blds; \
	fi

../bld_tools/be_cc: ../bld_tools/be_env ../bld_tools/be_root \
	../bld_tools/Makefile
	BEROOT=""; \
# REMOVE_START_ST \
	### ls -td /Build_* | read BEROOT DUMMY; \
	BEROOT="/"; \
	### if [[ ! -d $$BEROOT ]] \
	### then \
		### echo "ERROR: Cannot find BE $$BEROOT"; \
		### exit 1; \
	### fi; \
# REMOVE_END_ST \
	cd ../bld_tools; $(MAKE) be_cc be_ld be_lint BEROOT=$$BEROOT

../bld_tools/be_ld: ../bld_tools/be_env ../bld_tools/be_root \
	../bld_tools/Makefile
	BEROOT=""; \
# REMOVE_START_ST \
	### ls -td /Build_* | read BEROOT DUMMY; \
	BEROOT="/"; \
	### if [[ ! -d $$BEROOT ]] \
	### then \
		### echo "ERROR: Cannot find BE $$BEROOT"; \
		### exit 1; \
	### fi; \
# REMOVE_END_ST \
	cd ../bld_tools; $(MAKE) be_cc be_ld be_lint BEROOT=$$BEROOT

../bld_tools/be_lint: ../bld_tools/be_env ../bld_tools/be_root \
	../bld_tools/Makefile
	BEROOT=""; \
# REMOVE_START_ST \
	### ls -td /Build_* | read BEROOT DUMMY; \
	BEROOT="/"; \
	### if [[ ! -d $$BEROOT ]] \
	### then \
		### echo "ERROR: Cannot find BE $$BEROOT"; \
		### exit 1; \
	### fi; \
# REMOVE_END_ST \
	cd ../bld_tools; $(MAKE) be_cc be_ld be_lint BEROOT=$$BEROOT

mk_tools: ../bld_tools ../bld_tools/be_cc ../bld_tools/be_ld \
	../bld_tools/be_lint

$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
		$(MAKE) -f $(MAKEFILE) ROOT=$(ROOT) DEST=$(DEST) install

# Make makefile (not Makefile).
# NOTE: You can make four (4) different makefiles.
#       The makefile can use the BE compilers or the standard compilers.
#       The makefile can build a standard boot or a debug boot.
#
#	Your four choices are:
#
#	1) Build with BE compilers a standard boot (the default).
#	2) Build with BE compilers a debug boot.
#	3) Build standard compilers a standard boot.
#	4) Build standard compilers a debug boot.
#
# USE_STD=XDB
# USE_STD=STD
# USE_BE=BE
# USE_BE=ST

make_makefile:
	sed \
	-e "/^# REMOVE_START_$(USE_STD)/,/^# REMOVE_END_$(USE_STD)/d" \
	-e "/^# REMOVE_START_$(USE_BE)/,/^# REMOVE_END_$(USE_BE)/d" \
	-e "/^# REMOVE_START_USAGE/,/^# REMOVE_END_USAGE/d" \
	-e "/^#/n" \
	-e 's/M_BE_ST/$(USE_BE)/g' \
	-e 's/M_STD_XDB/$(USE_STD)/g' \
		Makefile > makefile

makefile:
	make -f Makefile makefile.be_std

makefile.be_std:
	make -f Makefile make_makefile USE_BE=BE USE_STD=STD

makefile.be_xdb:
	make -f Makefile make_makefile USE_BE=BE USE_STD=XDB

makefile.st_std:
	make -f Makefile make_makefile USE_BE=ST USE_STD=STD

makefile.st_xdb:
	make -f Makefile make_makefile USE_BE=ST USE_STD=XDB

make_mkincs:
	echo make_mkincs

###

bcache.o: bcache.h syscall.h

boot.o: defines.h syscall.h

btboot.o: defines.h gputil.h syscall.h

btcons.o: gputil.h

btdisc.o: bcache.h defines.h gputil.h machdep.h syscall.h

btlan.o: bcache.h defines.h gputil.h machdep.h syscall.h

btmem.o: defines.h gputil.h

bttape.o: bcache.h defines.h gputil.h machdep.h syscall.h

call.o: defines.h gputil.h syscall.h

cat.o: defines.h syscall.h

conf.o: conf.h defines.h exec.h gputil.h machdep.h syscall.h

cvtutl.o: gputil.h

dd.o: gputil.h syscall.h

elf64.o: exec.h langtypes.h libelf.h machdep.h syscall.h

env.o: defines.h

error.o: defines.h gputil.h

exec.o: defines.h exec.h gputil.h syscall.h

flags.o: defines.h gputil.h kdep.h syscall.h

gputil.o: gputil.h

hpux_rel.o: syscall.h

install.o: defines.h gputil.h

interact.o: defines.h gputil.h syscall.h

iob.o: defines.h saio.h

iodc_util.o: bcache.h defines.h gputil.h machdep.h syscall.h

kdep.o: defines.h gputil.h kdep.h syscall.h

ldvm.o: conf.h defines.h gputil.h saio.h

lfsm.o: conf.h defines.h gputil.h syscall.h

lifcmds.o: defines.h gputil.h lifio.h syscall.h

lifio.o: defines.h gputil.h lifio.h syscall.h

listenv.o: gputil.h syscall.h

ls.o: defines.h gputil.h syscall.h

lvol.o: defines.h gputil.h lifio.h partition.h syscall.h

machdep.o: defines.h gputil.h machdep.h syscall.h

malloc.o:

memutl.c: gputil.h

nfs.o: defines.h gputil.h saio.h syscall.h

nullfs.o: defines.h gputil.h saio.h syscall.h

parse.o:

partition.o: partition.h

peek.o: gputil.h syscall.h

pif.o: defines.h gputil.h kdep.h syscall.h

prf.o: gputil.h

reboot.o: syscall.h

reloc_it.o:

rmp.o: defines.h gputil.h machdep.h syscall.h

show.o: defines.h gputil.h syscall.h

som.o: exec.h gputil.h machdep.h syscall.h

strutl.o: gputil.h

sys.o: defines.h gputil.h saio.h syscall.h

tftp.o: defines.h gputil.h machdep.h syscall.h tftp.h

uif.o: defines.h gputil.h kdep.h syscall.h

xdbconf.o: machdep.h tftp.h xdbconf.h

xdbio.o: gputil.h machdep.h xdbconf.h

xdbpdc.o: gputil.h machdep.h xdbconf.h

xdbrmp_iodc.o: defines.h gputil.h machdep.h xdbconf.h

xdbstd_iodc.o: gputil.h machdep.h xdbconf.h

xdbtftp_iodc.o: defines.h gputil.h machdep.h tftp.h xdbconf.h

