You can include rules into your makefiles. These can extend the targets SRT defines, add dependencies to existing targets, or define new normal and implicit rules. In general, you should place all such rules after the inclusion of standard.mk. This takes care of two problematic aspects: you can use SRT-defined special variables like $(libext) in the rules safely, and all remains the first target in the makefile. The latter point may sound obscure, but is easily explained: when make is not told to build any particular target, it builds the first one in the makefile. It would be a shame for that target to be something that deleted your makefile, for instance.
Now, let us examine some examples of typical applications for custom rules. First, suppose a package builds a library and an executable, and you want the executable to use the library. To get the library always before the executable, you must add a dependency such as shown below. If you omit the dependency, make is free to build the targets in any order it likes, and probably will if you enable parallel build with the -j option.
TARGET_BINS = program TARGET_LIBS = libstuff.a program_USES = c program_SRC = program.c program_LDFLAGS = -L. program_LIBS = -lstuff libstuff.a_USES = c libstuff.a_SRC = stuff.c ###################################################################### include $(SRT_HOME)/standard.mk program$(exeext): $(libprefix)stuff.$(libext) |
As another example, suppose you write a short documentation note for your package FooPackage in SGML (like the document you are reading at this very moment), and that you want to convert that into a HTML page that you want to install. The custom rules will be the ones that convert the SGML into HTML, and could be written like below.
TARGET_BINS = program
TARGET_DOC = index.html:FooPackage/index.html
JADE = jade
program_USES = c
program_SRC = program.c
######################################################################
include $(SRT_HOME)/standard.mk
index.html: $(srcdir)/doc.sgml $(srcdir)/doc.dsl $(srcdir)/doc.cat
[ -d html ] || mkdir html
$(JADE) -c $(srcdir)/doc.cat -d $(srcdir)/doc.dsl -t sgml $< |