xref: /netbsd-src/usr.bin/crunch/crunchgen/crunchgen.1 (revision 7d3af8c6a2070d16ec6d1aef203d052d6683100d)
1.\"	$NetBSD: crunchgen.1,v 1.29 2012/04/08 22:00:38 wiz Exp $
2.\"
3.\" Copyright (c) 1994 University of Maryland
4.\" All Rights Reserved.
5.\"
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.
15.\"
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.
22.\"
23.\" Author: James da Silva, Systems Design and Analysis Group
24.\"			   Computer Science Department
25.\"			   University of Maryland at College Park
26.\"
27.Dd October 18, 2006
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.Nm
35.Op Fl fOoq
36.Op Fl c Ar c-file-name
37.Op Fl D Ar src-root
38.Op Fl d Ar build-options
39.Op Fl e Ar exec-file-name
40.Op Fl L Ar lib-dir
41.Op Fl m Ar makefile-name
42.Op Fl v Ar var-spec
43.Ar conf-file
44.Sh DESCRIPTION
45A crunched binary is a program made up of many other programs linked
46together into a single executable.
47The crunched binary
48.Fn main
49function determines which component program to run by the contents of
50argv[0].
51The main reason to crunch programs together is for fitting as many
52programs as possible onto an installation or system recovery floppy.
53.Pp
54.Nm
55reads in the specifications in
56.Ar conf-file
57for a crunched binary, and generates a Makefile and accompanying
58top-level C source file that when built create the crunched executable
59file from the component programs.
60For each component program,
61.Nm
62can optionally attempt to determine the object (.o) files that make up
63the program from its source directory Makefile.
64This information is cached between runs.
65.Nm
66uses the companion program
67.Em crunchide
68to eliminate link-time conflicts between the component programs by
69hiding all unnecessary symbols.
70.Pp
71After
72.Nm
73is run, the crunched binary can be built by running
74.Dq make -f Ao conf-name Ac Ns .mk .
75The component programs' object files must already be built.
76An
77.Dq objs
78target, included in the output makefile, will
79run make in each component program's source dir to build the object
80files for the user.
81This is not done automatically since in release
82engineering circumstances it is generally not desirable to be
83modifying objects in other directories.
84.Pp
85The options are as follows:
86.Bl -tag -width indent
87.It Fl c Ar c-file-name
88Set output C file name to
89.Ar c-file-name .
90The default name is
91.Dq Ao confname Ac Ns .c .
92.It Fl D Ar src-root
93Assume that relative source directory specifications begin with
94.Ar src-root .
95.It Fl d Ar build-options
96Set the DBG variable in the generated makefile to
97.Ar build-options .
98The default flags are -Os.
99.It Fl e Ar exec-file-name
100Set crunched binary executable file name to
101.Ar exec-file-name .
102The default name is
103.Dq Aq conf-name .
104.It Fl f
105Flush cache.
106Forces the recalculation of cached parameters.
107.It Fl L Ar lib-dir
108Try to obtain libraries from
109.Ar lib-dir .
110.It Fl m Ar makefile-name
111Set output Makefile name to
112.Ar makefile-name .
113The default name is
114.Dq Ao conf-name Ac Ns .mk .
115.It Fl O
116Force
117.Nm
118to parse the program's Makefile in determine the list of .o files.
119Without this option
120.Nm
121expects the program's Makefile to have a program.ro target that links all
122the program objects into a single relocatable.
123.It Fl o
124Use existing object files.
125Rather than rebuilding object files via reach-over
126makefiles, instead search for and use existing object files.
127.It Fl q
128Quiet operation.
129Status messages are suppressed.
130.It Fl v Ar varspec
131Append a variable specification to the on-the fly generated Makefile.
132.El
133.Sh CRUNCHGEN CONFIGURATION FILE COMMANDS
134.Nm
135reads specifications from the
136.Ar conf-file
137that describe the components of the crunched binary.
138In its simplest
139use, the component program names are merely listed along with the
140top-level source directories in which their sources can be found.
141.Nm
142then calculates (via the source makefiles) and caches the
143list of object files and their locations.
144For more specialized
145situations, the user can specify by hand all the parameters that
146.Nm
147needs.
148.Pp
149The
150.Ar conf-file
151commands are as follows:
152.Bl -tag -width indent
153.It Nm srcdirs Ar dirname ...
154A list of source trees in which the source directories of the
155component programs can be found.
156These dirs are searched using the
157.Bx
158.Dq Ao source-dir Ac Ns / Ns Ao progname Ac Ns /
159convention.
160Multiple
161.Em srcdirs
162lines can be specified.
163The directories are searched in the order they are given.
164.It Nm progs Ar progname ...
165A list of programs that make up the crunched binary.
166Multiple
167.Em progs
168lines can be specified.
169.It Nm libs Ar libspec ...
170A list of library specifications to be included in the crunched binary link.
171Multiple
172.Em libs
173lines can be specified.
174.It Nm ln Ar progname linkname
175Causes the crunched binary to invoke
176.Ar progname
177whenever
178.Ar linkname
179appears in argv[0].
180This allows programs that change their behavior when
181run under different names to operate correctly.
182.El
183.Pp
184To handle specialized situations, such as when the source is not
185available or not built via a conventional Makefile, the following
186.Em special
187commands can be used to set
188.Nm
189parameters for a component program.
190.Bl -tag -width indent
191.It Nm special Ar progname Nm keepsymbols Ar symbols ...
192Don't hide the specified symbols for
193.Ar progname .
194Normally all externally visible symbols for
195a program is hidden to avoid interference.
196Multiple
197.Em keepsymbols
198lines can be specified for given
199.Ar progname .
200.It Nm special Ar progname Nm srcdir Ar pathname
201Set the source directory for
202.Ar progname .
203This is normally calculated by searching the specified
204.Em srcdirs
205for a directory named
206.Ar progname .
207.It Nm special Ar progname Nm objdir Ar pathname
208Set the obj directory for
209.Ar progname .
210This is normally calculated by looking for a directory named
211.Dq Pa obj
212under the
213.Ar srcdir ,
214and if that is not found, the
215.Ar srcdir
216itself becomes the
217.Ar objdir .
218.Pp
219.Nm Note :
220This option only takes effect if the -o option to use existing object files is also
221specified.
222.It Nm special Ar progname Nm objs Ar object-file-name ...
223Set the list of object files for program
224.Ar progname .
225This is normally calculated by constructing a temporary makefile that includes
226.Dq Nm srcdir / Pa Makefile
227and outputs the value of $(OBJS).
228Multiple
229.Em objs
230lines can be specified for given
231.Ar progname .
232.It Nm special Ar progname Nm objpaths Ar full-pathname-to-object-file ...
233Sets the pathnames of the object files for program
234.Ar progname .
235This is normally calculated by prepending the
236.Em objdir
237pathname to each file in the
238.Nm objs
239list.
240Multiple
241.Em objpaths
242lines can be specified for given
243.Ar progname .
244.El
245.Pp
246Only the
247.Em objpaths
248parameter is actually needed by
249.Nm
250but it is calculated from
251.Em objdir
252and
253.Em objs ,
254which are in turn calculated from
255.Em srcdir ,
256so is sometimes convenient to specify the earlier parameters and let
257.Nm
258calculate forward from there if it can.
259.Pp
260The makefile produced by
261.Nm
262contains an optional
263.Ar objs
264target that will build the object files for each component program by
265running make inside that program's source directory.
266For this to work the
267.Em srcdir
268and
269.Em objs
270parameters must also be valid.
271If they are not valid for a particular program, that
272program is skipped in the
273.Ar objs
274target.
275.Sh ENVIRONMENT
276.Bl -tag -width MAKEOBJDIRPREFIX
277.It Ev MAKEOBJDIRPREFIX
278If the environment variable
279.Ev MAKEOBJDIRPREFIX
280is set, the object directory will be prefixed with the path contained in this
281environment variable.
282.Pp
283.Nm Note :
284This variable is only used if the -o option to use existing object files is also
285specified.
286.It Ev MACHINE
287If the environment variable
288.Ev MACHINE
289is set, it is used as the name of the machine type, when accessing object
290directories of the form obj.MACHINE.
291If it is not set, it defaults to the machine type returned by
292.Xr uname 3 .
293.Pp
294.Nm Note :
295This option is only used if the -o option to use existing object files is also
296specified.
297.It Ev MAKE
298If the environment variable
299.Ev MAKE
300is set, it is used as the name of the
301.Xr make 1
302executable to be called.
303If this environment variable is not set,
304.Nm
305defaults to
306.Dq make .
307.El
308.Sh EXAMPLES
309Here is an example
310.Em crunchgen
311input conf file, named
312.Dq Pa kcopy.conf :
313.Pp
314.Bd -literal -offset indent
315srcdirs /usr/src/bin /usr/src/sbin
316
317progs test cp echo sh fsck halt init mount umount myinstall
318ln test [       # test can be invoked via [
319ln sh -sh       # init invokes the shell with "-sh" in argv[0]
320
321special myprog objpaths /homes/leroy/src/myinstall.o # no sources
322
323libs -lutil -lcrypt
324.Ed
325.Pp
326This conf file specifies a small crunched binary consisting of some
327basic system utilities plus a home-grown install program
328.Dq myinstall ,
329for which no source directory is specified, but its object file is
330specified directly with the
331.Em special
332line.
333.Pp
334The crunched binary
335.Dq kcopy
336can be built as follows:
337.Pp
338.Bd -literal -offset indent
339% crunchgen -m Makefile kcopy.conf    # gen Makefile and kcopy.c
340% make objs             # build the component programs' .o files
341% make                  # build the crunched binary kcopy
342% kcopy sh              # test that this invokes a sh shell
343$			# it works!
344.Ed
345.Pp
346At this point the binary
347.Dq kcopy
348can be copied onto an install floppy
349and hard-linked to the names of the component programs.
350.Sh SEE ALSO
351.Xr crunchide 1 ,
352.Xr make 1
353.Sh AUTHORS
354.Nm
355was written by
356.An James da Silva Aq jds@cs.umd.edu .
357.Pp
358Copyright (c) 1994 University of Maryland.  All Rights Reserved.
359.Sh BUGS
360While
361.Nm
362takes care to eliminate link conflicts between the component programs
363of a crunched binary, conflicts are still possible between the
364libraries that are linked in.
365Some shuffling in the order of
366libraries may be required, and in some rare cases two libraries may
367have an unresolvable conflict and thus cannot be crunched together.
368.Pp
369Some versions of the
370.Bx
371build environment do not by default build the
372intermediate object file for single-source file programs.
373The
374.Dq make objs
375target must then be used to get those object files built, or
376some other arrangements made.
377.Pp
378If a program directory being searched for is found, but contains
379no objects, other directories are not searched.
380This causes the following directive to fail:
381.Pp
382.Bd -literal -offset indent
383srcdirs /usr/src/usr.bin /usr/src/usr.bin/less
384progs less gzip
385.Ed
386.Pp
387as the
388.Pa /usr/src/usr.bin/less
389directory will be found with the
390.Pa /usr/src/usr.bin
391.Em srcdirs
392entry, and as it does not contain the require objects,
393.Nm
394fails to find objects for the
395.Em less
396program.
397To avoid this problem, list specific srcdirs first, and
398the more general ones later, for e.g.:
399.Pp
400.Bd -literal -offset indent
401srcdirs /usr/src/usr.bin/less /usr/src/usr.bin
402progs less gzip
403.Ed
404.Pp
405will not have the above problem.
406