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