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