#Buildtemplate for .b file linker and utilities

VPATH = ../mi

#ifdef UNIX
OPTS = -DBOOTSTRAP -DStanford -I$(VSYS)/include -DLITTLE_ENDIAN
#else
OPTS = -DBOOTSTRAP -DStanford -I$(VSYS)/include
# -I$(VSYS)/include is used to pull in the m68k version of b.out.h.  The
#	source files which need it do "#include "m68k/b.out.h".  There aren't
#	(or shouldn't be) any files in $(VSYS)/include, only in its
#	subdirectories.
#	NOTE: Should we use PRODUCTION_VSYS instead of VSYS?
#	      And, is -I$(whatever_VSYS)/include a good thing to put in
#	      the general buildtemplates instead of in this one command?
#endif UNIX

#ifdef UNIX
ROOTS='-DVROOT="$(PRODUCTION_VSYS)/lib/m68k"' \
      '-DXVROOT="$(EXPERIMENTAL_VSYS)/lib/m68k"'
#else
ROOTS='-DVROOT="[V]lib/m68k"' '-DXVROOT="[xV]lib/m68k"'
#endif UNIX
# ^ The single and double quotation marks are needed.  The single
#   quotes are stripped by the V exec routines (or Unix sh),
#   leaving the double quotes intact.

#ifdef UNIX
COMMANDS = ld68.$(MACHINE) rev68.$(MACHINE) nm68.$(MACHINE) \
	   size68.$(MACHINE) rl68.$(MACHINE) pr68.$(MACHINE) \
	   dl68.$(MACHINE) ranlib68.$(MACHINE)
# ^ Do NOT include shell scripts (lorder68.sh) in this list unless you
#   consistently alter the use of COMMANDS throughout this buildtemplate.
#else
COMMANDS = ld68.$(MACHINE) rev68.$(MACHINE) ranlib68.$(MACHINE) \
	   ranlib.$(MACHINE)
# ^ Haven't bothered to check WHY it's difficult or useless to build V versions
#   of the other commands - I'll just blindly propagate this.  Consequently, I
#   haven't massaged these to check whether one can build MicroVAX V versions.
#endif

all: $(COMMANDS)

*.$(MACHINE): $*.$(OBJSUFFIX)
	$(CC) $(MIFLAGS) -o $@ $*.$(OBJSUFFIX) $(MDFLAGS) $(LIBRARIES)

*.$(OBJSUFFIX): $*.c
	$(CC) $(OPTS) $(ROOTS) $(MIFLAGS) $(SPECINCLUDES) $(INCLUDES) -c $*.c
#
# $(ROOTS) is only needed by ld68, but there's no great harm done.
#

#ifndef UNIX
# Kludge: Since ranlib68 has a superset of ranlib's functionality, (it
#  handles both 68000 and VAX executables), under V we install something
#  called "ranlib" that is really a copy of ranlib68.  Thus under UNIX,
#  saying "ranlib" gets the BSD ranlib, while under V, saying "ranlib"
#  gets ranlib68, which works just as well.
#
ranlib.$(MACHINE): ranlib68.$(MACHINE)
	rm -f $@
	cp ranlib68.$(MACHINE) $@
#endif UNIX

#ifdef UNIX
install: $(COMMANDS) lorder68.sh
	( echo    for i in $(COMMANDS) ; \
	  echo    do rcp \$$i $(UNIXDESTDIR)/\`basename \$$i .$(MACHINE)\` ; \
	  echo    done ) \
	| sh
# ... the "echo"s generate a three-line for-statement which sh then executes:
#		  for i in ld68.unix rev68.unix (etc)
#		  do rcp $i carmel:/usr/stanford/bin/`basename $i .unix`
#		  done
# ... i.e. rcp all the unix commands, stripping the ".unix" suffix.  Aaargh.
	rcp lorder68.sh $(UNIXDESTDIR)/lorder68
#else
install: $(COMMANDS)
	$(NETINSTALL) -p "$(COMMANDS)" $(VSYS)/bin
#endif

clean:
	rm -f *.$(OBJSUFFIX) *.BAK *.CKP .emacs* $(COMMANDS)

relink:
	rm -f $(COMMANDS)
