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