For most purposes, generating inline action definitions suffices for most purposes. However, if you have a lot of different classes for which you need descriptors defined, then compile times may become excessive. An alternative is to generate descriptor definition files for each class, and compile these into a library. This is achieved by the following rules:
.SUFFIXES: $(SUFFIXES) .h .cd .cdir .a .h.cd: rm -rf $*.cdir mkdir -p $*.cdir classdesc -workdir $*.cdir -include ../$< $(ACTIONS) <$< >$@ .cd.a: $(MAKE) $(patsubst %.cc,%.o,$(wildcard $*.cdir/*.cc)) ar r $@ $*.cdir/*.o
The -workdir option requests classdesc to write out the definition files into a
new directory ($*.cdir
expands to foo.cdir in the foo
example). Function declarations are written out on standard output,
which in this case is redirected to foo.cd.
The -include directive tells classdesc to insert
the line #include "../foo.h"
into the definition files, so that
the definitions can be compiled.
The next (rather complicated) line compiles each of the definition files. The reason for recursively calling make, rather than the compiler directly, is that GNU Make is able to compile the directory in parallel, reducing compilation times.
See the polymorph example, which uses this technique.