1 .\" $NetBSD: crunchgen.1,v 1.27 2006/10/26 10:49:35 wiz Exp $
3 .\" Copyright (c) 1994 University of Maryland
4 .\" All Rights Reserved.
6 .\" Permission to use, copy, modify, distribute, and sell this software and its
7 .\" documentation for any purpose is hereby granted without fee, provided that
8 .\" the above copyright notice appear in all copies and that both that
9 .\" copyright notice and this permission notice appear in supporting
10 .\" documentation, and that the name of U.M. not be used in advertising or
11 .\" publicity pertaining to distribution of the software without specific,
12 .\" written prior permission. U.M. makes no representations about the
13 .\" suitability of this software for any purpose. It is provided "as is"
14 .\" without express or implied warranty.
16 .\" U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 .\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 .\" IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 .\" Author: James da Silva, Systems Design and Analysis Group
24 .\" Computer Science Department
25 .\" University of Maryland at College Park
32 .Nd generates build environment for a crunched binary
37 .Op Fl c Ar c-file-name
43 .Op Fl d Ar build-options
46 .Op Fl e Ar exec-file-name
52 .Op Fl m Ar makefile-name
59 A crunched binary is a program made up of many other programs linked
60 together into a single executable.
63 function determines which component program to run by the contents of
65 The main reason to crunch programs together is for fitting as many
66 programs as possible onto an installation or system recovery floppy.
69 reads in the specifications in
71 for a crunched binary, and generates a Makefile and accompanying
72 top-level C source file that when built create the crunched executable
73 file from the component programs.
74 For each component program,
76 can optionally attempt to determine the object (.o) files that make up
77 the program from its source directory Makefile.
78 This information is cached between runs.
80 uses the companion program
82 to eliminate link-time conflicts between the component programs by
83 hiding all unnecessary symbols.
87 is run, the crunched binary can be built by running
88 .Dq make -f Ao conf-name Ac Ns .mk .
89 The component programs' object files must already be built.
92 target, included in the output makefile, will
93 run make in each component program's source dir to build the object
95 This is not done automatically since in release
96 engineering circumstances it is generally not desirable to be
97 modifying objects in other directories.
99 The options are as follows:
100 .Bl -tag -width indent
101 .It Fl c Ar c-file-name
102 Set output C file name to
105 .Dq Ao confname Ac Ns .c .
107 Assume that relative source directory specifications begin with
109 .It Fl d Ar build-options
110 Set the DBG variable in the generated makefile to
112 The default flags are -Os.
113 .It Fl e Ar exec-file-name
114 Set crunched binary executable file name to
120 Forces the recalculation of cached parameters.
122 Try to obtain libraries from
124 .It Fl m Ar makefile-name
125 Set output Makefile name to
128 .Dq Ao conf-name Ac Ns .mk .
132 to parse the program's Makefile in determine the list of .o files.
135 expects the program's Makefile to have a program.ro target that links all
136 the program objects into a single relocatable.
138 Use existing object files.
139 Rather than rebuilding object files via reach-over
140 makefiles, instead search for and use existing object files.
143 Status messages are suppressed.
145 Append a variable specification to the on-the fly generated Makefile.
147 .Sh CRUNCHGEN CONFIGURATION FILE COMMANDS
149 reads specifications from the
151 that describe the components of the crunched binary.
153 use, the component program names are merely listed along with the
154 top-level source directories in which their sources can be found.
156 then calculates (via the source makefiles) and caches the
157 list of object files and their locations.
159 situations, the user can specify by hand all the parameters that
165 commands are as follows:
166 .Bl -tag -width indent
167 .It Nm srcdirs Ar dirname ...
168 A list of source trees in which the source directories of the
169 component programs can be found.
170 These dirs are searched using the
172 .Dq Ao source-dir Ac Ns / Ns Ao progname Ac Ns /
176 lines can be specified.
177 The directories are searched in the order they are given.
178 .It Nm progs Ar progname ...
179 A list of programs that make up the crunched binary.
182 lines can be specified.
183 .It Nm libs Ar libspec ...
184 A list of library specifications to be included in the crunched binary link.
187 lines can be specified.
188 .It Nm ln Ar progname linkname
189 Causes the crunched binary to invoke
194 This allows programs that change their behavior when
195 run under different names to operate correctly.
198 To handle specialized situations, such as when the source is not
199 available or not built via a conventional Makefile, the following
201 commands can be used to set
203 parameters for a component program.
204 .Bl -tag -width indent
205 .It Nm special Ar progname Nm keepsymbols Ar symbols ...
206 Don't hide the specified symbols for
208 Normally all externally visible symbols for
209 a program is hidden to avoid interference.
212 lines can be specified for given
214 .It Nm special Ar progname Nm srcdir Ar pathname
215 Set the source directory for
217 This is normally calculated by searching the specified
219 for a directory named
221 .It Nm special Ar progname Nm objdir Ar pathname
222 Set the obj directory for
224 This is normally calculated by looking for a directory named
228 and if that is not found, the
234 This option only takes effect if the -o option to use existing object files is also
236 .It Nm special Ar progname Nm objs Ar object-file-name ...
237 Set the list of object files for program
239 This is normally calculated by constructing a temporary makefile that includes
240 .Dq Nm srcdir / Pa Makefile
241 and outputs the value of $(OBJS).
244 lines can be specified for given
246 .It Nm special Ar progname Nm objpaths Ar full-pathname-to-object-file ...
247 Sets the pathnames of the object files for program
249 This is normally calculated by prepending the
251 pathname to each file in the
256 lines can be specified for given
262 parameter is actually needed by
264 but it is calculated from
268 which are in turn calculated from
270 so is sometimes convenient to specify the earlier parameters and let
272 calculate forward from there if it can.
274 The makefile produced by
278 target that will build the object files for each component program by
279 running make inside that program's source directory.
284 parameters must also be valid.
285 If they are not valid for a particular program, that
286 program is skipped in the
290 .Bl -tag -width MAKEOBJDIRPREFIX
291 .It Ev MAKEOBJDIRPREFIX
292 If the environment variable
294 is set, the object directory will be prefixed with the path contained in this
295 environment variable.
298 This variable is only used if the -o option to use existing object files is also
301 If the environment variable
303 is set, it is used as the name of the machine type, when accessing object
304 directories of the form obj.MACHINE.
305 If it is not set, it defaults to the machine type returned by
309 This option is only used if the -o option to use existing object files is also
312 If the environment variable
314 is set, it is used as the name of the
316 executable to be called.
317 If this environment variable is not set,
325 input conf file, named
328 .Bd -literal -offset indent
329 srcdirs /usr/src/bin /usr/src/sbin
331 progs test cp echo sh fsck halt init mount umount myinstall
332 ln test [ # test can be invoked via [
333 ln sh -sh # init invokes the shell with "-sh" in argv[0]
335 special myprog objpaths /homes/leroy/src/myinstall.o # no sources
340 This conf file specifies a small crunched binary consisting of some
341 basic system utilities plus a home-grown install program
343 for which no source directory is specified, but its object file is
344 specified directly with the
350 can be built as follows:
352 .Bd -literal -offset indent
353 % crunchgen -m Makefile kcopy.conf # gen Makefile and kcopy.c
354 % make objs # build the component programs' .o files
355 % make # build the crunched binary kcopy
356 % kcopy sh # test that this invokes a sh shell
360 At this point the binary
362 can be copied onto an install floppy
363 and hard-linked to the names of the component programs.
370 .An James da Silva Aq jds@cs.umd.edu .
372 Copyright (c) 1994 University of Maryland. All Rights Reserved.
376 takes care to eliminate link conflicts between the component programs
377 of a crunched binary, conflicts are still possible between the
378 libraries that are linked in.
379 Some shuffling in the order of
380 libraries may be required, and in some rare cases two libraries may
381 have an unresolvable conflict and thus cannot be crunched together.
385 build environment do not by default build the
386 intermediate object file for single-source file programs.
389 target must then be used to get those object files built, or
390 some other arrangements made.
392 If a program directory being searched for is found, but contains
393 no objects, other directories are not searched.
394 This causes the following directive to fail:
396 .Bd -literal -offset indent
397 srcdirs /usr/src/usr.bin /usr/src/usr.bin/less
402 .Pa /usr/src/usr.bin/less
403 directory will be found with the
406 entry, and as it does not contain the require objects,
408 fails to find objects for the
411 To avoid this problem, list specific srcdirs first, and
412 the more general ones later, for e.g.:
414 .Bd -literal -offset indent
415 srcdirs /usr/src/usr.bin/less /usr/src/usr.bin
419 will not have the above problem.