MirBSD manpage: crunchgen(1)

CRUNCHGEN(1)                 BSD Reference Manual                 CRUNCHGEN(1)


     crunchgen - generates build environment for a crunched binary


     crunchgen [-fq] [-c c-file-name] [-D src-root] [-e exec-file-name]
               [-L lib-dir] [-m makefile-name] [-O objdir-name] conf-file


     A crunched binary is a program made up of many other programs linked to-
     gether into a single executable. The crunched binary main() function
     determines which component program to run by the contents of argv[0]. The
     main reason to crunch programs together is for fitting as many programs
     as possible onto an installation or system recovery floppy.

     crunchgen reads in the specifications in conf-file for a crunched binary,
     and generates a Makefile and accompanying top-level C source file that
     when built create the crunched executable file from the component pro-
     grams. For each component program, crunchgen can optionally attempt to
     determine the object (.o) files that make up the program from its source
     directory Makefile. This information is cached in a file named <conf-
     name>.cache between runs. crunchgen uses GNU objcopy(1) to eliminate
     link-time conflicts between the component programs by hiding all unneces-
     sary symbols and renaming the main() function.

     After crunchgen is run, the crunched binary can be built by running "make
     -f <conf-name>.mk". The component programs' object files must already be
     built. An "objs" target, included in the output makefile, will run make
     in each component program's source dir to build the object files for the
     user. This is not done automatically since in release engineering cir-
     cumstances it is generally not desirable to be modifying objects in other

     The options are as follows:

     -c c-file-name
             Set output C file name to c-file-name. The default name is

     -D src-root
             Assume that relative source directory specifications begin with

     -E      Ignored for compatibility with crunchgen version 0.x.

     -e exec-file-name
             Set crunched binary executable file name to exec-file-name. The
             default name is "<conf-name>".

     -f      Flush cache. Forces the recalculation of cached parameters.

     -L lib-dir
             Try to obtain libraries from lib-dir.

     -m makefile-name
             Set output Makefile name to makefile-name. The default name is

     -O objdir-name
             Specify an object directory to use. It defaults to "obj", though
             for cross building purposes it can be used to specify
             "obj.${HOST}.${MACHINE}". Normally used in combination with the
             make variable ${MAKEOBJDIR}.

     -q      Quiet operation. Status messages are suppressed.

     Distinguishing between executable formats with (COFF, a.out, PE) and
     without (ELF) leading underscores is no longer necessary.


     crunchgen reads specifications from the conf-file that describe the com-
     ponents of the crunched binary. In its simplest use, the component pro-
     gram names are merely listed along with the top-level source directories
     in which their sources can be found. crunchgen then calculates (via the
     source makefiles) and caches the list of object files and their loca-
     tions. For more specialised situations, the user can specify by hand all
     the parameters that crunchgen needs.

     The conf-file commands are as follows:

     srcdirs dirname ...
             A list of source trees in which the source directories of the
             component programs can be found. These dirs are searched using
             the BSD "<source-dir>/<progname>/" convention. Multiple srcdirs
             lines can be specified. The directories are searched in the order
             they are given.

     libdirs dirname
             A list of source trees in which the source directories for sup-
             plementary libraries can be found.

     progs progname ...
             A list of programs that make up the crunched binary. Multiple
             progs lines can be specified.

     libs libspec ...
             A list of library specifications to be included in the crunched
             binary link. Multiple libs lines can be specified.

     ln progname linkname
             Causes the crunched binary to invoke progname whenever linkname
             appears in argv[0]. This allows programs that change their
             behavior when run under different names to operate correctly.

     To handle specialised situations, such as when the source is not avail-
     able or not built via a conventional Makefile, the following special com-
     mands can be used to set crunchgen parameters for a component program.

     special progname srcdir pathname
             Set the source directory for progname. This is normally calculat-
             ed by searching the specified srcdirs for a directory named

     special progname objdir pathname
             Set the obj directory for progname. This is normally calculated
             by looking for a directory named "obj" under the srcdir, and if
             that is not found, the srcdir itself becomes the objdir.

     special progname objs object-file-name ...
             Set the list of object files for program progname. This is nor-
             mally calculated by constructing a temporary makefile that in-
             cludes "srcdir/Makefile" and outputs the value of $(OBJS).

     special progname objpaths full-pathname-to-object-file ...
             Sets the pathnames of the object files for program progname. This
             is normally calculated by prepending the objdir pathname to each
             file in the objs list.

     Only the objpaths parameter is actually needed by crunchgen, but it is
     calculated from objdir and objs, which are in turn calculated from
     srcdir, so it is sometimes convenient to specify the earlier parameters
     and let crunchgen calculate forward from there if it can.

     The makefile produced by crunchgen contains an optional objs target that
     will build the object files for each component program by running make
     inside that program's source directory. For this to work the srcdir and
     objs parameters must also be valid. If they are not valid for a particu-
     lar program, that program is skipped in the objs target.


     Here is an example crunchgen input conf file, named kcopy.conf:

           srcdirs /usr/src/bin /usr/src/sbin

           progs test cp echo sh fsck halt init mount umount myinstall
           ln test [       # test can be invoked via [
           ln sh -sh       # init invokes the shell with "-sh" in argv[0]

           special myprog objpaths /homes/leroy/src/myinstall.o # no sources

           libs -lutil

     This conf file specifies a small crunched binary consisting of some basic
     system utilities plus a home-grown install program "myinstall", for which
     no source directory is specified, but its object file is specified
     directly with the special line.

     The crunched binary "kcopy" can be built as follows:

           % crunchgen -m Makefile kcopy.conf    # gen Makefile and kcopy.c
           % make objs             # build the component programs' .o files
           % make                  # build the crunched binary kcopy
           % kcopy sh              # test that this invokes a sh shell
           $                       # it works!

     At this point the binary "kcopy" can be copied onto an install floppy and
     hard-linked to the names of the component programs.


     crunchgen was written by James da Silva <jds@cs.umd.edu>.

     Copyright (C) 1994 University of Maryland.  All Rights Reserved.

     Thorsten Glaser <tg@mirbsd.de> did major cleanup for MirBSD, replaced the
     traditional crunchide with GNU objcopy, made the -E switch and crunched
     stub objects obsolete.


     While crunchgen takes care to eliminate link conflicts between the com-
     ponent programs of a crunched binary, conflicts are still possible
     between the libraries that are linked in. Some shuffling in the order of
     libraries may be required, and in some rare cases two libraries may have
     an unresolvable conflict and thus cannot be crunched together.

     Some versions of the BSD build environment do not by default build the
     intermediate object file for single-source file programs. The "make objs"
     target must then be used to get those object files built, or some other
     arrangements made. Other build systems, like automake, suffer from the
     same issues.

MirBSD #10-current               July 7, 2007                                2

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung