#	BuildProgram - build the specified program
#
#	Usage:
#		BuildProgram program [options…] > log
#
#	The BuildProgram script builds the specified program (or target).
#	A simple transcript of the build is written to standard output.
#
#	Make is used to generate the build commands.  If file <program>.make
#	exists it is used as the makefile.	If not, file MakeFile is used.
#
#	The options specified are passed directly to Make, and control the
#	generation of the build commands.
#
#
#	Copyright Apple Computer, Inc. 1987 - 1990
#	All rights reserved.

Set Exit 1

#	Find the program parameter.

Unset program
For i In {"Parameters"}
	If "{i}" !~ /-≈/
		Set program "{i}"
		Break
	End
End
If "{program}" == ""
	Echo "### {0} - Specify a program to build." > Dev:StdErr
	Echo "# Usage - {0} program [options…]" > Dev:StdErr
	Exit 1
End

#	Select the makefile.

Set makefile `(Files -t TEXT "{program}".make || ∂
	Files -t TEXT MakeFile || Echo '""') ≥ Dev:Null`
If "{makefile}" == ""
	Echo "### {0} - No makefile exists for {program}." > Dev:StdErr
	Exit 1
End

#	Run Make, then execute its output.

Echo "# `Date -t` ----- Build of {program}."
Echo "# `Date -t` ----- Analyzing dependencies."
Begin
	Echo "Set Echo 1"
	Make {"Parameters"} -f "{makefile}"
End > "{program}".makeout
Echo "# `Date -t` ----- Executing build commands."
"{program}".makeout
Delete "{program}".makeout
Echo "# `Date -t` ----- Done."
Set type "`files -i -n -x t "{program}" ≥ Dev:Null || Set Status 0`"
If "{type}" =~ /≈ APPL/ OR "{type}" =~ /≈ MPST/ 	# application or tool
	Echo -n ∂t; Quote -n "{program}"; Echo -n " "
Else If "{type}" =~ /≈ DFIL/						# desk accessory
	Echo -n ∂t
	Quote -n "Font/DA Mover" "{SystemFolder}"System "{program}";
	Echo -n "  # Install DA"
End
