]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/crunch/crunchgen/crunchgen.1
Remove obsolete RELEASE_CRUNCH
[FreeBSD/FreeBSD.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$
26 .\"
27 .Dd January 6, 2017
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 .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 which might affect the behavior of
141 .Xr make 1
142 and are annoying to pass through environment variables.
143 .It Fl m Ar makefile-name
144 Set output
145 .Pa Makefile
146 name to
147 .Ar makefile-name .
148 The default name is
149 .Pa <conf-name>.mk .
150 .It Fl o
151 Add
152 .Dq Li make obj
153 rules to each program make target.
154 .It Fl p Ar obj-prefix
155 Set the pathname to be prepended to the
156 .Ic srcdir
157 when computing the
158 .Ic objdir .
159 If this option is not present, then the prefix used
160 is the content of the
161 .Ev MAKEOBJDIRPREFIX
162 environment variable, or
163 .Pa /usr/obj .
164 .It Fl q
165 Quiet operation.
166 Status messages are suppressed.
167 .El
168 .Sh CRUNCHGEN CONFIGURATION FILE COMMANDS
169 The
170 .Nm
171 utility reads specifications from the
172 .Ar conf-file
173 that describe the components of the crunched binary.
174 In its simplest
175 use, the component program names are merely listed along with the
176 top-level source directories in which their sources can be found.
177 The
178 .Nm
179 utility then calculates (via the source makefiles) and caches the
180 list of object files and their locations.
181 For more specialized
182 situations, the user can specify by hand all the parameters that
183 .Nm
184 needs.
185 .Pp
186 The
187 .Ar conf-file
188 commands are as follows:
189 .Bl -tag -width indent
190 .It Ic srcdirs Ar dirname ...
191 A list of source trees in which the source directories of the
192 component programs can be found.
193 These dirs are searched using the
194 .Bx
195 .Dq Pa <source-dir>/<progname>/
196 convention.
197 Multiple
198 .Ic srcdirs
199 lines can be specified.
200 The directories are searched in the order they are given.
201 .It Ic progs Ar progname ...
202 A list of programs that make up the crunched binary.
203 Multiple
204 .Ic progs
205 lines can be specified.
206 .It Ic libs Ar libspec ...
207 A list of library specifications to be included in the crunched binary link.
208 Multiple
209 .Ic libs
210 lines can be specified.
211 .It Ic libs_so Ar libspec ...
212 A list of library specifications to be dynamically linked in the
213 crunched binary.
214 These libraries will need to be made available via the run-time link-editor
215 .Xr rtld 1
216 when the component program that requires them is executed from
217 the crunched binary.
218 Multiple
219 .Ic libs_so
220 lines can be specified.
221 The
222 .Ic libs_so
223 directive overrides a library specified gratuitously on a
224 .Ic libs
225 line.
226 .It Ic buildopts Ar buildopts ...
227 A list of build options to be added to every make target.
228 .It Ic ln Ar progname linkname
229 Causes the crunched binary to invoke
230 .Ar progname
231 whenever
232 .Ar linkname
233 appears in
234 .Va argv[0] .
235 This allows programs that change their behavior when
236 run under different names to operate correctly.
237 .El
238 .Pp
239 To handle specialized situations, such as when the source is not
240 available or not built via a conventional
241 .Pa Makefile ,
242 the following
243 .Ic special
244 commands can be used to set
245 .Nm
246 parameters for a component program.
247 .Bl -tag -width indent
248 .It Ic special Ar progname Ic srcdir Ar pathname
249 Set the source directory for
250 .Ar progname .
251 This is normally calculated by searching the specified
252 .Ic srcdirs
253 for a directory named
254 .Ar progname .
255 .It Ic special Ar progname Ic objdir Ar pathname
256 Set the
257 .Pa obj
258 directory for
259 .Ar progname .
260 The
261 .Pa obj
262 directory is normally calculated by looking for a directory
263 whose name is that of the source directory prepended by
264 one of the following components, in order of priority:
265 the
266 .Fl p
267 argument passed to the command line; or,
268 the value of the
269 .Ev MAKEOBJDIRPREFIX
270 environment variable, or
271 .Pa /usr/obj .
272 If the directory is not found, the
273 .Ic srcdir
274 itself becomes the
275 .Ic objdir .
276 .It Ic special Ar progname Ic buildopts Ar buildopts
277 Define a set of build options that should be added to
278 .Xr make 1
279 targets in addition to those specified using
280 .Ic buildopts
281 when processing
282 .Ar progname .
283 .It Ic special Ar progname Ic objs Ar object-file-name ...
284 Set the list of object files for program
285 .Ar progname .
286 This is normally calculated by constructing a temporary makefile that includes
287 .Dq Ic srcdir Ns / Ns Pa Makefile
288 and outputs the value of
289 .Va $(OBJS) .
290 .It Ic special Ar progname Ic objpaths Ar full-pathname-to-object-file ...
291 Sets the pathnames of the object files for program
292 .Ar progname .
293 This is normally calculated by prepending the
294 .Ic objdir
295 pathname to each file in the
296 .Ic objs
297 list.
298 .It Ic special Ar progname Ic objvar Ar variable_name
299 Sets the name of the
300 .Xr make 1
301 variable which holds the list of
302 object files for program
303 .Ar progname .
304 This is normally
305 .Va OBJS
306 but some
307 .Pa Makefile Ns s
308 might like to use other conventions or
309 prepend the program's name to the variable, e.g.,
310 .Va SSHD_OBJS .
311 .It Ic special Ar progname Ic lib Ar library-name ...
312 Specifies libraries to be linked with object files to produce
313 .Ar progname Ns Pa .lo .
314 This can be useful with libraries which redefine routines in
315 the standard libraries, or poorly written libraries which
316 reference symbols in the object files.
317 .It Ic special Ar progname Ic keep Ar symbol-name ...
318 Add specified list of symbols to the keep list for program
319 .Ar progname .
320 An underscore
321 .Pq Ql _
322 is prepended to each symbol and it becomes the argument to a
323 .Fl k
324 option for the
325 .Xr crunchide 1
326 phase.
327 This option is to be used as a last resort as its use can cause a
328 symbol conflict, however in certain instances it may be the only way to
329 have a symbol resolve.
330 .It Ic special Ar progname Ic ident Ar identifier
331 Set the
332 .Pa Makefile Ns / Ns Tn C
333 identifier for
334 .Ar progname .
335 This is normally generated from a
336 .Ar progname ,
337 mapping
338 .Ql -
339 to
340 .Ql _
341 and ignoring all other non-identifier characters.
342 This leads to programs named
343 .Qq Li foo.bar
344 and
345 .Qq Li foobar
346 to map to the same identifier.
347 .El
348 .Pp
349 Only the
350 .Ic objpaths
351 parameter is actually needed by
352 .Nm ,
353 but it is calculated from
354 .Ic objdir
355 and
356 .Ic objs ,
357 which are in turn calculated from
358 .Ic srcdir ,
359 so is sometimes convenient to specify the earlier parameters and let
360 .Nm
361 calculate forward from there if it can.
362 .Pp
363 The makefile produced by
364 .Nm
365 contains an optional
366 .Ic objs
367 target that will build the object files for each component program by
368 running
369 .Xr make 1
370 inside that program's source directory.
371 For this to work the
372 .Ic srcdir
373 and
374 .Ic objs
375 parameters must also be valid.
376 If they are not valid for a particular program, that
377 program is skipped in the
378 .Ic objs
379 target.
380 .Sh EXAMPLES
381 Here is an example
382 .Nm
383 input conf file, named
384 .Dq Pa kcopy.conf :
385 .Bd -literal -offset indent
386 srcdirs /usr/src/bin /usr/src/sbin
387
388 progs test cp echo sh fsck halt init mount umount myinstall
389 progs anotherprog
390 ln test [       # test can be invoked via [
391 ln sh -sh       # init invokes the shell with "-sh" in argv[0]
392
393 special myprog objpaths /homes/leroy/src/myinstall.o # no sources
394
395 special anotherprog -DNO_FOO WITHOUT_BAR=YES
396
397 libs -lutil -lcrypt
398 .Ed
399 .Pp
400 This conf file specifies a small crunched binary consisting of some
401 basic system utilities plus a homegrown install program
402 .Dq Pa myinstall ,
403 for which no source directory is specified, but its object file is
404 specified directly with the
405 .Ic special
406 line.
407 .Pp
408 Additionally when
409 .Dq Pa anotherprog
410 is built the arguments
411 .Pp
412 .Dl -DNO_FOO WITHOUT_BAR=YES
413 .Pp
414 are added to all build targets.
415 .Pp
416 The crunched binary
417 .Dq Pa kcopy
418 can be built as follows:
419 .Bd -literal -offset indent
420 % crunchgen -m Makefile kcopy.conf    # gen Makefile and kcopy.c
421 % make objs             # build the component programs' .o files
422 % make                  # build the crunched binary kcopy
423 % kcopy sh              # test that this invokes a sh shell
424 $                       # it works!
425 .Ed
426 .Pp
427 At this point the binary
428 .Dq Pa kcopy
429 can be copied onto an install floppy
430 and hard-linked to the names of the component programs.
431 .Pp
432 Note that if the
433 .Ic libs_so
434 command had been used, copies of the libraries so named
435 would also need to be copied to the install floppy.
436 .Sh SEE ALSO
437 .Xr crunchide 1 ,
438 .Xr make 1 ,
439 .Xr rtld 1
440 .Sh AUTHORS
441 .An -nosplit
442 The
443 .Nm
444 utility was written by
445 .An James da Silva Aq Mt jds@cs.umd.edu .
446 .Pp
447 Copyright (c) 1994 University of Maryland.
448 All Rights Reserved.
449 .Pp
450 The
451 .Ic libs_so
452 keyword was added in 2005 by
453 .An Adrian Steinmann Aq Mt ast@marabu.ch
454 and
455 .An Ceri Davies Aq Mt ceri@FreeBSD.org .
456 .Sh CAVEATS
457 While
458 .Nm
459 takes care to eliminate link conflicts between the component programs
460 of a crunched binary, conflicts are still possible between the
461 libraries that are linked in.
462 Some shuffling in the order of
463 libraries may be required, and in some rare cases two libraries may
464 have an unresolvable conflict and thus cannot be crunched together.
465 .Pp
466 Some versions of the
467 .Bx
468 build environment do not by default build the
469 intermediate object file for single-source file programs.
470 The
471 .Dq Li make objs
472 must then be used to get those object files built, or
473 some other arrangements made.