chen chen - 1 year ago 102
C Question

How to make a makefile reference another makefile

I have a project in C that has many different modules, and one makefile for everything. What I would like to do is for each module to have its own makefile, and when that module is included in any project, that projects makefile can just reference the individual module's makefile. That way anytime I have a project in which I want to use a certain module, I don't have to do a bunch of editing to my project makefile.

Any help you can offer on this would be appreciated.

Answer Source

If you are using GNU Make utility, then my answer could be of some help to you. Recently, I was reading GNU Make Manual for my own project.

The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this:

include filenames

If you want make to simply ignore a makefile which does not exist or cannot be remade, with no error message, use the -include directive instead of include, like this:

-include filenames

However, there is another way which is variable MAKEFILES. If the environment variable MAKEFILES is defined, make considers its value as a list of names (separated by whitespace) of additional makefiles to be read before the others.

You can refer GNU Make Manual for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download