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