Makefile: how to detect changes within the makefile itself?

imagineerThat

I'm aware of the idea of using recursive makefiles. Will the subsequent makefiles such as the following be called be updated solely on any changes to the subsequent makefiles themselves?

e.g.:

#parent makefile. no changes here. 
subsystem:
    cd subdir && $(MAKE)

If the makefile within subdir was changed such that the following does not hold (e.g. only a gcc flag was changed), then will the object files be updated?

The recompilation must be done if the source file, or any of the header files named as dependencies, is more recent than the object file, or if the object file does not exist.

Etan Reisner

The only reason that, as written, make even runs that rule at all is because subsystem and subdir do not match.

If a subsystem file or directory were ever to be created in that directory that rule would cease to function.

If .PHONY: subsystem1 were added that problem would be fixed and that rule would always be run when listed on the command line (i.e. make subsystem). (As indicated in the comments .PHONY is a GNU Make extension. The section following the linked section discusses a portable alternative. Though it is worth noting that they are not completely identical in that .PHONY has some extra benefits and some extra limitations.)

In neither of those cases is the subsystem target paying any attention to modification dates of anything (as it lists no prerequisites).

To have a target depend on changes to a makefile you need to list the makefile(s) as prerequisites like anything else (i.e. subsystem: subdir/Makefile). Listing it as .PHONY is likely more correct and more what you want.

No, nothing in make itself tracks non-prerequisites. So flag changes/etc. do not trigger rebuilds. There are ways to make that work for make however (they involve storing the used flags in files that themselves are prerequisites of the targets that use those flags, etc.). There are questions and answers on SO about doing that (I don't have them ready offhand though).

Other tools do handle flag changes automatically however. I believe Electric Cloud's tools do this. I believe CMake does as well. There might also be others.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to include a makefile into an other makefile?

From Dev

Including arguments to make in a Makefile itself

From Dev

Explanation on how this makefile works?

From Dev

Using PETSc on makefile within my user-defined makefile

From Dev

How to define a variable in a makefile and then use it within Fortran code

From Dev

how to set this makefile

From Dev

Track branch changes from a Makefile

From Dev

How to use virtualenv in makefile

From Dev

How such makefile works? (is it normal?)

From Dev

How to understand this Go makefile?

From Dev

How to remove duplication in Makefile?

From Dev

How to parameterize makefile targets

From Dev

Hard linking within makefile

From Dev

How can I set long options within a makefile

From Dev

How to make a target in make that is itself named 'makefile'?

From Dev

How to set pipefail in a Makefile

From Dev

Makefile wants to compile itself

From Dev

GNU Makefile, detect architecture

From Dev

How can I run a pattern rule within another rule in a makefile?

From Dev

How to detect contiguous spans in which data changes linearly within a DataFrame?

From Dev

Including arguments to make in a Makefile itself

From Dev

how to set this makefile

From Dev

How such makefile works? (is it normal?)

From Dev

Hard linking within makefile

From Dev

Git commit from within a Makefile

From Dev

how can a makefile detect whether a command is available in the local machine?

From Dev

How can I set long options within a makefile

From Dev

How to make a target in make that is itself named 'makefile'?

From Dev

How to convert Makefile.am to Makefile.in?