Next: 9 Further Reading Up: Writing GNUstep Makefiles Previous: 7 Debugging an Application

8 Preamble and Postamble

You may happen to need to pass additional flags to the compiler (in order to link with additional libraries, for example) or to be willing to perform some additional actions after compilation or installation. The standard way of doing this is as follows: add a file called GNUmakefile.preamble to your project directory. An example of a GNUmakefile.preamble is the following:
ADDITIONAL_OBJCFLAGS += -Wextra
This simply adds the -Wextra flag when compiling, which causes GCC to print a lot more warnings than it would normally do. In general, you would use a GNUmakefile.preamble to add any additional flags you need (to tell the compiler/linker to search additional directories upon compiling/linking, to link with additional libraries, etc).

Now, you would want your GNUmakefile to include the contents of your GNUmakefile.preamble before any processing. This is usually done as follows:

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = PanelTest
PanelTest_OBJC_FILES = source.m

include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/application.make

The most important thing to notice is that the GNUmakefile.preamble is included before application.make. That is why is called a preamble.

Sometimes you also see people using

-include GNUmakefile.preamble
(with a hyphen, -, prepended). The hyphen before include tells the make tool not to complain if the file GNUmakefile.preamble is not found. If you want to make sure that the GNUmakefile.preamble is included, you should better not use the hyphen.

If you want to perform any special operation after the GNUmakefile package has done its work, you usually put them in a GNUmakefile.postamble file. The GNUmakefile.postamble is included after application.make; that is why is called a postamble:

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = PanelTest
PanelTest_OBJC_FILES = source.m

include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/application.make
include GNUmakefile.postamble

Here is a concrete example of a GNUmakefile.postamble:

after-install::
        $(MKINSTALLDIRS) /home/nicola/SpecialTools; \
        cd $(GNUSTEP_OBJ_DIR); \
        $(INSTALL) myTool /home/nicola/SpecialTools;
(make sure you start each indented line with TAB). This will install the tool myTool in the directory /home/nicola/SpecialTools after the standard installation has been performed.

You rarely need to use GNUmakefile.postambles, and they were mentioned mainly to give you a complete picture.


Next: 9 Further Reading Up: Writing GNUstep Makefiles Previous: 7 Debugging an Application
2010-02-14