Building Projects With Imake
Imake is tool for configuring the X Window System and its components for different platforms and compilers. Imake allows you to create a generic description of how your project should be built and leaves the system-specific details to centralized configuration files.
Put simply, Imake is built on the idea of applying the C preprocessor to Makefiles, rather than C programs. Much of the redundancy in common Makefiles has been turned into preprocessor macros, which have the same effect macros have in C programs—making things easier.
Imake should have come with your installation of X. If you run one of the common distributions of Linux, you need to check that some of the “development” packages are installed. For instance, I run Red Hat 4.0 on my system, and the Imake system is contained in the XFree86-devel RPM.
If you aren't sure if you have Imake installed or have it configured properly, it is easy to check. Just run these commands:
touch Imakefile xmkmf
There should now be a new file called Makefile in the current directory. There is quite a bit of “stuff” in the new Makefile, mostly generic rules and information generated from the configuration files.
If you've gotten this far, Imake is installed and configured just fine. Now, you should be able to run make and get output. For example on my Red Hat 4.2 system, I type make and get the following output:
make: Nothing to be done for 'emptyrule'.
Besides containing many programs, there are several programs that Imake depends on to function properly. However, most of them are basic things like bash, mv, rm and so on. If these basic programs are missing, you have more severe problems than whether Imake works properly. Still, there are a couple of major components that aren't vital to a working Linux system that are vital to Imake.
make isn't necessarily vital to the functioning of Imake, but the generated Makefiles are absolutely useless by themselves. If you don't have make, you should install GNU make. For more advanced uses of Imake, it is good to have a thorough understanding of how make works. At the end of this article are some references for more information on make.
Obviously, for a Makefile generation program to be useful, you need a compiler. However, that is not the only reason for having GCC installed. Imake relies on an external C preprocessor, installed in /lib/cpp by default. If you have GCC installed and configured, you should also have cpp (the C preprocessor) installed.
In case you don't have a /lib/cpp file, the simplest way to solve the problem is to make a symbolic (soft) link (use ln) from it to GCC's cpp executable. For example, on my system, /lib/cpp is a symbolic link to /usr/lib/gcc-lib/i486-linux/2.7.2/cpp.
The major user-visible component of the Imake system is the file Imakefile, in which the project-specific information needed by Imake to build your project is kept.
At a basic level Imakefile consists of rule invocations, variable definitions and variable invocations. The first, rule invocations, resemble C-function calls. The second resemble C-variable assignments. These two should be familiar to anyone who has used macros in C code. On the other hand, variable invocations are nothing like their C counterparts, but should be familiar to anyone who has done any work with plain make. Here's a simple example:
VARIABLE = value ARule(arg1,arg2,$(VARIABLE))
As with programming in general, there are many of syntax pitfalls with Imake. The following two sections describe a few of the problems to keep in mind.
Imake (actually, the underlying C preprocessor) is fairly strict about how the various rules must be invoked. First, there must be absolutely no extraneous white space around the commas between arguments. For example, this rule is incorrect:
ARule(arg1, arg2, arg3)
and this version is correct:
ARule(arg1,arg2,arg3)To confuse things even more, in some cases, it is valid for the argument to have space. For example, many rules take a list of files as one of the arguments, where each file is delimited by a space. Typically, this is fairly intuitive, and several of the examples later in this article show the most common cases.
The second problem with argument passing in Imake is empty arguments. Not all arguments are necessary for every rule, but the C preprocessor breaks if an argument is left out or has no value. To solve the problem, Imake provides the macro NullParameter to allow empty arguments in a rule. For example:
- Machine Learning Everywhere
- Smoothwall Express
- Bash Shell Script: Building a Better March Madness Bracket
- Own Your DNS Data
- Simple Server Hardening
- From vs. to + for Microsoft and Linux
- Understanding OpenStack's Success
- The Weather Outside Is Frightful (Or Is It?)
- Ensono M.O.
- Understanding Firewalld in Multi-Zone Configurations