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