1

A question regarding "sentinels" in included make files.

I've inherited a project with a hierarchy of gmake projects, which uses make recursively. Due to the structure of the project, some files are included multiple times (once for each use of recursive gmake). These files are nothing fancy. Just variable definitions with some very basic if-logic. No recipes or dependencies. No nested includes.

The multiple-inclusion creates maintenance headaches. E.g. One can't use += in these files. I'd like to block multiple inclusions.

Putting a sentinel in the included files is the obvious solution, e.g.

ifeq ($(FOO_INCLUDED),)
FOO_INCLUDED=yes
else
# everything else
endif

But .... adding such a sentinel makes some recipes disappear in some sub-projects. E.g. a "build" target might disappear, while the "clean" target for the same sub-project doesn't. Make reports no egregious errors - it does attempt to run things. It just reports a missing target.

So the question is ... what could cause recipes being lost?

Restructuring to avoid the multiple includes is unfortunately not an option. Each sub-project is supposed to be buildable from either it's own folder (cd sub-project ; gmake build), or from the root folder (cd proj-root ; gmake subproject_build)

Underhill
  • 408
  • 2
  • 13
  • 1
    Well, assuming that your actual implementation is correct unlike your example here which is, of course, wrong (there should be no `else` here), I can't think if any reason for the behavior you describe. All I can suggest is adding some `$(info ...)` statements in strategic places in your makefile to try to debug what is happening, and/or investigating the output of `make -p`. If you can come up with a reproducible test case and cut/paste it here we might be able to help further. – MadScientist Jan 31 '22 at 21:18
  • At the least if you could show us the definition of the rules that disappear maybe we could say _something_ about it. Also please show the exact errors (cut and paste with formatting) rather than paraphrasing them. And, the version of GNU make you're using and what platform you're using it on. – MadScientist Jan 31 '22 at 21:19
  • @MadScientist /head-desk It was the else. One of those days. – Underhill Feb 01 '22 at 16:48

0 Answers0