GAR: Automating Entire OS Builds
One way to think of GAR is as a consistent interface for compiling a piece of software. No matter what mechanism the program uses to compile or install, a make install will install the program. The user need not care whether a program is a Python script or a C program that uses Imake.
In fact, the system will even satisfy dependencies. If the robotfindskitten program uses libncurses, the GAR system will pause the robotfindskitten build process right before the configure stage and then go install libncurses.
The GAR system is also centrally configurable, allowing the user to specify installation directories, CFLAGS and other useful environment variables. It is possible to configure default download locations, so that you can grab the code from a local cache or a nearby mirror of all the files.
GAR was designed with the notion that the build system and the target system may be different machines. It is also possible that the build and target system are different architectures. The following changes to gar.conf.mk show a possible way to configure GAR for a cross-compiling environment:
prefix = /usr/local/build/mips-build LDFLAGS += -L$(libdir) -L/usr/local/lib-mips CC = /usr/local/bin/gcc-mipsel LD_LIBRARY_PATH += :$(libdir):/usr/local/lib-mips export prefix LDFLAGS CC LD_LIBRARY_PATH
All of these settings will propagate down into each individual package.
The best way to understand the process of making a new package is to look at an example. The following is the relevant parts of the grep package:
GARNAME = grep GARVERSION = 2.4.2 CATEGORIES = utils MASTER_SITES = ftp://ftp.gnu.org/pub/gnu/grep/ DISTFILES = $(DISTNAME).tar.gz CONFIGURE_SCRIPTS = $(WORKSRC)/configure BUILD_SCRIPTS = $(WORKSRC)/Makefile INSTALL_SCRIPTS = $(WORKSRC)/Makefile CONFIGURE_ARGS = $(DIRPATHS) include ../../gar.mk
The first few lines set some basic bookkeeping information. The GARNAME and GARVERSION refer to the package name and version string as the GAR system will manipulate them. They are also used to create the convenience variable DISTNAME, which is $(GARNAME)-$(GARVERSION) by default, since most GNU or automake-using packages name their tarballs in that fashion.
The actual build of the system depends on the CONFIGURE_SCRIPTS, BUILD_SCRIPTS and INSTALL_SCRIPTS variables. These point to a space-separated list of files that are essential to the configure, build and install steps (respectively).
The GAR system will know what to do with most types of scripts. It knows to run CONFIGURE_SCRIPTs named ``configure'', and to run make or make install in the directory where a Makefile lives. It also knows that Imakefiles use xmkmf, and so forth. For most packages, no extra work needs to be done here.
We usually need to specify the CONFIGURE_ARGS to include the directory settings that we define in gar.conf.mk. This currently requires setting it to include $(DIRPATHS).
Finally, we include the gar.mk library. This takes all of the variable setting we've done and puts it to good use. This allows your short Makefile to provide the seven basic targets described above. It must come last (or, at least, after all of the variables have been set) in order to function properly.
The automatic satisfaction of dependencies is deceptively simple. In order to specify a library dependency, for example, simply set the LIBDEPS variable to be a space-separated list of paths from the base GAR directory to the package you depend on. For example, the GNU parted program has the following:
LIBDEPS = lib/e2fsprogs-libs
Before the configure step is run, GAR will cd into ../../lib/e2fsprogs-libs/ and run make install.
Quite often, the default behavior isn't what one would hope. You can pass parameters to a package's configure script with CONFIGURE_ARGS, but what if the GAR system doesn't know about your configuration script type? What if the configuration steps aren't enough? What if they're flat-out wrong? What if the same is true for the fetch, extract or install rules?
Fortunately, the system provides for this in a number of ways. What follows are a few of the mechanisms that a package maintainer can use to override or enhance the default behaviors.
For each of the seven basic targets, there exists slots for per-package pre- and post- rules. That means that the package maintainer can specify work to be done immediately before or after a rule.
To define a rule in make, simply place it at the beginning of a line, followed by a colon. The shell commands it should execute follow, preceded by a tab on each line.
As an example, let's consider the util-linux package. It doesn't use a standard autoconf-style configure script, but it can be configured by setting a variable at the top of the MCONFIG file. Thus, the end of our utils/util-linux/Makefile looks like the following:
CONFIGURE_SCRIPTS = $(WORKSRC)/configure BUILD_SCRIPTS = $(WORKSRC)/Makefile INSTALL_SCRIPTS = $(WORKSRC)/Makefile CONFIGURE_ARGS = $(DIRPATHS) pre-configure: echo "DESTDIR=$(prefix)" > $(WORKSRC)/MCONFIG.NEW cat $(WORKSRC)/MCONFIG << $(WORKSRC)/MCONFIG.NEW mv $(WORKSRC)/MCONFIG.NEW $(WORKSRC)/MCONFIG $(MAKECOOKIE) include ../../gar.mk
So before the configure script is run, the package-defined preconfigure rule adds code setting DESTDIR to the $(prefix) variable in MCONFIG.
The $(MAKECOOKIE) variable is a macro that creates a cookie file signifying the completion of the preconfigure step; $(MAKECOOKIE) performs some housekeeping that ensures rules are run only once, so it's important to end each rule with $(MAKECOOKIE).
As another example, the Bourne Again SHell (bash) can be linked to with the name ``sh'' in order to cause it to behave (somewhat) like a POSIX Bourne Shell. To do this, the end of our shells/bash/Makefile looks like:
CONFIGURE_SCRIPTS = $(WORKSRC)/configure BUILD_SCRIPTS = $(WORKSRC)/Makefile INSTALL_SCRIPTS = $(WORKSRC)/Makefile CONFIGURE_ARGS = $(DIRPATHS) post-install: (cd $(bindir); ln -sf bash sh) $(MAKECOOKIE) include ../../gar.mk
Thus creating the symbolic link to sh.
- High-Availability Storage with HA-LVM
- DNSMasq, the Pint-Sized Super Dæmon!
- Localhost DNS Cache
- Real-Time Rogue Wireless Access Point Detection with the Raspberry Pi
- Days Between Dates: the Counting
- You're the Boss with UBOS
- The Usability of GNOME
- Linux for Astronomers
- Multitenant Sites
- PostgreSQL, the NoSQL Database