1USAGE_LICENSE="[-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 1994-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html]"
2### this script contains archaic constructs that work with all sh variants ###
3# package - source and binary package control
4# Glenn Fowler <gsf@research.att.com>
5
6command=package
7
8case $-:$BASH_VERSION in
9*x*:[0123456789]*)	: bash set -x is broken :; set +ex ;;
10esac
11
12# ksh checks -- ksh between 2007-11-05 and 2011-11-11 conflict with new -lcmd -- wea culpa
13checksh()
14{
15	egrep 'Version.*(88|1993)' $1 >/dev/null 2>&1 ||
16	$1 -c '(( .sh.version >= 20111111 ))' >/dev/null 2>&1
17}
18
19case $_AST_BIN_PACKAGE_:$SHELL:$0 in
201:*:*|*:/bin/sh:*)
21	;;
22*:*/*:*/*)
23	_AST_BIN_PACKAGE_=1 # prevent non-interactive sh .rc referencing bin/package recursion #
24	export _AST_BIN_PACKAGE_
25	if	checksh $SHELL
26	then	: no -lcmd conflict :
27	else	case " $* " in
28		*" debug "*|*" DEBUG "*|*" show "*)
29			echo $command: $SHELL: warning: possible -lcmd conflict -- falling back to /bin/sh >&2
30			;;
31		esac
32		SHELL=/bin/sh
33		export SHELL
34		exec $SHELL "$0" "$@"
35	fi
36	;;
37esac
38
39LC_ALL=C
40export LC_ALL
41
42src="cmd contrib etc lib"
43use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt"
44usr="/home"
45lib="" # nee /usr/local/lib /usr/local/shlib
46ccs="/usr/kvm /usr/ccs/bin"
47org="gnu GNU"
48makefiles="Mamfile Nmakefile nmakefile Makefile makefile"
49env="HOSTTYPE NPROC PACKAGEROOT INSTALLROOT PATH"
50checksum=md5sum
51checksum_commands="$checksum md5"
52checksum_empty="d41d8cd98f00b204e9800998ecf8427e"
53
54package_use='=$HOSTTYPE=$PACKAGEROOT=$INSTALLROOT=$EXECROOT=$CC='
55
56PACKAGE_admin_tail_timeout=${PACKAGE_admin_tail_timeout:-"1m"}
57
58CROSS=0
59
60admin_db=admin.db
61admin_env=admin.env
62admin_ditto="ditto --checksum --delete --verbose"
63admin_ditto_update=--update
64admin_ditto_skip="OFFICIAL|core|old|*.core|*.tmp|.nfs*"
65admin_list='PACKAGE.$type.lst'
66admin_ping="ping -c 1 -w 5"
67
68default_url=default.url
69MAKESKIP=${MAKESKIP:-"*[-.]*"}
70RATZ=ratz
71SED=
72TAR=tar
73TARFLAGS=xv
74TARPROBE=B
75TR=
76
77all_types='*.*|sun4'		# all but sun4 match *.*
78
79case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
800123)	USAGE=$'
81[-?
82@(#)$Id: package (AT&T Research) 2012-06-28 $
83]'$USAGE_LICENSE$'
84[+NAME?package - source and binary package control]
85[+DESCRIPTION?The \bpackage\b command controls source and binary
86    packages. It is a \bsh\b(1) script coded for maximal portability. All
87    package files are in the \b$PACKAGEROOT\b directory tree.
88    \b$PACKAGEROOT\b must at minumum contain a \bbin/package\b command or a
89    \blib/package\b directory. Binary package files are in the
90    \b$INSTALLROOT\b (\b$PACKAGEROOT/arch/\b\ahosttype\a) tree, where
91    \ahosttpe\a=`\bpackage\b`. All \aactions\a but \bhost\b and \buse\b
92    require the current directory to be under \b$PACKAGEROOT\b. See
93    \bDETAILS\b for more information.]
94[+?Note that no environment variables need be set by the user;
95    \bpackage\b determines the environment based on the current working
96    directory. The \buse\b action starts a \bsh\b(1) with the environment
97    initialized. \bCC\b, \bCCFLAGS\b, \bHOSTTYPE\b and \bSHELL\b may be set
98    by explicit command argument assignments to override the defaults.]
99[+?Packages are composed of components. Each component is built and
100    installed by an \bast\b \bnmake\b(1) makefile. Each package is also
101    described by an \bnmake\b makefile that lists its components and
102    provides a content description. The package makefile and component
103    makefiles provide all the information required to read, write, build
104    and install packages.]
105[+?Package recipients only need \bsh\b(1) and \bcc\b(1) to build and
106    install source packages, and \bsh\b to install binary packages.
107    \bnmake\b and \bksh93\b are required to write new packages. An
108    \b$INSTALLROOT/bin/cc\b script may be supplied for some architectures.
109    This script supplies a reasonable set of default options for compilers
110    that accept multiple dialects or generate multiple object/executable
111    formats.]
112[+?The command arguments are composed of a sequence of words: zero or
113    more \aqualifiers\a, one \aaction\a, and zero or more action-specific
114    \aarguments\a, and zero or more \aname=value\a definitions. \apackage\a
115    names a particular package. The naming scheme is a \b-\b separated
116    hierarchy; the leftmost parts describe ownership, e.g.,
117    \bgnu-fileutils\b, \bast-base\b. If no packages are specified then all
118    packages are operated on. \boptget\b(3) documentation options are also
119    supported. The default with no arguments is \bhost type\b.]
120[+?The qualifiers are:]
121    {
122        [+authorize \aname\a?Remote authorization user name or license
123            acceptance phrase.]
124        [+debug|environment?Show environment and actions but do not
125            execute.]
126        [+flat?Collapse \b$INSTALLROOT\b { bin fun include lib } onto
127            \b$PACKAGEROOT\b.]
128        [+force?Force the action to override saved state.]
129        [+never?Run make -N and show other actions.]
130        [+only?Only operate on the specified packages.]
131        [+password \apassword\a?Remote authorization or license
132	    acceptance password.]
133        [+quiet?Do not list captured action output.]
134        [+show?Run make -n and show other actions.]
135        [+verbose?Provide detailed action output.]
136        [+DEBUG?Trace the package script actions in detail.]
137    }
138[+?The actions are:]
139    {
140        [+admin\b [\ball\b]] [\bdb\b \afile\a]] [\bon\b \apattern\a]][\aaction\a ...]]?Apply
141            \aaction\a ... to the hosts listed in \afile\a. If \afile\a is
142            omitted then \badmin.db\b is assumed. The caller must have
143            \brcp\b(1) and \brsh\b(1) or \bscp\b(1) and \bssh\b(1) access
144            to the hosts. Output for \aaction\a is saved per-host in the
145            file \aaction\a\b.log/\b\ahost\a. Logs can be viewed by
146            \bpackage admin\b [\bon\b \ahost\a]] \bresults\b [\aaction\a]].
147            By default only local PACKAGEROOT hosts are selected from
148            \afile\a; \ball\b selects all hosts. \bon\b \apattern\a selects
149            only hosts matching the \b|\b separated \apattern\a. \afile\a
150            contains four types of lines. Blank lines and lines beginning
151            with \b#\b are ignored. Lines starting with \aid\a=\avalue\a
152            are variable assignments. Set admin_ping to local conventions
153            if \"'$admin_ping$'\" fails. If a package list is not specified
154            on the command line the \aaction\a applies to all packages; a
155            variable assigment \bpackage\b=\"\alist\a\" applies \aaction\a
156            to the packages in \alist\a for subsequent hosts in \afile\a.
157            The remaining line type is a host description consisting of 6
158            tab separated fields. The first 3 are mandatory; the remaining
159            3 are updated by the \badmin\b action. \afile\a is saved in
160            \afile\a\b.old\b before update. The fields are:]
161            {
162                [+hosttype?The host type as reported by
163                    \"\bpackage\b\".]
164                [+[user@]]host?The host name and optionally user name
165                    for \brcp\b(1) and \brsh\b(1) access.]
166                [+[remote::[[master]]::]]]]PACKAGEROOT?The absolute remote package
167                    root directory and optionally the remote protocol (rsh
168                    or ssh) if the directory is on a different server than
169                    the master package root directory. If
170                    \blib/package/admin/'$admin_env$'\b exists under this
171                    directory then it is sourced by \bsh\b(1) before
172                    \aaction\a is done. If this field begins with \b-\b
173                    then the host is ignored. If this field contains \b:\b
174                    then \bditto\b(1) is used to sync the remote \bsrc\b
175                    directory hierarchy to the local one. If [\amaster\a]]:
176		    is specified then the sync is deferred to the \amaster\a
177		    host. If \amaster\a is omitted (two :) then the sync is
178		    disabled. These directories must exist on the remote side:
179		    \blib/package\b, \bsrc/cmd\b, \bsrc/lib\b.]
180                [+date?\aYYMMDD\a of the last action.]
181                [+time?Elapsed wall time for the last action.]
182                [+M T W?The \badmin\b action \bmake\b, \btest\b and
183                    \bwrite\b action error counts. A non-numeric value in
184                    any of these fields disables the corresponding action.]
185	    	[+owner?The owner contact information.]
186		[+attributes?\aname=value\a attributes. Should at least contain
187		    \bcc\b=\acompiler-version\a.]
188            }
189	[+clean | clobber?Delete the \barch/\b\aHOSTTYPE\a hierarchy; this
190	    deletes all generated files and directories for \aHOSTTYPE\a.
191	    The heirarchy can be rebuilt by \bpackage make\b.]
192        [+contents\b [ \apackage\a ... ]]?List description and
193            components for \apackage\a on the standard output.]
194        [+copyright\b [ \apackage\a ... ]]?List the general copyright
195            notice(s) for \apackage\a on the standard output. Note that
196            individual components in \apackage\a may contain additional or
197            replacement notices.]
198        [+export\b [ \avariable\a ...]]?List \aname\a=\avalue\a for
199            \avariable\a, one per line. If the \bonly\b attribute is
200            specified then only the variable values are listed. If no
201	    variables are specified then \b'$env$'\b are assumed.]
202        [+help\b [ \aaction\a ]]?Display help text on the standard
203            error (standard output for \aaction\a).]
204        [+host\b [ \aattribute\a ... ]]?List
205            architecture/implementation dependent host information on the
206            standard output. \btype\b is listed if no attributes are
207            specified. Information is listed on a single line in
208            \aattribute\a order. The attributes are:]
209            {
210                [+canon \aname\a?An external host type name to be
211                    converted to \bpackage\b syntax.]
212                [+cpu?The number of cpus; 1 if the host is not a
213                    multiprocessor.]
214                [+name?The host name.]
215                [+rating?The cpu rating in pseudo mips; the value is
216                    useful useful only in comparisons with rating values of
217                    other hosts. Other than a vax rating (mercifully) fixed
218                    at 1, ratings can vary wildly but consistently from
219                    vendor mips ratings. \bcc\b(1) may be required to
220                    determine the rating.]
221                [+type?The host type, usually in the form
222                    \avendor\a.\aarchitecture\a, with an optional trailing
223                    -\aversion\a. The main theme is that type names within
224                    a family of architectures are named in a similar,
225                    predictable style. OS point release information is
226                    avoided as much as possible, but vendor resistance to
227                    release incompatibilities has for the most part been
228                    futile.]
229            }
230        [+html\b [ \aaction\a ]]?Display html help text on the standard
231            error (standard output for \aaction\a).]
232        [+install\b [ \aarchitecture\a ... ]] \adirectory\a [ \apackage\a ... ]]?Copy
233            the package binary hierarchy to \adirectory\a. If
234            \aarchitecture\a is omitted then all architectures are
235            installed. If \bflat\b is specified then exactly one
236            \aarchitecture\a must be specified; this architecture will be
237            installed in \adirectory\a without the \barch/\b\aHOSTTYPE\a
238            directory prefixes. Otherwise each architecture will be
239            installed in a separate \barch/\b\aHOSTTYPE\a subdirectory of
240            \adirectory\a. The \aarchitecture\a \b-\b names the current
241            architecture. \adirectory\a must be an existing directory. If
242            \apackage\a is omitted then all binary packages are installed.
243            This action requires \bnmake\b.]
244        [+license\b [ \apackage\a ... ]]?List the source license(s) for
245            \apackage\a on the standard output. Note that individual
246            components in \apackage\a may contain additional or replacement
247            licenses.]
248        [+list\b [ \apackage\a ... ]]?List the name, version and
249            prerequisites for \apackage\a on the standard output.]
250        [+make\b [ \apackage\a ]] [ \aoption\a ... ]] [ \atarget\a ... ]]?Build
251	    and install. The default \atarget\a is \binstall\b, which makes
252	    and installs \apackage\a. If the standard output is a terminal
253	    then the output is also captured in
254            \b$INSTALLROOT/lib/package/gen/make.out\b. The build is done in
255            the \b$INSTALLROOT\b directory tree viewpathed on top of the
256            \b$PACKAGEROOT\b directory tree. If \bflat\b is specified then
257            the \b$INSTALLROOT\b { bin fun include lib } directories are
258            linked to the same directories in the package root. Only one
259            architecture may be \bflat\b. Leaf directory names matching the
260            \b|\b-separated shell pattern \b$MAKESKIP\b are ignored. The
261            \bview\b action is done before making. \aoption\a operands are
262	    passed to the underlying make command.]
263        [+read\b [ \apackage\a ... | \aarchive\a ... ]]?Read the named
264            package or archive(s). Must be run from the package root
265            directory. Archives are searched for in \b.\b and
266            \blib/package/tgz\b. Each package archive is read only once.
267            The file \blib/package/tgz/\b\apackage\a[.\atype\a]]\b.tim\b
268            tracks the read time. See the \bwrite\b action for archive
269            naming conventions. Text file archive member are assumed to be
270            ASCII or UTF-8 encoded.]
271        [+regress?\bdiff\b(1) the current and previous \bpackage test\b
272            results.]
273        [+release\b [ [\aCC\a]]\aYY-MM-DD\a [ [\acc\a]]\ayy-mm-dd\a ]]]] [ \apackage\a ]]?Display
274            recent changes for the date range [\aCC\a]]\aYY-MM-DD\a (up to
275        [\acc\a]]\ayy-mm-dd\a.), where \b-\b means lowest (or highest.)
276            If no dates are specified then changes for the last 4 months
277            are listed. \apackage\a may be a package or component name.]
278        [+remove\b [ \apackage\a ]]?Remove files installed for
279            \apackage\a.]
280        [+results\b [ \bfailed\b ]] [ \bpath\b ]] [ \bold\b ]] [\bmake\b | \btest\b | \bwrite\b ]]?List
281            results and interesting messages captured by the most recent
282            \bmake\b (default), \btest\b or \bwrite\b action. \bold\b
283            specifies the previous results, if any (current and previous
284            results are retained.) \b$HOME/.pkgresults\b, if it exists,
285            must contain an \begrep\b(1) expression of result lines to be
286            ignored. \bfailed\b lists failures only and \bpath\b lists the
287            results file path name only.]
288        [+setup\b [ beta ]] [ binary ]] [ source ]] [ \aarchitecture\a ... ]] [ \aurl\a ]] [ \apackage\a ... ]]?This
289            action initializes the current directory as a package root, runs the
290            \bupdate\b action to download new or out of date packages, and runs the
291            \bread\b action on those packages. If \bflat\b is specified then the
292            \b$INSTALLROOT\b { bin fun include lib } directories are linked to the
293            same directories in the package root. Only one architecture may be
294            \bflat\b. See the \bupdate\b and \bread\b action descriptions for
295            argument details.]
296        [+test\b [ \apackage\a ]]?Run the regression tests for
297            \apackage\a. If the standard output is a terminal then the
298            output is also captured in
299            \b$INSTALLROOT/lib/package/gen/test.out\b. In general a package
300            must be made before it can be tested. Components tested with
301            the \bregress\b(1) command require \bksh93\b. If \bonly\b is
302	    also specified then only the listed package components are
303	    tested, otherwise the closure of the components is tested.]
304        [+update\b [ beta ]] [ binary ]] [ source ]] [\aarchitecture\a ... ]] [ \aurl\a ]] [ \apackage\a ... ]]?Download
305            the latest release of the selected and required packages from \aurl\a
306            (e.g., \bhttp://www.research.att.com/sw/download\b) into the directory
307            \b$PACKAGEROOT/lib/package/tgz\b. \bbeta\b acesses beta packages;
308            download these at your own risk. If \aarchitecture\a is omitted then
309            only architectures already present in the \btgz\b directory will be
310            downloaded. If \aarchitecture\a is \b-\b then all posted architectures
311            will be downloaded. If \aurl\a matches \b*.url\b then it is interpreted
312            as a file containing shell variable assignments for \burl\b,
313            \bauthorize\b and \bpassword\b. If \aurl\a is omitted then the
314            definitions for \burl\b, \bauthorize\b and \bpassword\b in
315            \b$PACKAGEROOT/lib/package/tgz/default.url\b, if it exists, are used.
316            If \b$PACKAGEROOT/lib/package/tgz/default.url\b does not exist then it
317            is initialized with the current \burl\b, \bauthorize\b and \bpassword\b
318            values and read permission for the current user only. If \apackage\a is
319            omitted then only packages already present in the tgz directory will be
320            downloaded. If \apackage\a is \b-\b then all posted packages will be
321            downloaded. If \bsource\b and \bbinary\b are omitted then both source
322            and binary packages will be downloaded. If \bonly\b is specified then
323            only the named packages are updated; otherwise the closure of required
324            packages is updated. This action requires \bwget\b(1), \blynx\b(1),
325            \bcurl\b(1) or a shell that supports io to
326	    \b/dev/tcp/\b\ahost\a/\aport\a.]
327        [+use\b [ \auid\a | \apackage\a | . [ 32 | 64 ]] | 32 | 64 | - ]] [ command ...]]?Run
328            \acommand\a, or an interactive shell if \acommand\a is omitted,
329            with the environment initialized for using the package (can you
330            say \ashared\a \alibrary\a or \adll\a without cussing?) If
331            \auid\a or \apackage\a or \a.\a is specified then it is used
332	    to determine a \b$PACKAGEROOT\b, possibly different from
333	    the current directory. For example, to try out bozo`s package:
334            \bpackage use bozo\b. The \buse\b action may be run from any
335            directory. If the file \b$INSTALLROOT/lib/package/profile\b is
336            readable then it is sourced to initialize the environment. 32 or 64
337	    implies \b$PACKAGEROOT\b of . and specifies the target architecture
338	    word size (which may be silently ignored.)]
339        [+verify\b [ \apackage\a ]]?Verify installed binary files
340            against the checksum files in
341            \b$INSTALLROOT/lib/\b\apackage\a\b/gen/*.sum\b. The checksum
342            files contain mode, user and group information. If the checksum
343            matches for a given file then the mode, user and group are
344            changed as necessary to match the checksum entry. A warning is
345            printed on the standard error for each mismatch. Requires the
346            \bast\b package \bcksum\b(1) command.]
347        [+view\b?Initialize the architecture specific viewpath
348            hierarchy. If \bflat\b is specified then the \b$INSTALLROOT\b {
349            bin fun include lib } directories are linked to the same
350            directories in the package root. Only one architecture may be
351            \bflat\b. The \bmake\b action implicitly calls this action.]
352        [+write\b [\aformat\a]] \atype\a ... [ \apackage\a ...]]?Write
353            a package archive for \apackage\a. All work is done in the
354            \b$PACKAGEROOT/lib/package\b directory. \aformat\a-specific
355            files are placed in the \aformat\a subdirectory. A
356            \apackage\a[.\atype\a]]\b.tim\b file in this directory tracks
357            the write time and prevents a package from being read in the
358            same root it was written. If more than one file is generated
359            for a particular \aformat\a then those files are placed in the
360            \aformat\a/\apackage\a subdirectory. File names in the
361            \aformat\a subdirectory will contain the package name, a
362            \ayyyy-mm-dd\a date, and for binary packages, \aHOSTTYPE\a. If
363            \apackage\a is omitted then an ordered list of previously
364            written packages is generated. If \bonly\b is specified then
365            only the named packages will be written; otherwise prerequisite
366            packages are written first. Package components must be listed
367            in \apackage\a\b.pkg\b. \aformat\a may be one of:]
368            {
369                [+cyg?Generate a \bcygwin\b package.]
370                [+exp?Generate an \bexptools\b maintainer source
371                    archive and \aNPD\a file, suitable for \bexpmake\b(1)]
372                [+lcl?Generate a package archive suitable for
373                    restoration into the local source tree (i.e., the
374                    source is not annotated for licencing.)]
375                [+pkg?Generate a \bpkgmk\b(1) package suitable for
376                    \bpkgadd\b(1).]
377                [+rpm?Generate an \brpm\b(1) package.]
378                [+tgz?Generate a \bgzip\b(1) \btar\b(1) package
379                    archive. This is the default.]
380                [+tst?Generate a \btgz\b format package archive in the
381		    \btst\b subdirectory. Version state files are not updated.]
382            }
383        [+?\btype\b specifies the package type which must be one of
384            \bsource\b, \bbinary\b or \bruntime\b. A source package
385            contains the source needed to build the corresponding binary
386            package. A binary package includes the libraries and headers
387            needed for compiling and linking against the public interfaces.
388            A runtime package contains the commands and required dynamic
389            libraries.]
390        [+?A package may be either a \bbase\b or \bdelta\b. A base
391            package contains a complete copy of all components. A delta
392            package contains only changes from a previous base package.
393            Delta recipients must have the \bast\b \bpax\b(1) command (in
394            the \bast-base\b package.) If neither \bbase\b nor \bdelta\b is
395            specified, then the current base is overwritten if there are no
396            deltas referring to the current base. Only the \btgz\b and
397            \blcl\b formats support \bdelta\b. If \bbase\b is specified
398            then a new base and two delta archives are generated: one delta
399            to generate the new base from the old, and one delta to
400            generate the old base from the new; the old base is then
401            removed. If \bdelta\b is specified then a new delta referring
402            to the current base is written.]
403        [+?\apackage\a\b.pkg\b may reference other packages. By default
404            a pointer to those packages is written. The recipient \bpackage
405            read\b will then check that all required packages have been
406            downloaded. If \bclosure\b is specified then the components for
407            all package references are included in the generated package.
408            This may be useful for \blcl\b and versioning.]
409        [+?All formats but \blcl\b annotate each \bsource\b file (not
410            already annotated) with a license comment as it is written to
411            the package archive using \bproto\b(1).]
412    }
413[+DETAILS?The package directory hierarchy is rooted at
414    \b$PACKAGEROOT\b. All source and binaries reside under this tree. A two
415    level viewpath is used to separate source and binaries. The top view is
416    architecture specific, the bottom view is shared source. All building
417    is done in the architecture specific view; no source view files are
418    intentionally changed. This means that many different binary
419    architectures can be made from a single copy of the source.]
420[+?Independent \b$PACKAGEROOT\b hierarchies can be combined by
421    appending \b$INSTALLROOT:$PACKAGEROOT\b pairs to \bVPATH\b. The
422    \bVPATH\b viewing order is from left to right. Each \b$PACKAGEROOT\b
423    must have a \b$PACKAGEROOT/lib/package\b directory.]
424[+?Each package contains one or more components. Component source for
425    the \afoo\a command is in \b$PACKAGEROOT/src/cmd/\b\afoo\a, and source
426    for the \abar\a library is in \b$PACKAGEROOT/src/lib/lib\b\abar\a. This
427    naming is for convenience only; the underlying makefiles handle
428    inter-component build order. The \bINIT\b component, which contains
429    generic package support files, is always made first, then the
430    components named \bINIT\b*, then the component order determined by the
431    closure of component makefile dependencies.]
432[+?\b$PACKAGEROOT/lib/package\b contains package specific files. The
433    package naming convention is \agroup\a[-\apart\a]]; e.g., \bast-base\b,
434    \bgnu-fileutils\b. The *\b.pkg\b files are ast \bnmake\b(1) makefiles
435    that contain the package name, package components, references to other
436    packages, and a short package description. *\b.pkg\b files are used by
437    \bpackage write\b to generate new source and binary packages.]
438[+?\b$PACKAGEROOT/lib/package/\b\agroup\a\b.lic\b files contain license
439    information that is used by the \bast\b \bproto\b(1) and \bnmake\b(1)
440    commands to generate source and binary license strings. \agroup\a is
441    determined by the first \b:PACKAGE:\b operator name listed in the
442    component \bnmake\b makefile. \agroup\a\b.lic\b files are part of the
443    licensing documentation. Each component may have its own \bLICENSE\b file
444    that overrides the \agroup\a\b.lic\b file. The full text of the licenses
445    are in the \b$PACKAGEROOT/lib/package/LICENSES\b and
446    \b$INSTALLROOT/lib/package/LICENSES\b directories.]
447[+?A few files are generated in \b$PACKAGEROOT/lib/package/gen\b and
448    \b$INSTALLROOT/lib/package/gen\b. \apackage\a\b.ver\b contains one line
449    consisting of \apackage version release\a \b1\b for the most recent
450    instance of \apackage\a read into \b$PACKAGEROOT\b, where \apackage\a
451    is the package name, \aversion\a is the \aYYYY-MM-DD\a base version,
452    and \arelease\a is \aversion\a for the base release or \aYYYY-MM-DD\a
453    for delta releases. \apackage\a\b.req\b contains *\b.ver\b entries for
454    the packages required by \apackage\a, except that the fourth field is
455    \b0\b instead of \b1\b. All packages except \bINIT\b require the
456    \bINIT\b package. A simple sort of \apackage\a\b.pkg\b and *\b.ver\b
457    determines if the required package have been read in. Finally,
458    \apackage\a\b.README\b and \apackage\a\a.html\b contain the README text
459    for \apackage\a and all its components. Included are all changes added
460    to the component \bRELEASE\b, \bCHANGES\b or \bChangeLog\b files dated
461    since the two most recent base releases. Component \bRELEASE\b files
462    contain tag lines of the form [\aYY\a]]\aYY-MM-DD\a [ \atext\a ]] (or
463    \bdate\b(1) format dates) followed by README text, in reverse
464    chronological order (newer entries at the top of the file.) \bpackage
465    release\b lists this information, and \bpackage contents ...\b lists
466    the descriptions and components.]
467[+?\b$HOSTYPE\b names the current binary architecture and is determined
468    by the output of \bpackage\b (no arguments.) The \b$HOSTTYPE\b naming
469    scheme is used to separate incompatible executable and object formats.
470    All architecture specific binaries are placed under \b$INSTALLROOT\b
471    (\b$PACKAGEROOT/arch/$HOSTTYPE\b.) There are a few places that match
472    against \b$HOSTTYPE\b when making binaries; these are limited to
473    makefile compiler workarounds, e.g., if \b$HOSTTYPE\b matches \bhp.*\b
474    then turn off the optimizer for these objects. All other architecture
475    dependent logic is handled either by the \bast\b \biffe\b(1) command or
476    by component specific configure scripts. Explicit \b$HOSTYPE\b
477    values matching *,*cc*[,-*,...]] optionally set the default \bCC\b and
478    \bCCFLAGS\b. This is handy for build farms that support different
479    compilers on the same architecture.]
480[+?Each component contains an \bast\b \bnmake\b(1) makefile (either
481    \bNmakefile\b or \bMakefile\b) and a \bMAM\b (make abstract machine)
482    file (\bMamfile\b.) A Mamfile contains a portable makefile description
483    that is used by \bmamake\b(1) to simulate \bnmake\b. Currently there is
484    no support for old-make/gnu-make makefiles; if the binaries are just
485    being built then \bmamake\b will suffice; if source or makefile
486    modifications are anticipated then \bnmake\b (in the \bast-base\b
487    package) should be used. Mamfiles are automatically generated by
488    \bpackage write\b.]
489[+?Most component C source is prototyped. If \b$CC\b (default value
490    \bcc\b) is not a prototyping C compiler then \bpackage make\b runs
491    \bproto\b(1) on portions of the \b$PACKAGEROOT/src\b tree and places
492    the converted output files in the \b$PACKAGEROOT/proto/src\b tree.
493    Converted files are then viewpathed over the original source.
494    \bproto\b(1) converts an ANSI C subset to code that is compatible with
495    K&R, ANSI, and C++ dialects.]
496[+?All scripts and commands under \b$PACKAGEROOT\b use \b$PATH\b
497    relative pathnames (via the \bast\b \bpathpath\b(3) function); there
498    are no imbedded absolute pathnames. This means that binaries generated
499    under \b$PACKAGEROOT\b may be copied to a different root; users need
500    only change their \b$PATH\b variable to reference the new installation
501    root \bbin\b directory. \bpackage install\b installs binary packages in
502    a new \b$INSTALLROOT\b.]
503
504[ qualifier ... ] [ action ] [ arg ... ] [ n=v ... ]
505
506[+SEE ALSO?\bautoconfig\b(1), \bcksum\b(1), \bexecrate\b(1), \bexpmake\b(1),
507	\bgzip\b(1), \bmake\b(1), \bmamake\b(1), \bnmake\b(1), \bpax\b(1),
508	\bpkgadd\b(1), \bpkgmk\b(1), \bproto\b(1), \bratz\b(1), \brpm\b(1),
509	\bsh\b(1), \btar\b(1), \boptget\b(3)]
510'
511	case $* in
512	help)	set -- --man ;;
513	esac
514	while	getopts -a $command "$USAGE" OPT
515	do	:
516	done
517	shift $OPTIND-1
518	;;
519esac
520
521# check the args
522
523case $AR in
524'')	AR=ar ;;
525esac
526case $CC in
527'')	CC=cc ;;
528esac
529case $LD in
530'')	LD=ld ;;
531esac
532case $NM in
533'')	NM=nm ;;
534esac
535
536action=
537admin_all=1
538admin_on=
539authorize=
540bit=
541exec=
542flat=0
543force=0
544global=
545hi=
546html=0
547ifs=${IFS-'
548	 '}
549lo=
550make=
551makeflags='-k -K'
552nmakeflags=
553nmakesep=
554nl="
555"
556noexec=
557only=0
558output=
559package_src=
560password=
561quiet=0
562show=:
563tab="        "
564verbose=0
565AUTHORIZE=
566DEBUG=
567HURL=
568PROTOROOT=-
569SHELLMAGIC=-
570
571unset FIGNORE BINDIR DLLDIR ETCDIR FUNDIR INCLUDEDIR LIBDIR LOCALEDIR MANDIR SHAREDIR 2>/dev/null || true
572
573while	:
574do	case $# in
575	0)	set host type ;;
576	esac
577	case $1 in
578	admin|clean|clobber|contents|copyright|export|host|install|license|list|make|read|regress|release|remove|results|setup|test|update|use|verify|view|write|TEST)
579		action=$1
580		shift
581		break
582		;;
583	authorize)
584		case $# in
585		1)	echo $command: $1: authorization user name argument expected >&2; exit 1 ;;
586		esac
587		shift
588		authorize=$1
589		shift
590		continue
591		;;
592	debug|environment)
593		exec=echo make=echo show=echo
594		;;
595	flat)	flat=1
596		;;
597	force)	force=1
598		;;
599	never)	exec=echo noexec=-N
600		;;
601	only)	only=1
602		;;
603	password)
604		case $# in
605		1)	echo $command: $1: authorization password argument expected >&2; exit 1 ;;
606		esac
607		shift
608		password=$1
609		shift
610		continue
611		;;
612	quiet)	quiet=1
613		;;
614	show)	exec=echo noexec=-n
615		;;
616	verbose)verbose=1
617		;;
618	DEBUG)	DEBUG=1
619		PS4='+$LINENO:$SECONDS+ '
620		set -x
621		;;
622	help|HELP|html|man|--[?m]*)
623		case $1 in
624		help)	code=0
625			case $2 in
626			'')	exec 1>&2 ;;
627			esac
628			;;
629		html)	code=0 html=1
630			;;
631		*)	code=2
632			exec 1>&2
633			;;
634		esac
635		case $html in
636		1)	bO="<HTML>
637<HEAD>
638<TITLE>$2 package installation instructions</TITLE>
639<HEAD>
640<BODY bgcolor=white link=teal vlink=dimgray>"
641			eO='</BODY>
642</HTML>'
643			bH="<CENTER><H3><FONT face=courier color=red>"
644			eH='</FONT></H3></CENTER>'
645			bP='<P>'
646			bL='<P><TABLE cellpadding=0 cellspacing=2>'
647			bL2='<P><TABLE border=0 cellpadding=0 cellspacing=2>'
648			eL='</TABLE><P>'
649			bT='<TR><TD align=right valign=top><B>'
650			bD='</B></TD><TD align=left>'	eD='</TD></TR>'
651			bB='<B>'			eB='</B>'
652			bI='<I>'			eI='</I>'
653			bX='<PRE>'			eX='</PRE>'
654			bF='<TT>'			eF='</TT>'
655			Camp='&amp;'
656			Mcurl='<A href=../../man/man1/curl.html>curl</A>(1)'
657			Mdate='<A href=../../man/man1/date.html>date</A>(1)'
658			Mfile='<A href=../../man/man1/file.html>file</A>(1)'
659			Mgunzip='<A href=../../man/man1/gzip.html>gunzip</A>(1)'
660			Mhurl='<A href=../../man/man1/hurl.html>hurl</A>(1)'
661			Mlynx='<A href=../../man/man1/lynx.html>lynx</A>(1)'
662			Mnmake='<A href=../../man/man1/nmake.html>nmake</A>(1)'
663			Mpackage='<A href=../../man/man1/package.html>package</A>(1)'
664			Mproto='<A href=../../man/man1/proto.html>proto</A>(1)'
665			Mratz='<A href=../../man/man1/ratz.html>ratz</A>'
666			Mtar='<A href=../../man/man1/tar.html>tar</A>(1)'
667			Mwget='<A href=../../man/man1/wget.html>wget</A>(1)'
668			;;
669		*)	bO=''				eO=''
670			bH=''				eH=':'
671			bP=''
672			bL=''				eL=''
673			bL2=''
674			bT='  '
675			bD=' '				eD=''
676			bB=''				eB=''
677			bI=''				eI=''
678			bX=''				eX=''
679			bF='"'				eF='"'
680			Camp='&'
681			Mcurl='curl(1)'
682			Mdate='date(1)'
683			Mfile='file(1)'
684			Mgunzip='gunzip(1)'
685			Mhurl='hurl(1)'
686			Mlynx='lynx(1)'
687			Mnmake='nmake(1)'
688			Mpackage='package(1)'
689			Mproto='proto(1)'
690			Mratz='ratz'
691			Mtar='tar(1)'
692			Mwget='wget(1)'
693			;;
694		esac
695		case $2 in
696		binary)	echo "${bO}
697${bH}Binary Package Installation Instructions${eH}
698${bL}
699${bT}(1)${bD}Do not install packages as ${bI}root/super-user${eI}. Although some components may
700      have setuid executables, few must be owned by ${bI}root${eI}. These are best
701      changed manually when the security implications are understood.${eD}
702${bT}(2)${bD}Choose a package root directory and cd to it. This will be a local work
703      area for all packages.${eD}
704${bT}(3)${bD}These instructions bypass the ${bI}click to download${eI} package links on the
705      download site. If you already clicked, or if your system does not have
706      ${Mcurl}, ${Mhurl}, ${Mlynx} or ${Mwget} then use the alternate instructions
707      for (3),(4),(5) in plan ${bB}B${eB} below. Plan ${bB}B${eB} installs the ${Mhurl}
708      script which works with ksh and modern bash. The top level URL is:${bX}
709		URL=http://www.research.att.com/sw/download${eX}${eD}
710${bT}(4)${bD}If the ${bB}bin/package${eB} script does not exist then run:${bX}
711		test -d bin || mkdir bin
712		url=\$URL/package
713		(wget -O - \$url||curl -L \$url||hurl \$url) > bin/package
714		chmod +x bin/package${eX}${eD}
715${bT}(5)${bD}Determine the list of package names you want from the download site, then
716      use the ${Mpackage} command to do the actual download:${bX}
717		bin/package authorize \"${bI}NAME${eI}\" password \"${bI}PASSWORD${eI}\" \\
718			setup binary \$URL ${bI}PACKAGE${eI} ...${eX}
719      (Refer to the ${bB}AUTHORIZATION${eB} paragraph on the main download page for
720      ${bI}NAME${eI}/${bI}PASSWORD${eI} details.)  This downloads the closure of the latest
721      binary package(s); covered and up-to-date packages are not downloaded again unless
722      ${bB}package force ...${eB} is specified. Package content is verified using ${bB}${checksum}${eB}.
723      If the package root will contain only one architecture then you can install in ${bB}bin${eB} and
724      ${bB}lib${eB} instead of ${bB}arch/${eB}${bI}HOSTTYPE${eI}${bB}/bin${eB} and ${bB}arch/${eB}${bI}HOSTTYPE${eI}${bB}/lib${eB} by running this
725      instead:${bX}
726		bin/package authorize \"${bI}NAME${eI}\" password \"${bI}PASSWORD${eI}\" \\
727			flat setup binary \$URL ${bB}PACKAGE${eB} ...${eX}
728      To update the same packages from the same URL run:${bX}
729		bin/package setup binary${eX}${eD}
730${bT}(6)${bD}The packaged binaries are position independent, i.e., they do not
731      contain hard-coded paths. However, commands with related files, like
732      ${Mfile} and ${Mnmake}, require the path of the bin directory to be
733      exported in ${bB}PATH${eb}.${eD}
734${bT}(7)${bD}You can run the binaries directly from the package root, or you can
735      install them in a public root (requires the ${bI}AT${Camp}T${eI} ${Mnmake} command):${bX}
736		bin/package flat install ${bI}DIRECTORY PACKAGE${eI}${eX}
737      This will install in ${bI}DIRECTORY${eI}${bB}/bin${eB} and ${bI}DIRECTORY${eI}${bB}/lib${eB}. If you want to
738      preserve the ${bB}arch/${eB}${bI}HOSTTYPE${eI} hierarchy under ${bI}DIRECTORY${eI} then omit the
739      ${bB}flat${eB} argument. If you don't have ${Mnmake} then the following will do a
740      flat install:${bX}
741		cd \$INSTALLROOT
742		cp -p -r bin lib include ${bI}DIRECTORY${eI}${eX}${eD}
743${bT}(8)${bD}To summarize, after the first time, the download cycle for the latest
744      binary release is:${bX}
745		bin/package setup binary${eX}${eD}${eL}
746
747${bH}Binary Package Installation Instructions -- Plan B${eH}
748${bL}
749${bT}(3)${bD}Create the subdirectory ${bB}lib/package/tgz${eB} and download all package archives
750      into that directory.${eD}
751${bT}(4)${bD}If the ${bB}bin/package${eB} script does not exist then manually read the ${bB}INIT${eB}
752      binary package:${bX}
753		gunzip < lib/package/tgz/INIT.${bI}YYYY-MM-DD.HOSTTYPE${eI}.tgz |
754			${TAR} ${TARFLAGS}f -${eX}
755      Note that some browsers automatically unzip downloaded without warning.
756      If the gunzip fails try:
757		${TAR} ${TARFLAGS}f -${eX} lib/package/tgz/INIT.${bI}YYYY-MM-DD.HOSTTYPE${eI}.tgz
758      If your system does not have ${Mtar} or ${Mgunzip} then download the ${Mratz}
759      binary package:${bX}
760		mkdir bin
761		cp lib/package/tgz/ratz.${bI}YYYY-MM-DD.HOSTTYPE${eI}.exe bin/ratz
762		chmod +x bin/ratz
763		bin/ratz -lm < lib/package/tgz/INIT.${bI}YYYY-MM-DD/HOSTTYPE${eI}.tgz
764${bT}(5)${bD}Read all unread package archive(s):${bX}
765		bin/package read${eX}
766      Both source and binary packages will be read by this step.${eD}${eL}${eO}"
767			;;
768		intro)	echo "${bO}
769${bH}Package Hierarchy Details${eH}
770${bP}
771The package directory hierarchy is rooted at ${bB}\$PACKAGEROOT${eB}. All source and
772binaries reside under this tree. A two level viewpath is used to separate
773source and binaries. The top view is architecture specific, the bottom view
774is shared source. All building is done in the architecture specific view;
775no source view files are intentionally changed. This means that many
776different binary architectures can be made from a single copy of the source.
777${bP}
778Each package contains one or more components. Component source for the ${bI}FOO${eI}
779command is in ${bB}\$PACKAGEROOT/src/cmd/${eB}${bI}FOO${eI}, and source for the ${bI}BAR${eI} library is
780in ${bB}\$PACKAGEROOT/src/lib/lib${eB}${bI}BAR${eI}. This naming is for convenience only; the
781underlying makefiles handle inter-component build order. The ${bB}INIT${eB} component,
782which contains generic package support files, is always made first, then the
783components named ${bB}INIT${eB}*, then the order determined by the closure of component
784makefile dependencies.
785${bP}
786${bB}\$PACKAGEROOT/lib/package${eB} contains package specific files. The package naming
787convention is ${bI}GROUP${eI}[${bI}-PART${eI}]; e.g., ${bB}ast-base${eB}, ${bB}gnu-fileutils${eB}. The *${bB}.pkg${eB} files
788are ${bB}ast${eB} ${Mnmake} makefiles that contain the package name, package components,
789references to other packages, and a short package description. *${bB}.pkg${eB} files
790are used by ${bF}package write${eF} to generate new source and binary packages.
791${bP}
792${bB}\$PACKAGEROOT/lib/package/${eB}${bI}GROUP${eI}${bB}.lic${eB} files contain license information that
793is used by the ${bB}ast${eB} ${Mproto} and ${Mnmake} commands to generate source and
794binary license strings. ${bI}GROUP${eI} is determined by the first ${bB}:PACKAGE:${eB} operator
795name listed in the component ${bB}nmake${eB} makefile. ${bI}GROUP${eI}${bB}.lic${eB} files are part of the
796licensing documentation.  Each component may have its own ${bB}LICENSE${eB} file that
797overrides the ${bI}GROUP${eI}${bB}.lic${eB} file.  The full text of the licenses are in the
798${bB}\$PACKAGEROOT/lib/package/LICENSES${eB} and ${bB}\$INSTALLROOT/lib/package/LICENSES${eB}
799directories.
800${bP}
801A few files are generated in ${bB}\$PACKAGEROOT/lib/package/gen${eB} and
802${bB}\$INSTALLROOT/lib/package/gen${eB}. ${bI}PACKAGE${eI}${bB}.ver${eB} contains one line consisting of${bX}
803	${bI}PACKAGE VERSION RELEASE${eI} 1${eX}
804for the most recent instance of ${bI}PACKAGE${eI} read into ${bB}\$PACKAGEROOT${eB}, where
805${bI}PACKAGE${eI} is the package name, ${bI}VERSION${eI} is the ${bI}YYYY-MM-DD${eI} base version,
806and ${bI}RELEASE${eI} is ${bI}VERSION${eI} for the base release or ${bI}YYYY-MM-DD${eI} for delta releases.
807${bI}PACKAGE${eI}${bB}.req${eB} contains *${bB}.ver${eB} entries for the packages required by
808${bI}PACKAGE${eI}, except that the fourth field is 0 instead of 1. All packages
809except ${bB}INIT${eB} and ${Mratz} require the ${bB}INIT${eB} package. A simple sort of ${bI}PACKAGE${eI}${bB}.pkg${eB}
810and *${bB}.ver${eB} determines if the required package have been read in. Finally,
811${bI}PACKAGE${eI}${bB}.README${eB} contains the ${bB}README${eB} text for ${bI}PACKAGE${eI} and all its
812components. Included are all changes added to the component ${bB}RELEASE${eB},
813${bB}CHANGES${eB} or ${bB}ChangeLog${eB} files dated since the two most recent base
814releases. Component ${bB}RELEASE${eB} files contain tag lines of the form
815[${bI}CC${eI}]${bI}YY-MM-DD${eI} [ ${bI}TEXT${eI} ] (or ${Mdate} format dates) followed by README
816text, in reverse chronological order (newer entries at the top of the
817file.) ${bF}package release${eF} generates this information, and
818${bF}package contents ...${eF} lists the descriptions and components.
819${bP}
820${bB}\$HOSTYPE${eB} names the current binary architecture and is determined by the
821output of ${bF}package${eF} (no arguments.) The ${bB}\$HOSTTYPE${eB} naming scheme is used
822to separate incompatible executable and object formats. All architecture
823specific binaries are placed under ${bB}\$INSTALLROOT${eB} (${bB}\$PACKAGEROOT/arch/\$HOSTTYPE${eB}.)
824There are a few places that match against ${bB}\$HOSTTYPE${eB} when making binaries; these
825are limited to makefile compiler workarounds, e.g., if ${bB}\$HOSTTYPE${eB} matches
826'hp.*' then turn off the optimizer for these objects. All other architecture
827dependent logic is handled either by ${bB}\$INSTALLROOT/bin/iffe${eB} or by component
828specific configure scripts. Explicit ${bB}\$HOSTYPE${eB} values matching *,*cc*[,-*,...]
829optionally set the default ${bB}CC${eB} and ${bB}CCFLAGS${eB}. This is handy for build
830farms that support different compilers on the same architecture.
831${bP}
832Each component contains an ${bB}ast${eB} ${Mnmake} makefile (either ${bB}Nmakefile${eB} or ${bB}Makefile${eB})
833and a ${bI}MAM${eI} (make abstract machine) file (${bB}Mamfile${eB}.) A Mamfile contains a portable
834makefile description that is used by ${bB}\$INSTALLROOT/bin/mamake${eB} to simulate
835${bB}nmake${eB}. Currently there is no support for old-make/gnu-make makefiles; if
836the binaries are just being built then ${bB}mamake${eB} will suffice; if source or
837makefile modifications are anticipated then ${bB}nmake${eB} (from the ${bB}ast-open${eB} or
838${bB}ast-base${eB} package) should be used. Mamfiles are automatically generated by
839${bF}package write${eF}.
840${bP}
841Most component C source is prototyped. If ${bB}\$CC${eB} (default value ${bB}cc${eB}) is not a
842prototyping C compiler then ${bF}package make${eF} runs ${Mproto} on portions of the
843${bB}\$PACKAGEROOT/src${eB} tree and places the converted output files in the
844${bB}\$PACKAGEROOT/proto/src${eB} tree. Converted files are then viewpathed over the
845original source. The ${bB}ast${eB} ${Mproto} command converts an ANSI C subset to code
846that is compatible with K&R, ANSI, and C++ dialects.
847${bP}
848All scripts and commands under ${bB}\$PACKAGEROOT${eB} use ${bB}\$PATH${eB} relative pathnames;
849there are no imbedded absolute pathnames. This means that binaries generated
850under ${bB}\$PACKAGEROOT${eB} may be copied to a different root; users need only change
851their ${bB}\$PATH${eB} variable to reference the new instalation root bin directory.
852${bF}package install${eF} installs binary packages in a new ${bB}\$INSTALLROOT${eB}.
853${eO}"
854			;;
855		source)	echo "${bO}
856${bH}Source Package Installation Instructions${eH}
857${bL}
858${bT}(1)${bD}Do not install packages as ${bI}root/super-user${eI}. Although some components may
859      have setuid executables, few must be owned by ${bI}root${eI}. These are best
860      changed manually when the security implications are understood.${eD}
861${bT}(2)${bD}Choose a package root directory and cd to it. This will be a local work
862      area for all packages.
863${bT}(3)${bD}These instructions bypass the ${bI}click to download${eI} package links on the
864      download site. If you already clicked, or if your system does not have
865      ${Mcurl}, ${Mhurl}, ${Mlynx} or ${Mwget} then use the alternate instructions
866      for (3),(4),(5) in plan ${bB}B${eB} below. Plan ${bB}B${eB} installs the ${Mhurl}
867      script which works with ksh and modern bash. The top level URL is:${bX}
868		URL=http://www.research.att.com/sw/download${eX}${eD}
869${bT}(4)${bD}If the ${bB}bin/package${eB} script does not exist then run:${bX}
870		test -d bin || mkdir bin
871		url=\$URL/package
872		(wget -O - \$url||curl -L \$url||hurl \$url) > bin/package
873		chmod +x bin/package${eX}${eD}
874${bT}(5)${bD}Determine the list of package names you want from the download site, then
875      use the ${Mpackage} command to do the actual download:${bX}
876		bin/package authorize \"${bI}NAME${eI}\" password \"${bI}PASSWORD${eI}\" \\
877			setup source \$URL ${bB}PACKAGE${eB} ...${eX}
878      (Refer to the ${bB}AUTHORIZATION${eB} paragraph on the main download page for
879      ${bI}NAME${eI}/${bI}PASSWORD${eI} details.)  This downloads the closure of the latest
880      source package(s); covered and up-to-date packages are not downloaded again unless
881      ${bB}package force ...${eB} is specified. Package content is verified using ${bB}${checksum}${eB}.
882      If the package root will contain only one architecture then you can install in ${bB}bin${eB} and
883      ${bB}lib${eB} instead of ${bB}arch/${eB}${bI}HOSTTYPE${eI}${bB}/bin${eB} and ${bB}arch/${eB}${bI}HOSTTYPE${eI}${bB}/lib${eB} by running this
884      instead:${bX}
885		bin/package authorize \"${bI}NAME${eI}\" password \"${bI}PASSWORD${eI}\" \\
886			flat setup source \$URL ${bB}PACKAGE${eB} ...${eX}
887      To update the same packages from the same URL run:${bX}
888		bin/package setup source${eX}${eD}
889${bT}(6)${bD}Build and install; all generated files are placed under ${bB}arch/${eB}${bI}HOSTTYPE${eI}
890      (${bB}\$INSTALLROOT${eB}), where ${bI}HOSTTYPE${eI} is the output of ${bB}bin/package${eB} (with no
891      arguments.) ${bI}name=value${eI} arguments are supported; ${bB}CC${eB} and ${bB}debug=1${eB} (compile
892      with -g instead of -O) are likely candidates. The output is written to
893      the terminal and captured in ${bB}\$INSTALLROOT/lib/package/gen/make.out${eB}:${bX}
894		bin/package make${eX}${eD}
895${bT}(7)${bD}List make results and interesting errors:${bX}
896		bin/package results${eX}
897      Run the regression tests:${bX}
898		bin/package test${eX}
899      List test results and errors:${bX}
900		bin/package results test${eX}${eD}
901${bT}(8)${bD}The generated binaries are position independent, i.e., they do not
902      contain hard-coded paths. However, commands with related files, like
903      ${Mfile} and ${Mnmake}, require the path of the bin directory to be
904      exported in ${bB}PATH${eb}.${eD}
905${bT}(9)${bD}You can run the binaries directly from the package root, or you can
906      install them in a public root after you are satisfied with the make and
907      test actions (requires the ${bI}AT${Camp}T${eI} ${Mnmake} command):${bX}
908		bin/package flat install ${bI}DIRECTORY PACKAGE${eI}${eX}
909      This will install in ${bI}DIRECTORY${eI}${bB}/bin${eB} and ${bI}DIRECTORY${eI}${bB}/lib${eB}. If you want to
910      preserve the ${bB}arch/${eB}${bI}HOSTTYPE${eI} hierarchy under ${bI}DIRECTORY${eI} then omit the
911      ${bB}flat${eB} argument. If you don't have ${Mnmake} then the following will do a
912      flat install:${bX}
913		cd \$INSTALLROOT
914		cp -p -r bin lib include ${bI}DIRECTORY${eI}${eX}${eD}
915${bT}(10)${bD}To summarize, after the first time the download, build, and test cycle
916      for the latest source release is:${bX}
917		bin/package setup source
918		bin/package make
919		bin/package test${eX}${eD}${eL}
920
921${bH}Source Package Installation Instructions -- Plan B${eH}
922${bL}
923${bT}(3)${bD}Create the subdirectory ${bB}lib/package/tgz${eB} and download all package archives
924      into that directory.${eD}
925${bT}(4)${bD}If the ${bB}bin/package${eB} script does not exist then manually read the ${bB}INIT${eB}
926      source package:${bX}
927		gunzip < lib/package/tgz/INIT.${bI}YYYY-MM-DD${eI}.tgz | ${TAR} ${TARFLAGS}f -${eX}
928      Note that some browsers automatically unzip downloaded without warning.
929      If the gunzip fails try:
930		${TAR} ${TARFLAGS}f -${eX} lib/package/tgz/INIT.${bI}YYYY-MM-DD${eI}.tgz
931      If your system does not have ${Mtar} or ${Mgunzip} then download the ${Mratz}
932      source package, compile it, and manually read the ${bB}INIT${eB}
933      source package:${bX}
934		mkdir bin
935		cp lib/package/tgz/ratz.${bI}YYYY-MM-DD${eI}.c lib/package/tgz/ratz.c
936		cc -o bin/ratz lib/package/tgz/ratz.c
937		bin/ratz -lm < lib/package/tgz/INIT.${bI}YYYY-MM-DD${eI}.tgz
938${bT}(5)${bD}Read all unread package archive(s):${bX}
939		bin/package read${eX}
940      Both source and binary packages will be read by this step.${eD}${eL}${eO}"
941			;;
942		*)	echo "Usage: $command [ qualifier ... ] [ action ] [ arg ... ] [ n=v ... ]
943
944   The $command command controls source and binary packages. It must be run
945   within the package root directory tree. See \"$command help intro\" for
946   details. In the following, PACKAGE names either a package or a component
947   within a package; if omitted, all packages are operated on. The default
948   action is \"host type\".
949
950   qualifier:
951	authorize NAME Remote authorization name or license acceptance phrase.
952	debug|environment Show environment and actions; do not execute.
953	flat    Collapse \$INSTALLROOT { bin fun include lib } onto \$PACKAGEROOT.
954	force	Force the action to override saved state.
955	never	Run make -N; otherwise show other actions.
956	only	Only operate on the specified packages.
957	password PASSWORD Remote authorization or license acceptance password.
958	quiet	Do not list captured make and test action output.
959	show	Run make -n; otherwise show other actions.
960	DEBUG	Trace the package script actions in detail for debugging.
961   action:
962	admin [ all ] [ db FILE ] [ on PATTERN ] [ action ... ]
963		Apply ACTION ... to the hosts listed in FILE. If FILE is
964		omitted then "admin.db" is assumed. The caller must have rcp(1)
965		and rsh(1) or scp(1) and ssh(1) access to the hosts. Output
966		for the action is saved per-host in ACTION.log/HOST. Logs
967		can be viewed by \"package admin [on HOST] results [ACTION]\".
968		By default only local PACKAGEROOT hosts are selected from FILE;
969		\"all\" selects all hosts. \"on PATTERN\" selects only
970		hosts matching the | separated PATTERN. FILE contains four
971		types of lines. Blank lines and lines beginning with # are
972		ignored. Lines starting with id=value are variable assignments.
973		Set admin_ping to local conventions if \"$admin_ping\" fails.
974		If a package list is not specified on the command line the
975		action applies to all packages; a variable assigment
976		package=list applies action to the packages in list for
977		subsequent hosts in FILE. The remaining line type is a host
978		description consisting of 6 tab separated fields. The first 3
979		are mandatory; the remaining 3 are updated by the admin action:
980		   hosttype
981			   The host type as reported by package.
982		   [user@]host
983			   The host name and optionally user name for rcp(1)
984			   and rsh(1) access.
985		   [remote:[[master]:]]PACKAGEROOT
986			   The absolute remote package root directory and
987			   optionally the remote prorocol (rsh or ssh) if
988			   the directory is on a different server than the
989			   master package root directory. If
990			   lib/package/admin/$admin_env exists under
991			   this directory then it is sourced by sh(1)
992			   before ACTION is done. If this field begins with -
993			   then the host is ignored. If this field contains
994			   : then ditto(1) is used to sync the remote src
995			   directory hierarchy to the local one. If [master]:
996			   is specified then the sync is deferred to the
997			   master host. If master is omitted (two :) then
998			   the sync is disabled. These directories must exist
999			   on the remote side: lib/package, src/cmd, src/lib.
1000		   date    YYMMDD of the last action.
1001		   date    Elapsed wall time of the last action.
1002		   M T W   The admin action make, test and write action error
1003			   counts. A non-numeric value in any of these fields
1004			   disables the corresponding action.
1005	    	   owner   The owner contact information.
1006		   attributes
1007		           NAME=VALUE attributes. Should at least contain
1008			   cc=compiler-version.
1009	clean | clobber
1010	    Delete the arch/HOSTTYPE hierarchy; this deletes all generated
1011	    files and directories for HOSTTYPE. The heirarchy can be rebuilt
1012	    by package make.]
1013	contents [ package ... ]
1014		List description and components for PACKAGE on the standard
1015		output.
1016	copyright [ package ... ]
1017		List the general copyright notice(s) for PACKAGE on the
1018		standard output. Note that individual components in PACKAGE
1019		may contain additional or replacement notices.
1020	export [ VARIABLE ... ]
1021		List NAME=VALUE for each VARIABLE, one per line. If the
1022		\"only\" attribute is specified then only the variable
1023		values are listed. If no variables are specified then
1024		$env are assumed.
1025	help [ ACTION ]
1026		Display help text on the standard error [ standard output
1027		for ACTION ].
1028	host [ canon cpu name rating type ... ]
1029		List architecture/implementation dependent host information
1030		on the standard output. type is listed if no attributes are
1031		specified. Information is listed on a single line in attributes
1032		order. The attributes are:
1033		   canon   The next argument is a host type name to be
1034			   converted to package syntax.
1035		   cpu     The number of cpus; 1 if the host is not a
1036			   multiprocessor.
1037		   name    The host name.
1038		   rating  The cpu rating in pseudo mips; the value is useful
1039			   useful only in comparisons with rating values of
1040			   other hosts. Other than a vax rating fixed at 1,
1041			   ratings can vary wildly but consistently from
1042			   vendor mips ratings. cc(1) may be required to
1043			   determine the rating.
1044	           type    The host type, usually of the form
1045			   vendor.architecture, with an optional trailing
1046			   -version. The main theme is that type names within
1047			   a family of architectures are named in a similar,
1048			   predictable style. Os point release information is
1049			   avoided as much as possible, but vendor resistance
1050			   to release incompatibilities has for the most part
1051			   been futile.
1052	html [ ACTION ]
1053		Display html help text on the standard error [ standard output
1054		for ACTION ].
1055	install [ ARCHITECTURE ... ] DIR [ PACKAGE ... ]
1056		Copy the package binary hierarchy to DIR. If ARCHITECTURE is
1057		omitted then all architectures are installed. If the \"flat\"
1058		attribute is specified then exactly one ARCHITECTURE must be
1059		specified; this architecture will be installed in DIR without
1060		the \"arch/HOSTTYPE\" directory prefixes. Otherwise each
1061		architecture will be installed in a separate \"arch/HOSTTYPE\"
1062		subdirectory of DIR. The ARCHITECTURE - names the current
1063		architecture. DIR must be an existing directory. If PACKAGE
1064		is omitted then all binary packages are installed. This action
1065		requires nmake.
1066	license [ package ... ]
1067		List the source license(s) for PACKAGE on the standard output.
1068		Note that individual components in PACKAGE may contain
1069		additional or replacement licenses.
1070	list [ PACKAGE ... ]
1071		List the name, version and prerequisites for PACKAGE on the
1072		standard output.
1073	make [ PACKAGE ] [ OPTION ... ] [ TARGET ... ]
1074		Build and install. The default TARGET is install, which
1075		makes and installs all packages. If the standard output
1076		is a terminal then the output is also captured in
1077		\$INSTALLROOT/lib/package/gen/make.out. The build is done
1078		in the \$INSTALLROOT directory tree viewpathed on top of
1079		the \$PACKAGEROOT directory tree. If \"flat\" is specified then
1080		the \$INSTALLROOT { bin fun include lib } directories are
1081		linked to the same directories in the package root. Only
1082		one architecture may be flat. Leaf directory names matching
1083		the |-separated shell pattern \$MAKESKIP are ignored. The
1084		view action is done before making. OPTION operands are
1085		passed to the underlying make command.
1086	read [ package ... | archive ... ]
1087		Read the named package archive(s). Must be run from the
1088		package root directory. Archives are searched for in .
1089		and lib/package/tgz. Each package is read only once. The
1090		file lib/package/tgz/package[.type].tim tracks the read time.
1091		See the write action for archive naming conventions. Text
1092		file archive member are assumed to be ASCII or UTF-8 encoded.
1093	regress diff(1) the current and previous package test results.
1094	release [ [CC]YY-MM-DD [ [cc]yy-mm-dd ] ] [ package ]
1095		Display recent changes since [CC]YY-MM-DD (up to [cc]yy-mm-dd),
1096		where - means lowest (or highest.) If no dates are specified
1097		then changes for the last 4 months are listed. PACKAGE may
1098		be a package or component name.
1099	remove PACKAGE
1100		Remove files installed for PACKAGE.
1101	results [ path ] [ old ] [ make | test ]
1102		List results and interesting messages captured by the most
1103		recent make (default), test or write action. old specifies the
1104		previous results, if any (current and previous results are
1105		retained.) $HOME/.pkgresults, if it exists, must contain an
1106		egrep(1) expression of result lines to be ignored. failed lists
1107		failures only and path lists the results file path only.
1108	setup [ beta ] [ binary ] [ source ] [ ARCHITECTURE ... ] [ URL ] [ PACKAGE ... ]
1109		The action initializes the current directory as a package root,
1110		runs the update action to download new or out of date packages,
1111		and runs the read action on those packages. If \"flat\" is
1112		specified then the \$INSTALLROOT { bin fun include lib }
1113		directories are linked to the same directories in the package
1114		root. Only one architecture may be flat. See the update and
1115		read actions for argument details.
1116	test [ PACKAGE ]
1117		Run the regression tests for PACKAGE. If the standard output
1118		is a terminal then the output is also captured in
1119		\$INSTALLROOT/lib/package/gen/test.out. In general a package
1120		must be made before it can be tested. Components tested with
1121		the \bregress\b(1) command require \bksh93\b. If only is
1122		also specified then only the listed package components are
1123		tested, otherwise the closure of the components is tested.
1124	update [ beta ] [ binary ] [ source ] [ ARCHITECTURE ... ] [ URL ] [ PACKAGE ... ]
1125		Download the latest release of the selected and required
1126		packages from URL (e.g.,
1127		http://www.research.att.com/sw/download) into the directory
1128		\$PACKAGEROOT/lib/package/tgz. beta acesses beta packages;
1129		download these at your own risk. If ARCHITECTURE is omitted
1130		then only architectures already present in the tgz directory
1131		will be downloaded. If ARCHITECTURE is - then all posted
1132		architectures will be downloaded. If URL matches *.url then
1133		it is interpreted as a file containing shell variable
1134		assignments for url, authorize and password. If URL is
1135		omitted then the definitions for url, authorize and password
1136		in \$PACKAGEROOT/lib/package/tgz/$default_url, if it exists,
1137		are used. If \$PACKAGEROOT/lib/package/tgz/$default_url does
1138		not exist then it is initialized with the current url,
1139		authorize and password values and read permission for the
1140		current user only. If PACKAGE is omitted then only
1141		packages already present in the tgz directory will be
1142		downloaded. If PACKAGE is - then all posted packages will be
1143		downloaded. If source and binary are omitted then both source
1144		and binary packages will be downloaded. If \bonly\b is
1145		specified then only the named packages are updated; otherwise
1146		the closure of required packages is updated. This action
1147		requires wget(1), lynx(1), curl(1) or a shell that supports
1148		io to /dev/tcp/HOST/PORT.
1149   	use [ uid | PACKAGE | . [ 32 | 64 ] | 32 | 64 | - ] [ COMMAND ... ]
1150   		Run COMMAND or an interactive shell if COMMAND is omitted, with
1151		the environment initialized for using the package (can you say
1152		shared library without cussing?) If uid or PACKAGE or . is
1153		specified then it is used to determine a \$PACKAGEROOT,
1154		possibly different from the current directory. For example, to
1155		try out bozo's package: \"package use bozo\". In this case the
1156		command may be run from any directory. If the file
1157		\$INSTALLROOT/lib/package/profile is readable then it is
1158		sourced to initialize the environment. 32 or 64 implies
1159		\$PACKAGEROOT of . and specifies the target architecture word
1160		size (which may be silently ignored.)
1161	verify [ PACKAGE ]
1162		Verify installed binary files against the checksum files in
1163		\$INSTALLROOT/lib/package/gen/*.sum. The checksum files contain
1164		mode, user and group information. If the checksum matches
1165		for a given file then the mode, user and group are changed
1166		as necessary to match the checksum entry. A warning is printed
1167		on the standard error for each mismatch. Requires the ast
1168		package cksum(1) command.
1169	view
1170		Initialize the architecture specific viewpath hierarchy. The
1171		make action implicitly calls this action. If \"flat\" is specified
1172		then the \$INSTALLROOT { bin fun include lib } directories are
1173		linked to the same directories in the package root. Only one
1174		architecture may be flat.
1175	write [closure] [cyg|exp|lcl|pkg|rpm|tgz|tst] [base|delta]
1176			[binary|runtime|source] PACKAGE
1177		Write a package archive for PACKAGE. All work is done in the
1178		\$PACKAGEROOT/lib/package directory. FORMAT-specific files
1179		are placed in the FORMAT subdirectory. A PACKAGE[.TYPE].tim
1180		file in this directory tracksthe write time and prevents a
1181		package from being read in the same root it was written. If
1182		more than one file is generated for a particular FORMAT then
1183		those files are placed in the FORMAT/PACKAGE subdirectory.
1184		File names in the FORMAT subdirectory will contain the package
1185		name, a YYYY-MM-DD date, and for binary packages, HOSTTYPE.
1186		If PACKAGE is omitted then an ordered list of previously
1187		written packages is generated. If \"only\" is specified then
1188		only the named packages will be written; otherwise
1189		prerequisite packages are written first. Package components
1190		must be listed in PACKAGE.pkg. FORMAT may be one of:
1191		   cyg  generate a cygwin package
1192		   exp  generate an exptools(1) maintainer source archive
1193		        and NPD file in the exp subdirectory, suitable for
1194			expmake(1); support files are placed in the
1195			exp/PACKAGE subdirectory
1196		   lcl	generate a package archive or delta in the lcl
1197			subdirectory, suitable for restoration into the
1198			primary source tree (no source licence annotation)
1199		   pkg	generate a pkgmk(1) package, suitable for pkgadd(1)
1200		   rpm  generate an rpm(1) package
1201		   tgz  generate a gzip(1) tar(1) package archive; this is
1202			the default
1203		   tst  generate tgz FORMAT package archive in the tst
1204			subdirectory; version state files are not updated
1205		The package type must be one of source, binary or runtime.
1206		A source package contains the source needed to build the
1207		corresponding binary package. A binary package includes the
1208		libraries and headers needed for compiling and linking
1209		against the public interfaces. A runtime package contains
1210		the commands and required dynamic libraries.  A package may
1211		be either a base or delta. A base package contains a
1212		complete copy of all components.  A delta package contains
1213		only changes from a previous base package. Delta recipients
1214		must have the ast pax(1) command (in the ast-base package.)
1215		If neither base nor delta is specified, then the current
1216		base is overwritten if there are no deltas referring to the
1217		current base. Only the tgz and lcl formats support delta.
1218		If base is specified then a new base and two delta archives
1219		are generated: one delta to generate the new base from the
1220		old, and one delta to generate the old base from the new;
1221		the old base is then removed. If delta is specified then a
1222		new delta referring to the current base is written.
1223		package.pkg may reference other packages. By default a
1224		pointer to those packages is written. The recipient package
1225		read will then check that all required packages have been
1226		downloaded. If closure is specified then the components for
1227		all package references are included in the generated
1228		package.  This may be useful for lcl and versioning.  All
1229		formats but lcl annotate each source file (not already
1230		annotated) with a license comment as it is written to the
1231		package archive using proto(1).
1232   name=value:
1233	variable definition: typically CC=cc or CCFLAGS=-g."
1234			;;
1235		esac
1236		exit $code
1237		;;
1238	*=*)	set DEFAULT host type "$@"
1239		;;
1240	*)	echo "Usage: $command [ options ] [ qualifier ... ] [ action ] [ arg ... ] [ n=v ... ]" >&2
1241		exit 2
1242		;;
1243	esac
1244	global="$global $1"
1245	shift
1246done
1247
1248# gather HOSTTYPE *,* options
1249# 	,*cc*,-*,...	set CC and CCFLAGS
1250
1251hostopts()
1252{
1253	_ifs_=$IFS
1254	IFS=,
1255	set '' $HOSTTYPE
1256	IFS=$_ifs_
1257	shift
1258	while	:
1259	do	case $# in
1260		0|1)	break ;;
1261		esac
1262		shift
1263		case $1 in
1264		*cc*)	CC=$1
1265			while	:
1266			do	case $# in
1267				0|1)	break ;;
1268				esac
1269				case $2 in
1270				-*)	case $assign_CCFLAGS in
1271					?*)	assign_CCFLAGS="$assign_CCFLAGS " ;;
1272					esac
1273					assign_CCFLAGS="$assign_CCFLAGS$2"
1274					shift
1275					;;
1276				*)	break
1277					;;
1278				esac
1279			done
1280			;;
1281		esac
1282	done
1283}
1284
1285# collect command line targets and definitions
1286
1287case $_PACKAGE_HOSTTYPE_ in
1288?*)	HOSTTYPE=$_PACKAGE_HOSTTYPE_
1289	KEEP_HOSTTYPE=1
1290	;;
1291*)	KEEP_HOSTTYPE=0
1292	;;
1293esac
1294KEEP_PACKAGEROOT=0
1295KEEP_SHELL=0
1296USER_VPATH=
1297args=
1298assign=
1299assign_CCFLAGS=
1300for i
1301do	case $i in
1302	*:*=*)	args="$args $i"
1303		continue
1304		;;
1305	*=*)	eval `echo ' ' "$i" | sed 's,^[ 	]*\([^=]*\)=\(.*\),n=\1 v='\''\2'\'','`
1306		;;
1307	esac
1308	case $i in
1309	AR=*|LD=*|NM=*)
1310		assign="$assign $n='$v'"
1311		eval $n='$'v
1312		;;
1313	CC=*)	eval $n='$'v
1314		;;
1315	CCFLAGS=*)
1316		eval $n='$'v
1317		assign_CCFLAGS="CCFLAGS=\"\$CCFLAGS\""
1318		;;
1319	HOSTTYPE=*)
1320		eval $n='$'v
1321		case $HOSTTYPE in
1322		?*)	KEEP_HOSTTYPE=1 ;;
1323		esac
1324		;;
1325	HURL=*)	eval $n='$'v
1326		;;
1327	PACKAGEROOT=*)
1328		eval $n='$'v
1329		case $PACKAGEROOT in
1330		?*)	KEEP_PACKAGEROOT=1 ;;
1331		esac
1332		;;
1333	SHELL=*)eval $n='$'v
1334		case $SHELL in
1335		?*)	KEEP_SHELL=1 ;;
1336		esac
1337		;;
1338	TAR=*)	eval $n='$'v
1339		;;
1340	TARFLAGS=*)
1341		eval $n='$'v
1342		;;
1343	VPATH=*)eval USER_$n='$'v
1344		;;
1345	'debug=1')
1346		makeflags="$makeflags --debug-symbols"
1347		;;
1348	'strip=1')
1349		makeflags="$makeflags --strip-symbols"
1350		;;
1351	*=*)	assign="$assign $n='$v'"
1352		;;
1353	*)	args="$args $i"
1354		;;
1355	esac
1356done
1357case $HOSTTYPE in
1358*,*)	hostopts $HOSTTYPE ;;
1359esac
1360case $assign_CCFLAGS in
1361?*)	assign="$assign $assign_CCFLAGS"
1362esac
1363case $CC in
1364''|cc)	;;
1365*)	export CC ;;
1366esac
1367
1368# grab action specific args
1369
1370case $action in
1371admin)	while	:
1372	do	case $# in
1373		0)	set list
1374			break
1375			;;
1376		esac
1377		case $1 in
1378		all)	admin_all=1
1379			;;
1380		db)	case $# in
1381			1)	echo $command: $action: $1: db file argument expected >&2
1382				exit 1
1383				;;
1384			esac
1385			shift
1386			admin_db=$1
1387			;;
1388		on)	case $# in
1389			1)	echo $command: $action: $1: host pattern argument expected >&2
1390				exit 1
1391				;;
1392			esac
1393			shift
1394			admin_on=$1
1395			;;
1396		*)	break
1397			;;
1398		esac
1399		shift
1400	done
1401	admin_action=$1
1402	admin_args=$*
1403	for i
1404	do	case $i in
1405		debug|environment|force|never|only|quiet|show|DEBUG)
1406			;;
1407		*)	admin_action=$i
1408			break
1409			;;
1410		esac
1411	done
1412	;;
1413setup)	PACKAGEROOT=${PWD:-`pwd`}
1414	export PACKAGEROOT
1415	KEEP_PACKAGEROOT=1
1416	;;
1417use)	case $1 in
1418	.|32|64)case $1 in
1419		32|64)	bit=$1 ;;
1420		esac
1421		shift
1422
1423		# HOSTTYPE specific setup
1424
1425		case $HOSTTYPE in
1426		win32.*)sys=uwin
1427			wow=`uname -i`
1428			case $bit in
1429			32)	case $HOSTTYPE in
1430				*-64)	HOSTTYPE=${HOSTTYPE%-64} ;;
1431				esac
1432				case $wow in
1433				*/32)	;;
1434				*)	vpath / /$bit ;;
1435				esac
1436				;;
1437			64)	case $HOSTTYPE in
1438				*-64)	;;
1439				*)	HOSTTYPE=$HOSTTYPE-64 ;;
1440				esac
1441				case $wow in
1442				*/32)	echo $command: cannot build $bit-bit on $wow $sys >&2; exit 2 ;;
1443				*)	vpath / /$bit ;;
1444				esac
1445				;;
1446			esac
1447			case $bit in
1448			'')	PS1="($sys) " ;;
1449			*)	PS1="($sys-$bit) " ;;
1450			esac
1451
1452			$exec umask 002
1453			$exec unset MAKESKIP
1454
1455			$exec export P=$PWD
1456			$exec export A=$P/arch/$HOSTTYPE
1457
1458			$exec export CDPATH=:..:$A/src/cmd:$A/src/lib:$A/src/uwin:$P/lib/package
1459			$exec export INSTALLROOT=$A
1460			$exec export PACKAGEROOT=$P
1461			$exec export PATH=$A/bin:$P/bin:$PATH
1462			$exec export PS1="$PS1"
1463			$exec export VPATH=$A:$P
1464			$exec export nativepp=/usr/lib
1465
1466			if	test '' != "$INSTALLROOT" -a -d $INSTALLROOT/include/ast
1467			then	$exec export PACKAGE_ast=$INSTALLROOT
1468			elif	test -d ${PWD%/*}/ast/arch/$HOSTTYPE
1469			then	$exec export PACKAGE_ast=${PWD%/*}/ast/arch/$HOSTTYPE
1470			fi
1471
1472			# run the command
1473
1474			case $# in
1475			0)	case $show in
1476				':')	$exec exec $SHELL ;;
1477				esac
1478				;;
1479			*)	$exec exec $SHELL -c "$@"
1480				;;
1481			esac
1482			exit
1483			;;
1484		esac
1485		PACKAGEROOT=${PWD:-`pwd`}
1486		$show export PACKAGEROOT
1487	esac
1488	;;
1489esac
1490
1491# true if arg is a valid PACKAGEROOT
1492
1493packageroot() # dir
1494{
1495	test -d $1/lib/$command -o -x $1/bin/$command
1496}
1497
1498# true if arg is executable
1499
1500executable() # [!] command
1501{
1502	case $1 in
1503	'!')	test ! -x "$2" -a ! -x "$2.exe"; return ;;
1504	*)	test -x "$1" -o -x "$1.exe"; return ;;
1505	esac
1506}
1507
1508# initialize SHELLMAGIC
1509# tangible proof of cygwin's disdain for unix (well, this and execrate)
1510
1511shellmagic()
1512{
1513	case $SHELLMAGIC in
1514	'')	;;
1515	-)	if	test -f /emx/bin/sh.exe
1516		then	SHELLMAGIC='#!/emx/bin/sh.exe'$nl
1517		elif	test -f /bin/env.exe
1518		then	SHELLMAGIC='#!/bin/env sh'$nl
1519		else	SHELLMAGIC=
1520		fi
1521		;;
1522	esac
1523}
1524
1525# true if arg is executable command on $PATH
1526
1527onpath() # command
1528{
1529	_onpath_b=$1
1530	case $_onpath_b in
1531	/*)	if	executable $_onpath_b
1532		then	_onpath_=$_onpath_b
1533			return 0
1534		fi
1535		return 1
1536		;;
1537	esac
1538	IFS=':'
1539	set '' $PATH
1540	IFS=$ifs
1541	shift
1542	for _onpath_d
1543	do	case $_onpath_d in
1544		'')	_onpath_d=. ;;
1545		esac
1546		if	executable "$_onpath_d/$_onpath_b"
1547		then	_onpath_=$_onpath_d/$_onpath_b
1548			return 0
1549		fi
1550	done
1551	return 1
1552}
1553
1554# true if no nmake or nmake not from AT&T or nmake too old
1555
1556nonmake() # nmake
1557{
1558	_nonmake_version=`( $1 -n -f - 'print $(MAKEVERSION:@/.*AT&T.* //:/-//G:@/.* .*/19960101/)' . ) </dev/null 2>/dev/null || echo 19840919`
1559	if	test $_nonmake_version -lt 20001031
1560	then	return 0
1561	fi
1562	return 1
1563}
1564
1565# determine local host attributes
1566
1567hostinfo() # attribute ...
1568{
1569	case $DEBUG in
1570	1)	set -x ;;
1571	esac
1572	map=
1573	something=
1574	path=$PATH
1575	for i in $ccs
1576	do	PATH=$PATH:$i
1577	done
1578	for i in $use
1579	do	for j in $org
1580		do	PATH=$PATH:$i/$j/bin
1581		done
1582		PATH=$PATH:$i/bin
1583	done
1584	# LD_LIBRARY_PATH may be out of sync with PATH here
1585	case $SED in
1586	'')	SED=sed
1587		$SED 1d < /dev/null > /dev/null 2>&1 ||
1588		for dir in /bin /usr/bin
1589		do	if	test -x $dir/$SED
1590			then	SED=$dir/$SED
1591				break
1592			fi
1593		done
1594		TR=tr
1595		$TR < /dev/null > /dev/null 2>&1 ||
1596		for dir in /bin /usr/bin
1597		do	if	test -x $dir/$TR
1598			then	TR=$dir/$TR
1599				break
1600			fi
1601		done
1602		;;
1603	esac
1604	case $PACKAGE_PATH in
1605	?*)	for i in `echo $PACKAGE_PATH | $SED 's,:, ,g'`
1606		do	PATH=$PATH:$i/bin
1607		done
1608		;;
1609	esac
1610
1611	# validate the args
1612
1613	canon=
1614	cc=$CC
1615	for info
1616	do	case $canon in
1617		-)	canon=$info
1618			;;
1619		*)	case $info in
1620			*/*|*[cC][cC])
1621				cc=$info
1622				;;
1623			canon)	canon=-
1624				something=1
1625				;;
1626			cpu|name|rating|type)
1627				something=1
1628				;;
1629			*)	echo "$command: $action: $info: unknown attribute" >&2
1630				exit 1
1631				;;
1632			esac
1633			;;
1634		esac
1635	done
1636	case $canon in
1637	-)	echo "$command: $action: canon: host type name expected" >&2
1638		exit 1
1639		;;
1640	esac
1641	case $something in
1642	"")	set "$@" type ;;
1643	esac
1644	case $DEBUG in
1645	'')	exec 9>&2
1646		exec 2>/dev/null
1647		;;
1648	esac
1649
1650	# compute the info
1651
1652	_hostinfo_=
1653	for info
1654	do
1655	case $info in
1656	cpu)	case $NPROC in
1657		[123456789]*)
1658			_hostinfo_="$_hostinfo_ $NPROC"
1659			continue
1660			;;
1661		esac
1662		cpu=`grep -ic '^processor[ 	][ 	]*:[ 	]*[0123456789]' /proc/cpuinfo`
1663		case $cpu in
1664		[123456789]*)
1665			_hostinfo_="$_hostinfo_ $cpu"
1666			continue
1667			;;
1668		esac
1669		cpu=1
1670		# exact match
1671		set							\
1672			hinv			'^Processor [0123456789]'	\
1673			psrinfo			'on-line'		\
1674			'cat /reg/LOCAL_MACHINE/Hardware/Description/System/CentralProcessor'					'.'			\
1675			'cat /proc/registry/HKEY_LOCAL_MACHINE/Hardware/Description/System/CentralProcessor'			'.'			\
1676
1677		while	:
1678		do	case $# in
1679			0)	break ;;
1680			esac
1681			i=`$1 2>/dev/null | grep -c "$2"`
1682			case $i in
1683			[123456789]*)
1684				cpu=$i
1685				break
1686				;;
1687			esac
1688			shift;shift
1689		done
1690		case $cpu in
1691		0|1)	set						\
1692			/bin/mpstat
1693
1694			while	:
1695			do	case $# in
1696				0)	break ;;
1697				esac
1698				if	executable $1
1699				then	case `$1 | grep -ic '^cpu '` in
1700					1)	cpu=`$1 | grep -ic '^ *[0123456789][0123456789]* '`
1701						break
1702						;;
1703					esac
1704				fi
1705				shift
1706			done
1707			;;
1708		esac
1709		case $cpu in
1710		0|1)	# token match
1711			set						\
1712			/usr/kvm/mpstat			'cpu[0123456789]'	\
1713			/usr/etc/cpustatus		'enable'	\
1714			/usr/alliant/showsched		'CE'		\
1715			'ls /config/hw/system/cpu'	'cpu'		\
1716			prtconf				'cpu-unit'	\
1717
1718			while	:
1719			do	case $# in
1720				0)	break ;;
1721				esac
1722				i=`$1 2>/dev/null | $TR ' 	' '
1723
1724' | grep -c "^$2"`
1725				case $i in
1726				[123456789]*)
1727					cpu=$i
1728					break
1729					;;
1730				esac
1731				shift;shift
1732			done
1733			;;
1734		esac
1735		case $cpu in
1736		0|1)	# special match
1737			set						\
1738									\
1739			hinv						\
1740			'/^[0123456789][0123456789]* .* Processors*$/'		\
1741			'/[ 	].*//'					\
1742									\
1743			/usr/bin/hostinfo				\
1744			'/^[0123456789][0123456789]* .* physically available\.*$/'	\
1745			'/[ 	].*//'					\
1746
1747			while	:
1748			do	case $# in
1749				0)	break ;;
1750				esac
1751				i=`$1 2>/dev/null | $SED -e "${2}!d" -e "s${3}"`
1752				case $i in
1753				[123456789]*)
1754					cpu=$i
1755					break
1756					;;
1757				esac
1758				shift;shift;shift
1759			done
1760			;;
1761		esac
1762		case $cpu in
1763		0|1)	cpu=`(
1764			cd ${TMPDIR:-/tmp}
1765			tmp=hi$$
1766			trap 'rm -f $tmp.*' 0 1 2
1767			cat > $tmp.c <<!
1768#include <stdio.h>
1769#include <pthread.h>
1770int main()
1771{
1772	printf("%d\n", pthread_num_processors_np());
1773	return 0;
1774}
1775!
1776			for o in -lpthread ''
1777			do	if	$CC $o -O -o $tmp.exe $tmp.c $o >/dev/null 2>&1 ||
1778					gcc $o -O -o $tmp.exe $tmp.c $o >/dev/null 2>&1
1779				then	./$tmp.exe
1780					break
1781				fi
1782			done
1783			)`
1784			case $cpu in
1785			[0123456789]*)	;;
1786			*)	cpu=1 ;;
1787			esac
1788			;;
1789		esac
1790		_hostinfo_="$_hostinfo_ $cpu"
1791		;;
1792	name)	_name_=`hostname || uname -n || cat /etc/whoami || echo local`
1793		_hostinfo_="$_hostinfo_ $_name_"
1794		;;
1795	rating)	for rating in `grep -i ^bogomips /proc/cpuinfo 2>/dev/null | $SED -e 's,.*:[ 	]*,,' -e 's,\(...*\)\..*,\1,' -e 's,\(\..\).*,\1,'`
1796		do	case $rating in
1797			[0123456789]*)	break ;;
1798			esac
1799		done
1800		case $rating in
1801		[0123456789]*)	;;
1802		*)	cd ${TMPDIR:-/tmp}
1803			tmp=hi$$
1804			trap 'rm -f $tmp.*' 0 1 2
1805			cat > $tmp.c <<!
1806#include <stdio.h>
1807#include <sys/types.h>
1808#if TD || TZ
1809#include <sys/time.h>
1810#else
1811extern time_t	time();
1812#endif
1813int main()
1814{
1815	register unsigned long	i;
1816	register unsigned long	j;
1817	register unsigned long	k;
1818	unsigned long		l;
1819	unsigned long		m;
1820	unsigned long		t;
1821	int			x;
1822#if TD || TZ
1823	struct timeval		b;
1824	struct timeval		e;
1825#if TZ
1826	struct timezone		z;
1827#endif
1828#endif
1829	l = 500;
1830	m = 890;
1831	x = 0;
1832	for (;;)
1833	{
1834#if TD || TZ
1835#if TZ
1836		gettimeofday(&b, &z);
1837#else
1838		gettimeofday(&b);
1839#endif
1840#else
1841		t = (unsigned long)time((time_t*)0);
1842#endif
1843		k = 0;
1844		for (i = 0; i < l; i++)
1845			for (j = 0; j < 50000; j++)
1846				k += j;
1847#if TD || TZ
1848#if TZ
1849		gettimeofday(&e, &z);
1850#else
1851		gettimeofday(&e);
1852#endif
1853		t = (e.tv_sec - b.tv_sec) * 1000 + (e.tv_usec - b.tv_usec) / 1000;
1854		if (!x++ && t < 1000)
1855		{
1856			t = 10000 / t;
1857			l = (l * t) / 10;
1858			continue;
1859		}
1860#else
1861		t = ((unsigned long)time((time_t*)0) - t) * 1000;
1862		if (!x++ && t < 20000)
1863		{
1864			t = 200000l / t;
1865			l = (l * t) / 10;
1866			continue;
1867		}
1868#endif
1869#if PR
1870		printf("[ k=%lu l=%lu m=%lu t=%lu ] ", k, l, m, t);
1871#endif
1872		if (t == 0)
1873			t = 1;
1874		break;
1875	}
1876	printf("%lu\n", ((l * m) / 10) / t);
1877	return k == 0;
1878}
1879!
1880			rating=
1881			for o in -DTZ -DTD ''
1882			do	if	$CC $o -O -o $tmp.exe $tmp.c >/dev/null 2>&1 ||
1883					gcc $o -O -o $tmp.exe $tmp.c >/dev/null 2>&1
1884				then	rating=`./$tmp.exe`
1885					break
1886				fi
1887			done
1888			case $rating in
1889			[0123456789]*)	;;
1890			*)	rating=1 ;;
1891			esac
1892			;;
1893		esac
1894		_hostinfo_="$_hostinfo_ $rating"
1895		;;
1896	type|canon)
1897		case $CROSS:$canon in
1898		0:)	case $cc in
1899			cc)	case $KEEP_HOSTTYPE:$HOSTTYPE in
1900				0:?*)	if	test -d ${PACKAGEROOT:-.}/arch/$HOSTTYPE
1901					then	KEEP_HOSTTYPE=1
1902					fi
1903					;;
1904				esac
1905				;;
1906			esac
1907			case $KEEP_HOSTTYPE in
1908			1)	_hostinfo_="$_hostinfo_ $HOSTTYPE"
1909				continue
1910				;;
1911			esac
1912			;;
1913		esac
1914		case $cc in
1915		/*)	a=`$cc -dumpmachine $CCFLAGS 2>/dev/null`
1916			case $a in
1917			'')	case $CCFLAGS in
1918				?*)	a=`$cc -dumpmachine 2>/dev/null` ;;
1919				esac
1920				;;
1921			esac
1922			case $a in
1923			''|*' '*|*/*:*)
1924				;;
1925			*.*-*)	_hostinfo_="$_hostinfo_ $a"
1926				continue
1927				;;
1928			*-*-*)	case $canon in
1929				'')	canon=$a ;;
1930				esac
1931				;;
1932			*)	_hostinfo_="$_hostinfo_ $a"
1933				continue
1934				;;
1935			esac
1936			;;
1937		esac
1938		IFS=:
1939		set /$IFS$PATH
1940		IFS=$ifs
1941		shift
1942		f=../lib/hostinfo/typemap
1943		for i
1944		do	case $i in
1945			"")	i=. ;;
1946			esac
1947			case $canon in
1948			'')	case $cc in
1949				/*|cc)	;;
1950				*)	if	executable $i/$cc
1951					then	a=`$i/$cc -dumpmachine $CCFLAGS 2>/dev/null`
1952						case $a in
1953						'')	case $CCFLAGS in
1954							?*)	a=`$cc -dumpmachine 2>/dev/null` ;;
1955							esac
1956							;;
1957						esac
1958						case $a in
1959						''|*' '*|*/*:*)
1960							;;
1961						*-*)	canon=$a
1962							;;
1963						*)	_hostinfo_="$_hostinfo_ $a"
1964							continue 2
1965							;;
1966						esac
1967					fi
1968					;;
1969				esac
1970				;;
1971			esac
1972			if	test -f "$i/$f"
1973			then	map="`grep -v '^#' $i/$f` $map"
1974			fi
1975		done
1976
1977		# inconsistent -dumpmachine filtered here
1978
1979		case -${canon}- in
1980		--|*-powerpc-*)
1981			h=`hostname || uname -n || cat /etc/whoami`
1982			case $h in
1983			'')	h=local ;;
1984			esac
1985			a=`arch || uname -m || att uname -m || uname -s || att uname -s`
1986			case $a in
1987			*[\ \	]*)	a=`echo $a | $SED "s/[ 	]/-/g"` ;;
1988			esac
1989			case $a in
1990			'')	a=unknown ;;
1991			esac
1992			m=`mach || machine || uname -p || att uname -p`
1993			case $m in
1994			*[\ \	]*)	m=`echo $m | $SED "s/[ 	]/-/g"` ;;
1995			esac
1996			case $m in
1997			'')	m=unknown ;;
1998			esac
1999			x=`uname -a || att uname -a`
2000			case $x in
2001			'')	x="unknown $host unknown unknown unknown unknown unknown" ;;
2002			esac
2003			set "" $h $a $m $x
2004			expected=$1 host=$2 arch=$3 mach=$4 os=$5 sys=$6 rel=$7 ver=$8
2005			;;
2006		*)	case $canon in
2007			*-*)	IFS=-
2008				set "" $canon
2009				shift
2010				IFS=$ifs
2011				case $# in
2012				2)	host= mach= arch=$1 os=$2 sys= rel= ;;
2013				*)	host= mach=$2 arch=$1 os=$3 sys= rel= ;;
2014				esac
2015				case $os in
2016				[abcdefghijklmnopqrstuvwxyz]*[0123456789])
2017					eval `echo $os | $SED -e 's/^\([^0123456789.]*\)\.*\(.*\)/os=\1 rel=\2/'`
2018					;;
2019				esac
2020				;;
2021			*)	arch=$canon mach= os= sys= rel=
2022				;;
2023			esac
2024			;;
2025		esac
2026		type=unknown
2027		case $host in
2028		*.*)	host=`echo $host | $SED -e 's/\..*//'` ;;
2029		esac
2030		case $mach in
2031		unknown)
2032			mach=
2033			;;
2034		[Rr][0123][0123456789][0123456789][0123456789])
2035			mach=mips1
2036			;;
2037		[Rr][4][0123456789][0123456789][0123456789])
2038			mach=mips2
2039			;;
2040		[Rr][56789][0123456789][0123456789][0123456789]|[Rr][123456789][0123456789][0123456789][0123456789][0123456789])
2041			mach=mips4
2042			;;
2043		pc)	arch=i386
2044			mach=
2045			;;
2046		[Pp][Oo][Ww][Ee][Rr][Pp][Cc])
2047			arch=ppc
2048			mach=
2049			;;
2050		*)	case $arch in
2051			34[0123456789][0123456789])
2052				os=ncr
2053				arch=i386
2054				;;
2055			esac
2056			;;
2057		esac
2058		case $canon in
2059		'')	set						\
2060									\
2061			/NextDeveloper		-d	next	-	\
2062			/config/hw/system/cpu	-d	tandem	mach	\
2063
2064			while	:
2065			do	case $# in
2066				0)	break ;;
2067				esac
2068				if	test $2 $1
2069				then	os=$3
2070					case $4 in
2071					arch)	mach=$arch ;;
2072					mach)	arch=$mach ;;
2073					esac
2074					break
2075				fi
2076				shift;shift;shift;shift
2077			done
2078			;;
2079		esac
2080		case $os in
2081		AIX*|aix*)
2082			type=ibm.risc
2083			;;
2084		HP-UX)	case $arch in
2085			9000/[78]*)
2086				type=hp.pa
2087				;;
2088			*/*)	type=hp.`echo $arch | $SED 's,/,_,g'`
2089				;;
2090			*)	type=hp.$arch
2091				;;
2092			esac
2093			;;
2094		[Ii][Rr][Ii][Xx]*)
2095			set xx `hinv | $SED -e '/^CPU:/!d' -e 's/CPU:[ 	]*\([^ 	]*\)[ 	]*\([^ 	]*\).*/\1 \2/' -e q | $TR ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
2096			shift
2097			type=$1
2098			n=
2099			case $2 in
2100			r[0123][0123456789][0123456789][0123456789])
2101				n=1
2102				;;
2103			r[4][0123][0123456789][0123456789])
2104				n=2
2105				;;
2106			r[4][456789][0123456789][0123456789]|r[5][0123456789][0123456789][0123456789])
2107				n=3
2108				;;
2109			r[6789][0123456789][0123456789][0123456789]|r[123456789][0123456789][0123456789][0123456789][0123456789])
2110				n=4
2111				;;
2112			esac
2113			case $rel in
2114			[01234].*|5.[012]|5.[012].*)
2115				case $n in
2116				1)	;;
2117				*)	n=2 ;;
2118				esac
2119				;;
2120			5.*)	case $n in
2121				2)	n=3 ;;
2122				esac
2123				;;
2124			esac
2125			if	executable $cc
2126			then	a=$cc
2127			else	IFS=:
2128				set /$IFS$PATH
2129				IFS=$ifs
2130				shift
2131				for i
2132				do	a=$i/$cc
2133					if	executable $a
2134					then	break
2135					fi
2136				done
2137			fi
2138			split='
2139'
2140			a=`strings $a < /dev/null | $SED -e 's/[^abcdefghijklmnopqrstuvwxyz0123456789]/ /g' -e 's/[ 	][ 	]*/\'"$split"'/g' | $SED -e "/^${type}[0123456789]$/!d" -e "s/^${type}//" -e q`
2141			case $a in
2142			[0123456789])	n=$a ;;
2143			esac
2144			case $n in
2145			4)	a=`$cc -${type}3 2>&1`
2146				case $a in
2147				*unknown*|*install*|*conflict*)
2148					;;
2149				*)	n=3
2150					;;
2151				esac
2152				;;
2153			esac
2154			a=`$cc -show F0oB@r.c 2>&1`
2155			case $n:$a in
2156			[!2]:*mips2*)	n=2 ;;
2157			[!23]:*mips3*)	n=3 ;;
2158			[!234]:*mips4*)	n=4 ;;
2159			esac
2160			case $n:$a in
2161			[!2]:*[Oo]32*)	abi=-o32 ;;
2162			[!3]:*[Nn]32*)	abi=-n32 ;;
2163			esac
2164			mach=${type}$n
2165			type=sgi.$mach
2166			;;
2167		OSx*|SMP*|pyramid)
2168			type=pyr
2169			;;
2170		OS/390)	type=mvs.390
2171			;;
2172		[Ss][Cc][Oo]*)
2173			type=sco
2174			;;
2175		[Ss]ol*)
2176			v=`echo $rel | $SED -e 's/^[25]\.//' -e 's/\.[^.]*$//'`
2177			case $v in
2178			[6789]|[1-9][0-9])
2179				;;
2180			*)	v=
2181				;;
2182			esac
2183			case $arch in
2184			'')	case $mach in
2185				'')	arch=sun4 ;;
2186				*)	arch=$mach ;;
2187				esac
2188				;;
2189			esac
2190			case $arch in
2191			sparc)	arch=sun4 ;;
2192			esac
2193			type=sol$v.$arch
2194			;;
2195		[Ss]un*)type=`echo $arch | $SED -e 's/\(sun.\).*/\1/'`
2196			case $type in
2197			sparc)	type=sun4 ;;
2198			esac
2199			case $rel in
2200			[01234]*)
2201				;;
2202			'')	case $os in
2203				*[Oo][Ss])
2204					;;
2205				*)	type=sol.$type
2206					;;
2207				esac
2208				;;
2209			*)	case $type in
2210				'')	case $mach in
2211					sparc*)	type=sun4 ;;
2212					*)	type=$mach ;;
2213					esac
2214					;;
2215				esac
2216				v=`echo $rel | $SED -e 's/^[25]\.//' -e 's/\.[^.]*$//'`
2217				case $v in
2218				[6789]|[1-9][0-9])
2219					;;
2220				*)	v=
2221					;;
2222				esac
2223				type=sol$v.$type
2224				;;
2225			esac
2226			case $type in
2227			sun*|*.*)
2228				;;
2229			*)	type=sun.$type
2230				;;
2231			esac
2232			;;
2233		[Uu][Nn][Ii][Xx]_[Ss][Vv])
2234			type=unixware
2235			;;
2236		UTS*|uts*)
2237			if	test -x /bin/u370 -o -x /bin/u390
2238			then	type=uts.390
2239			else	case $arch in
2240				'')	arch=$mach ;;
2241				esac
2242				type=uts.$arch
2243			fi
2244			;;
2245		$host)	type=$arch
2246			case $type in
2247			*.*|*[0123456789]*86|*68*)
2248				;;
2249			*)	case $mach in
2250				*[0123456789]*86|*68*|mips)
2251					type=$type.$mach
2252					;;
2253				esac
2254				;;
2255			esac
2256			;;
2257		unknown)
2258			case $arch in
2259			?*)	case $arch in
2260				sun*)	mach= ;;
2261				esac
2262				type=$arch
2263				case $mach in
2264				?*)	type=$type.$mach ;;
2265				esac
2266				;;
2267			esac
2268			;;
2269		*)	case $ver in
2270			FTX*|ftx*)
2271				case $mach in
2272				*[0123456789][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]*)
2273					mach=`echo $mach | $SED -e 's/[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]*$//'`
2274					;;
2275				esac
2276				type=stratus.$mach
2277				;;
2278			*)	case $arch in
2279				[Oo][Ss][-/.]2)
2280					type=os2
2281					arch=$rel
2282					;;
2283				*)	type=`echo $os | $SED -e 's/[0123456789].*//' -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789.].*//'`
2284					;;
2285				esac
2286				case $type in
2287				[Cc][Yy][Gg][Ww][Ii][Nn]_*)
2288					type=cygwin
2289					;;
2290				[Uu][Ww][Ii][Nn]*|[Ww]indows_[0123456789][0123456789]|[Ww]indows_[Nn][Tt])
2291					type=win32
2292					arch=`echo $arch | $SED -e 's/_[^_]*$//'`
2293					;;
2294				esac
2295				case $arch in
2296				'')	case $mach in
2297					?*)	type=$type.$mach ;;
2298					esac
2299					;;
2300				*)	type=$type.$arch ;;
2301				esac
2302				;;
2303			esac
2304		esac
2305		case $type in
2306		[0123456789]*)
2307			case $mach in
2308			?*)	type=$mach ;;
2309			esac
2310			case $type in
2311			*/MC)	type=ncr.$type ;;
2312			esac
2313			;;
2314		*.*)	;;
2315		*[0123456789]*86|*68*)
2316			case $rel in
2317			[34].[0123456789]*)
2318				type=att.$type
2319				;;
2320			esac
2321			;;
2322		[abcdefghijklmnopqrstuvwxyz]*[0123456789])
2323			;;
2324		[abcdefghijklmnopqrstuvwxyz]*)	case $mach in
2325			$type)	case $ver in
2326				Fault*|fault*|FAULT*)
2327					type=ft.$type
2328					;;
2329				esac
2330				;;
2331			?*)	case $arch in
2332				'')	type=$type.$mach ;;
2333				*)	type=$type.$arch ;;
2334				esac
2335				;;
2336			esac
2337			;;
2338		esac
2339		case $type in
2340		*[-_]32|*[-_]64|*[-_]128)
2341			bits=`echo $type | $SED 's,.*[-_],,'`
2342			type=`echo $type | $SED 's,[-_][0-9]*$,,'`
2343			;;
2344		*)	bits=
2345			;;
2346		esac
2347		type=`echo $type | $SED -e 's%[-+/].*%%' | $TR ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
2348		case $type in
2349		*.*)	lhs=`echo $type | $SED -e 's/\..*//'`
2350			rhs=`echo $type | $SED -e 's/.*\.//'`
2351			case $rhs in
2352			[x0123456789]*86)	rhs=i$rhs ;;
2353			68*)			rhs=m$rhs ;;
2354			esac
2355			case $rhs in
2356			i[x23456789]86|i?[x23456789]86|*86pc)
2357						rhs=i386 ;;
2358			powerpc)		rhs=ppc ;;
2359			s[0123456789]*[0123456789]x)
2360						rhs=`echo $rhs | $SED -e 's/x$/-64/'` ;;
2361			esac
2362			case $rhs in
2363			arm[abcdefghijklmnopqrstuvwxyz_][0123456789]*)
2364						rhs=arm ;;
2365			hppa)			rhs=pa ;;
2366			esac
2367			case $lhs in
2368			?*coff|?*dwarf|?*elf)
2369				case $lhs in
2370				?*coff)	x=coff ;;
2371				?*dwarf)x=coff ;;
2372				?*elf)	x=elf ;;
2373				esac
2374				lhs=`echo ${lhs}XXX | $SED -e "s/${x}XXX//"`
2375				;;
2376			esac
2377			case $lhs in
2378			bsdi)			lhs=bsd ;;
2379			darwin)			case $rel in
2380						[01234567].*)	lhs=${lhs}7 ;;
2381						esac
2382						;;
2383			freebsd)		case $rel in
2384						[01234].*)	lhs=${lhs}4 ;;
2385						[123456789]*.*)	lhs=${lhs}`echo $rel | $SED -e 's/\..*//'` ;;
2386						esac
2387						;;
2388			hpux)			lhs=hp ;;
2389			mvs)			rhs=390 ;;
2390			esac
2391			case $lhs in
2392			'')			type=$rhs ;;
2393			$rhs)			type=$lhs ;;
2394			*)			type=$lhs.$rhs ;;
2395			esac
2396			;;
2397		esac
2398		case $type in
2399		sgi.mips*)
2400			case $mach in
2401			mips2)	type=sgi.$mach
2402				abi=-o32
2403				;;
2404			mips3)	type=sgi.$mach
2405				abi=-n32
2406				;;
2407			mips[456789])
2408				type=sgi.$mach
2409				case $abi in
2410				*-n32) ;;
2411				*) abi=-64 ;;
2412				esac
2413				;;
2414			*)	pwd=`pwd`
2415				cd ${TMPDIR:-/tmp}
2416				tmp=hi$$
2417				trap 'rm -f $tmp.*' 0 1 2
2418				cat > $tmp.a.c <<!
2419extern int b();
2420int main() { return b(); }
2421!
2422				cat > $tmp.b.c <<!
2423int b() { return 0; }
2424!
2425				abi=
2426				if	$cc -c $tmp.a.c
2427				then	for i in -n32 -o32 -64
2428					do	if	$cc $i -c $tmp.b.c &&
2429							$cc -o $tmp.exe $tmp.a.o $tmp.b.o
2430						then	abi=$i
2431							for i in 2 3 4 5 6 7 8 9
2432							do	case $i:$abi in
2433								2:-n32|2:-64|3:-64)
2434									continue
2435									;;
2436								esac
2437								if	$cc $abi -mips$i -c $tmp.b.c &&
2438									$cc -o $tmp.exe $tmp.a.o $tmp.b.o
2439								then	type=`echo $type | $SED -e 's/.$//'`$i
2440									break
2441								fi
2442							done
2443							break
2444						fi
2445					done
2446				fi </dev/null >/dev/null 2>&1
2447				rm -f $tmp.*
2448				trap - 0 1 2
2449				cd $pwd
2450				;;
2451			esac
2452			case $type$abi in
2453			sgi.mips2-o32)
2454				;;
2455			sgi.mips3)
2456				type=$type-o32
2457				;;
2458			sgi.mips3-n32)
2459				;;
2460			sgi.mips4)
2461				type=$type-o32
2462				;;
2463			sgi.mips[456789]-64)
2464				;;
2465			*)	type=$type$abi
2466				;;
2467			esac
2468			;;
2469		*)	case $bits in
2470			'')	case `file /bin/sh 2>/dev/null` in
2471				*universal*64*)
2472					pwd=`pwd`
2473					cd ${TMPDIR:-/tmp}
2474					tmp=hi$$
2475					trap 'rm -f $tmp.*' 0 1 2
2476					cat > $tmp.a.c <<!
2477int main() { return 0; }
2478!
2479					if	$cc -o $tmp.a.exe $tmp.a.c
2480					then	case `file $tmp.a.exe` in
2481						*64*)	bits=64 ;;
2482						esac
2483					fi </dev/null >/dev/null 2>&1
2484					rm -f $tmp.*
2485					trap - 0 1 2
2486					cd $pwd
2487					;;
2488				esac
2489				;;
2490			esac
2491			;;
2492		esac
2493		case $bits in
2494		32)	case $type in
2495			*.i386)	bits= ;;
2496			esac
2497			;;
2498		esac
2499		case $bits in
2500		?*)	type=$type-$bits ;;
2501		esac
2502
2503		# last chance mapping
2504
2505		set "" "" $map
2506		while	:
2507		do	case $# in
2508			[012])	break ;;
2509			esac
2510			shift;shift
2511			eval "	case \$type in
2512				$1)	type=\$2; break ;;
2513				esac"
2514		done
2515		_hostinfo_="$_hostinfo_ $type"
2516		;;
2517	esac
2518	done
2519	set '' $_hostinfo_
2520	shift
2521	_hostinfo_=$*
2522
2523	# restore the global state
2524
2525	PATH=$path
2526	case $DEBUG in
2527	'')	exec 2>&9
2528		exec 9>&-
2529		;;
2530	esac
2531}
2532
2533# info message
2534
2535note() # message ...
2536{
2537	echo $command: "$@" >&2
2538}
2539
2540# cc checks
2541#
2542#	CC: compiler base name name
2543#	cc: full path, empty if not found
2544
2545checkcc()
2546{
2547	cc=
2548	if	onpath $CC
2549	then	cc=$_onpath_
2550	else	case $CC in
2551		cc)	if	onpath gcc
2552			then	CC=gcc
2553				cc=$_onpath_
2554			fi
2555			;;
2556		esac
2557	fi
2558	case $cc in
2559	'')	case $action in
2560		make|test)	note "$CC: not found"; exit 1 ;;
2561		*)		note "warning: $CC: not found" ;;
2562		esac
2563		;;
2564	esac
2565}
2566
2567# some actions have their own PACKAGEROOT or kick out early
2568
2569case $action in
2570host)	eval u=$package_use
2571	case $u in
2572	$PACKAGE_USE)
2573		;;
2574	*)	if	onpath $0
2575		then	case $_onpath_ in
2576			*/arch/$HOSTTYPE/bin/package)
2577				KEEP_HOSTTYPE=1
2578				;;
2579			*)	KEEP_HOSTTYPE=0
2580				;;
2581			esac
2582		else	KEEP_HOSTTYPE=0
2583		fi
2584		;;
2585	esac
2586	hostinfo $args
2587	echo $_hostinfo_
2588	exit 0
2589	;;
2590export|setup|use)
2591	x=
2592	;;
2593*)	x=
2594	eval u=$package_use
2595	case $u in
2596	$PACKAGE_USE)
2597		case :$PATH: in
2598		*:$INSTALLROOT/bin:*)
2599			case $LIBPATH: in
2600			$INSTALLROOT/bin:$INSTALLROOT/lib:*)
2601				case $SHLIB_PATH: in
2602				$INSTALLROOT/lib:*)
2603					x=1
2604					;;
2605				esac
2606				;;
2607			esac
2608			;;
2609		esac
2610		;;
2611	esac
2612	;;
2613esac
2614run=-
2615case $x in
26161)	: accept the current package use environment
2617
2618	OK=ok
2619	KSH=$EXECROOT/bin/ksh
2620	MAKE=nmake
2621	NMAKE=$EXECROOT/bin/$MAKE
2622	SUM=$EXECROOT/bin/sum
2623	TEE=$EXECROOT/bin/tee
2624	INITROOT=$PACKAGEROOT/src/cmd/INIT
2625	checkcc
2626	;;
2627*)	hosttype=
2628	case $KEEP_PACKAGEROOT in
2629	0)	case $action in
2630		use)	PACKAGEROOT=
2631			case $show in
2632			echo)	exec=echo make=echo show=echo ;;
2633			esac
2634			set '' $args
2635			shift
2636			case $# in
2637			0)	;;
2638			*)	case $1 in
2639				-|.)	;;
2640				/*)	PACKAGEROOT=$1
2641					;;
2642				*)	i=`echo ~$1`
2643					if	packageroot $i
2644					then	PACKAGEROOT=$i
2645					else	for i in `echo $HOME | sed -e 's,/[^/]*$,,'` $usr $use
2646						do	if	packageroot $i/$1
2647							then	PACKAGEROOT=$i/$1
2648								break
2649							fi
2650						done
2651						case $PACKAGEROOT in
2652						'')	hosttype=$1 ;;
2653						esac
2654					fi
2655					;;
2656				esac
2657				shift
2658				;;
2659			esac
2660			run="$@"
2661			;;
2662		esac
2663		case $PACKAGEROOT in
2664		'')	PACKAGEROOT=${PWD:-`pwd`} ;;
2665		esac
2666
2667		# . must be within the PACKAGEROOT tree
2668
2669		i=X$PACKAGEROOT
2670		IFS=/
2671		set $i
2672		IFS=$ifs
2673		while	:
2674		do	i=$1
2675			shift
2676			case $i in
2677			X)	break ;;
2678			esac
2679		done
2680		case $PACKAGEROOT in
2681		//*)	d=/ ;;
2682		*)	d= ;;
2683		esac
2684		case $1 in
2685		home)	k=1 ;;
2686		*)	k=0 ;;
2687		esac
2688		for i
2689		do	case $i in
2690			'')	continue ;;
2691			esac
2692			d=$d/$i
2693			case $k in
2694			2)	k=1
2695				;;
2696			1)	k=0
2697				;;
2698			0)	case $i in
2699				arch)	k=2
2700					;;
2701				*)	if	packageroot $d
2702					then	PACKAGEROOT=$d
2703					fi
2704					;;
2705				esac
2706				;;
2707			esac
2708		done
2709		;;
2710	esac
2711	INITROOT=$PACKAGEROOT/src/cmd/INIT
2712	$show PACKAGEROOT=$PACKAGEROOT
2713	$show export PACKAGEROOT
2714	export PACKAGEROOT
2715
2716	# initialize the architecture environment
2717
2718	case $KEEP_HOSTTYPE in
2719	0)	hostinfo type
2720		HOSTTYPE=$_hostinfo_
2721		;;
2722	1)	_PACKAGE_HOSTTYPE_=$HOSTTYPE
2723		export _PACKAGE_HOSTTYPE_
2724		;;
2725	esac
2726	$show HOSTTYPE=$HOSTTYPE
2727	$show export HOSTTYPE
2728	export HOSTTYPE
2729	INSTALLROOT=$PACKAGEROOT/arch/$HOSTTYPE
2730	case $action in
2731	admin|install|make|read|remove|test|verify|view|write)
2732		;;
2733	*)	if	test ! -d $INSTALLROOT
2734		then	INSTALLROOT=$PACKAGEROOT
2735		fi
2736		;;
2737	esac
2738	$show INSTALLROOT=$INSTALLROOT
2739	$show export INSTALLROOT
2740	export INSTALLROOT
2741
2742	# check the basic package hierarchy
2743
2744	case $action in
2745	export|use)
2746		packageroot $PACKAGEROOT || {
2747			echo "$command: $PACKAGEROOT: invalid package root directory" >&2
2748			exit 1
2749		}
2750		case $KEEP_HOSTTYPE:$hosttype in
2751		0:?*)	if	test -d ${PACKAGEROOT:-.}/arch/$hosttype
2752			then	KEEP_HOSTTYPE=1
2753				HOSTTYPE=$hosttype
2754			else	echo "$command: $hosttype: package root not found" >&2
2755				exit 1
2756			fi
2757			;;
2758		esac
2759		;;
2760	*)	packageroot $PACKAGEROOT || {
2761			case $KEEP_PACKAGEROOT in
2762			1)	;;
2763			*)	echo "$command: $PACKAGEROOT: must be in the package root directory tree" >&2
2764				exit 1
2765				;;
2766			esac
2767		}
2768
2769		case $action in
2770		admin)	;;
2771		*)	for i in arch arch/$HOSTTYPE
2772			do	test -d $PACKAGEROOT/$i || $exec mkdir $PACKAGEROOT/$i || exit
2773			done
2774			for i in lib
2775			do	test -d $INSTALLROOT/$i || $exec mkdir $INSTALLROOT/$i || exit
2776			done
2777			;;
2778		esac
2779
2780		# no $INITROOT means INIT already installed elsewhere
2781
2782		if	test -d $INITROOT
2783		then
2784			# update the basic package commands
2785
2786			for i in execrate ignore mamprobe silent
2787			do	test -h $PACKAGEROOT/bin/$i 2>/dev/null ||
2788				case `ls -t $INITROOT/$i.sh $PACKAGEROOT/bin/$i 2>/dev/null` in
2789				"$INITROOT/$i.sh"*)
2790					note update $PACKAGEROOT/bin/$i
2791					shellmagic
2792					case $SHELLMAGIC in
2793					'')	$exec cp $INITROOT/$i.sh $PACKAGEROOT/bin/$i || exit
2794						;;
2795					*)	case $exec in
2796						'')	{
2797							echo "$SHELLMAGIC"
2798							cat $INITROOT/$i.sh
2799							} > $PACKAGEROOT/bin/$i || exit
2800							;;
2801						*)	echo "{
2802echo \"$SHELLMAGIC\"
2803cat $INITROOT/$i.sh
2804} > $PACKAGEROOT/bin/$i"
2805							;;
2806						esac
2807						;;
2808					esac
2809					$exec chmod +x $PACKAGEROOT/bin/$i || exit
2810					;;
2811				esac
2812			done
2813		fi
2814		;;
2815	esac
2816	path=$PATH
2817	PATH=$INSTALLROOT/bin:$PACKAGEROOT/bin:$PATH
2818	checkcc
2819	PATH=$path
2820	case $cc in
2821	?*)	if	test -f $INITROOT/hello.c
2822		then
2823			# check if $CC (full path $cc) is a cross compiler
2824
2825			(
2826				cd /tmp || exit 3
2827				cp $INITROOT/hello.c pkg$$.c || exit 3
2828				$cc -o pkg$$.exe pkg$$.c > pkg$$.e 2>&1 || {
2829					if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1
2830					then	echo "$command: ${warn}$CC: must be a C compiler (not C++)" >&2
2831					else	cat pkg$$.e
2832						echo "$command: ${warn}$CC: failed to compile and link $INITROOT/hello.c -- is it a C compiler?" >&2
2833					fi
2834					exit 2
2835				}
2836				if ./pkg$$.exe >/dev/null 2>&1
2837				then	code=0
2838				else	code=1
2839				fi
2840				rm -f pkg$$.*
2841				exit $code
2842			)
2843			code=$?
2844			case $code in
2845			1)	CROSS=1 ;;
2846			esac
2847		fi
2848		;;
2849	esac
2850	EXECTYPE=$HOSTTYPE
2851	EXECROOT=$INSTALLROOT
2852	case $CROSS in
2853	0) 	# dll hackery -- why is this so complicated?
2854
2855		abi=
2856		case $HOSTTYPE in
2857		sgi.mips[0123456789]*)
2858			x=rld
2859			if	executable /lib32/$x || executable /lib64/$x
2860			then	case $INSTALLROOT in
2861				*/sgi.mips[0123456789]*)
2862					u=`echo $INSTALLROOT | sed -e 's,-[^-/]*$,,' -e 's,.$,,'`
2863					;;
2864				*)	u=
2865					;;
2866				esac
2867				for a in "n=2 v= l=" "n=3 v=N32 l=lib32" "n=4-n32 v=N32 l=lib32" "n=4 v=64 l=lib64"
2868				do	eval $a
2869					case $v in
2870					N32)	case $n:$HOSTTYPE in
2871						*-n32:*-n32)	;;
2872						*-n32:*)	continue ;;
2873						*:*-n32)	continue ;;
2874						esac
2875						;;
2876					esac
2877					case $l in
2878					?*)	if	executable ! /$l/$x
2879						then	continue
2880						fi
2881						;;
2882					esac
2883					case $u in
2884					'')	case $HOSTTYPE in
2885						sgi.mips$n|sgi.mips$n-*)
2886							abi="$abi 'd=$INSTALLROOT v=$v'"
2887							;;
2888						*)	continue
2889							;;
2890						esac
2891						;;
2892					*)	if	test -d $u$n
2893						then	abi="$abi 'd=$u$n v=$v'"
2894						fi
2895						;;
2896					esac
2897				done
2898			fi
2899			;;
2900		esac
2901		case $abi in
2902		'')	abi="'d=$INSTALLROOT v='" ;;
2903		esac
2904		p=0
2905		eval "
2906			for a in $abi
2907			do	eval \$a
2908				eval \"
2909					case \\\$LD_LIBRARY\${v}_PATH: in
2910					\\\$d/lib:*)
2911						;;
2912					*)	x=\\\$LD_LIBRARY\${v}_PATH
2913						case \\\$x in
2914						''|:*)	;;
2915						*)	x=:\\\$x ;;
2916						esac
2917						LD_LIBRARY\${v}_PATH=\$d/lib\\\$x
2918						export LD_LIBRARY\${v}_PATH
2919						p=1
2920						;;
2921					esac
2922				\"
2923			done
2924		"
2925		case $LD_LIBRARY_PATH in
2926		'')	;;
2927		*)	for d in $lib
2928			do	case $HOSTTYPE in
2929				*64)	if	test -d ${d}64
2930					then	d=${d}64
2931					fi
2932					;;
2933				esac
2934				case :$LD_LIBRARY_PATH: in
2935				*:$d:*)	;;
2936				*)	if	test -d $d
2937					then	LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$d
2938						p=1
2939					fi
2940					;;
2941				esac
2942			done
2943			;;
2944		esac
2945		case $p in
2946		1)	$show LD_LIBRARY_PATH=$LD_LIBRARY_PATH
2947			$show export LD_LIBRARY_PATH
2948			export LD_LIBRARY_PATH
2949			;;
2950		esac
2951		case $LIBPATH: in
2952		$INSTALLROOT/bin:$INSTALLROOT/lib:*)
2953			;;
2954		*)	case $LIBPATH in
2955			'')	LIBPATH=/usr/lib:/lib ;;
2956			esac
2957			LIBPATH=$INSTALLROOT/bin:$INSTALLROOT/lib:$LIBPATH
2958			$show LIBPATH=$LIBPATH
2959			$show export LIBPATH
2960			export LIBPATH
2961			;;
2962		esac
2963		case $SHLIB_PATH: in
2964		$INSTALLROOT/lib:*)
2965			;;
2966		*)	SHLIB_PATH=$INSTALLROOT/lib${SHLIB_PATH:+:$SHLIB_PATH}
2967			$show SHLIB_PATH=$SHLIB_PATH
2968			$show export SHLIB_PATH
2969			export SHLIB_PATH
2970			;;
2971		esac
2972		case $DYLD_LIBRARY_PATH: in
2973		$INSTALLROOT/lib:*)
2974			;;
2975		*)	DYLD_LIBRARY_PATH=$INSTALLROOT/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
2976			$show DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
2977			$show export DYLD_LIBRARY_PATH
2978			export DYLD_LIBRARY_PATH
2979			;;
2980		esac
2981		case $_RLD_ROOT in
2982		$INSTALLROOT/arch*)	;;
2983		':')	_RLD_ROOT=$INSTALLROOT/arch:/ ;;
2984		/|*:/)	_RLD_ROOT=$INSTALLROOT/arch:$_RLD_ROOT ;;
2985		*)	_RLD_ROOT=$INSTALLROOT/arch:$_RLD_ROOT:/ ;;
2986		esac
2987		$show _RLD_ROOT=$_RLD_ROOT
2988		$show export _RLD_ROOT
2989		export _RLD_ROOT
2990
2991		# now set up PATH
2992		#
2993		# NOTE: PACKAGEROOT==INSTALLROOT is possible for binary installations
2994
2995		case $PATH: in
2996		$PACKAGEROOT/bin:*)
2997			;;
2998		*)	PATH=$PACKAGEROOT/bin:$PATH
2999			;;
3000		esac
3001		case $PATH: in
3002		$INSTALLROOT/bin:*)
3003			;;
3004		*)	PATH=$INSTALLROOT/bin:$PATH
3005			;;
3006		esac
3007		$show PATH=$PATH
3008		$show export PATH
3009		export PATH
3010		;;
3011	*)	for i in package proto nmake
3012		do	if	onpath $i
3013			then	EXECROOT=`echo $_onpath_ | sed -e 's,//*[^/]*//*[^/]*$,,'`
3014				EXECTYPE=`echo $EXECROOT | sed -e 's,.*/,,'`
3015				break
3016			fi
3017		done
3018		case $HOSTTYPE in
3019		$EXECTYPE)
3020			OCC=$CC
3021			CC=cc
3022			hostinfo type
3023			EXECTYPE=$_hostinfo_
3024			case $HOSTTYPE in
3025			$EXECTYPE)
3026				echo "$command: $CC: seems to be a cross-compiler" >&2
3027				echo "$command: set HOSTTYPE to something other than the native $EXECTYPE" >&2
3028				exit 1
3029				;;
3030			esac
3031			;;
3032		esac
3033		$show EXECTYPE=$EXECTYPE
3034		$show export EXECTYPE
3035		export EXECTYPE
3036		;;
3037	esac
3038	$show EXECROOT=$EXECROOT
3039	$show export EXECROOT
3040	export EXECROOT
3041
3042	# use these if possible
3043
3044	OK=ok
3045	KSH=$EXECROOT/bin/ksh
3046	MAKE=nmake
3047	NMAKE=$EXECROOT/bin/$MAKE
3048	SUM=$EXECROOT/bin/sum
3049	TEE=$EXECROOT/bin/tee
3050
3051	# grab a decent default shell
3052
3053	case $KEEP_SHELL in
3054	0)	executable "$SHELL" || SHELL=
3055		case $SHELL in
3056		?*)	checksh $SHELL || SHELL= ;;
3057		esac
3058		case $SHELL in
3059		''|/bin/*|/usr/bin/*)
3060			case $SHELL in
3061			'')	SHELL=/bin/sh ;;
3062			esac
3063			for i in ksh sh bash
3064			do	if	onpath $i && checksh $_onpath_
3065				then	SHELL=$_onpath_
3066					break
3067				fi
3068			done
3069			;;
3070		*/*ksh)	if	executable $KSH
3071			then	SHELL=$KSH
3072			fi
3073			;;
3074		esac
3075		;;
3076	esac
3077
3078	# $SHELL must be /bin/sh compatible
3079
3080	case $SHELL in
3081	/bin/sh);;
3082	'')	SHELL=/bin/sh
3083		;;
3084	*)	$SHELL -c 'trap "exit 0" 0; exit 1' 2>/dev/null
3085		case $? in
3086		1)	SHELL=/bin/sh
3087			;;
3088		*)	# catch (our own) pipe/socket configuration mismatches
3089			$SHELL -c "date | $SHELL -c 'read x'"
3090			case $? in
3091			0)	;;
3092			*)	SHELL=/bin/sh ;;
3093			esac
3094			;;
3095		esac
3096		;;
3097	esac
3098	export SHELL
3099	$show SHELL=$SHELL
3100	$show export SHELL
3101	COSHELL=$SHELL
3102	export COSHELL
3103	$show COSHELL=$COSHELL
3104	$show export COSHELL
3105
3106	# tame the environment
3107
3108	case $action in
3109	use)	;;
3110	*)	ENV=
3111		ERROR_OPTIONS=
3112		export ENV ERROR_OPTIONS
3113		;;
3114	esac
3115
3116	# finalize the views
3117
3118	case $USER_VPATH in
3119	'')	case $VPATH in
3120		?*)	IFS=':'
3121			set '' $VPATH
3122			shift
3123			IFS=$ifs
3124			USER_VPATH=
3125			for i
3126			do	case $i in
3127				*/arch/$HOSTTYPE)	;;
3128				*/arch/*/*)		;;
3129				*/arch/*)		continue ;;
3130				esac
3131				if	packageroot $i
3132				then	case $USER_VPATH in
3133					'')	USER_VPATH=$i ;;
3134					?*)	USER_VPATH=$USER_VPATH:$i ;;
3135					esac
3136				fi
3137			done
3138		esac
3139		;;
3140	esac
3141	case $USER_VPATH in
3142	?*)	IFS=':'
3143		set '' $USER_VPATH
3144		shift
3145		IFS=$ifs
3146		USER_VPATH=
3147		USER_VPATH_CHAIN=
3148		p=$PACKAGEROOT
3149		for i
3150		do	case $i in
3151			''|$PACKAGEROOT|$INSTALLROOT)
3152				;;
3153			?*)	USER_VPATH=$USER_VPATH:$i
3154				USER_VPATH_CHAIN="$USER_VPATH_CHAIN $p $i"
3155				p=$i
3156				case $PROTOROOT in
3157				-)	executable $i/bin/mamake && PROTOROOT= ;;
3158				esac
3159				;;
3160			esac
3161		done
3162		;;
3163	esac
3164	;;
3165esac
3166
3167PACKAGESRC=$PACKAGEROOT/lib/package
3168PACKAGEBIN=$INSTALLROOT/lib/package
3169case $action:$run in
3170use:-)	set '' $args
3171	shift
3172	case $# in
3173	0)	;;
3174	*)	shift ;;
3175	esac
3176	run="$@"
3177	;;
3178esac
3179
3180# HOSTTYPE specific package profile
3181
3182if	test -r $INSTALLROOT/lib/package/profile
3183then	. $INSTALLROOT/lib/package/profile
3184fi
3185
3186# more cygwin hassles
3187
3188case $HOSTTYPE in
3189cygwin.*)
3190	lose=
3191	case $CYGWIN in
3192	*nontsec*)
3193		lose=ntsec
3194		;;
3195	*ntsec*);;
3196	*)	exe=/tmp/pkg$$.exe
3197		rm -f $exe
3198		: > $exe
3199		if	test -x $exe
3200		then	lose=ntsec
3201		fi
3202		;;
3203	esac
3204	case $CYGWIN in
3205	*nobinmode*)
3206		case $lose in
3207		'')	lose=binmode ;;
3208		*)	lose="$lose binmode" ;;
3209		esac
3210		;;
3211	esac
3212	case $lose in
3213	?*)	echo "$command: $HOSTTYPE: export '$lose' in CYGWIN or languish in windows" >&2
3214		exit 1
3215		;;
3216	esac
3217	;;
3218esac
3219
3220# set up the view state
3221
3222VIEW_bin=$INSTALLROOT VIEW_src=$PACKAGEROOT VIEW_all="$INSTALLROOT $PACKAGEROOT"
3223if	(vpath $INSTALLROOT $PACKAGEROOT $USER_VPATH_CHAIN) >/dev/null 2>&1 &&
3224	 vpath $INSTALLROOT $PACKAGEROOT $USER_VPATH_CHAIN
3225then	$show vpath $INSTALLROOT $PACKAGEROOT $USER_VPATH_CHAIN
3226else	VPATH=$INSTALLROOT:$PACKAGEROOT$USER_VPATH
3227	$show VPATH=$VPATH
3228	$show export VPATH
3229	export VPATH
3230	IFS=':'
3231	set '' $VPATH
3232	shift
3233	IFS=$ifs
3234	for i
3235	do	case $i in
3236		*/arch/*/*)
3237			VIEW_src="$VIEW_src $i"
3238			;;
3239		*/arch/*)
3240			VIEW_bin="$VIEW_bin $i"
3241			;;
3242		*)
3243			VIEW_src="$VIEW_src $i"
3244			;;
3245		esac
3246		VIEW_all="$VIEW_all $i"
3247	done
3248fi
3249
3250# return 0 if arg in src|bin|all view
3251
3252view() # [test] [-|type] [src|bin|all] file
3253{
3254	case $1 in
3255	-[dfsx])_view_T_=$1; shift ;;
3256	*)	_view_T_=-f ;;
3257	esac
3258	case $1 in
3259	-)	_view_t_= ;;
3260	*)	_view_t_=$1 ;;
3261	esac
3262	shift
3263	case $1 in
3264	all)	shift; _view_v_=$VIEW_all ;;
3265	bin)	shift; _view_v_=$VIEW_bin ;;
3266	src)	shift; _view_v_=$VIEW_src ;;
3267	*)	_view_v_=$VIEW_all ;;
3268	esac
3269	case $1 in
3270	/*)	if	test $_view_T_ $1
3271		then	_view_=$1
3272			return 0
3273		fi
3274		;;
3275	*)	for _view_d_ in $_view_v_
3276		do	if	test $_view_T_ $_view_d_/$1
3277			then	_view_=$_view_d_/$1
3278				return 0
3279			fi
3280		done
3281		;;
3282	esac
3283	_view_=
3284	case $_view_t_ in
3285	?*)	echo $command: $1: $_view_t_ not found >&2 ;;
3286	esac
3287	return 1
3288}
3289
3290# determine the package and targets
3291
3292case $action in
3293admin)	case $admin_action in
3294	results)action=$admin_action
3295		set '' $admin_args
3296		shift;shift
3297		admin_args="admin $*"
3298		case $admin_on in
3299		'')	target=$admin_args ;;
3300		*)	target="on $admin_on $admin_args" ;;
3301		esac
3302		;;
3303	esac
3304	;;
3305release)set '' $args
3306	target=
3307	while	:
3308	do	shift
3309		case $1 in
3310		-|[0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]|[0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789])
3311			target="$target $1"
3312			;;
3313		*)	break
3314			;;
3315		esac
3316	done
3317	package=$*
3318	;;
3319setup)	# { update read } with optional (bin|fun|include|lib) symlinks
3320	# flat option sets up { bin fun include lib } symlinks from
3321	# $INSTALLROOT to $PACKAGEROOT
3322
3323	# . is the package root
3324
3325	set '' $args
3326	shift
3327	types=
3328	url=
3329	while	:
3330	do	case $# in
3331		0)	break ;;
3332		esac
3333		case $1 in
3334		--)	shift
3335			break
3336			;;
3337		flat)	flat=1 # backwards compatibility -- documentation dropped
3338			;;
3339		*://*|*.url)
3340			url=$1
3341			shift
3342			break
3343			;;
3344		*)	types="$types $1"
3345			;;
3346		esac
3347		shift
3348	done
3349	if	test ! -d $PACKAGEROOT/lib/package/tgz
3350	then	$exec mkdir -p $PACKAGEROOT/lib/package/tgz || exit
3351	fi
3352	case " $types " in
3353	*" source "*)
3354		case " $* " in
3355		'  ')	;;
3356		*" INIT "*)
3357			;;
3358		*)	view - all src/cmd/INIT ||
3359			set INIT "$@"
3360			;;
3361		esac
3362		;;
3363	esac
3364	packages=`$0 $global authorize "$authorize" password "$password" update setup $types $url "$@" PACKAGEROOT=$PACKAGEROOT`
3365	case $packages in
3366	?*)	$0 $global read $packages PACKAGEROOT=$PACKAGEROOT
3367	esac
3368	exit
3369	;;
3370*)	package=
3371	target=
3372	set '' $args
3373	while	:
3374	do	shift
3375		case $# in
3376		0)	break ;;
3377		esac
3378		case $1 in
3379		''|-)	target="$target $package"
3380			package=
3381			;;
3382		*)	if	view - src "lib/package/$1.pkg"
3383			then	package="$package $1"
3384			else	target="$target $package $1"
3385				package=
3386			fi
3387			;;
3388		esac
3389	done
3390	;;
3391esac
3392
3393# flatten -- assumes symlink support
3394
3395case $flat in
33961)	case $action in
3397	make|read|setup|update|use|view)
3398		if	test ! -d $INSTALLROOT
3399		then	$exec mkdir -p $INSTALLROOT || exit
3400		fi
3401		for i in bin include lib fun man share
3402		do	if	test ! -d $INSTALLROOT/../../$i
3403			then	$exec mkdir $INSTALLROOT/../../$i
3404			fi
3405			if	test ! -d $INSTALLROOT/$i
3406			then	if	test ! -h $INSTALLROOT/$i
3407				then	$exec ln -s ../../$i $INSTALLROOT/$i
3408				fi
3409			elif	test ! -h $INSTALLROOT/$i
3410			then	for x in $INSTALLROOT/$i/.[a-z]* $INSTALLROOT/$i/*
3411				do	if	test -f $x -o -d $x
3412					then	if	test ! -d $INSTALLROOT/$i/$x || test ! -d $INSTALLROOT/../../$i/$x
3413						then	$exec mv $x $INSTALLROOT/../../$i
3414						fi
3415					fi
3416				done
3417				$exec rm -rf $INSTALLROOT/$i
3418				$exec ln -s ../../$i $INSTALLROOT/$i
3419			fi
3420		done
3421		;;
3422	esac
3423	;;
3424esac
3425
3426# check that cmd args are up to date a.out's
3427
3428checkaout()	# cmd ...
3429{
3430	case $PROTOROOT in
3431	-)	PROTOROOT=
3432		case $* in
3433		ratz)	if	test -f $INITROOT/ratz.c -a -w $PACKAGEROOT
3434			then	test -f $INITROOT/hello.c || {
3435					cat > $INITROOT/hello.c <<'!'
3436#ifndef printf
3437#include <stdio.h>
3438#endif
3439int main() { int new = 0; printf("hello world\n"); return new;}
3440!
3441				}
3442				test -f $INITROOT/p.c || {
3443					cat > $INITROOT/p.c <<'!'
3444/*
3445 * small test for prototyping cc
3446 */
3447
3448int main(int argc, char** argv) { return argc || argv; }
3449!
3450				}
3451			fi
3452			;;
3453		esac
3454		test -f $INITROOT/hello.c -a -f $INITROOT/p.c -a -w $PACKAGEROOT || {
3455			for i
3456			do	onpath $i || {
3457					echo "$command: $i: command not found" >&2
3458					return 1
3459				}
3460			done
3461			return 0
3462		}
3463		case $cc in
3464		'')	_PACKAGE_cc=0
3465			;;
3466		*)	_PACKAGE_cc=1
3467			test -f $INITROOT/hello.c -a -f $INITROOT/p.c || {
3468				echo "$command: $INITROOT: INIT package source not found" >&2
3469				return 1
3470			}
3471			executable $INSTALLROOT/bin/nmake || {
3472				# check for prototyping cc
3473				# NOTE: proto.c must be K&R compatible
3474
3475				$CC -c $INITROOT/p.c >/dev/null 2>&1
3476				c=$?
3477				rm -f p.*
3478				test 0 != "$c" && {
3479					checkaout proto || return
3480					PROTOROOT=$PACKAGEROOT/proto
3481					$show PROTOROOT=$PACKAGEROOT/proto
3482					export PROTOROOT
3483					INITPROTO=$PROTOROOT/src/cmd/INIT
3484					note proto convert $PACKAGEROOT/src into $PROTOROOT/src
3485					if	test -d $PACKAGEROOT/src/cmd/nmake
3486					then	dirs="src/cmd/INIT src/lib/libast src/lib/libardir src/lib/libcoshell src/lib/libpp src/cmd/probe src/cmd/cpp src/cmd/nmake"
3487					else	dirs="src"
3488					fi
3489					(
3490						if	test -f $PROTOROOT/UPDATE
3491						then	newer="-newer $PROTOROOT/UPDATE"
3492						else	newer=""
3493						fi
3494						case $exec in
3495						'')	cd $PACKAGEROOT
3496							find $dirs -name '*.[CcHh]' $newer -print | proto -v -L - -C proto
3497							;;
3498						*)	$exec cd $PACKAGEROOT
3499							$exec "find $dirs -name '*.[CcHh]' $newer -print | proto -L - -C proto"
3500							;;
3501						esac
3502						$exec touch $PROTOROOT/UPDATE
3503					)
3504					if	(vpath $INSTALLROOT - $INSTALLROOT $PROTOROOT $PROTOROOT $PACKAGEROOT) >/dev/null 2>&1 &&
3505						 vpath $INSTALLROOT - $INSTALLROOT $PROTOROOT $PROTOROOT $PACKAGEROOT
3506					then	$show vpath $INSTALLROOT $PROTOROOT $PROTOROOT $PACKAGEROOT $USER_VPATH_CHAIN
3507					else	VPATH=$INSTALLROOT:$PROTOROOT:$PACKAGEROOT$USER_VPATH
3508						$show VPATH=$VPATH
3509						export VPATH
3510					fi
3511				}
3512			}
3513			for i in arch arch/$HOSTTYPE arch/$HOSTTYPE/bin
3514			do	test -d $PACKAGEROOT/$i || $exec mkdir $PACKAGEROOT/$i || return
3515			done
3516			;;
3517		esac
3518		;;
3519	esac
3520	case $_PACKAGE_cc in
3521	'')	case $cc in
3522		'')	_PACKAGE_cc=0 ;;
3523		*)	_PACKAGE_cc=1 ;;
3524		esac
3525		;;
3526	esac
3527	for i
3528	do	eval j=\$_PACKAGE_AOUT_$i
3529		case $j in
3530		'')	eval _PACKAGE_AOUT_$i=1 ;;
3531		*)	continue ;;
3532		esac
3533		k=$_PACKAGE_cc
3534		if	test -f $INITROOT/$i.c
3535		then	k=${k}1
3536		else	k=${k}0
3537		fi
3538		if	executable $EXECROOT/bin/$i
3539		then	k=${k}1
3540		else	k=${k}0
3541		fi
3542		: $k : compiler : source : binary :
3543		case $k in
3544		*00)	view - bin/$i && continue ;;
3545		esac
3546		case $k in
3547		000)	echo "$command: $i: not found: download the INIT package $HOSTTYPE binary to continue" >&2
3548			return 1
3549			;;
3550		010)	echo "$command: $i: not found: set CC=C-compiler or download the INIT package $HOSTTYPE binary to continue" >&2
3551			return 1
3552			;;
3553		100)	echo "$command: $i: not found: download the INIT package source or $HOSTTYPE binary to continue" >&2
3554			return 1
3555			;;
3556		110)	case $CROSS in
3557			1)	echo "$command: $i: not found: make the local $EXECTYPE binary package before $HOSTTYPE" >&2
3558				return 1
3559				;;
3560			esac
3561			;;
3562		?01)	: accept binary
3563			continue
3564			;;
3565		011)	: accept binary
3566			continue
3567			;;
3568		??1)	case $CROSS in
3569			1)	continue ;;
3570			esac
3571			;;
3572		esac
3573		case `ls -t $INITROOT/$i.c $INSTALLROOT/bin/$i 2>/dev/null` in
3574		"$INITROOT/$i.c"*)
3575			note update $INSTALLROOT/bin/$i
3576			if	test proto != "$i" && executable $INSTALLROOT/bin/proto
3577			then	case $exec in
3578				'')	$INSTALLROOT/bin/proto -p $INITROOT/$i.c > $i.c || return ;;
3579				*)	$exec "$INSTALLROOT/bin/proto -p $INITROOT/$i.c > $i.c" ;;
3580				esac
3581				$exec $CC $CCFLAGS -o $INSTALLROOT/bin/$i $i.c || return
3582				$exec rm -f $i.c
3583			else	if	test ! -d $INSTALLROOT/bin
3584				then	for j in arch arch/$HOSTTYPE arch/$HOSTTYPE/bin
3585					do	test -d $PACKAGEROOT/$j || $exec mkdir $PACKAGEROOT/$j || return
3586					done
3587				fi
3588				if	test '' != "$PROTOROOT" -a -f $INITPROTO/$i.c
3589				then	$exec $CC $CCFLAGS -o $INSTALLROOT/bin/$i $INITPROTO/$i.c || return
3590				else	$exec $CC $CCFLAGS -o $INSTALLROOT/bin/$i $INITROOT/$i.c || return
3591				fi
3592				case $i:$exec in
3593				proto:)	test -d $INSTALLROOT/include || mkdir $INSTALLROOT/include
3594					$INSTALLROOT/bin/proto -f /dev/null > $i.c
3595					cmp -s $i.c $INSTALLROOT/include/prototyped.h 2>/dev/null || cp $i.c $INSTALLROOT/include/prototyped.h
3596					rm $i.c
3597					;;
3598				esac
3599			fi
3600			test -f $i.o && $exec rm -f $i.o
3601			i=$PATH
3602			PATH=/bin
3603			PATH=$i
3604			;;
3605		esac
3606	done
3607	return 0
3608}
3609
3610# check package requirements against received packages
3611
3612requirements() # source|binary [ package ]
3613{
3614	case $1 in
3615	binary)	r=$VIEW_BIN ;;
3616	source)	r=$VIEW_SRC ;;
3617	*)	r=$VIEW_ALL ;;
3618	esac
3619	shift
3620	case $1 in
3621	'')	x= ;;
3622	*)	x=$* ;;
3623	esac
3624	set ''
3625	for d in $r
3626	do	set "$@" $d/gen/*.ver
3627		case $x in
3628		'')	set "$@" $d/gen/*.req
3629			;;
3630		*)	for p in $x
3631			do	set "$@" $d/gen/$p.req
3632			done
3633			;;
3634		esac
3635	done
3636	shift
3637	e=0
3638	x=$*
3639	y=
3640	n=
3641	set ''
3642	for i in $x
3643	do	p=`echo $i | sed -e 's,.*/,,' -e 's,\....$,,'`
3644		if	test -f $i
3645		then	set "$@" $i
3646			y="$y $p"
3647		else	case $p in
3648			'*')	;;
3649			*)	n="$n $p" ;;
3650			esac
3651		fi
3652	done
3653	for i in $n
3654	do	case " $y " in
3655		*" $i "*)
3656			;;
3657		*)	echo "$command: $i: must read or write package" >&2
3658			e=1
3659			;;
3660		esac
3661	done
3662	case $e in
3663	1)	exit 1 ;;
3664	esac
3665	shift
3666	test 0 != "$#" && release=`sort -r "$@" | {
3667		q=
3668		e=0
3669		o=
3670		while	read p v r s
3671		do	q="$q
3672$v $r"
3673			case $p in
3674			$o)	continue ;;
3675			esac
3676			case $s in
3677			0)	e=1
3678				case $r in
3679				base)	echo "$command: base package $p.$v or newer required" >&2 ;;
3680				*)	echo "$command: delta package $p.$v.$r or newer required" >&2 ;;
3681				esac
3682				;;
3683			esac
3684			o=$p
3685		done
3686		case $e in
3687		0)	echo "$q" | sort | { read v r; read v r; echo $v; } ;;
3688		1)	echo ERROR ;;
3689		esac
3690	}`
3691	case $release in
3692	ERROR)	case $force in
3693		0)	exit 1 ;;
3694		esac
3695		;;
3696	?*)	eval `echo $release | sed -e 's,\(.*\)-\(.*\)-\(.*\),yy=\1 mm=\2 dd=\3,'`
3697		# slide back 4 months
3698		case $mm in
3699		01)	mm=09 dd=1 ;;
3700		02)	mm=10 dd=1 ;;
3701		03)	mm=11 dd=1 ;;
3702		04)	mm=12 dd=1 ;;
3703		05)	mm=01 dd=0 ;;
3704		06)	mm=02 dd=0 ;;
3705		07)	mm=03 dd=0 ;;
3706		08)	mm=04 dd=0 ;;
3707		09)	mm=05 dd=0 ;;
3708		10)	mm=06 dd=0 ;;
3709		11)	mm=07 dd=0 ;;
3710		12)	mm=08 dd=0 ;;
3711		esac
3712		case $dd in
3713		1)	yy=`expr $yy - 1` ;;
3714		esac
3715		release=$yy-$mm-01
3716		count=1
3717		lo=$release
3718		release="-f $release -r $count"
3719		;;
3720	esac
3721}
3722
3723# write ordered package prerequisite list to the standard output
3724
3725order() # [ package ]
3726{
3727	_order_t_=lib/package/tgz
3728	case $action in
3729	binary)	_order_a_=.$HOSTTYPE ;;
3730	*)	_order_a_= ;;
3731	esac
3732	_order_n_=$#
3733	case $_order_n_ in
3734	0)	_order_p_=
3735		for _order_v_ in $VIEW_all
3736		do	for _order_f_ in $_order_v_/lib/package/*.pkg
3737			do	if	test -f $_order_f_
3738				then	_order_p_="$_order_p_ $_order_f_"
3739				fi
3740			done
3741		done
3742		set '' $_order_p_
3743		shift
3744	esac
3745	{
3746	if	test ratz != "$*"
3747	then	for _order_f_ in ratz INIT
3748		do	if	view -s - src $_order_t_/$_order_f_$_order_a_.tim
3749			then	echo $_order_f_ $_order_f_
3750			fi
3751		done
3752	fi
3753	for _order_f_
3754	do	while	:
3755		do	view - src $_order_f_ && break
3756			case $_order_f_ in
3757			*.pkg)	;;
3758			*)	_order_f_=$_order_f_.pkg; view - src $_order_f_ && break ;;
3759			esac
3760			case $_order_f_ in
3761			*/*)	;;
3762			*)	_order_f_=lib/package/$_order_f_; view - src $_order_f_ && break ;;
3763			esac
3764			echo "$command: $_order_f_: not a package" >&2
3765			continue 2
3766		done
3767		_order_f_=$_view_
3768		_order_p_=`echo $_order_f_ | sed -e 's,.*/,,' -e 's,\.pkg$,,'`
3769		case $_order_n_ in
3770		0)	view -s - src $_order_t_/$_order_p_$_order_a_.tim || continue ;;
3771		esac
3772		echo $_order_p_ $_order_p_
3773		case $_order_p_ in
3774		INIT|ratz)
3775			;;
3776		*)	echo INIT $_order_p_
3777			;;
3778		esac
3779		{
3780		req= req_sep=
3781		op=::
3782		while	read line
3783		do	IFS=' 	\\'
3784			set '' $line
3785			IFS=$ifs
3786			while	:
3787			do	shift
3788				case $# in
3789				0)	break ;;
3790				esac
3791				case $1 in
3792				:*:)	op=$1
3793					;;
3794				INIT|'$('*|*')')
3795					;;
3796				*)	case $op in
3797					:REQUIRES:)
3798						req="$req$req_sep$1"
3799						req_sep=" "
3800						;;
3801					esac
3802					;;
3803				esac
3804			done
3805		done
3806		for _order_i_ in $req
3807		do	if	view - src lib/package/$_order_i_.pkg
3808			then	case $_order_u_ in
3809				0)	view -s - src $_order_t_/$_order_i_$_order_a_.tim || continue ;;
3810				esac
3811				echo $_order_i_ $_order_i_; echo INIT $_order_i_; echo $_order_i_ $_order_p_
3812			fi
3813		done
3814		} < $_order_f_
3815	done
3816	} | tsort
3817}
3818
3819# generate the package component list in _components_
3820
3821components() # [ package ]
3822{
3823	_components_=
3824	for p
3825	do	case $p in
3826		'')	;;
3827		INIT)	case " $_components_ " in
3828			*" $p "*)	;;
3829			*)		_components_="$_components_ $p" ;;
3830			esac
3831			;;
3832		*)	if	view - src lib/package/$p.pkg
3833			then	p=$_view_
3834				op=::
3835				exec < $p
3836				while	read line
3837				do	IFS=' 	\\'
3838					set '' $line
3839					IFS=$ifs
3840					while	:
3841					do	shift
3842						case $# in
3843						0)	break ;;
3844						esac
3845						case $1 in
3846						:*:)	op=$1
3847							;;
3848						INIT|'$('*|*')')
3849							;;
3850						*)	case $op in
3851							:PACKAGE:)
3852								case " $_components_ " in
3853								*" $1 "*)	;;
3854								*)		_components_="$_components_ $1" ;;
3855								esac
3856								;;
3857							esac
3858							;;
3859						esac
3860					done
3861				done
3862				exec < /dev/null
3863			elif	test -d $PACKAGEROOT/src/cmd/$p -o -d $PACKAGEROOT/src/lib/$p
3864			then	_components_="$_components_ $p"
3865			else	echo "$command: $p: package or component not found" >&2
3866				exit 1
3867			fi
3868			;;
3869		esac
3870	done
3871}
3872
3873# list main environment values
3874
3875showenv()
3876{
3877	case $1 in
3878	''|make)for __i__ in CC SHELL $env
3879		do	eval echo $__i__='$'$__i__
3880		done
3881		;;
3882	esac
3883}
3884
3885# capture command output
3886
3887capture() # file command ...
3888{
3889	case $make:$noexec in
3890	:)	case $action in
3891		install|make|view)
3892			o=$action
3893			;;
3894		*)	case $package in
3895			''|*' '*)
3896				o=$action
3897				;;
3898			*)	o=$package
3899				;;
3900			esac
3901			;;
3902		esac
3903		case $action in
3904		write)	d=$PACKAGESRC/gen ;;
3905		*)	d=$PACKAGEBIN/gen ;;
3906		esac
3907		test -d $d || $exec mkdir $d
3908		o=$d/$o
3909		case $o in
3910		$output)o=$o.out
3911			s=
3912			;;
3913		*)	output=$o
3914			if	test -f $o.old
3915			then	mv $o.old $o.out.1
3916				if	test -f $o.out
3917				then	mv $o.out $o.out.2
3918				fi
3919			elif	test -f $o.out
3920			then	for i in `ls -t $o.out.? 2>/dev/null`
3921				do	break
3922				done
3923				case $i in
3924				*.1)	i=2 ;;
3925				*.2)	i=3 ;;
3926				*.3)	i=4 ;;
3927				*.4)	i=5 ;;
3928				*.5)	i=6 ;;
3929				*.6)	i=7 ;;
3930				*.7)	i=8 ;;
3931				*.8)	i=9 ;;
3932				*)	i=1 ;;
3933				esac
3934				mv $o.out $o.out.$i
3935			fi
3936			o=$o.out
3937			: > $o
3938			note $action output captured in $o
3939			s="$command: $action start at `date` in $INSTALLROOT"
3940			case $quiet in
3941			0)	trap "echo \"$command: $action done  at \`date\`\" in $INSTALLROOT 2>&1 | \$TEE -a $o" 0 1 2 ;;
3942			*)	trap "echo \"$command: $action done  at \`date\`\" in $INSTALLROOT >> $o" 0 1 2 ;;
3943			esac
3944			;;
3945		esac
3946		case $quiet in
3947		0)	if	executable ! $TEE
3948			then	TEE=tee
3949			fi
3950			{
3951				case $s in
3952				?*)	echo "$s"  ;;
3953				esac
3954				showenv $action
3955				"$@"
3956			} < /dev/null 2>&1 | $TEE -a $o
3957			;;
3958		*)	{
3959				case $s in
3960				?*)	echo "$s"  ;;
3961				esac
3962				showenv $action
3963				"$@"
3964			} < /dev/null > $o 2>&1
3965			;;
3966		esac
3967		;;
3968	*)	$make "$@"
3969		;;
3970	esac
3971}
3972
3973package_install() # dest sum
3974{
3975	dest=$1 sum=$2
3976	ot=
3977	code=0
3978	sed -e '/ /!d' -e 's,[^ ]* ,,' -e 's, \(arch/[^/]*\)/, \1 ,' -e '/ arch\//!s,^[^ ]* [^ ]* [^ ]*,& .,' -e 's,/\([^ /]*\)$, \1,' $sum |
3979	while	read mode user group arch dir file
3980	do	case $flat:$arch in
3981		1:*|?:.)t=$dest/$dir ;;
3982		*)	t=$dest/$arch/$dir ;;
3983		esac
3984		case $t in
3985		$ot)	;;
3986		*)	if	test ! -d "$t"
3987			then	$exec mkdir -p "$t" || exit
3988			fi
3989			ot=$t
3990			;;
3991		esac
3992		case $file in
3993		?*)	case $arch in
3994			.)	f=$dir/$file ;;
3995			*)	f=$arch/$dir/$file ;;
3996			esac
3997			if	test -f "$f"
3998			then	t=$t/$file
3999				case $quiet in
4000				0)	echo "$t" ;;
4001				esac
4002				$exec cp -f "$f" "$t" || code=1
4003				$exec chmod $mode "$t" || code=1
4004			fi
4005			;;
4006		esac
4007	done
4008	return $code
4009}
4010
4011package_verify() # sum
4012{
4013	$exec $SUM -cp $1
4014}
4015
4016make_recurse() # dir
4017{
4018	for _make_recurse_j in $makefiles
4019	do	if	view - $1/$_make_recurse_j
4020		then	return
4021		fi
4022	done
4023	if	test -d $1
4024	then	case $exec in
4025		'')	echo :MAKE: > $1/Makefile || exit ;;
4026		*)	$exec "echo :MAKE: > $1/Makefile" ;;
4027		esac
4028	fi
4029}
4030
4031get() # host path [ file size ]
4032{
4033	case $HURL in
4034	'')	HURL=.
4035		for i in wget lynx curl
4036		do	if	onpath $i
4037			then	HURL=$i
4038				break;
4039			fi
4040		done
4041		AUTHORIZE="User-Agent: package AT&T Research\\r\\n"
4042		case $HURL:$authorize in
4043		.:?*)	AUTHORIZE="${AUTHORIZE}Authorization: Basic `print -n -r -- $authorize:$password | uuencode -h -x base64`\\r\\n" ;;
4044		esac
4045		;;
4046	esac
4047	getfd=8
4048	case $3 in
4049	'')	case $HURL in
4050		.)	host=$1
4051			path=$2
4052			while	:
4053			do	eval "exec $getfd<> /dev/tcp/$host/80" || exit
4054				case $path in
4055				/*)	;;
4056				*)	path=/$path ;;
4057				esac
4058				print "GET $path HTTP/1.0\\r\\nHost: $host\\r\\n$AUTHORIZE\\r" >&$getfd
4059				cat <&8 > get.tmp
4060				got=`sed -e 1q get.tmp`
4061				case $got in
4062				*" "200" "*)
4063					got=`sed -e '1,/^.$/d' -e '/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ]/!d' get.tmp`
4064					: > get.err
4065					code=0
4066					break
4067					;;
4068				*" "30[123]" "*)
4069					got=`sed -e '/^Location: /!d' -e 's,^Location: \(.*\)://\([^/]*\)\(/.*\),prot='\''\1'\'' host='\''\2'\'' path='\''\3'\'',' get.tmp`
4070					case $got in
4071					'')	rm get.tmp
4072						echo "$command: $action: $url: redirect error" >&2
4073						exit 1
4074						;;
4075					esac
4076					eval $got
4077					;;
4078				*)	rm get.tmp
4079					echo "$command: $action: $url: $got" >&2
4080					echo '' "$got" > get.err
4081					code=1
4082					break
4083					;;
4084				esac
4085			done
4086			;;
4087		curl)	case $authorize in
4088			'')	curl -s -L -o get.tmp http://$1/$2 2> get.err; code=$? ;;
4089			*)	curl -s -L -o get.tmp -u "$authorize":"$password" http://$1/$2 2> get.err; code=$? ;;
4090			esac
4091			got=`grep '^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ]' get.tmp 2>/dev/null`
4092			case $code in
4093			0)	if	grep '^<H1>Authorization Required</H1>' get.tmp > get.err
4094				then	code=1
4095				fi
4096				;;
4097			esac
4098			;;
4099		hurl)	case $authorize in
4100			'')	hurl http://$1/$2 > get.tmp 2> get.err; code=$? ;;
4101			*)	hurl -a "$authorize":"$password" http://$1/$2 > get.tmp 2> get.err; code=$? ;;
4102			esac
4103			got=`grep '^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ]' get.tmp`
4104			;;
4105		lynx)	case $authorize in
4106			'')	lynx -source http://$1/$2 > get.tmp 2> get.err; code=$? ;;
4107			*)	lynx -source -auth "$authorize":"$password" http://$1/$2 > get.tmp 2> get.err; code=$? ;;
4108			esac
4109			got=`grep '^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ]' get.tmp`
4110			;;
4111		wget)	wget -nv -O get.tmp ${authorize:+--http-user="$authorize"} ${password:+--http-passwd="$password"} http://$1/$2 2> get.err
4112			code=$?
4113			got=`grep '^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ]' get.tmp 2>/dev/null`
4114			;;
4115		*)	echo $command: $action: $HURL: url get command not found >&2
4116			exit 1
4117			;;
4118		esac
4119		if	test 0 != "$code"
4120		then	case `cat get.err get.tmp 2>/dev/null` in
4121			*[Aa][Uu][Tt][Hh][Oo][Rr][Ii][SsZz]*|*[Dd][Ee][Nn][Ii][Ee][Dd]*)
4122				echo $command: $action: authorization required -- see $url for license acceptance authorization name and password >&2
4123				;;
4124			*)	cat get.err
4125				;;
4126			esac
4127			rm -f get.tmp get.err
4128			echo $command: $action: $2: download failed >&2
4129			exit 1
4130		fi
4131		rm -f get.tmp get.err
4132		;;
4133	*)	case $exec in
4134		'')	echo "$3 ($4 bytes):" >&2
4135			case $HURL in
4136			.)	eval "exec $getfd<> /dev/tcp/$1/80" || exit
4137				path=$2/$3
4138				case $path in
4139				/*)	;;
4140				*)	path=/$path ;;
4141				esac
4142				print "GET $path HTTP/1.0\\r\\nHost: $host\\r\\n$AUTHORIZE\\r" >&$getfd
4143				read got <&$getfd
4144				case $got in
4145				*" 200 "*)
4146					code=0
4147					: > get.err
4148					;;
4149				*)	echo '' "$got" > get.err
4150					code=1
4151					;;
4152				esac
4153				while	read got <&$getfd
4154				do	case $got in
4155					''|?)	break ;;
4156					esac
4157				done
4158				cat <&$getfd > get.tmp
4159				;;
4160			curl)	case $authorize in
4161				'')	curl -s -L -o get.tmp http://$1/$2/$3 2> get.err; code=$? ;;
4162				*)	curl -s -L -o get.tmp -u "$authorize":"$password" http://$1/$2/$3 2> get.err; code=$?
4163				esac
4164				case $code in
4165				0)	if	grep '^<H1>Authorization Required</H1>' get.tmp > get.err
4166					then	code=1
4167					fi
4168					;;
4169				esac
4170				;;
4171			hurl)	case $authorize in
4172				'')	ksh -x hurl http://$1/$2/$3 > get.tmp 2> get.err; code=$? ;;
4173				*)	ksh -x hurl -a "$authorize":"$password" http://$1/$2/$3 > get.tmp 2> get.err; code=$? ;;
4174				esac
4175				;;
4176			lynx)	case $authorize in
4177				'')	lynx -source http://$1/$2/$3 > get.tmp 2> get.err; code=$? ;;
4178				*)	lynx -source -auth "$authorize":"$password" http://$1/$2/$3 > get.tmp 2> get.err; code=$? ;;
4179				esac
4180				;;
4181			wget)	wget -nv -O get.tmp ${authorize:+--http-user="$authorize"} ${password:+--http-passwd="$password"} http://$1/$2/$3 2> get.err
4182				code=$?
4183				;;
4184			*)	echo $command: $action: $HURL: url get command not found >&2
4185				exit 1
4186				;;
4187			esac
4188			if	test 0 != "$code"
4189			then	case `cat get.err get.tmp` in
4190				*[Aa][Uu][Tt][Hh][Oo][Rr][Ii][SsZz]*|*[Dd][Ee][Nn][Ii][Ee][Dd]*)
4191					echo $command: $action: authorization required -- see $url for license acceptance authorization name and password >&2
4192					;;
4193				*)	cat get.err
4194					;;
4195				esac
4196				rm get.tmp get.err
4197				echo $command: $action: $3: download failed >&2
4198				exit 1
4199			fi
4200			rm get.err
4201			case $checksum:$5 in
4202			:*|*:-)	z=`wc -c < get.tmp`
4203				case " $z " in
4204				*" $4 "*)
4205					;;
4206				*)	rm -f get.tmp
4207					echo $command: $3: download error: expected $4 bytes, got $z >&2
4208					exit 1
4209					;;
4210				esac
4211				;;
4212			*)	z=`$checksum < get.tmp | sed -e 's,^[ 	][ 	]*,,' -e 's,[ 	].*,,'`
4213				case " $z " in
4214				*" $5 "*)
4215					;;
4216				*)	rm -f get.tmp
4217					echo $command: $3: download $checksum error: expected $5, got $z >&2
4218					exit 1
4219					;;
4220				esac
4221				;;
4222			esac
4223			mv get.tmp $3 || exit
4224			;;
4225		*)	echo "$3 ($4 bytes)" >&2
4226			;;
4227		esac
4228	esac
4229}
4230
4231# generate copyright notice
4232
4233copyright()
4234{
4235	if	test -f $1.lic
4236	then	echo $1 package general copyright notice
4237		echo
4238		proto -c'#' -p -s -l $1.lic -o type=verbose,author='*' /dev/null
4239		return 0
4240	fi
4241	case $1 in
4242	*-*)	eval `echo '' $1 | sed 's/\([^-]*\)-\(.*\)/__j__="\1" __i__="\2"/'`
4243		if	copyright $__i__ || copyright $__j__
4244		then	return 0
4245		fi
4246		;;
4247	esac
4248	return 1
4249}
4250
4251# run remote make on host
4252
4253remote() # host no-exec-background
4254{
4255	host=$1
4256	background=$2
4257	eval name=\$${host}_name user=\$${host}_user snarf=\$${host}_snarf type=\$${host}_type rsh=\$${host}_rsh root=\$${host}_root keep=\$${host}_keep log=\$${host}_log
4258	case $keep in
4259	1*)	;;
4260	*)	return ;;
4261	esac
4262	case $host in
4263	$main)	;;
4264	*)	case $exec in
4265		'')	exec > $admin_log/$log 2>&1 ;;
4266		*)	echo "exec > $admin_log/$log 2>&1" ;;
4267		esac
4268		;;
4269	esac
4270	if	$admin_ping $name >/dev/null 2>&1 || $admin_ping $name >/dev/null 2>&1
4271	then	cmd=". ./.profile"
4272		case $root in
4273		.)	root=
4274			;;
4275		*)	cmd="$cmd && cd $root"
4276			root=$root/
4277			;;
4278		esac
4279		cmd="$cmd && { test -f lib/package/admin/$admin_env && . ./lib/package/admin/$admin_env || true ;} && PATH=\${PWD:-\`pwd\`}/bin:\$PATH \${SHELL:-/bin/sh} -c 'package $admin_args PACKAGEROOT=\${PWD:-\`pwd\`} HOSTTYPE=$type VPATH='"
4280		case $admin_binary in
4281		'')	snarf= ;;
4282		esac
4283		case $snarf in
4284		'')	$exec $rsh $user$name "$cmd" $background
4285			;;
4286		*?)	rcp=`echo $rsh | sed 's/\(.\).*/\1/'`cp
4287			case $background in
4288			?*)	$exec "{" ;;
4289			esac
4290			$exec $rsh $user$name "$cmd"
4291			eval lst=$admin_list
4292			case $admin_pkgs in
4293			'')	filter=cat ;;
4294			*)	filter="egrep lib/package/tgz/($admin_pkgs)\\." ;;
4295			esac
4296			if	$exec $rcp $user$name:${root}lib/package/tgz/$lst $PACKAGESRC/tgz
4297			then	$exec $rcp `$filter $PACKAGESRC/tgz/$lst | sed "s,^,$user$name:,"` $PACKAGESRC/tgz
4298			else	echo "$command: $user$name:${root}lib/package/tgz/$lst: not found" >&2
4299			fi
4300			case $background in
4301			?*)	$exec "} $background" ;;
4302			esac
4303			;;
4304		esac
4305	else	echo "$command: $name: down" >&2
4306	fi
4307}
4308
4309# update package_src
4310
4311checksrc()
4312{
4313	case $package_src in
4314	'')	package_src=$src
4315		for _i_ in `cd $PACKAGESRC; ls *.def *.lic *.pkg 2>/dev/null | sed 's/[-.].*//'`
4316		do	case " $package_src " in
4317			*" $_i_ "*)
4318				;;
4319			*)	package_src="$package_src $_i_"
4320				;;
4321			esac
4322		done
4323		;;
4324	esac
4325}
4326
4327# check for native ascii 0:yes 1:no
4328
4329__isascii__=
4330
4331isascii()
4332{
4333	case $__isascii__ in
4334	'')	case `echo A | od -o | sed -e 's/[ 	]*$//' -e '/[ 	]/!d' -e 's/.*[ 	]//'` in
4335		005101|040412)	__isascii__=0 ;;
4336		*)		__isascii__=1 ;;
4337		esac
4338	esac
4339	return $__isascii__
4340}
4341
4342case $action in
4343
4344admin)	while	test ! -f $admin_db
4345	do	case $admin_db in
4346		/*)	echo $command: $action: $admin_db: data file not found >&2
4347			exit 1
4348			;;
4349		esac
4350		view file src lib/package/admin/$admin_db || exit 1
4351		admin_db=$_view_
4352	done
4353	admin_components=
4354	case $admin_action in
4355	list)	cat $admin_db
4356		exit
4357		;;
4358	test)	set $admin_args
4359		while	:
4360		do	case $# in
4361			1)	break ;;
4362			esac
4363			shift
4364			case $1 in
4365			*=*)	;;
4366			*)	admin_components=-$1
4367				break
4368				;;
4369			esac
4370		done
4371		;;
4372	esac
4373	: all work done in $PACKAGESRC/admin
4374	cd $PACKAGESRC/admin || exit
4375	checksrc
4376	packages=
4377	admin_log=${admin_action}${admin_components}.log
4378	exec < $admin_db || exit
4379	test -d $admin_log || $exec mkdir $admin_log || exit
4380	case $admin_on in
4381	'')	admin_on="*" ;;
4382	esac
4383	hostname=
4384	hosts=
4385	logs=
4386	local_hosts=
4387	local_types=
4388	pids=
4389	remote_hosts=
4390	sync_hosts=
4391	admin_host=_admin_host_
4392	admin_out=
4393	case " $admin_args " in
4394	*" write binary "*|*" write "*" binary "*)
4395		admin_binary=1
4396		;;
4397	*)	admin_binary=
4398		;;
4399	esac
4400	case $only in
4401	1)	admin_args="only $admin_args" ;;
4402	esac
4403	trap 'kill $pids >/dev/null 2>&1' 1 2 3 15
4404	index=0
4405	while	read type host root date time make test write owner attributes
4406	do	case $type in
4407		''|'#'*);;
4408		*=*)	eval "$type $host $root $date $time $make $test $write $owner $attributes"
4409			;;
4410		*)	case $admin_action in
4411			make|test|write)
4412				eval f='$'$admin_action
4413				case $f in
4414				*[!0123456789]*)	continue ;;
4415				esac
4416				;;
4417			esac
4418			rsh=rsh
4419			case $host in
4420			*@*)	IFS=@
4421				set '' $host
4422				IFS=$ifs
4423				user=${2}@
4424				host=$3
4425				;;
4426			*)	user=
4427				;;
4428			esac
4429			: type=$type host=$host root=$root date=$date time=$time make=$make test=$test write=$write :
4430			name=$host
4431			host=`echo $name | sed 's,[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789],__,g'`
4432			eval x='$'${host}_index
4433			eval ${host}_index=1
4434			case $x in
4435			1)	i=0
4436				while	:
4437				do	case $i in
4438					$index)	h=''
4439						break
4440						;;
4441					esac
4442					i=`expr $i + 1`
4443					eval h='$'${admin_host}${i}_name
4444					case $h in
4445					$host)	host=${admin_host}${i}
4446						eval user='$'${host}_user root='$'${host}_rsh:$host:'$'${host}_root
4447						break
4448						;;
4449					esac
4450				done
4451				;;
4452			esac
4453			case $root in
4454			*:$name:*)root=`echo '' $root | sed 's,:.*,:,'` ;;
4455			esac
4456			case $root in
4457			*:*:*)	index=`expr $index + 1`
4458				host=${admin_host}$index
4459				;;
4460			*:*)	case " $sync_hosts " in
4461				*" $name ${admin_host}"*)
4462					set '' '' $sync_hosts
4463					while	:
4464					do	shift
4465						shift
4466						case $1 in
4467						$name)	host=$2
4468							break
4469							;;
4470						esac
4471					done
4472					;;
4473				*)	index=`expr $index + 1`
4474					host=${admin_host}$index
4475					sync_hosts="$sync_hosts $name $host"
4476					;;
4477				esac
4478				;;
4479			*)	index=`expr $index + 1`
4480				host=${admin_host}$index
4481				;;
4482			esac
4483			case $root in
4484			-*)	continue
4485				;;
4486			*:*)	case $admin_all in
4487				0)	continue ;;
4488				esac
4489				case $root in
4490				*:)	root=${root}. ;;
4491				esac
4492				IFS=:
4493				set '' $root
4494				IFS=$ifs
4495				sync=$host
4496				case $hostname in
4497				'')	hostinfo name
4498					hostname=$_hostinfo_
4499					;;
4500				esac
4501				shift
4502				case $# in
4503				0)	;;
4504				1)	root=$1
4505					;;
4506				2)	rsh=$1 root=$2
4507					;;
4508				*)	rsh=$1 sync=$2 root=$3
4509					case $sync in
4510					${admin_host}*)
4511						;;
4512					?*)	case " $sync_hosts " in
4513						*" $sync ${admin_host}"*)
4514							set '' '' $sync_hosts
4515							while	:
4516							do	shift
4517								shift
4518								case $1 in
4519								$sync)	sync=$2
4520									break
4521									;;
4522								esac
4523							done
4524							;;
4525						*)	index=`expr $index + 1`
4526							x=${admin_host}$index
4527							sync_hosts="$sync_hosts $sync $x"
4528							sync=$x
4529							;;
4530						esac
4531						;;
4532					esac
4533					;;
4534				esac
4535				;;
4536			*)	sync=
4537				;;
4538			esac
4539			case $name in
4540			$admin_on)
4541				keep=1
4542				;;
4543			*)	case " $admin_on " in
4544				*" $name "*)	keep=1 ;;
4545				*)		keep=0 ;;
4546				esac
4547				;;
4548			esac
4549			case " $admin_out " in
4550			*" $name "*)
4551				log=$name.$type
4552				;;
4553			*)	admin_out="$admin_out $name"
4554				log=$name
4555				;;
4556			esac
4557			case $sync in
4558			'')	local_types="$local_types $type" ;;
4559			esac
4560			case $sync in
4561			$host)	remote_hosts="$remote_hosts $host"
4562				;;
4563			?*)	eval ${sync}_share=\"\$${sync}_share $host\"
4564				;;
4565			'')	local_hosts="$local_hosts $host"
4566				;;
4567			esac
4568			eval ${host}_name='$'name ${host}_type='$'type ${host}_user='$'user ${host}_sync='$'sync ${host}_snarf='$'sync ${host}_rsh='$'rsh ${host}_root='$'root ${host}_keep='$'keep ${host}_log='$'log
4569			;;
4570		esac
4571	done
4572	p=
4573	for i in $admin_args
4574	do	p="$i $p"
4575	done
4576	admin_pkgs=
4577	for i in $p
4578	do	if	view - src "lib/package/$i.pkg"
4579		then	case $admin_pkgs in
4580			'')	admin_pkgs="$i" ;;
4581			*)	admin_pkgs="$admin_pkgs|$i" ;;
4582			esac
4583		fi
4584	done
4585	: "admin_binary :" $admin_binary
4586	: "admin_args   :" $admin_args
4587	: "admin_pkgs   :" $admin_pkgs
4588	: "admin_on     :" "$admin_on"
4589	: "local_hosts  :" $local_hosts
4590	: "local_types  :" $local_types
4591	: "remote_hosts :" $remote_hosts
4592	: "sync_hosts   :" $sync_hosts
4593	: "sync_share   :" $sync_share
4594	case $admin_binary in
4595	1)	admin_bin_types=
4596		admin_bin_main=
4597		for main in $local_hosts $remote_hosts
4598		do	eval share=\$${main}_share keep=\$${main}_keep
4599			case $keep in
4600			0*)	continue ;;
4601			esac
4602			for host in $main $share
4603			do	case " $admin_bin_hosts " in
4604				*" $host "*)
4605					continue
4606					;;
4607				esac
4608				eval type=\$${host}_type
4609				case " $admin_bin_types " in
4610				*" $type "*)
4611					continue
4612					;;
4613				esac
4614				case " $types " in
4615				"  ")	;;
4616				*" $type "*)
4617					;;
4618				*)	continue
4619					;;
4620				esac
4621				admin_bin_hosts="$admin_bin_hosts $host"
4622				admin_bin_types="$admin_bin_types $type"
4623				case " $admin_bin_hosts " in
4624				*" $main "*)
4625					;;
4626				*)	case " $admin_bin_main " in
4627					*" $main "*)
4628						;;
4629					*)	admin_bin_main="$admin_bin_main $main"
4630						;;
4631					esac
4632					;;
4633				esac
4634			done
4635		done
4636		local=
4637		remote=
4638		for host in $admin_bin_main $admin_bin_hosts
4639		do	case " $local_hosts " in
4640			*" $host "*)
4641				local="$local $host"
4642				;;
4643			*)	case " $remote_hosts " in
4644				*" $host "*)
4645					remote="$remote $host"
4646					;;
4647				esac
4648				;;
4649			esac
4650		done
4651		local_hosts=$local
4652		remote_hosts=$remote
4653		;;
4654	esac
4655	for host in $remote_hosts $local_hosts
4656	do	eval share=\$${host}_share
4657		case $share in
4658		?*)	while	:
4659			do	oshare=$share
4660				for s in $share
4661				do	eval r='$'${s}_share
4662					case $r in
4663					?*)	case " $share " in
4664						*" $r "*)	;;
4665						*)		share="$share $r" ;;
4666						esac
4667						;;
4668					esac
4669				done
4670				case $share in
4671				$oshare)	eval ${host}_share="'$share'"
4672						break
4673						;;
4674				esac
4675			done
4676			;;
4677		esac
4678	done
4679	for host in $remote_hosts
4680	do	eval type=\$${host}_type
4681		case " $local_types " in
4682		*" $type "*)
4683			eval ${host}_snarf=
4684			;;
4685		esac
4686		eval name=\$${host}_name keep=\$${host}_keep share=\$${host}_share
4687		for share in $share
4688		do	eval type=\$${share}_type keep=\$keep\$${share}_keep
4689			case " $local_types " in
4690			*" $type "*)
4691				eval ${share}_snarf=
4692				;;
4693			esac
4694		done
4695		case $keep in
4696		0*1*)	keep=2$keep ;;
4697		*1*)	;;
4698		*)	keep=0 ;;
4699		esac
4700		eval ${host}_keep=$keep
4701	done
4702	for host in $remote_hosts $local_hosts
4703	do	eval name=\$${host}_name user=\$${host}_user type=\$${host}_type sync=\$${host}_sync snarf=\$${host}_snarf share=\$${host}_share rsh=\$${host}_rsh root=\$${host}_root keep=\$${host}_keep
4704		case $keep in
4705		0*)	continue ;;
4706		esac
4707		case $sync in
4708		'')	case $admin_action in
4709			ditto)	continue ;;
4710			esac
4711			case $admin_binary in
4712			1)	case $keep in
4713				1*|?*1*);;
4714				*)	continue ;;
4715				esac
4716				;;
4717			esac
4718			;;
4719		esac
4720		eval main_log='$'${host}_log
4721		main=
4722		share_keep=
4723		for i in $host $share
4724		do	eval n='$'${i}_name t='$'${i}_type q='$'${i}_sync s='$'${i}_snarf l='$'${i}_log k='$'${i}_keep
4725			case $main:$k in
4726			:*)	;;
4727			*:0)	continue ;;
4728			esac
4729			case $admin_binary in
4730			1)	case $s:$q in
4731				:?*)	continue ;;
4732				esac
4733				case " $admin_bin_hosts " in
4734				*" $i "*)
4735					;;
4736				*)	continue
4737					;;
4738				esac
4739				;;
4740			esac
4741			case $main in
4742			'')	main=$i ;;
4743			*)	share_keep="$share_keep $i" ;;
4744			esac
4745			echo package "$admin_args" "[ $n $t ]"
4746			case $exec in
4747			'')	: > $admin_log/$l ;;
4748			*)	$exec ": > $admin_log/$l" ;;
4749			esac
4750		done
4751		host=$main
4752		share=$share_keep
4753		case $force in
4754		0)	admin_ditto_update=--update ;;
4755		*)	admin_ditto_update= ;;
4756		esac
4757		case $exec in
4758		'')	{
4759			case $admin_binary:$sync in
4760			:?*)	eval syncname='$'${sync}_name
4761				test -x $PACKAGEROOT/bin/package && $admin_ditto $admin_ditto_update --remote=$rsh --expr="name=='package'" $PACKAGEROOT/bin $user$syncname:$root/bin
4762				test -d $PACKAGESRC && $admin_ditto $admin_ditto_update --remote=$rsh --expr="if(level>1&&path!='LICENSES/*')status=SKIP;path=='LICENSES*|*.(pkg|lic|def)'" $PACKAGESRC $user$syncname:$root/lib/package
4763				for dir in $package_src
4764				do	case $MAKESKIP in
4765					'')	expr="--expr=if(name=='$admin_ditto_skip')status=SKIP" ;;
4766					*)	expr="--expr=if(name=='$admin_ditto_skip'||level==1&&name=='$MAKESKIP')status=SKIP" ;;
4767					esac
4768					test -d $PACKAGEROOT/src/$dir && $admin_ditto $admin_ditto_update --remote=$rsh "$expr" $PACKAGEROOT/src/$dir $user$syncname:$root/src/$dir
4769				done
4770				;;
4771			esac
4772			case $admin_action in
4773			ditto)	;;
4774			?*)	pids=
4775				set '' $host $share
4776				while	:
4777				do	shift
4778					case $# in
4779					0)	break
4780						;;
4781					1)	remote $1
4782						;;
4783					*)	remote $1 &
4784						pids="$pids $!"
4785						;;
4786					esac
4787				done
4788				case $pids in
4789				?*)	wait $pids ;;
4790				esac
4791				;;
4792			esac
4793			} < /dev/null > $admin_log/$main_log 2>&1 &
4794			pids="$pids $!"
4795			;;
4796		*)	echo "{"
4797			case $admin_binary:$sync in
4798			:?*)	eval syncname='$'${sync}_name
4799				test -d $PACKAGESRC && echo $admin_ditto $admin_ditto_update --remote=$rsh --expr="if(level>1)status=SKIP;name=='*.(pkg|lic|def)'" $PACKAGESRC $user$syncname:$root/lib/package
4800				for dir in $package_src
4801				do	case $MAKESKIP in
4802					'')	expr="--expr=if(name=='$admin_ditto_skip')status=SKIP" ;;
4803					*)	expr="--expr=if(name=='$admin_ditto_skip'||level==1&&name=='$MAKESKIP')status=SKIP" ;;
4804					esac
4805					test -d $PACKAGEROOT/src/$dir && echo $admin_ditto $admin_ditto_update --remote=$rsh "$expr" $PACKAGEROOT/src/$dir $user$syncname:$root/src/$dir
4806				done
4807				;;
4808			esac
4809			case $admin_action in
4810			ditto)	;;
4811			?*)	pids=
4812				set '' $host $share
4813				while	:
4814				do	shift
4815					case $# in
4816					0)	break
4817						;;
4818					1)	remote $1
4819						;;
4820					*)	remote $1 "&"
4821						pids=1
4822						;;
4823					esac
4824				done
4825				case $pids in
4826				1)	echo wait ;;
4827				esac
4828				;;
4829			esac
4830			echo "} < /dev/null > $admin_log/$main_log 2>&1 &"
4831			;;
4832		esac
4833		eval name='$'${main}_name
4834		hosts="$hosts $name"
4835		logs="$logs $main_log"
4836		for share in $share
4837		do	eval keep=\$${share}_keep
4838			case $keep in
4839			1)	eval name='$'${share}_name log='$'${share}_log
4840				hosts="$hosts $name"
4841				logs="$logs $log"
4842				;;
4843			esac
4844		done
4845	done
4846	case $exec in
4847	'')	# track the progress
4848		case $quiet in
4849		0)	cd $admin_log
4850			tail -t $PACKAGE_admin_tail_timeout -f $logs
4851			cd ..
4852			;;
4853		esac
4854		# wait for the remote actions to complete
4855		wait
4856		trap - 1 2 3 15
4857		# update the db
4858		exec < $admin_db || exit
4859		exec 9>&1
4860		D=`date +%y%m%d`
4861		while	read line
4862		do	set -- $line
4863			case $1 in
4864			''|'#'*|*=*)
4865				;;
4866			*)	case " $hosts " in
4867				*" $2 "*)
4868					: ast date command assumed :
4869					E=`eval date -E \`egrep '[ 	](start|done)[ 	][ 	]*at[ 	]' $admin_log/$2 | sed -e 's/.*[ 	][ 	]*at[ 	][ 	]*//' -e 's/[ 	][ 	]*in[ 	].*$//' -e 's/.*/"&"/'\``
4870					M=$6 T=$7 W=$8
4871					case $admin_action in
4872					make|view)
4873						M=`egrep -c ']:.* (\*\*\*.* code|don'\''t know) | \*\*\* termination code ' $admin_log/$2` ;;
4874					test)	T=`grep -ci 'fail[es]' $admin_log/$2` ;;
4875					*)	W=`grep '^[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]*:.' $admin_log/$2 | egrep -cv 'start at|done  at|output captured|warning:|: package not found|whence: command not found'` ;;
4876					esac
4877					case $1 in
4878					?|??|???|????|?????|??????|???????)
4879						t1='		'
4880						;;
4881					????????|?????????|??????????|???????????|????????????|?????????????|??????????????|???????????????)
4882						t1='	'
4883						;;
4884					*)	t1=''
4885						;;
4886					esac
4887					case $2 in
4888					?|??|???|????|?????|??????|???????)
4889						t2='	'
4890						;;
4891					*)	t2=''
4892						;;
4893					esac
4894					case $3 in
4895					?|??|???|????|?????|??????|???????)
4896						t3='	'
4897						;;
4898					*)	t3=''
4899						;;
4900					esac
4901					case $E in
4902					?????)	E=" $E" ;;
4903					????)	E="  $E" ;;
4904					???)	E="   $E" ;;
4905					??)	E="    $E" ;;
4906					?)	E="     $E" ;;
4907					esac
4908					case $M in
4909					???)	M="$M" ;;
4910					??)	M=" $M" ;;
4911					?)	M="  $M" ;;
4912					'')	M="  0" ;;
4913					esac
4914					case $T in
4915					???)	T="$T" ;;
4916					??)	T=" $T" ;;
4917					?)	T="  $T" ;;
4918					'')	T="  0" ;;
4919					esac
4920					case $W in
4921					???)	W="$W" ;;
4922					??)	W=" $W" ;;
4923					?)	W="  $W" ;;
4924					'')	W="  0" ;;
4925					esac
4926					A=$1$t1
4927					H=$2$t2
4928					R=$3$t3
4929					case $# in
4930					[0-8])	O=
4931						K=
4932						;;
4933					*)	shift 8
4934						O=$1
4935						K=$2
4936						case $O in
4937						''|?|??|???)	K="	$K" ;;
4938						esac
4939						case $# in
4940						[0-2])	;;
4941						*)	K="$K $*" ;;
4942						esac
4943						;;
4944					esac
4945					echo "$A	$H	$R	$D	$E	$M $T $W $O	$K"
4946					echo "$A	$H	$R	$D	$E	$M $T $W $O	$K" >&9
4947					continue
4948					;;
4949				esac
4950				;;
4951			esac
4952			echo "$line"
4953		done > $admin_db.new
4954		mv $admin_db $admin_db.old
4955		mv $admin_db.new $admin_db
4956		;;
4957	esac
4958	;;
4959
4960clean|clobber)
4961	cd $PACKAGEROOT
4962	$exec rm -rf $INSTALLROOT
4963	exit
4964	;;
4965
4966contents|list)
4967	# all work in $PACKAGESRC
4968
4969	cd $PACKAGESRC
4970
4971	# generate the package list
4972
4973	set '' $target $package
4974	shift
4975	argc=$#
4976	case $# in
4977	0)	set '' *.pkg
4978		case $2 in
4979		'*.pkg')
4980			echo $command: $action: no packages >&2
4981			exit 1
4982			;;
4983		esac
4984		set '' `echo $* | sed 's,\.pkg,,g'`
4985		shift
4986		;;
4987	esac
4988	sep="$nl    "
4989	echo packages in $PACKAGEROOT
4990	case $action in
4991	list)	echo
4992		echo "NAME${nl}VERSION${nl}RELEASE${nl}TYPE${nl}STATUS${nl}REQUIRES${nl}----${nl}-------${nl}-------${nl}----${nl}------${nl}--------" | pr -6 -a -o4 -t
4993		;;
4994	esac
4995	{
4996	omit=:
4997	for pkg
4998	do	if	test ! -f $pkg.pkg
4999		then	echo $command: $action: $pkg: not a package >&2
5000		else	if	test -f gen/$pkg.ver
5001			then	set '' `cat gen/$pkg.ver`
5002				case $3 in
5003				$2)	ver=base ;;
5004				*)	ver=$3 ;;
5005				esac
5006				if	test -s tgz/$pkg.tim
5007				then	sts=local
5008				else	sts=
5009				fi
5010			else	ver=
5011				sts=unwritten
5012			fi
5013			typ=
5014			txt=
5015			cmp= cmp_sep=
5016			req= req_sep=
5017			op=::
5018			exec < $pkg.pkg
5019			while	read line
5020			do	IFS=' 	\\'
5021				set '' $line
5022				IFS=$ifs
5023				while	:
5024				do	shift
5025					case $# in
5026					0)	break ;;
5027					esac
5028					case $1 in
5029					:*:)	op=$1
5030						;;
5031					INIT|'$('*|*')')
5032						;;
5033					*)	case $op in
5034						:DESCRIPTION:)
5035							txt="$txt$sep$line"
5036							break
5037							;;
5038						:PACKAGE:)
5039							cmp="$cmp$cmp_sep$1"
5040							cmp_sep=$nl
5041							;;
5042						:REQUIRES:)
5043							req="$req$req_sep$1"
5044							req_sep=" "
5045							;;
5046						esac
5047						;;
5048					esac
5049				done
5050			done
5051			exec < /dev/null
5052			case $txt in
5053			?*)	txt="$nl$txt" ;;
5054			esac
5055			case :$ver: in
5056			*::*)	;;
5057			*)	case $action in
5058				list)	case $sts in
5059					'')	case `ls -t "tgz/$pkg.$ver.base" "tgz/$pkg.tim" 2>/dev/null` in
5060						"tgz/$pkg.tim"*)
5061							sts=read
5062							;;
5063						*)	sts=unread
5064							;;
5065						esac
5066						;;
5067					esac
5068					echo "$pkg${nl}$ver${nl}base${nl}$typ${nl}$sts${nl}$req"
5069					case $typ in
5070					'')	omit=$omit$pkg.$ver.base: ;;
5071					esac
5072					;;
5073				*)	case $req in
5074					?*)	req=": $req" ;;
5075					esac
5076					echo
5077					echo $pkg $ver $req "$txt"
5078					case $cmp in
5079					?*)	echo "${sep}Components in this package:$nl"
5080						echo "$cmp" | pr -4 -o4 -t ;;
5081					esac
5082					;;
5083				esac
5084				;;
5085			esac
5086		fi
5087	done
5088	case $argc:$action in
5089	0:list)	if	test -d tgz
5090		then	cd tgz
5091			# f:file p:package v:version r:release t:type u:update
5092			for f in `find . -name '*?[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.]*' -print | sed 's,^\./,,' | sort -r`
5093			do	eval `echo "$f" | sed -e 's,\.c$,,' -e 's,\.gz$,,' -e 's,\.exe$,,' -e 's,\.tgz$,,' -e 's,\([^_.]*\)[_.]\([0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]\)[_.]\([0123456789][0123456789][0123456789][0123456789][^_.]*\)[_.]*\(.*\),p=\1 v=\2 r=\3 t=\4,' -e 's,\([^_.]*\)[_.]\([0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]\)[_.]*\(.*\),p=\1 v=\2 r=base t=\3,'`
5094				case $t in
5095				'')	case $omit in
5096					*:$p.$v.$r:*)	continue ;;
5097					esac
5098					u=$p.tim
5099					;;
5100				*)	u=$p.$t.tim
5101					;;
5102				esac
5103				if	test -s "$u"
5104				then	s=local
5105				elif	test -f "$u"
5106				then	case `ls -t "$f" "$u" 2>/dev/null` in
5107					"$u"*)	s=read ;;
5108					*)	s=unread ;;
5109					esac
5110				else	s=unread
5111				fi
5112				echo "$p$nl$v$nl$r$nl$t$nl$s$nl"
5113			done
5114		fi
5115		;;
5116	esac
5117	} |
5118	case $action in
5119	list)	pr -6 -a -o4 -t | sort -u ;;
5120	*)	cat ;;
5121	esac
5122	case $argc in
5123	0)	if	test -d $PACKAGEROOT/arch
5124		then	echo
5125			echo architectures in $PACKAGEROOT
5126			echo
5127			for i in `ls $PACKAGEROOT/arch`
5128			do	if	test -f $PACKAGEROOT/arch/$i/lib/package/gen/host
5129				then	h=`cat $PACKAGEROOT/arch/$i/lib/package/gen/host`
5130				else	h=
5131				fi
5132				echo $i
5133				echo $h
5134				echo
5135				echo
5136			done | pr -4 -a -o4 -t
5137		fi
5138		;;
5139	esac
5140	;;
5141
5142copyright)
5143	# all work in $PACKAGESRC
5144
5145	cd $PACKAGESRC
5146
5147	# generate the package list
5148
5149	set '' $target $package
5150	shift
5151	argc=$#
5152	case $# in
5153	0)	set '' `echo *.lic | sed 's,\.lic,,g'`
5154		shift
5155		case $1 in
5156		'*')	echo $command: $action: no packages >&2
5157			exit 1
5158			;;
5159		esac
5160		;;
5161	esac
5162	checkaout proto || exit
5163	for i
5164	do	copyright $i
5165	done
5166	;;
5167
5168export)	case $INSTALLROOT in
5169	$PACKAGEROOT)
5170		INSTALLROOT=$INSTALLROOT/arch/$HOSTTYPE
5171		;;
5172	esac
5173	case $only in
5174	0)	v='$i=' ;;
5175	*)	v= ;;
5176	esac
5177	set '' $target $package
5178	case $# in
5179	1)	set '' $env ;;
5180	esac
5181	while	:
5182	do	case $# in
5183		1)	break ;;
5184		esac
5185		shift
5186		i=$1
5187		eval echo ${v}'$'${i}
5188	done
5189	;;
5190
5191install)cd $PACKAGEROOT
5192	set '' $package
5193	shift
5194	case $only in
5195	0)	set '' `order "$@"`
5196		shift
5197		;;
5198	esac
5199	case $# in
5200	0)	echo "$command: at least one package name expected" >&2
5201		exit 1
5202		;;
5203	esac
5204	package=$*
5205	requirements - $package
5206	set '' $target
5207	shift
5208	case $1 in
5209	flat)	flat=1 # backwards compatibility -- documentation dropped
5210		shift
5211		;;
5212	esac
5213	case $# in
5214	0)	echo "$command: $action: target directory argument expected" >&2
5215		exit 1
5216		;;
5217	esac
5218	target=
5219	while	:
5220	do	case $# in
5221		1)	directory=$1
5222			break
5223			;;
5224		esac
5225		target="$target $1"
5226		shift
5227	done
5228	if	test ! -d $directory
5229	then	echo "$command: $action: $directory: target directory not found" >&2
5230		exit 1
5231	fi
5232	case $target in
5233	'')	cd arch
5234		set '' *
5235		shift
5236		target=$*
5237		cd ..
5238		;;
5239	esac
5240	code=0
5241	makecheck=1
5242	for a in $target
5243	do	case $a in
5244		-)	a=$HOSTTYPE ;;
5245		esac
5246		case $flat:$a in
5247		1:*|?:.)dest=$directory
5248			;;
5249		*)	dest=$directory/arch/$a
5250			if	test "" = "$exec" -a ! -d $dest
5251			then	mkdir -p $dest || {
5252					echo "$command: $dest: destination directory must exist" >&2
5253					exit 1
5254				}
5255			fi
5256			;;
5257		esac
5258		for i in $package
5259		do	if	test "ratz" = "$i"
5260			then	: skip
5261			elif	test -f arch/$a/lib/package/gen/$i.sum
5262			then	package_install $directory arch/$a/lib/package/gen/$i.sum || code=1
5263			elif	test ! -d arch/$a/bin
5264			then	echo "$command: $a: invalid architecture" >&2
5265			elif	test ! -d $dest
5266			then	echo "$command: $dest: destination directory must exist" >&2
5267			else	if	test "" != "$makecheck"
5268				then	if	onpath $MAKE
5269					then	MAKE=$_onpath_
5270					else	echo "$command: $MAKE: not found" >&2
5271						exit 1
5272					fi
5273					makecheck=
5274				fi
5275				if	test "" != "$exec"
5276				then	(
5277						trap - 0 1 2 15
5278						echo "=== $i installation manifest ==="
5279						cd arch/$a
5280						(
5281						cd lib/package
5282						INSTALLROOT=$PACKAGEROOT/arch/$a
5283						VPATH=$INSTALLROOT:$PACKAGEROOT:$VPATH
5284						export INSTALLROOT VPATH
5285						$MAKE -s $makeflags -f $i.pkg $qualifier list.installed $assign
5286						) | sort -u
5287					)
5288				else	(
5289						set -
5290						cd arch/$a
5291						(
5292						cd lib/package
5293						INSTALLROOT=$PACKAGEROOT/arch/$a
5294						VPATH=$INSTALLROOT:$PACKAGEROOT:$VPATH
5295						export INSTALLROOT VPATH
5296						echo lib/$command
5297						$MAKE -s $makeflags -f $i.pkg $qualifier list.installed $assign
5298						) | sort -u | pax -drw -ps $dest
5299					)
5300				fi
5301			fi
5302		done
5303	done
5304	exit $code
5305	;;
5306
5307license)# all work in $PACKAGESRC/LICENSES
5308
5309	cd $PACKAGESRC/LICENSES || exit
5310
5311	# generate the package list
5312
5313	set '' $target $package
5314	shift
5315	argc=$#
5316	case $# in
5317	0)	set '' *
5318		shift
5319		case $1 in
5320		'*')	echo $command: $action: no licenses >&2
5321			exit 1
5322			;;
5323		esac
5324		;;
5325	*)	checkaout proto || exit
5326		a=
5327		for i
5328		do	while	:
5329			do	if	test -f ../$i.lic
5330				then	j=`proto -df -l ../$i.lic -o query=type /dev/null 2>/dev/null`
5331					case $j in
5332					?*)	if	test -f $j
5333						then	case " $a " in
5334							*" $j "*)	;;
5335							*)		a="$a $j" ;;
5336							esac
5337						fi
5338						break
5339						;;
5340					esac
5341				fi
5342				case $i in
5343				*-*)	i=`echo $i | sed 's/-[^-]*$//'`
5344					;;
5345				*)	echo "$command: $i: package license not found" >&2
5346					break
5347					;;
5348				esac
5349			done
5350		done
5351		set '' $a
5352		shift
5353		;;
5354	esac
5355	for i
5356	do	case $exec in
5357		'')	echo
5358			echo "		--- $i source license ---"
5359			echo
5360			cat $i
5361			;;
5362		*)	echo $PACKAGESRC/LICENSES/$i
5363			;;
5364		esac
5365	done
5366	;;
5367
5368make|view)
5369	cd $PACKAGEROOT
5370	case $package in
5371	'')	lic="lib/package/*.lic"
5372		;;
5373	*) 	for i in $package
5374		do	lic="$lic lib/package/$i.lic"
5375			case $i in
5376			*-*)	lic="$lic lib/package/"`echo $i | sed 's,-.*,,'`".lic" ;;
5377			esac
5378		done
5379		;;
5380	esac
5381	checksrc
5382	requirements source $package
5383	components $package
5384	package=$_components_
5385
5386	# check for some required commands
5387
5388	must="$AR"
5389	warn="$NM yacc bison"
5390	test="$must $warn"
5391	have=
5392	IFS=:
5393	set /$IFS$PATH
5394	IFS=$ifs
5395	shift
5396	for t in $test
5397	do	if	executable $t
5398		then	have="$have $t"
5399		fi
5400	done
5401	for d
5402	do	for t in $test
5403		do	case " $have " in
5404			*" $t "*)
5405				;;
5406			*)	if	executable $d/$t
5407				then	have="$have $t"
5408				fi
5409				;;
5410			esac
5411		done
5412	done
5413	case " $have " in
5414	*" bison "*)	;;
5415	*" yacc "*)	have="$have bison" ;;
5416	esac
5417	case " $have " in
5418	*" yacc "*)	;;
5419	*" bison "*)	have="$have yacc" ;;
5420	esac
5421	for t in $test
5422	do	case " $have " in
5423		*" $t "*)
5424			;;
5425		*)	case " $must " in
5426			*" $t "*)
5427				echo "$command: $t: not found -- must be on PATH to $action" >&2
5428				exit 1
5429				;;
5430			*)	echo "$command: warning: $t: not found -- some $action actions may fail" >&2
5431				;;
5432			esac
5433			;;
5434		esac
5435	done
5436
5437	# verify the top view
5438
5439	if	test ! -d $PACKAGEROOT/src
5440	then	note no source packages to make
5441		exit 0
5442	elif	test ! -d $INSTALLROOT/src
5443	then	note initialize the $INSTALLROOT view
5444	fi
5445	for i in arch arch/$HOSTTYPE
5446	do	test -d $PACKAGEROOT/$i || $exec mkdir $PACKAGEROOT/$i || exit
5447	done
5448	for i in bin bin/$OK bin/$OK/lib fun include lib lib/package lib/package/gen src man man/man1 man/man3 man/man8
5449	do	test -d $INSTALLROOT/$i || $exec mkdir $INSTALLROOT/$i || exit
5450	done
5451	make_recurse src
5452	o= k=
5453	for i in $makefiles
5454	do	case $o in
5455		?*)	o="$o -o" k="$k|" ;;
5456		esac
5457		o="$o -name $i"
5458		k="$k$i"
5459	done
5460	o="( $o ) -print"
5461	for d in $package_src
5462	do	i=src/$d
5463		if	test -d $i
5464		then	test -d $INSTALLROOT/$i || $exec mkdir $INSTALLROOT/$i || exit
5465			make_recurse $i
5466			for j in `cd $i; find . $o 2>/dev/null | sed -e 's,^\./,,' -e '/\//!d' -e 's,/[^/]*$,,' | sort -u`
5467			do	case $j in
5468				$k|$MAKESKIP) continue ;;
5469				esac
5470				test -d $INSTALLROOT/$i/$j ||
5471				$exec mkdir -p $INSTALLROOT/$i/$j || exit
5472			done
5473		fi
5474	done
5475	def=
5476	for i in $lic
5477	do	test -f $i || continue
5478		cmp -s $i $INSTALLROOT/$i 2>/dev/null ||
5479		$exec cp $PACKAGEROOT/$i $INSTALLROOT/$i
5480		for j in `grep '^. .*\.def$' $i`
5481		do	case $j in
5482			.)	;;
5483			*)	case " $def " in
5484				*" $i "*)	;;
5485				*)		def="$def $i" ;;
5486				esac
5487				;;
5488			esac
5489		done
5490	done
5491	for i in $def
5492	do	i=lib/package/$i
5493		test -f $i || continue
5494		cmp -s $i $INSTALLROOT/$i 2>/dev/null ||
5495		$exec cp $PACKAGEROOT/$i $INSTALLROOT/$i
5496	done
5497
5498	# check $CC and { ar cc ld ldd } intercepts
5499
5500	h="${HOSTTYPE} ${HOSTTYPE}.*"
5501	case $HOSTTYPE in
5502	*.*)	t=`echo $HOSTTYPE | sed 's/[.][^.]*//'`
5503		h="$h $t"
5504		;;
5505	*)	t=$HOSTTYPE
5506		;;
5507	esac
5508	case $t in
5509	*[0123456789])
5510		t=`echo $t | sed 's/[0123456789]*$//'`
5511		h="$h $t"
5512		;;
5513	esac
5514	case $CC in
5515	cc)	c=cc
5516		b=$INSTALLROOT/bin/$c
5517		t=$INSTALLROOT/lib/package/gen/$c.tim
5518		intercept=0
5519		for k in $h
5520		do	for s in $INITROOT/$c.$k
5521			do	test -x "$s" || continue
5522				if	cmp -s "$s" "$b" >/dev/null 2>&1
5523				then	intercept=1
5524					break 2
5525				fi
5526				case `ls -t "$t" "$b" "$s" 2>/dev/null` in
5527				$t*)	;;
5528				$b*)	cc=$b
5529					;;
5530				$s*)	cd $INSTALLROOT/lib/package/gen
5531					tmp=pkg$$
5532					eval '$'exec echo "'int main(){return 0;}' > $tmp.c"
5533					if	$exec $s -o $tmp.exe $tmp.c >/dev/null 2>&1 &&
5534						test -x $tmp.exe
5535					then	case $HOSTTYPE in
5536						*.mips*)$s -version >/dev/null 2>&1 || s= ;;
5537						esac
5538						case $s in
5539						?*)	$exec sed "s/^HOSTTYPE=.*/HOSTTYPE=$HOSTTYPE/" < "$s" > "$b" || exit
5540							$exec chmod +x "$b" || exit
5541							cc=$b
5542							intercept=1
5543							note update $b
5544							;;
5545						esac
5546					fi
5547					$exec rm -f $tmp.*
5548					$exec touch "$t"
5549					cd $PACKAGEROOT
5550					;;
5551				esac
5552				break 2
5553			done
5554		done
5555		case $intercept in
5556		1)	c=ld
5557			b=$INSTALLROOT/bin/$c
5558			for k in $h
5559			do	for s in $INITROOT/$c.$k
5560				do	test -x "$s" || continue
5561					case `ls -t "$b" "$s" 2>/dev/null` in
5562					$b*)	;;
5563					$s*)	$exec cp "$s" "$b"
5564						note update $b
5565						;;
5566					esac
5567				done
5568			done
5569			;;
5570		esac
5571		;;
5572	esac
5573	c=ldd
5574	b=$INSTALLROOT/bin/$c
5575	for t in $h
5576	do	s=$INITROOT/$c.$t
5577		test -x "$s" || continue
5578		onpath $c ||
5579		case `ls -t "$b" "$s" 2>/dev/null` in
5580		$b*)	;;
5581		$s*)	$exec cp "$s" "$b"
5582			note update $b
5583			;;
5584		esac
5585	done
5586# following code stubbed out just in case ar.ibm.risc is needed
5587#	c=ar
5588#	b=$INSTALLROOT/bin/$c
5589#	for t in $h
5590#	do	s=$INITROOT/$c.$t
5591#		test -x "$s" || continue
5592#		onpath $c ||
5593#		case `ls -t "$b" "$s" 2>/dev/null` in
5594#		$b*)	;;
5595#		$s*)	x=`$s -tv /foo/bar.a 2>&1 | egrep -i 'option|usage'`
5596#			case $x in
5597#			'')	$exec cp "$s" "$b"
5598#				note update $b
5599#				;;
5600#			esac
5601#			;;
5602#		esac
5603#	done
5604	case $cc in
5605	/*)	;;
5606	*)	echo "$command: $CC: not found -- set CC=C-compiler" >&2
5607		exit 1
5608		;;
5609	esac
5610	case $exec in
5611	'')	cd $INSTALLROOT/lib/package/gen
5612		tmp=pkg$$
5613		echo 'int main(){return 0;}' > $tmp.c
5614		if	$CC -o $tmp.exe $tmp.c > /dev/null 2> $tmp.err &&
5615			test -x $tmp.exe
5616		then	: ok
5617		else	echo "$command: $CC: failed to compile this program:" >&2
5618			cat $tmp.c >&2
5619			if	test -s $tmp.err
5620			then	cat $tmp.err >&2
5621			else	echo "$command: $CC: not a C compiler" >&2
5622			fi
5623			rm -f $tmp.*
5624			exit 1
5625		fi
5626		rm -f $tmp.*
5627		cd $PACKAGEROOT
5628		;;
5629	esac
5630
5631	# remember the default $CC
5632
5633	case $CC in
5634	cc)	;;
5635	*)	if	test -x $INSTALLROOT/bin/cc
5636		then	case `sed 1q $INSTALLROOT/bin/cc` in
5637			": $CC :")
5638				CC=cc
5639				export CC
5640				;;
5641			*)	assign="$assign CC=\"\$CC\""
5642				;;
5643			esac
5644		else	case $CROSS in
5645			1)	assign="$assign CC=\"\$CC\""
5646				;;
5647			*)	case $exec in
5648				'')	{
5649					echo ": $CC :"
5650					echo "$CC \"\$@\""
5651					} > $INSTALLROOT/bin/cc
5652					chmod +x $INSTALLROOT/bin/cc
5653					;;
5654				*)	note generate a $INSTALLROOT/bin/cc wrapper for $CC
5655					;;
5656				esac
5657				CC=cc
5658				export CC
5659				;;
5660			esac
5661		fi
5662		;;
5663	esac
5664
5665	# no $INITROOT means INIT already installed elsewhere
5666
5667	if	test -d $INITROOT
5668	then
5669		# update probe scripts
5670
5671		for i in lib/probe lib/probe/C lib/probe/C/make
5672		do	test -d $INSTALLROOT/$i || $exec mkdir $INSTALLROOT/$i || exit
5673		done
5674		i=$INSTALLROOT/lib/probe/C/make/probe
5675		j=$INITROOT/C+probe
5676		k=$INITROOT/make.probe
5677		case `ls -t $i $j $k 2>/dev/null` in
5678		$i*)	;;
5679		*)	if	test -f $j -a -f $k
5680			then	note update $i
5681				shellmagic
5682				case $exec in
5683				'')	{
5684					case $SHELLMAGIC in
5685					?*)	echo "$SHELLMAGIC" ;;
5686					esac
5687					cat $j $k
5688					} > $i || exit
5689					;;
5690				*)	echo "{
5691echo $SHELLMAGIC
5692cat $j $k
5693} > $i"
5694					;;
5695				esac
5696				$exec chmod +x $i || exit
5697			fi
5698			;;
5699		esac
5700	fi
5701
5702	# initialize a few mamake related commands
5703
5704	checkaout mamake proto ratz release || exit
5705
5706	# execrate if necessary
5707
5708	if	(execrate) >/dev/null 2>&1
5709	then	execrate=execrate
5710		$make cd $INSTALLROOT/bin
5711		for i in chmod chgrp cmp cp ln mv rm
5712		do	if	test ! -x $OK/$i -a -x /bin/$i.exe
5713			then	shellmagic
5714				case $exec in
5715				'')	echo "$SHELLMAGIC"'execrate /bin/'$i' "$@"' > $OK/$i
5716					chmod +x $OK/$i
5717					;;
5718				*)	$exec echo \'"$SHELLMAGIC"'execrate /bin/'$i' "$@"'\'' >' $OK/$i
5719					$exec chmod +x $OK/$i
5720					;;
5721				esac
5722			fi
5723		done
5724		PATH=$INSTALLROOT/bin/$OK:$PATH
5725		export PATH
5726	else	execrate=
5727	fi
5728	case $action in
5729	view)	exit 0 ;;
5730	esac
5731
5732	# all work under $INSTALLROOT/src
5733
5734	$make cd $INSTALLROOT/src
5735
5736	# record the build host name
5737
5738	case $noexec in
5739	'')	hostinfo name
5740		echo "$_hostinfo_" | sed 's,\..*,,' > $PACKAGEBIN/gen/host
5741		;;
5742	esac
5743
5744	# make in parallel if possible
5745
5746	case $NPROC in
5747	'')	hostinfo cpu
5748		case $_hostinfo_ in
5749		0|1)	;;
5750		*)	NPROC=$_hostinfo_
5751			$show NPROC=$NPROC
5752			$show export NPROC
5753			export NPROC
5754			;;
5755		esac
5756		;;
5757	esac
5758
5759	# separate flags from target list
5760
5761	case $target in
5762	*-*)	a=
5763		for t in $target
5764		do	case $t in
5765			-[eiknFKNV]*|--*-symbols)
5766				makeflags="$makeflags $t"
5767				;;
5768			-*)	nmakeflags="$nmakeflags $t"
5769				;;
5770			*)	a="$a $t"
5771				;;
5772			esac
5773		done
5774		target=$a
5775		;;
5776	esac
5777
5778	# generate nmake first if possible
5779
5780	if	executable ! $NMAKE && test -d $PACKAGEROOT/src/cmd/nmake
5781	then	if	nonmake $MAKE
5782		then	note make $NMAKE with mamake
5783			c=$CC
5784			a=$assign
5785			case $HOSTTYPE in
5786			win32*|cygwin*)
5787				CC="$CC -D_BLD_STATIC"
5788				accept="libast"
5789				case $assign in
5790				*' CC='*)	;;
5791				*)		assign="$assign CC=\"\$CC\"" ;;
5792				esac
5793				;;
5794			*)	accept=nmake
5795				;;
5796			esac
5797			eval capture mamake \$makeflags \$nmakeflags \$noexec install nmake $assign
5798			assign=$a
5799			CC=$c
5800			case $make$noexec in
5801			'')	if	executable ! $NMAKE
5802				then	echo "$command: $action: errors making $NMAKE" >&2
5803					exit 1
5804				fi
5805				;;
5806			*)	make=echo
5807				;;
5808			esac
5809			if	test '' != "$PROTOROOT"
5810			then	if	(vpath $INSTALLROOT - $PROTOROOT - $INSTALLROOT $PACKAGEROOT) >/dev/null 2>&1 &&
5811					 vpath $INSTALLROOT - $PROTOROOT - $INSTALLROOT $PACKAGEROOT
5812				then	$show vpath $INSTALLROOT $PACKAGEROOT $USER_VPATH_CHAIN
5813				else	VPATH=$INSTALLROOT:$PACKAGEROOT$USER_VPATH
5814					$show VPATH=$VPATH
5815					export VPATH
5816				fi
5817			fi
5818			note believe generated files for $accept
5819			eval capture \$NMAKE \$makeflags \$nmakeflags \$noexec recurse believe \$nmakesep $accept $assign
5820			$exec touch $INSTALLROOT/bin/.paths
5821			note make the remaining targets with $NMAKE
5822		else	eval capture $MAKE \$makeflags \$nmakeflags \$noexec install nmake $assign
5823			case $make$noexec in
5824			'')	if	executable ! $NMAKE
5825				then	echo "$command: $action: errors making $NMAKE" >&2
5826					exit 1
5827				fi
5828				;;
5829			*)	make=echo
5830				;;
5831			esac
5832		fi
5833	fi
5834
5835	# generate ksh next if possible
5836
5837	if	nonmake $MAKE
5838	then	: no need to generate ksh next -- it could be the only package
5839	elif	test "$KEEP_SHELL" != 1 -a -d $PACKAGEROOT/src/cmd/ksh93 && executable ! $KSH
5840	then	eval capture nmake $nmakeflags \$makeflags \$noexec install ksh93 $assign
5841		case $make$noexec in
5842		'')	if	executable ! $KSH
5843			then	echo "$command: $action: errors making $KSH" >&2
5844				exit 1
5845			fi
5846			;;
5847		*)	make=echo
5848			;;
5849		esac
5850	fi
5851
5852	# mamprobe data should have been generated by this point
5853
5854	case $exec in
5855	'')	if	test ! -f $INSTALLROOT/bin/.paths -o -w $INSTALLROOT/bin/.paths
5856		then	N='
5857'
5858			b= f= h= n= p= u= B= L=
5859			if	test -f $INSTALLROOT/bin/.paths
5860			then	exec < $INSTALLROOT/bin/.paths
5861				while	read x
5862				do	case $x in
5863					'#'?*)		case $h in
5864							'')	h=$x ;;
5865							esac
5866							;;
5867					*BUILTIN_LIB=*)	b=$x
5868							;;
5869					*FPATH=*)	f=$x
5870							;;
5871					*PLUGIN_LIB=*)	p=$x
5872							;;
5873					*)		case $u in
5874							?*)	u=$u$N ;;
5875							esac
5876							u=$u$x
5877							;;
5878					esac
5879				done
5880			fi
5881			ifs=$IFS
5882			m=
5883			case $p in
5884			?*)	b=
5885				;;
5886			esac
5887			case $b in
5888			?*)	IFS='='
5889				set $b
5890				IFS=$ifs
5891				shift
5892				p="PLUGIN_LIB=$*"
5893				case $b in
5894				[Nn][Oo]*)	p=no$p ;;
5895				esac
5896				m=1
5897				;;
5898			esac
5899			case $f in
5900			'')	f="FPATH=../fun"
5901				m=1
5902				;;
5903			esac
5904			case $h in
5905			'')	h='# use { no NO } prefix to permanently disable #' ;;
5906			esac
5907			case $p in
5908			'')	p="PLUGIN_LIB=cmd"
5909				if	grep '^setv mam_cc_DIALECT .* EXPORT=[AD]LL' $INSTALLROOT/lib/probe/C/mam/* >/dev/null 2>&1
5910				then	p=no$p
5911				fi
5912				m=1
5913				;;
5914			esac
5915			case $m in
5916			1)	case $u in
5917				?*)	u=$N$u ;;
5918				esac
5919				echo "$h$N$p$N$f$N$u" > $INSTALLROOT/bin/.paths
5920				;;
5921			esac
5922		fi
5923		;;
5924	esac
5925
5926	# run from separate copies since nmake and ksh may be rebuilt
5927
5928	case $EXECROOT in
5929	$INSTALLROOT)
5930		$make cd $INSTALLROOT/bin
5931		if	executable /bin/cp
5932		then	cp=/bin/cp
5933		else	cp=cp
5934		fi
5935		if	executable /bin/mv
5936		then	mv=/bin/mv
5937		else	mv=mv
5938		fi
5939		if	executable /bin/rm
5940		then	rm=/bin/rm
5941		else	rm=rm
5942		fi
5943		for i in \
5944			ksh nmake tee cp ln mv rm \
5945			*ast*.dll *cmd*.dll *dll*.dll *shell*.dll
5946		do	executable $i && {
5947				cmp -s $i $OK/$i 2>/dev/null || {
5948					test -f $OK/$i &&
5949					$exec $execrate $rm $OK/$i </dev/null
5950					test -f $OK/$i &&
5951					$exec $execrate $mv $OK/$i $OK/$i.old </dev/null
5952					test -f $OK/$i &&
5953					case $exec:$i in
5954					:nmake|:ksh)
5955						echo "$command: $OK/$i: cannot update [may be in use by a running process] remove manually and try again" >&2
5956						exit 1
5957						;;
5958					esac
5959					$exec $execrate $cp $i $OK/$i
5960				}
5961			}
5962		done
5963		if	test -f ../lib/make/makerules.mo
5964		then	cmp -s ../lib/make/makerules.mo $OK/lib/makerules.mo ||
5965			$exec $execrate $cp -p ../lib/make/makerules.mo $OK/lib/makerules.mo ||
5966			$exec $execrate $cp ../lib/make/makerules.mo $OK/lib/makerules.mo
5967		fi
5968		if	executable $OK/nmake
5969		then	MAKE="$INSTALLROOT/bin/$OK/nmake LOCALRULESPATH=$INSTALLROOT/bin/$OK/lib"
5970		fi
5971		if	executable $OK/tee
5972		then	TEE=$INSTALLROOT/bin/$OK/tee
5973		fi
5974		if	test "$KEEP_SHELL" != 1 && executable $OK/ksh
5975		then	SHELL=$INSTALLROOT/bin/$OK/ksh
5976			export SHELL
5977			COSHELL=$SHELL
5978			export COSHELL
5979		fi
5980		case :$PATH: in
5981		*:$INSTALLROOT/bin/$OK:*)
5982			;;
5983		*)	PATH=$INSTALLROOT/bin/$OK:$PATH
5984			export PATH
5985			;;
5986		esac
5987		$make cd $INSTALLROOT/src
5988		;;
5989	esac
5990
5991	# fall back to mamake if nmake not found or too old
5992
5993	if	nonmake $MAKE
5994	then	note make with mamake
5995		case $target in
5996		'')	target="install" ;;
5997		esac
5998		eval capture mamake \$makeflags \$noexec \$target $assign
5999	else	case $target in
6000		'')	target="install cc-" ;;
6001		esac
6002		eval capture \$MAKE \$makeflags \$nmakeflags \$noexec recurse \$target \$nmakesep \$package $assign
6003	fi
6004	;;
6005
6006read)	case ${PWD:-`pwd`} in
6007	$PACKAGEROOT)
6008		;;
6009	*)	echo "$command: must be in package root directory" >&2
6010		exit 1
6011		;;
6012	esac
6013	PAX=
6014	if	onpath pax
6015	then	case `$_onpath_ -rw --?meter 2>&1` in
6016		*--meter*)	PAX=pax ;;
6017		esac
6018	fi
6019	code=0
6020	i=
6021	x=
6022	remove=
6023	touch=
6024	set '' $target
6025	case $2 in
6026	lcl|tgz)tgz=$2
6027		shift 2
6028		target=$*
6029		;;
6030	*)	tgz=tgz
6031		;;
6032	esac
6033	set '' $package $target
6034	case $# in
6035	1)	verbose=:
6036		set '' `ls lib/package/$tgz/*?[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.]* 2>/dev/null`
6037		;;
6038	*)	verbose=
6039		;;
6040	esac
6041	shift
6042	files=
6043	for f
6044	do	if	test -f "$f"
6045		then	: ok
6046		elif	test -f "lib/package/$tgz/$f"
6047		then	f=lib/package/$tgz/$f
6048		else	set '' `ls -r ${f}[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.]* 2>/dev/null`
6049			if	test '' != "$2" -a -f "$2"
6050			then	f=$2
6051			else	set '' `ls -r lib/package/$tgz/${f}[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.]* 2>/dev/null`
6052				if	test '' != "$2" -a -f "$2"
6053				then	f=$2
6054				else	echo "$command: $f: package archive not found" >&2
6055					continue
6056				fi
6057			fi
6058		fi
6059		files="$files $f"
6060	done
6061	case $files in
6062	'')	echo "$command: lib/package/$tgz: no package archives" >&2
6063		exit 1
6064		;;
6065	esac
6066	set '' `ls -r $files 2>/dev/null`
6067	shift
6068	f1= f2= f3= f4=
6069	for f
6070	do	case $f in
6071		ratz.*|*/ratz.*)
6072			f1="$f1 $f"
6073			;;
6074		INIT.*|*/INIT.*)
6075			f2="$f2 $f"
6076			;;
6077		INIT*|*/INIT*)
6078			f3="$f3 $f"
6079			;;
6080		*)	f4="$f4 $f"
6081			;;
6082		esac
6083	done
6084	gen=
6085	set '' $f1 $f2 $f3 $f4
6086	while	:
6087	do	shift
6088		case $# in
6089		0)	break ;;
6090		esac
6091		f=$1
6092		case $f in
6093		*.gz)	: standalone packages unbundled manually
6094			continue
6095			;;
6096		*.md5)	: tarball checksum
6097			continue
6098			;;
6099		*?[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.]*)
6100			;;
6101		*)	echo "$command: $f: not a package archive" >&2
6102			code=1
6103			continue
6104			;;
6105		esac
6106		case $f in
6107		*/*)	eval `echo "$f" | sed -e 's,\(.*/\)\(.*\),d=\1 a=\2,'` ;;
6108		*)	d= a=$f ;;
6109		esac
6110		# f:file d:dir a:base p:package v:version r:release t:type
6111		eval `echo "$a" | sed -e 's,\.c$,,' -e 's,\.gz$,,' -e 's,\.exe$,,' -e 's,\.tgz$,,' -e 's,\([^_.]*\)[_.]\([0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]\)[_.]\([0123456789][0123456789][0123456789][0123456789][^_.]*\)[_.]*\(.*\),p=\1 v=\2 r=\3 t=\4,' -e 's,\([^_.]*\)[_.]\([0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]\)[_.]*\(.*\),p=\1 v=\2 r=base t=\3,'`
6112		case $r in
6113		base)	y=$p.base ;;
6114		*)	y=$p.delta ;;
6115		esac
6116		case " $x " in
6117		*" $y "*)
6118			continue
6119			;;
6120		esac
6121		case $t in
6122		'')	w=$PACKAGESRC
6123			q=
6124			Q=
6125			m=
6126			;;
6127		*)	w=$PACKAGEROOT/arch/$t/lib/package
6128			q=".$t"
6129			Q="_$t"
6130			m="[_.]$t"
6131			;;
6132		esac
6133		u=$d$p$q.tim
6134		if	test -s "$u"
6135		then	continue
6136		else	case $force in
6137			0)	case `ls -t "$f" "$u" 2>/dev/null` in
6138				"$u"*)	case $verbose in
6139					1)	note $p already read ;;
6140					esac
6141					continue
6142					;;
6143				esac
6144				;;
6145			esac
6146		fi
6147		case $p in
6148		INIT)	if	test -f $PACKAGEROOT/bin/package
6149			then	$exec mv $PACKAGEROOT/bin/package $PACKAGEROOT/bin/package.old
6150			fi
6151			;;
6152		esac
6153		z=
6154		case $r in
6155		base)	# base archive
6156			if	test ratz = "$p"
6157			then	# ratz packages are not archives
6158				case $t in
6159				'')	for i in src src/cmd src/cmd/INIT
6160					do	test -d $PACKAGEROOT/$i || $exec mkdir $PACKAGEROOT/$i || exit
6161					done
6162					$exec cp $f $PACKAGEROOT/src/cmd/INIT/$p.c
6163					;;
6164				*)	for i in arch arch/$t arch/$t/bin
6165					do	test -d $PACKAGEROOT/$i || $exec mkdir $PACKAGEROOT/$i || exit
6166					done
6167					$exec cp $f $PACKAGEROOT/arch/$t/bin/$p &&
6168					$exec chmod +x $PACKAGEROOT/arch/$t/bin/$p
6169					;;
6170				esac
6171			elif	test "" != "$PAX"
6172			then	$exec pax -L --from=ascii --local -m -ps -rvf "$f" || {
6173					code=1
6174					continue
6175				}
6176			else	if	onpath gunzip && onpath $TAR && isascii
6177				then	case $TARPROBE in
6178					?*)	for i in $TARPROBE
6179						do	if	$TAR ${i}f - /dev/null > /dev/null 2>&1
6180							then	TARFLAGS=$TARFLAGS$i
6181							fi
6182						done
6183						TARPROBE=
6184						;;
6185					esac
6186					if	gunzip -l < "$f" > /dev/null 2>&1
6187					then	case $exec in
6188						'')	$exec gunzip < "$f" | $TAR ${TARFLAGS}f - ;;
6189						*)	$exec "gunzip < $f | $TAR ${TARFLAGS}f -" ;;
6190						esac || {
6191							code=1
6192							continue
6193						}
6194					else	$exec $TAR ${TARFLAGS}f "$f" || {
6195							code=1
6196							continue
6197						}
6198					fi
6199				else	checkaout ratz && onpath ratz || {
6200						code=1
6201						continue
6202					}
6203					RATZ=$_onpath_
6204					case $exec in
6205					'')	echo $f:
6206						$exec $RATZ -lm < "$f"
6207						;;
6208					*)	$exec "$RATZ -lm < $f"
6209						;;
6210					esac || {
6211						code=1
6212						continue
6213					}
6214				fi
6215				if	test -f $PACKAGEBIN/gen/$p.sum
6216				then	while	read md5 mode usr grp file
6217					do	case $file in
6218						-*)	file=./$file ;;
6219						esac
6220						case $mode in
6221						[01234567][01234567][01234567][01234567])
6222							case $grp in
6223							-)	;;
6224							*)	$exec chgrp $grp "$file" ;;
6225							esac
6226							case $usr in
6227							-)	;;
6228							*)	$exec chown $usr "$file" ;;
6229							esac
6230							$exec chmod $mode "$file"
6231							;;
6232						esac
6233					done < $PACKAGEBIN/gen/$p.sum
6234				fi
6235			fi
6236			;;
6237		*)	# delta archive
6238			test "" != "$PAX" || {
6239				echo "$command: $f: pax required to read delta archive" >&2
6240				code=1
6241				continue
6242			}
6243			case `echo "$v:
6244$r:" | sort` in
6245			$r:*)	y=$p.base
6246				b=${d}${p}_${r}${Q}.tgz
6247				test -f "$b" || b=${d}${p}.${r}${q}.tgz
6248				test -f "$b" || {
6249					case " $gen " in
6250					*" $b "*)
6251						;;
6252					*)	case $# in
6253						1)	echo "$command: $f: base archive $b required to read delta" >&2
6254							code=1
6255							;;
6256						*)	shift
6257							y=$1
6258							shift
6259						set '' $y $f "$@"
6260						esac
6261						continue
6262						;;
6263					esac
6264				}
6265				# -m with delta bug fixed 2005-02-08
6266				$exec pax -L --from=ascii --local -ps -rvf "$f" -z "$b" || {
6267					code=1
6268					continue
6269				}
6270				note $f: generate new base $d$p.$v$q.tgz
6271				$exec pax -rf "$f" -z "$b" -wf $d$p.$v$q.tgz -x tgz || {
6272					code=1
6273					continue
6274				}
6275				case $exec in
6276				'')	echo $p $v $v 1 > $w/gen/$p.ver
6277					;;
6278				*)	z=$d${p}[_.]$v$q.tgz
6279					$exec "echo $p $v $v 1 > $w/gen/$p.ver"
6280					gen="$gen $d$p.$v$q.tgz"
6281					;;
6282				esac
6283				case " $remove " in
6284				*" $f "*)	;;
6285				*)		remove="$remove $f" ;;
6286				esac
6287				;;
6288			*)	b=${d}${p}_${v}${Q}.tgz
6289				test -f "$b" || b=${d}${p}.${v}${q}.tgz
6290				test -f "$b" || {
6291					case " $gen " in
6292					*" $b "*)
6293						;;
6294					*)	case $# in
6295						1)	echo "$command: $f: base archive $b required to read delta" >&2
6296							code=1
6297							;;
6298						*)	shift
6299							y=$1
6300							shift
6301							set '' $y $f "$@"
6302						esac
6303						continue
6304						;;
6305					esac
6306				}
6307				# -m with delta bug fixed 2005-02-08
6308				$exec pax -L --from=ascii --local -ps -rvf "$f" -z "$b" || {
6309					code=1
6310					continue
6311				}
6312				;;
6313			esac
6314			;;
6315		*)	echo "$command: $f: unknown archive type" >&2
6316			code=1
6317			continue
6318			;;
6319		esac
6320
6321		# check for ini files
6322
6323		if	executable $w/$p.ini
6324		then	$exec $w/$p.ini read || {
6325				code=1
6326				continue
6327			}
6328		fi
6329
6330		# add to the obsolete list
6331
6332		k=
6333		for i in `ls $d$p[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.]????$m* $z 2>/dev/null`
6334		do	case $i in
6335			*.md5)	continue
6336				;;
6337			$d${p}[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789][_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]$m*)
6338				;;
6339			$d${p}[_.][0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]$m*)
6340				continue
6341				;;
6342			esac
6343			case $k in
6344			?*)	case " $remove " in
6345				*" $k "*)	;;
6346				*)		remove="$remove $k" ;;
6347				esac
6348				;;
6349			esac
6350			k=$i
6351		done
6352		x="$x $y"
6353		case " $touch " in
6354		*" $u "*)	;;
6355		*)		touch="$touch $u" ;;
6356		esac
6357	done
6358	if	test ! -f $PACKAGEROOT/bin/package -a -f $PACKAGEROOT/bin/package.old
6359	then	$exec cp $PACKAGEROOT/bin/package.old $PACKAGEROOT/bin/package
6360	fi
6361
6362	# drop obsolete archives
6363
6364	case $remove in
6365	?*)	$exec rm -f $remove ;;
6366	esac
6367
6368	# mark the updated archives
6369
6370	case $touch in
6371	?*)	sleep 1; $exec touch $touch ;;
6372	esac
6373
6374	# check the requirements
6375
6376	case $code$exec in
6377	0)	requirements - $x ;;
6378	esac
6379	exit $code
6380	;;
6381
6382regress)if	test ! -d $PACKAGEBIN/gen
6383	then	echo "$command: 'package make' and 'package test' required for regression" >&2
6384		exit 1
6385	fi
6386	dir=$PACKAGEBIN/gen
6387	cd $dir
6388	for s in out old
6389	do	case `ls -t regress.$s test.$s 2>/dev/null` in
6390		regress*)
6391			;;
6392		test*)	if	test -f regress.$s
6393			then	$exec mv regress.$s regress.old
6394			fi
6395			case $exec in
6396			'')	egrep -i '\*\*\*|FAIL|^TEST.* [123456789][0123456789]* error|core.*dump' test.$s |
6397				sed 	-e '/\*\*\* [0123456789]/d' \
6398					-e '/^TEST.\//s,/[^ ]*/,,' \
6399					-e 's,[ 	][ 	]*$,,' \
6400					-e 's/[0123456789][0123456789]*:* \([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 ]*([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 ]*[Cc][Oo][Rr][Ee][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 ]*)\)/\1/' \
6401					-e 's/\.sh failed at .* with /.sh failed /' \
6402					> regress.$s
6403				;;
6404			*)	$exec filter test failures from $dir/test.$s to $dir/regress.$s
6405				;;
6406			esac
6407			;;
6408		esac
6409	done
6410	if	test -f regress.out -a -f regress.old
6411	then	$exec diff -b regress.out regress.old
6412	else	echo "$command: at least 2 test runs required for regression" >&2
6413			exit 1
6414	fi
6415	;;
6416
6417release)count= lo= hi=
6418	checksrc
6419	checkaout release || exit
6420	requirements source $package
6421	components $package
6422	package=$_components_
6423	set '' $target
6424	shift
6425	case $# in
6426	0)	;;
6427	*)	case $1 in
6428		-|[0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]|[0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789])
6429			case $1 in
6430			-)	lo= release= ;;
6431			*)	lo=$1 release="-f $1" ;;
6432			esac
6433			shift
6434			case $1 in
6435			-|[0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]|[0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789])
6436				case $1 in
6437				-)	hi= ;;
6438				*)	hi=$1 release="$release -t $1" ;;
6439				esac
6440				shift
6441				;;
6442			esac
6443			;;
6444		[0123456789]|[0123456789][0123456789]|[0123456789][0123456789][0123456789]|[0123456789][0123456789][0123456789][0123456789]|[0123456789][0123456789][0123456789][0123456789][0123456789]*)
6445			count=$1
6446			release="-r $count"
6447			shift
6448			;;
6449		esac
6450		;;
6451	esac
6452	case $# in
6453	0)	case $package in
6454		'')	package=* ;;
6455		esac
6456		;;
6457	*)	case $package in
6458		'')	package=$*
6459			;;
6460		*)	echo $command: $*: lo-date hi-date arguments expected >&2
6461			exit 1
6462			;;
6463		esac
6464		;;
6465	esac
6466	echo
6467	case $count:$lo:$hi in
6468	::)	echo "All recorded changes follow." ;;
6469	1::)	echo "Changes since the last release follow." ;;
6470	?*::)	echo "Changes since the last $count releases follow." ;;
6471	1:?*:)	echo "Changes since $lo or the last release follow." ;;
6472	*:?*:*)	echo "Changes since $lo follow." ;;
6473	*::?*)	echo "Changes before $hi follow." ;;
6474	*)	echo "Changes between $lo and $hi follow." ;;
6475	esac
6476	x=
6477	for r in $INSTALLROOT $PACKAGEROOT
6478	do	for s in $package_src
6479		do	d=$r/src/$s
6480			if	test -d $d
6481			then	cd $d
6482				for i in $package
6483				do	if	test -h $i 2>/dev/null
6484					then	continue
6485					fi
6486					case " $x " in
6487					*" $i "*)	continue ;;
6488					esac
6489					for f in RELEASE CHANGES ChangeLog
6490					do	if	test -f $i/$f
6491						then	$exec release $release $i/$f
6492							x="$x $i"
6493							for f in $i/*/$f
6494							do	if	test -f $f
6495								then	$exec release $release $f
6496								fi
6497							done
6498							break
6499						fi
6500					done
6501				done
6502			fi
6503		done
6504	done
6505	;;
6506
6507remove)	echo "$command: $action: not implemented yet" >&2
6508	exit 1
6509	;;
6510
6511results)set '' $target
6512	shift
6513	def=make
6514	dir=$PACKAGEBIN/gen
6515	case $verbose in
6516	0)	filter=yes ;;
6517	*)	filter=cat ;;
6518	esac
6519	path=0
6520	suf=out
6521	on=
6522	while	:
6523	do	case $# in
6524		0)	break ;;
6525		esac
6526		case $1 in
6527		--)	shift
6528			break
6529			;;
6530		admin)	dir=$PACKAGESRC/admin
6531			;;
6532		error*|fail*)
6533			filter=errors
6534			;;
6535		make|test|view|write)
6536			def=$1
6537			case $filter:$1:$SHELL in
6538			errors:*:*)	;;
6539			*:test:*/ksh*)	filter=rt ;;
6540			esac
6541			;;
6542		old)	suf=old
6543			;;
6544		on)	case $# in
6545			1)	echo $command: $action: $1: host pattern argument expected >&2
6546				exit 1
6547				;;
6548			esac
6549			shift
6550			case $on in
6551			?*)	on="$on|" ;;
6552			esac
6553			on="$on$1"
6554			;;
6555		path)	path=1
6556			;;
6557		test)	def=test
6558			filter=rt
6559			;;
6560		*)	break
6561			;;
6562		esac
6563		shift
6564	done
6565	case $dir in
6566	*/admin)case $on in
6567		'')	on="*" ;;
6568		*)	on="@($on)" ;;
6569		esac
6570		def=$def.log/$on
6571		;;
6572	esac
6573	case $# in
6574	0)	set "$def" ;;
6575	esac
6576	m=
6577	t=
6578	for i
6579	do	k=0
6580		eval set '""' $i - $i.$suf - $dir/$i - $dir/$i.$suf -
6581		shift
6582		for j
6583		do	case $j in
6584			-)	case $k in
6585				1)	continue 2 ;;
6586				esac
6587				;;
6588			*)	if	test -f $j
6589				then	k=1
6590					case /$j in
6591					*/test.*)	t="$t $j" ;;
6592					*)		m="$m $j" ;;
6593					esac
6594				fi
6595				;;
6596			esac
6597		done
6598		echo "$command: $i action output not found" >&2
6599		exit 1
6600	done
6601	sep=
6602	case $t in
6603	?*)	case $path in
6604		0)	for j in $t
6605			do	echo "$sep==> $j <=="
6606				sep=$nl
6607				case $filter in
6608				cat)	$exec cat $j
6609					;;
6610				errors)	$exec egrep -i '\*\*\*|FAIL[ES]|^TEST.* [123456789][0123456789]* error|core.*dump' $j | sed -e '/^TEST.\//s,/[^ ]*/,,'
6611					;;
6612				rt)	$exec $KSH rt - $j
6613					;;
6614				*)	$exec egrep -i '^TEST|FAIL' $j
6615					;;
6616				esac
6617			done
6618			;;
6619		1)	echo $t
6620			;;
6621		esac
6622		;;
6623	esac
6624	case $m in
6625	?*)	case $path in
6626		0)	case $filter in
6627			cat)	cat $m
6628				;;
6629			*)	if	test -f $HOME/.pkgresults
6630				then	i="`cat $HOME/.pkgresults`"
6631					case $i in
6632					'|'*)	;;
6633					*)	i="|$i" ;;
6634					esac
6635				else	i=
6636				fi
6637				for j in $m
6638				do	echo "$sep==> $j <=="
6639					sep=$nl
6640					case $filter in
6641					errors)	$exeg egrep '^pax:|\*\*\*' $j
6642						;;
6643					*)	$exec egrep -iv '^($||[\+\[]|cc[^-:]|kill |make.*(file system time|has been replaced)|so|[0123456789]+ error|uncrate |[0123456789]+ block|ar: creat|iffe: test: |conf: (check|generate|test)|[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*=|gsf@research|ar:.*warning|cpio:|ld:.*(duplicate symbol|to obtain more information)|[0123456789]*$|(checking|creating|touch) [/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789])| obsolete predefined symbol | is (almost always misused|dangerous|deprecated|not implemented)| trigraph| assigned to | cast .* different size| integer overflow .*<<| optimization may be attained | passed as |::__builtin|pragma.*prototyped|^creating.*\.a$|warning.*not optimized|exceeds size thresh|ld:.*preempts|is unchanged|with value >=|(-l|lib)\*|/(ast|sys)/(dir|limits|param|stropts)\.h.*redefined|usage|base registers|`\.\.\.` obsolete'"$i" $j |
6644						$exec grep :
6645						;;
6646					esac
6647				done
6648				;;
6649			esac
6650			;;
6651		1)	echo $m
6652			;;
6653		esac
6654	esac
6655	;;
6656
6657test)	requirements source $package
6658	components $package
6659	package=$_components_
6660	case $only in
6661	0)	only= ;;
6662	1)	only=--recurse=only ;;
6663	esac
6664
6665	# must have nmake
6666
6667	if	nonmake $MAKE
6668	then	echo $command: $action: must have $MAKE to test >&2
6669		exit 1
6670	fi
6671
6672	# all work under $INSTALLROOT/src
6673
6674	$make cd $INSTALLROOT/src
6675
6676	# disable core dumps (could be disasterous over nfs)
6677
6678	(ulimit -c 0) > /dev/null 2>&1 && ulimit -c 0
6679
6680	# do the tests
6681
6682	eval capture \$MAKE \$makeflags \$noexec \$only recurse test \$target \$nmakesep \$package $assign
6683	;;
6684
6685update)	# download the latest release.version for selected packages
6686
6687	# all work in $PACKAGEROOT/lib/package/tgz
6688
6689	if	test ! -d $PACKAGEROOT/lib/package/tgz
6690	then	$exec mkdir -p $PACKAGEROOT/lib/package/tgz || exit
6691		$exec cd $PACKAGEROOT/lib/package/tgz
6692	else	cd $PACKAGEROOT/lib/package/tgz
6693	fi
6694
6695	# get the architectures, update query url, and packages
6696
6697	set '' $args
6698	op=update
6699	tgz=tgz
6700	source=
6701	binary=
6702	setup=
6703	types=
6704	url=
6705	urlfile=$default_url
6706	while	:
6707	do	shift
6708		case $# in
6709		0)	break ;;
6710		esac
6711		case $1 in
6712		--)	shift
6713			break
6714			;;
6715		beta)	op=beta
6716			tgz=beta
6717			;;
6718		binary)	binary=1
6719			;;
6720		setup)	setup=1
6721			;;
6722		source)	source=1
6723			;;
6724		*://*)	url=$1
6725			shift
6726			break
6727			;;
6728		*.url)	urlfile=$1
6729			if	test ! -s $urlfile
6730			then	echo $command: $urlfile: not found >&2; exit 1
6731			fi
6732			break
6733			;;
6734		$all_types)
6735			binary=1
6736			types="$types $1"
6737			;;
6738		*)	break
6739			;;
6740		esac
6741	done
6742	case $source:$binary in
6743	:)	source=1 binary=1
6744		;;
6745	:1)	case $types in
6746		'')	types=$HOSTTYPE ;;
6747		esac
6748		;;
6749	esac
6750	case $url in
6751	'')	case $urlfile in
6752		$default_url)
6753			if	test ! -s $urlfile
6754			then	echo $command: url argument expected >&2; exit 1
6755			fi
6756			;;
6757		*)	default_url=
6758			;;
6759		esac
6760		url=
6761		if	grep '^url=' $urlfile >/dev/null
6762		then	a=$authorize
6763			p=$password
6764			case $urlfile in
6765			*/*)	;;
6766			*)	urlfile=./$urlfile ;;
6767			esac
6768			. $urlfile
6769			case $a:$p in
6770			$authorize:$password)
6771				default_url=
6772				;;
6773			*)	case $a in
6774				?*)	authorize=$a ;;
6775				esac
6776				case $p in
6777				?*)	password=$p ;;
6778				esac
6779				;;
6780			esac
6781		else	url=`cat $urlfile`
6782		fi
6783		;;
6784	esac
6785	case $exec in
6786	?*)	default_url= ;;
6787	esac
6788
6789	# get the update list
6790
6791	eval `echo $url | sed 's,\(.*\)://\([^/]*\)/\(.*\),prot=\"\1\" host=\"\2\" dir=\"\3\",'`
6792	get $host $dir/$op.html
6793
6794	# get/check the package names
6795
6796	case " $* " in
6797	*" - "*)case $source in
6798		1)	source_packages=$* ;;
6799		*)	source_packages= ;;
6800		esac
6801		case $binary in
6802		1)	binary_packages=$* ;;
6803		*)	binary_packages= ;;
6804		esac
6805		package_hit=$*
6806		;;
6807	"  ")	nl="
6808"
6809		case $source in
6810		1)	p=
6811			for f in `ls *.????-??-??.* 2>/dev/null`
6812			do	case $f in
6813				*.????-??-??.????-??-??.*.*)
6814					;;
6815				*.????-??-??.????-??-??.*)
6816					p=$p$nl$f
6817					;;
6818				*.????-??-??.*.*)
6819					;;
6820				*.????-??-??.*)
6821					p=$p$nl$f
6822					;;
6823				esac
6824			done
6825			set '' `echo "$p" | sed 's,\..*,,' | sort -u`
6826			shift
6827			source_packages=$*
6828			;;
6829		*)	source_packages=
6830			;;
6831		esac
6832		case $binary in
6833		1)	p=
6834			for f in `ls *.????-??-??.* 2>/dev/null`
6835			do	case $f in
6836				*.????-??-??.????-??-??.*.*)
6837					p=$p$nl$f
6838					;;
6839				*.????-??-??.????-??-??.*)
6840					;;
6841				*.????-??-??.*.*)
6842					p=$p$nl$f
6843					;;
6844				*.????-??-??.*)
6845					;;
6846				esac
6847			done
6848			set '' `echo "$p" | sed 's,\..*,,' | sort -u`
6849			shift
6850			binary_packages=$*
6851			;;
6852		*)	binary_packages=
6853			;;
6854		esac
6855		package_hit="$source_packages $binary_packages"
6856		;;
6857	*)	case $source in
6858		1)	source_packages=$* ;;
6859		*)	source_packages= ;;
6860		esac
6861		case $binary in
6862		1)	binary_packages=$* ;;
6863		*)	binary_packages= ;;
6864		esac
6865		package_hit=
6866		;;
6867	esac
6868
6869	# get the latest updates
6870
6871	types_test=
6872	types_local=
6873	dir=$dir/$tgz
6874	case $default_url in
6875	?*)	echo "url='$url' authorize='$authorize' password='$password'" > $default_url
6876		case $authorize in
6877		?*)	chmod go-rwx $default_url ;;
6878		esac
6879		;;
6880	esac
6881	echo "$got" > got.tmp
6882	case $only in
6883	0)	exec < got.tmp
6884		covered=
6885		while	read name suffix type base base_size delta delta_size sync sync_size requires covers base_sum delta_sum sync_sum comment
6886		do	case $requires in
6887			''|-*)	continue ;;
6888			esac
6889			IFS=:
6890			set '' $requires
6891			IFS=$ifs
6892			case $type in
6893			-)	case " $source_packages " in
6894				*" $name "*|*" - "*)
6895					for name
6896					do	case " $source_packages " in
6897						*" $name "*)
6898							;;
6899						*)	source_packages="$source_packages $name"
6900							covered=$covered:$covers
6901							;;
6902						esac
6903					done
6904					;;
6905				esac
6906				;;
6907			*)	case " $binary_packages " in
6908				*" $name "*|*" - "*)
6909					for name
6910					do	case " $binary_packages " in
6911						*" $name "*)
6912							;;
6913						*)	binary_packages="$binary_packages $name"
6914							covered=$covered:$covers
6915							;;
6916						esac
6917					done
6918					;;
6919				esac
6920				;;
6921			esac
6922		done
6923		case $covered in
6924		?*)	x=$source_packages
6925			source_packages=
6926			for name in $x
6927			do	case :$covered: in
6928				*:$name:*)	;;
6929				*)		source_packages="$source_packages $name" ;;
6930				esac
6931			done
6932			x=$binary_packages
6933			binary_packages=
6934			for name in $x
6935			do	case :$covered: in
6936				*:$name:*)	;;
6937				*)		binary_packages="$binary_packages $name" ;;
6938				esac
6939			done
6940			;;
6941		esac
6942		;;
6943	esac
6944	checksum=
6945	for i in $checksum_commands
6946	do	case `( $i ) < /dev/null 2> /dev/null` in
6947		${checksum_empty}|${checksum_empty}[\ \	]*)
6948			checksum=$i
6949			break
6950			;;
6951		esac
6952	done
6953	case $checksum in
6954	'')	echo $command: warning: '{' $checksum_commands '}' command not found -- only download sizes will be checked >&2 ;;
6955	esac
6956	exec < got.tmp
6957	while	read name suffix type base base_size delta delta_size sync sync_size requires covers base_sum delta_sum sync_sum comment
6958	do	case $verbose in
6959		1)	case $type in
6960			-)	i= ;;
6961			*)	i=.$type ;;
6962			esac
6963			j="$name.$base$i.$suffix"
6964			case $delta in
6965			-)	j="$j -" ;;
6966			*)	j="$j $name.$base.$delta$i.$suffix" ;;
6967			esac
6968			case $sync in
6969			-)	j="$j -" ;;
6970			*)	j="$j $name.$base.$sync$i.$suffix" ;;
6971			esac
6972			echo $command: $j $base_size:$base_sum $delta_size:$delta_sum $sync_size:$sync_sum $requires >&2
6973		esac
6974		case " $package_hit " in
6975		*" $name "*|*" - "*)
6976			;;
6977		*)	package_hit="$package_hit $name"
6978			;;
6979		esac
6980		case $type in
6981		-)	case " $source_packages " in
6982			*" $name "*|*" - "*)
6983				if	test -s $name.tim
6984				then	continue
6985				fi
6986				lcl=$name.$base.$suffix
6987				if	test -f $lcl
6988				then	case $checksum:$base_sum in
6989					:*|*:-)	size=`wc -c < $lcl | sed 's, ,,g'` sum=$base_sum ;;
6990					*)	size=$base_size sum=`$checksum < $lcl | sed -e 's,^[ 	][ 	]*,,' -e 's,[ 	].*,,'` ;;
6991					esac
6992				else	size=X sum=X
6993				fi
6994				if	test "0" != "$force" -a "X-" = "X$delta" -o "$base_size" != "$size" -o "$base_sum" != "$sum"
6995				then	rmt=
6996					case $sync:$sync_size in
6997					-*|*[-:])
6998						;;
6999					*)	lcl=$name.$base.$sync.$suffix
7000						if	test -f $lcl
7001						then	rmt=1
7002							get $host $dir $lcl $sync_size $sync_sum
7003						fi
7004						;;
7005					esac
7006					case $base:$base_size in
7007					-*|*[-:])
7008						;;
7009					*)	case $rmt in
7010						'')	lcl=$name.$base.$suffix
7011							get $host $dir $lcl $base_size $base_sum
7012							;;
7013						esac
7014						;;
7015					esac
7016				fi
7017				case $delta:$delta_size in
7018				-*|*[-:])
7019					;;
7020				*)	lcl=$name.$delta.$base.$suffix
7021					if	test -f $lcl
7022					then	case $checksum:$delta_sum in
7023						:*|*:-)	size=`wc -c < $lcl | sed 's, ,,g'` sum=$delta_sum ;;
7024						*)	size=$base_size sum=`$checksum < $lcl | sed -e 's,^[ 	][ 	]*,,' -e 's,[ 	].*,,'` ;;
7025						esac
7026					else	size=X sum=X
7027					fi
7028					if	test "0" != "$force" -o "$delta_size" != "$size" -o "$delta_sum" != "$sum"
7029					then	get $host $dir $lcl $delta_size $delta_sum
7030					fi
7031					;;
7032				esac
7033				;;
7034			esac
7035			;;
7036		*)	case " $binary_packages " in
7037			*" $name "*|*" - "*)
7038				if	test -s $name.$type.tim
7039				then	continue
7040				fi
7041				case " $types " in
7042				*" - "*);;
7043				"  ")	case " $types_test " in
7044					*" $type "*)
7045						;;
7046					*)	types_test="$types_test $type"
7047						for i in *.????-??-??.$type.* *.????-??-??.????-??-??.$type.*
7048						do	if	test -f $i
7049							then	types_local="$types_local $type"
7050							fi
7051							break
7052						done
7053						;;
7054					esac
7055					case " $types_local " in
7056					*" $type "*)
7057						;;
7058					*)	continue
7059						;;
7060					esac
7061					;;
7062				*)	case " $types " in
7063					*" $type "*)
7064						;;
7065					*)	continue
7066						;;
7067					esac
7068					;;
7069				esac
7070				lcl=$name.$base.$type.$suffix
7071				if	test -f $lcl
7072				then	case $checksum:$base_sum in
7073					:*|*:-)	size=`wc -c < $lcl | sed 's, ,,g'` sum=$base_sum ;;
7074					*)	size=$base_size sum=`$checksum < $lcl | sed -e 's,^[ 	][ 	]*,,' -e 's,[ 	].*,,'` ;;
7075					esac
7076				else	size=X sum=X
7077				fi
7078				if	test "0" != "$force" -a "X-" = "X$delta" -o "$base_size" != "$size" -o "$base_sum" != "$sum"
7079				then	rmt=
7080					case $sync:$sync_size in
7081					-*|*[-:])
7082						;;
7083					*)	lcl=$name.$base.$sync.$type.$suffix
7084						if	test -f $lcl
7085						then	rmt=1
7086							get $host $dir $lcl $sync_size $sync_sum
7087						fi
7088						;;
7089					esac
7090					case $base:$base_size in
7091					-*|*[-:])
7092						;;
7093					*)	case $rmt in
7094						'')	lcl=$name.$base.$type.$suffix
7095							get $host $dir $lcl $base_size $base_sum
7096							;;
7097						esac
7098						;;
7099					esac
7100				fi
7101				case $delta:$delta_size in
7102				-*|*[-:])
7103					;;
7104				*)	lcl=$name.$delta.$base.$type.$suffix
7105					if	test -f $lcl
7106					then	sum=`$checksum < $lcl | sed -e 's,^[ 	][ 	]*,,' -e 's,[ 	].*,,'`
7107					else	sum=X
7108					fi
7109					if	test -f $lcl
7110					then	case $checksum:$delta_sum in
7111						:*|*:-)	size=`wc -c < $lcl | sed 's, ,,g'` sum=$delta_sum ;;
7112						*)	size=$base_size sum=`$checksum < $lcl | sed -e 's,^[ 	][ 	]*,,' -e 's,[ 	].*,,'` ;;
7113						esac
7114					else	size=X sum=X
7115					fi
7116					if	test "0" != "$force" -o "$delta_size" != "$size" -o "$delta_sum" != "$sum"
7117					then	get $host $dir $lcl $delta_size $delta_sum
7118					fi
7119					;;
7120				esac
7121				;;
7122			esac
7123			;;
7124		esac
7125	done
7126	closure=
7127	for name in $source_packages $binary_packages
7128	do	case $name in
7129		-)	;;
7130		*)	case " $package_hit " in
7131			*" $name "*)
7132				case $setup in
7133				1)	case " $closure " in
7134					*" $name "*)
7135						;;
7136					*)	closure="$closure $name"
7137						;;
7138					esac
7139					;;
7140				esac
7141				;;
7142			*)	echo $command: $name: unknown package >&2
7143				;;
7144			esac
7145			;;
7146		esac
7147	done
7148	exec <&-
7149	rm -f got.tmp
7150	case $closure in
7151	?*)	echo $closure ;;
7152	esac
7153	;;
7154
7155use)	# finalize the environment
7156
7157	x=:..
7158	for d in `( cd $PACKAGEROOT; ls src/*/Makefile src/*/Nmakefile 2>/dev/null | sed 's,/[^/]*$,,' | sort -u )`
7159	do	x=$x:$INSTALLROOT/$d
7160	done
7161	x=$x:$INSTALLROOT
7162	case $CDPATH: in
7163	$x:*)	;;
7164	*)	CDPATH=$x:$CDPATH
7165		$show CDPATH=$CDPATH
7166		$show export CDPATH
7167		export CDPATH
7168		;;
7169	esac
7170	P=$PACKAGEROOT
7171	$show P=$P
7172	$show export P
7173	export P
7174	A=$INSTALLROOT
7175	$show A=$A
7176	$show export A
7177	export A
7178	case $NPROC in
7179	'')	hostinfo cpu
7180		case $_hostinfo_ in
7181		0|1)	;;
7182		*)	NPROC=$_hostinfo_
7183			$show NPROC=$NPROC
7184			$show export NPROC
7185			export NPROC
7186			;;
7187		esac
7188		;;
7189	esac
7190	eval PACKAGE_USE=$package_use
7191	export PACKAGE_USE
7192
7193	# run the command
7194
7195	case $run in
7196	'')	case $show in
7197		':')	$exec exec $SHELL ;;
7198		esac
7199		;;
7200	*)	$exec exec $SHELL -c "$run"
7201		;;
7202	esac
7203	;;
7204
7205verify)	cd $PACKAGEROOT
7206	requirements binary $package
7207	if	executable ! $SUM
7208	then	echo "$command: $action: $SUM command required" >&2
7209		exit 1
7210	fi
7211	case $target in
7212	'')	cd arch
7213		set '' *
7214		shift
7215		target=$*
7216		cd ..
7217		;;
7218	esac
7219	code=0
7220	for a in $target
7221	do	case $package in
7222		'')	set '' arch/$a/lib/package/gen/*.sum
7223			shift
7224			if	test -f $1
7225			then	for i
7226				do	package_verify $i || code=1
7227				done
7228			else	echo "$command: warning: $a: no binary packages" >&2
7229			fi
7230			;;
7231		*)	for i in $package
7232			do	if	test -f arch/$a/lib/package/gen/$i.sum
7233				then	package_verify arch/$a/lib/package/gen/$i.sum || code=1
7234				else	echo "$command: warning: $a: no binary package for $i" >&2
7235				fi
7236			done
7237			;;
7238		esac
7239	done
7240	exit $code
7241	;;
7242
7243write)	set '' $target
7244	shift
7245	action=
7246	list=
7247	qualifier=
7248	while	:
7249	do	case $1 in
7250		base|closure|delta|exp|lcl|pkg|rpm|tgz)
7251			qualifier="$qualifier $1"
7252			;;
7253		binary)	action=$1
7254			type=$HOSTTYPE
7255			eval list=$PACKAGESRC/tgz/$admin_list
7256			;;
7257		cyg)	qualifier="$qualifier $1"
7258			assign="$assign closure=1"
7259			only=1
7260			;;
7261		runtime|source)
7262			action=$1
7263			;;
7264		tst)	qualifier="$qualifier tgz"
7265			assign="$assign copyright=0 'PACKAGEDIR=\$(PACKAGESRC)/tst'"
7266			;;
7267		nocopyright)
7268			assign="$assign copyright=0"
7269			;;
7270		*)	break
7271			;;
7272		esac
7273		shift
7274	done
7275	case $action in
7276	'')	echo "$command: binary or source operand expected" >&2
7277		exit 1
7278		;;
7279	esac
7280	set '' "$@" $package
7281	shift
7282	case $only in
7283	0)	set '' `order "$@"`
7284		shift
7285		;;
7286	esac
7287	case $# in
7288	0)	echo "$command: at least one package name expected" >&2
7289		exit 1
7290		;;
7291	esac
7292	if	nonmake $MAKE
7293	then	echo "$command: must have $MAKE to generate archives" >&2
7294		exit 1
7295	fi
7296
7297	# all work under $PACKAGEBIN
7298
7299	$make cd $PACKAGEBIN
7300	case $list in
7301	?*)	$exec rm -f $list ;;
7302	esac
7303
7304	# go for it
7305
7306	for package
7307	do	if	view - all $package.pkg || view - all lib/package/$package.pkg
7308		then	eval capture \$MAKE \$makeflags -X ignore \$noexec -f \$package.pkg \$qualifier \$action $assign
7309		else	echo "$command: $package: not a package" >&2
7310		fi
7311	done
7312	;;
7313
7314TEST)	set '' $target $package
7315	shift
7316	case $1 in
7317	binary|source)
7318		action=$1
7319		shift
7320		;;
7321	esac
7322	order "$@"
7323	;;
7324
7325*)	echo "$command: $action: internal error" >&2
7326	exit 1
7327	;;
7328
7329esac
7330