CRUNCHGEN(1)
π
CRUNCHGEN(1) β okay so this is crunchgen, bestie β¨
the manual name is crunchgen and it lives in the General Commands Manual, and honestly? it's giving "quietly the most powerful floppy-disk tool you've never met." let's get into it π«Ά
πΈ NAME πΈ
crunchgen β generates build environment for a crunched binary π
β¨ SYNOPSIS β¨
crunchgen [-foql] [-h makefile-header-name] [-m makefile-name]
[-p obj-prefix] [-c c-file-name] [-e exec-file-name] conf-file
π DESCRIPTION π
okay so. first of all, what even is a crunched binary? so glad you asked. π¦
A crunched binary is a program made up of many other programs linked together into a single executable. that's the whole bit. and the way it works is genuinely iconic β the crunched binary's main() function determines which component program to run by the contents of argv[0]. one binary, many personalities. main character energy fr fr π
the main reason to crunch programs together is for fitting as many programs as possible onto an installation or system recovery floppy. yes, floppy. we respect the classics. πΎ
So, the crunchgen utility 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 creates the crunched executable file from the component programs. π
For each component program, crunchgen can optionally attempt to determine the object (.o) files that make up the program from its source directory Makefile. ngl that's kind of a lot of work and it's literally caching it for you β this information is cached between runs. efficiency slay β¨
The crunchgen utility uses the companion program crunchide(1) to eliminate link-time conflicts between the component programs by hiding all unnecessary symbols. teamwork makes the dream work π
β οΈ heads up bestie, there are requirements: Thecrunchgenutility places specific requirements on packageMakefiles which make it unsuitable for use with non-BSD sources. In particular, theMakefilemust contain the targetdepend, and it must define all object files in the variableOBJS. no cap, it will not vibe with anything else.
In some cases, you can use a fake Makefile: before looking for Makefile in the source directory foo, crunchgen looks for the file Makefile.foo in the current directory. sneaky? yes. useful? also yes. π
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(1) in each component program's source dir to build the object files for the user. This is not done automatically since in release engineering circumstances it is generally not desirable to be modifying objects in other directories. like, respect the boundaries. π«Ά
The options are as follows:
π OPTIONS π
-cc-file-name β Set output C file name to c-file-name. The default name is<conf-name>.c. π-eexec-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. out with the old, in with the new π-lβ List names. Lists the names this binary will respond to. this is your vibe check list, lowkey π-hmakefile-header-name β Set the name of a file to be included at the beginning of theMakefiles generated bycrunchgen. This is useful to define some make variables which might affect the behavior ofmake(1)and are annoying to pass through environment variables. no more env-var gymnastics, we love to see it π-mmakefile-name β Set outputMakefilename to makefile-name. The default name is<conf-name>.mk.-oβ Add βmake objβ rules to each program make target. π οΈ-pobj-prefix β Set the pathname to be prepended to the srcdir when computing the objdir. If this option is not present, then the prefix used is the content of theMAKEOBJDIRPREFIXenvironment variable, or/usr/obj. (yes, that literal slash-and-usr-and-obj. write it down π)-qβ Quiet operation. Status messages are suppressed. silent but slaying π€«
π§ CRUNCHGEN CONFIGURATION FILE COMMANDS π§
The crunchgen utility reads specifications from the conf-file that describe the components of the crunched binary. In its simplest use, the component program names are merely listed along with the top-level source directories in which their sources can be found. The crunchgen utility then calculates (via the source makefiles) and caches the list of object files and their locations. For more specialized situations, the user can specify by hand all the parameters that crunchgen needs.
The conf-file commands are as follows:
srcdirsdirname ... β 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. Multiplesrcdirslines can be specified. The directories are searched in the order they are given. order matters, bestie, first match wins πprogsprogname ... β A list of programs that make up the crunched binary. Multipleprogslines can be specified. πΈlibslibspec ... β A list of library specifications to be included in the crunched binary link. Multiplelibslines can be specified.libs_solibspec ... β A list of library specifications to be dynamically linked in the crunched binary. These libraries will need to be made available via the run-time link-editorrtld(1)when the component program that requires them is executed from the crunched binary. Multiplelibs_solines can be specified. Thelibs_sodirective overrides a library specified gratuitously on alibsline. π¦buildoptsbuildopts ... β A list of build options to be added to every make target. blanket treatment, periodt π«Άlnprogname linkname β Causes the crunched binary to invoke progname whenever linkname appears inargv[0]. This allows programs that change their behavior when run under different names to operate correctly. shapeshifter behavior, iconic π
To handle specialized situations, such as when the source is not available or not built via a conventional Makefile, the following special commands can be used to set crunchgen parameters for a component program.
π the special commands π
specialprognamesrcdirpathname β Set the source directory for progname. This is normally calculated by searching the specifiedsrcdirsfor a directory named progname.specialprognameobjdirpathname β Set the obj directory for progname. The obj directory is normally calculated by looking for a directory whose name is that of the source directory prepended by one of the following components, in order of priority: the-pargument passed to the command line; or, the value of theMAKEOBJDIRPREFIXenvironment variable, or/usr/obj. If the directory is not found, the srcdir itself becomes the objdir. πspecialprognamebuildoptsbuildopts β Define a set of build options that should be added tomake(1)targets in addition to those specified usingbuildoptswhen processing progname.specialprognameobjsobject-file-name ... β Set the list of object files for program progname. This is normally calculated by constructing a temporary makefile that includes βsrcdir/Makefileβ and outputs the value of$(OBJS).specialprognameobjpathsfull-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 theobjslist.specialprognameobjvarvariable_name β Sets the name of themake(1)variable which holds the list of object files for program progname. This is normallyOBJSbut someMakefiles might like to use other conventions or prepend the program's name to the variable, e.g.,SSHD_OBJS. quirky but valid πspecialprognameliblibrary-name ... β Specifies libraries to be linked with object files to produce progname.lo. This can be useful with libraries which redefine routines in the standard libraries, or poorly written libraries which reference symbols in the object files. (we don't judge the poorly written libraries, we just accommodate them π)specialprognamekeepsymbol-name ... β Add specified list of symbols to the keep list for program progname. An underscore (β_β) is prepended to each symbol and it becomes the argument to a-koption for thecrunchide(1)phase. This option is to be used as a last resort as its use can cause a symbol conflict, however in certain instances it may be the only way to have a symbol resolve. πspecialprognameidentidentifier β Set theMakefile/C identifier for progname. This is normally generated from a progname, mapping β-β to β_β and ignoring all other non-identifier characters. This leads to programs named"foo.bar"and"foobar"to map to the same identifier. yeah. that's a real thing that happens. π
π the actual tea: Only theobjpathsparameter is actually needed bycrunchgen, but it is calculated fromobjdirandobjs, which are in turn calculated fromsrcdir, so is sometimes convenient to specify the earlier parameters and letcrunchgencalculate forward from there if it can. it's giving delegation, it's giving trust the process β¨
The makefile produced by crunchgen contains an optional objs target that will build the object files for each component program by running make(1) 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 particular program, that program is skipped in the objs target. not ghosted exactly, butβ¦ yeah, kinda ghosted π«
π EXAMPLES π
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
progs anotherprog
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
special anotherprog -DNO_FOO WITHOUT_BAR=YES
libs -lutil -lcrypt
This conf file specifies a small crunched binary consisting of some basic system utilities plus a homegrown install program βmyinstallβ, for which no source directory is specified, but its object file is specified directly with the special line. π
Additionally when βanotherprogβ is built the arguments
-DNO_FOO WITHOUT_BAR=YES
are added to all build targets.
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. π¦β¨
βοΈ Note that if the libs_so command had been used, copies of the libraries so named would also need to be copied to the install floppy. don't forget the libraries bestie, they will not copy themselves π
π₯ SEE ALSO π₯
crunchide(1), make(1), rtld(1)
π AUTHORS π
The crunchgen utility was written by James da Silva <jds@cs.umd.edu>.
Copyright (c) 1994 University of Maryland. All Rights Reserved.
The libs_so keyword was added in 2005 by Adrian Steinmann <ast@marabu.ch> and Ceri Davies <ceri@FreeBSD.org>.
π CAVEATS π
Okay bestie, real talk β this is the part where things can get a little messy. π«Ά crunchgen does its absolute best to eliminate link conflicts between the component programs of a crunched binary, and we love that for it. But conflicts are still possible between the libraries that get linked in. π Some shuffling in the order of libraries may be required, and in some rare cases two libraries may have an unresolvable conflict, meaning they literally cannot be crunched together. Periodt. π
Also, some versions of the BSD build environment do not by default build the intermediate object file for single-source file programs. In that case, make objs must then be used to get those object files built, or some other arrangements made. No cap. β¨
π Thatβs the tea: this page is from Debian, dated January 6, 2017, and itβs CRUNCHGEN(1) β iconic, honestly. Byeee! π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1994 University of Maryland
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms