Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / crunch / crunchgen / crunchgen.1
1 .\"
2 .\" Copyright (c) 1994 University of Maryland
3 .\" All Rights Reserved.
4 .\"
5 .\" Permission to use, copy, modify, distribute, and sell this software and its
6 .\" documentation for any purpose is hereby granted without fee, provided that
7 .\" the above copyright notice appear in all copies and that both that
8 .\" copyright notice and this permission notice appear in supporting
9 .\" documentation, and that the name of U.M. not be used in advertising or
10 .\" publicity pertaining to distribution of the software without specific,
11 .\" written prior permission.  U.M. makes no representations about the
12 .\" suitability of this software for any purpose.  It is provided "as is"
13 .\" without express or implied warranty.
14 .\"
15 .\" U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
17 .\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
20 .\" IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 .\"
22 .\" Author: James da Silva, Systems Design and Analysis Group
23 .\"                        Computer Science Department
24 .\"                        University of Maryland at College Park
25 .\" $FreeBSD: src/usr.sbin/crunch/crunchgen/crunchgen.1,v 1.11.2.11 2003/03/12 22:08:13 trhodes Exp $
26 .\"
27 .Dd November 16, 2000
28 .Dt CRUNCHGEN 1
29 .Os
30 .Sh NAME
31 .Nm crunchgen
32 .Nd generates build environment for a crunched binary
33 .Sh SYNOPSIS
34 .Bk -words
35 .Nm
36 .Op Fl foql
37 .Op Fl h Ar makefile-header-name
38 .Op Fl m Ar makefile-name
39 .Op Fl p Ar obj-prefix
40 .Op Fl c Ar c-file-name
41 .Op Fl e Ar exec-file-name
42 .Op Ar conf-file
43 .Ek
44 .Sh DESCRIPTION
45 A crunched binary is a program made up of many other programs linked
46 together into a single executable.
47 The crunched binary
48 .Fn main
49 function determines which component program to run by the contents of
50 .Va argv[0] .
51 The main reason to crunch programs together is for fitting
52 as many programs as possible onto an installation or system recovery
53 floppy.
54 .Pp
55 The
56 .Nm
57 utility reads in the specifications in
58 .Ar conf-file
59 for a crunched binary, and generates a
60 .Pa Makefile
61 and accompanying
62 top-level C source file that when built creates the crunched executable
63 file from the component programs.
64 For each component program,
65 .Nm
66 can optionally attempt to determine the object (.o) files that make up
67 the program from its source directory
68 .Pa Makefile .
69 This information is cached between runs.
70 The
71 .Nm
72 utility uses the companion program
73 .Xr crunchide 1
74 to eliminate link-time conflicts between the component programs by
75 hiding all unnecessary symbols.
76 .Pp
77 The
78 .Nm
79 utility places specific requirements on package
80 .Pa Makefile Ns s
81 which make it unsuitable for use with
82 .No non- Ns Bx
83 sources.
84 In particular, the
85 .Pa Makefile
86 must contain the target
87 .Ic depend ,
88 and it must define all object files in the variable
89 .Va OBJS .
90 In some cases, you can use a fake
91 .Pa Makefile :
92 before looking for
93 .Pa Makefile
94 in the source directory
95 .Pa foo ,
96 .Nm
97 looks for the file
98 .Pa Makefile.foo
99 in the current directory.
100 .Pp
101 After
102 .Nm
103 is run, the crunched binary can be built by running
104 .Dq Li make -f <conf-name>.mk .
105 The component programs' object files must already be built.
106 An
107 .Ic objs
108 target, included in the output makefile, will
109 run
110 .Xr make 1
111 in each component program's source dir to build the object
112 files for the user.
113 This is not done automatically since in release
114 engineering circumstances it is generally not desirable to be
115 modifying objects in other directories.
116 .Pp
117 The options are as follows:
118 .Bl -tag -width indent
119 .It Fl c Ar c-file-name
120 Set output C file name to
121 .Ar c-file-name .
122 The default name is
123 .Pa <conf-name>.c .
124 .It Fl e Ar exec-file-name
125 Set crunched binary executable file name to
126 .Ar exec-file-name .
127 The default name is
128 .Pa <conf-name> .
129 .It Fl f
130 Flush cache.
131 Forces the recalculation of cached parameters.
132 .It Fl l
133 List names.
134 Lists the names this binary will respond to.
135 .It Fl h Ar makefile-header-name
136 Set the name of a file to be included at the beginning of the
137 .Pa Makefile Ns s
138 generated by
139 .Nm .
140 This is useful to define some make variables such as
141 .Va RELEASE_CRUNCH
142 or similar, which might affect the behaviour of
143 .Xr make 1
144 and are annoying to pass through environment variables.
145 .It Fl m Ar makefile-name
146 Set output
147 .Pa Makefile
148 name to
149 .Ar makefile-name .
150 The default name is
151 .Pa <conf-name>.mk .
152 .It Fl o
153 Add
154 .Dq Li make obj
155 rules to each program make target.
156 .It Fl p Ar obj-prefix
157 Set the pathname to be prepended to the
158 .Ic srcdir
159 when computing the
160 .Ic objdir .
161 If this option is not present, then the prefix used
162 is the content of the
163 .Ev MAKEOBJDIRPREFIX
164 environment variable, or
165 .Pa /usr/obj .
166 .It Fl q
167 Quiet operation.
168 Status messages are suppressed.
169 .El
170 .Sh CRUNCHGEN CONFIGURATION FILE COMMANDS
171 The
172 .Nm
173 utility reads specifications from the
174 .Ar conf-file
175 that describe the components of the crunched binary.
176 In its simplest
177 use, the component program names are merely listed along with the
178 top-level source directories in which their sources can be found.
179 The
180 .Nm
181 utility then calculates (via the source makefiles) and caches the
182 list of object files and their locations.
183 For more specialized
184 situations, the user can specify by hand all the parameters that
185 .Nm
186 needs.
187 .Pp
188 The
189 .Ar conf-file
190 commands are as follows:
191 .Bl -tag -width indent
192 .It Ic srcdirs Ar dirname ...
193 A list of source trees in which the source directories of the
194 component programs can be found.
195 These dirs are searched using the
196 .Bx
197 .Dq Pa <source-dir>/<progname>/
198 convention.
199 Multiple
200 .Ic srcdirs
201 lines can be specified.
202 The directories are searched in the order they are given.
203 .It Ic progs Ar progname ...
204 A list of programs that make up the crunched binary.
205 Multiple
206 .Ic progs
207 lines can be specified.
208 .It Ic libs Ar libspec ...
209 A list of library specifications to be included in the crunched binary link.
210 Multiple
211 .Ic libs
212 lines can be specified.
213 .It Ic buildopts Ar buildopts ...
214 A list of build options to be added to every make target.
215 .It Ic ln Ar progname linkname
216 Causes the crunched binary to invoke
217 .Ar progname
218 whenever
219 .Ar linkname
220 appears in
221 .Va argv[0] .
222 This allows programs that change their behavior when
223 run under different names to operate correctly.
224 .El
225 .Pp
226 To handle specialized situations, such as when the source is not
227 available or not built via a conventional
228 .Pa Makefile ,
229 the following
230 .Ic special
231 commands can be used to set
232 .Nm
233 parameters for a component program.
234 .Bl -tag -width indent
235 .It Ic special Ar progname Ic srcdir Ar pathname
236 Set the source directory for
237 .Ar progname .
238 This is normally calculated by searching the specified
239 .Ic srcdirs
240 for a directory named
241 .Ar progname .
242 .It Ic special Ar progname Ic objdir Ar pathname
243 Set the
244 .Pa obj
245 directory for
246 .Ar progname .
247 The
248 .Pa obj
249 directory is normally calculated by looking for a directory
250 whose name is that of the source directory prepended by
251 one of the following components, in order of priority:
252 the
253 .Fl p
254 argument passed to the command line; or,
255 the value of the
256 .Ev MAKEOBJDIRPREFIX
257 environment variable, or
258 .Pa /usr/obj .
259 If the directory is not found, the
260 .Ic srcdir
261 itself becomes the
262 .Ic objdir .
263 .It Ic special Ar progname Ic buildopts Ar buildopts
264 Define a set of build options that should be added to
265 .Xr make 1
266 targets in addition to those specified using
267 .Ic buildopts
268 when processing
269 .Ar progname .
270 .It Ic special Ar progname Ic objs Ar object-file-name ...
271 Set the list of object files for program
272 .Ar progname .
273 This is normally calculated by constructing a temporary makefile that includes
274 .Dq Ic srcdir Ns / Ns Pa Makefile
275 and outputs the value of
276 .Va $(OBJS) .
277 .It Ic special Ar progname Ic objpaths Ar full-pathname-to-object-file ...
278 Sets the pathnames of the object files for program
279 .Ar progname .
280 This is normally calculated by prepending the
281 .Ic objdir
282 pathname to each file in the
283 .Ic objs
284 list.
285 .It Ic special Ar progname Ic objvar Ar variable_name
286 Sets the name of the
287 .Xr make 1
288 variable which holds the list of
289 object files for program
290 .Ar progname .
291 This is normally
292 .Va OBJS
293 but some
294 .Pa Makefile Ns s
295 might like to use other conventions or
296 prepend the program's name to the variable, e.g.\&
297 .Va SSHD_OBJS .
298 .It Ic special Ar progname Ic lib Ar library-name ...
299 Specifies libraries to be linked with object files to produce
300 .Ar progname Ns Pa .lo .
301 This can be useful with libraries which redefine routines in
302 the standard libraries, or poorly written libraries which
303 reference symbols in the object files.
304 .It Ic special Ar progname Ic keep Ar symbol-name ...
305 Add specified list of symbols to the keep list for program
306 .Ar progname .
307 An underscore
308 .Pq Ql _
309 is prepended to each symbol and it becomes the argument to a
310 .Fl k
311 option for the
312 .Xr crunchide 1
313 phase.
314 This option is to be used as a last resort as its use can cause a
315 symbol conflict, however in certain instances it may be the only way to
316 have a symbol resolve.
317 .It Ic special Ar progname Ic ident Ar identifier
318 Set the
319 .Pa Makefile Ns / Ns Tn C
320 identifier for
321 .Ar progname .
322 This is normally generated from a
323 .Ar progname ,
324 mapping
325 .Ql -
326 to
327 .Ql _
328 and ignoring all other non-identifier characters.
329 This leads to programs named
330 .Qq Li foo.bar
331 and
332 .Qq Li foobar
333 to map to the same identifier.
334 .El
335 .Pp
336 Only the
337 .Ic objpaths
338 parameter is actually needed by
339 .Nm ,
340 but it is calculated from
341 .Ic objdir
342 and
343 .Ic objs ,
344 which are in turn calculated from
345 .Ic srcdir ,
346 so is sometimes convenient to specify the earlier parameters and let
347 .Nm
348 calculate forward from there if it can.
349 .Pp
350 The makefile produced by
351 .Nm
352 contains an optional
353 .Ic objs
354 target that will build the object files for each component program by
355 running
356 .Xr make 1
357 inside that program's source directory.
358 For this to work the
359 .Ic srcdir
360 and
361 .Ic objs
362 parameters must also be valid.
363 If they are not valid for a particular program, that
364 program is skipped in the
365 .Ic objs
366 target.
367 .Sh EXAMPLES
368 Here is an example
369 .Nm
370 input conf file, named
371 .Dq Pa kcopy.conf :
372 .Pp
373 .Bd -literal -offset indent
374 srcdirs /usr/src/bin /usr/src/sbin
375
376 progs test cp echo sh fsck halt init mount umount myinstall
377 progs anotherprog
378 ln test [       # test can be invoked via [
379 ln sh -sh       # init invokes the shell with "-sh" in argv[0]
380
381 special myprog objpaths /homes/leroy/src/myinstall.o # no sources
382
383 special anotherprog -DNO_FOO WITHOUT_BAR=YES
384
385 libs -lutil -lcrypt
386 .Ed
387 .Pp
388 This conf file specifies a small crunched binary consisting of some
389 basic system utilities plus a homegrown install program
390 .Dq Pa myinstall ,
391 for which no source directory is specified, but its object file is
392 specified directly with the
393 .Ic special
394 line.
395 .Pp
396 Additionally when
397 .Dq Pa anotherprog
398 is built the arguments
399 .Pp
400 .Dl -DNO_FOO WITHOUT_BAR=YES
401 .Pp
402 are added to all build targets.
403 .Pp
404 The crunched binary
405 .Dq Pa kcopy
406 can be built as follows:
407 .Pp
408 .Bd -literal -offset indent
409 % crunchgen -m Makefile kcopy.conf    # gen Makefile and kcopy.c
410 % make objs             # build the component programs' .o files
411 % make                  # build the crunched binary kcopy
412 % kcopy sh              # test that this invokes a sh shell
413 $                       # it works!
414 .Ed
415 .Pp
416 At this point the binary
417 .Dq Pa kcopy
418 can be copied onto an install floppy
419 and hard-linked to the names of the component programs.
420 .Sh SEE ALSO
421 .Xr crunchide 1 ,
422 .Xr make 1
423 .Sh CAVEATS
424 While
425 .Nm
426 takes care to eliminate link conflicts between the component programs
427 of a crunched binary, conflicts are still possible between the
428 libraries that are linked in.
429 Some shuffling in the order of
430 libraries may be required, and in some rare cases two libraries may
431 have an unresolvable conflict and thus cannot be crunched together.
432 .Pp
433 Some versions of the
434 .Bx
435 build environment do not by default build the
436 intermediate object file for single-source file programs.
437 The
438 .Dq Li make objs
439 must then be used to get those object files built, or
440 some other arrangements made.
441 .Sh AUTHORS
442 The
443 .Nm
444 utility was written by
445 .An James da Silva Aq jds@cs.umd.edu .
446 .Pp
447 Copyright (c) 1994 University of Maryland.
448 All Rights Reserved.