Generate header dependencies so header edits trigger a rebuild - #426
Open
drbergman wants to merge 1 commit into
Open
Generate header dependencies so header edits trigger a rebuild#426drbergman wants to merge 1 commit into
drbergman wants to merge 1 commit into
Conversation
drbergman
force-pushed
the
claude/makefile-header-deps
branch
from
August 7, 2026 12:53
2ef8bf4 to
f750ba5
Compare
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
force-pushed
the
claude/makefile-header-deps
branch
from
August 7, 2026 16:57
f750ba5 to
47692be
Compare
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
marked this pull request as ready for review
August 8, 2026 20:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
maketo recompile.The change
-MMDmakes the compiler write a.dfile beside each.olisting the headers that object actually included.-MPadds 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.dfiles are then read back in as prerequisites. Nothing is hand-maintained.Three lines per Makefile, applied to all 30:
DEPFLAGS := -MMD -MP, appended toCOMPILE_COMMAND. Not toLINK_COMMAND, which does not compile.rm -f *.dinclean.unit_tests/cell_definition/Makefilehas nocleantarget, 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
.ddeclares rules for its own.o, so including them any earlier in the file makes the first of those the default goal —makewith no arguments would buildBioFVM_vector.oand stop instead of building the project.*.dis gitignored.Verification
Built four projects covering the shapes that differ — a plain one, one with an addon, and the two
COMPILE_COMMANDvariants — then touchedcore/PhysiCell_cell.hand asked make what it would do:.dwrittentemplateinteraction-samplephysimess-sampleworm-sampleThe 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
.dfiles only for the objects these Makefiles compile, which is strictly better than none.