Skip to content

Generate header dependencies so header edits trigger a rebuild - #426

Open
drbergman wants to merge 1 commit into
MathCancer:developmentfrom
drbergman:claude/makefile-header-deps
Open

Generate header dependencies so header edits trigger a rebuild#426
drbergman wants to merge 1 commit into
MathCancer:developmentfrom
drbergman:claude/makefile-header-deps

Conversation

@drbergman

@drbergman drbergman commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

The problem

Make rebuilds a target only when a listed prereq is newer, but the headers are not explicitly in the prereqs. Thus, they are invisible for rebuild purposes. This means that a change to the header does not get caught by make to recompile.

The change

-MMD makes the compiler write a .d file beside each .o listing the headers that object actually included. -MP adds a dummy target for each of those headers so that deleting or renaming one does not break the build with "No rule to make target". The .d files are then read back in as prerequisites. Nothing is hand-maintained.

Three lines per Makefile, applied to all 30:

  • DEPFLAGS := -MMD -MP, appended to COMPILE_COMMAND. Not to LINK_COMMAND, which does not compile.
  • rm -f *.d in clean. unit_tests/cell_definition/Makefile has no clean target, so it gets the flags and the include and nothing else.
  • -include $(ALL_OBJECTS:.o=.d) at the very end of the file.

That last point is load-bearing and I left a comment saying so in each file. Each .d declares rules for its own .o, so including them any earlier in the file makes the first of those the default goal — make with no arguments would build BioFVM_vector.o and stop instead of building the project.

*.d is gitignored.

Verification

Built four projects covering the shapes that differ — a plain one, one with an addon, and the two COMPILE_COMMAND variants — then touched core/PhysiCell_cell.h and asked make what it would do:

project objects .d written rebuilt after touching the header
template 28 29 14
interaction-sample 28 29 14
physimess-sample 32 33 16
worm-sample 28 29 11

The counts differ per project because only the objects that actually include that header rebuild, which is the point. The control is the interesting one: with the current Makefiles the same touch rebuilds zero objects and goes straight to relinking.

Scope

Deliberately mechanical and limited to the build system. No source file is touched. The intracellular projects that link prebuilt libraries get .d files only for the objects these Makefiles compile, which is strictly better than none.

Every object rule names only its .cpp, so make never rebuilds an object
when a header it includes changes. Editing a header and running make
relinks the stale objects and reports success.

That is merely confusing when the change is behavioural. It is dangerous
when the header changes a type's layout: the objects that did get
rebuilt disagree with the ones that did not about member offsets and
sizeof, the link succeeds because mangled names encode types rather than
layouts, and the result is a binary that reads fields at the wrong
addresses. The crash looks like a bug in the code under test.

-MMD makes the compiler emit a .d file beside each .o listing the
headers that object actually included; -MP adds a dummy target for each
so that deleting or renaming a header does not break the build. The .d
files are read back in at the bottom of each Makefile, which is where
they have to be: each one declares rules for its own .o, so including
them earlier would replace `all` as the default goal.

Applied to all 30 Makefiles, clean removes the generated .d files, and
they are gitignored. unit_tests/cell_definition has no clean target, so
it gets the flags and the include but nothing to extend.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@drbergman
drbergman force-pushed the claude/makefile-header-deps branch from f750ba5 to 47692be Compare August 7, 2026 16:57
drbergman added a commit to drbergman/PhysiCell that referenced this pull request Aug 7, 2026
Every object rule names only its .cpp, so make never rebuilds an object
when a header it includes changes. Editing a header and running make
relinks the stale objects and reports success.

That is merely confusing when the change is behavioural. It is dangerous
when the header changes a type's layout: the objects that did get
rebuilt disagree with the ones that did not about member offsets and
sizeof, the link succeeds because mangled names encode types rather than
layouts, and the result is a binary that reads fields at the wrong
addresses. The crash looks like a bug in the code under test.

-MMD makes the compiler emit a .d file beside each .o listing the
headers that object actually included; -MP adds a dummy target for each
so that deleting or renaming a header does not break the build. The .d
files are read back in at the bottom of each Makefile, which is where
they have to be: each one declares rules for its own .o, so including
them earlier would replace `all` as the default goal.

Applied to all 44 Makefiles, clean removes the generated .d files, and
they are gitignored.

Mirror of MathCancer#426 for my-physicell.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@drbergman
drbergman marked this pull request as ready for review August 8, 2026 20:03
Copilot AI lite review requested due to automatic review settings August 8, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants