1.18. Building a Complex Application with GNU make
Problem
You wish to use GNU make to build an executable which depends on several static and dynamic libraries.
Solution
Follow these steps:
Create makefiles for the libraries used by your application, as described in Recipe 1.16 and Recipe 1.17. These makefiles should reside in separate directories.
Create a makefile in yet another directory. This makefile can be used to build your application, but only after the makefiles in step 1 have been executed. Give this makefile a phony target
allwhose prerequisite is your executable. Declare a target for your executable with prerequisites consisting of the libraries which your application uses, together with the object files to be built from your application’s .cpp files. Write a command script to build the executable from the collection libraries and object files, as described in Recipe 1.5. If necessary, write a pattern rule to generate object files from .cpp files, as shown in Recipe 1.16. Addinstallandcleantargets, as shown in Recipe 1.15, and machinery to automatically generate source file dependencies, as shown in Recipe 1.16.Create a makefile in a directory which is an ancestor of the directories containing all the other makefiles — let’s call the new makefile the top-level makefile and the others the subordinate makefiles. Declare a default target
allwhose prerequisite is the directory containing the makefile created in step 2. Declare a rule whose targets consists of the ...