Multiple makefiles

From LSDevLinux
Revision as of 16:14, 17 April 2007 by LSDevManager (talk | contribs) (1 revision(s))

Jump to: navigation, search

There are times when it is desirable to use more than one makefile for a project. For example, the test code for VwGraphics depends on the VwGraphics library, which has its own makefile.

The following lines in the test makefile will make the library if it does not already exist:

../../lib/VwGraphics.o:
  @cd $(@D); $(MAKE)$(@F)
  • The @ before cd stops make from echoing the command
  • $(@D) is the directory (../../lib)
  • $(@F) is the file (VwGraphics.o)

This approach, however will only make the file if it does not exist. The file will not be rebuilt if it is out of date. To use the smarts from the makefile in the lib directory, we can add VwGraphics.o to the dependecies of .PHONY. These dependencies will be rebuilt every time they are needed.

.PHONY: ../../lib/VwGraphics.o