Skip to content

examples/c: rebuild on header changes via -MMD - #371

Merged
danielocfb merged 1 commit into
libbpf:masterfrom
Dhanya16:fix/makefile-header-deps-mmd
Aug 25, 2026
Merged

examples/c: rebuild on header changes via -MMD#371
danielocfb merged 1 commit into
libbpf:masterfrom
Dhanya16:fix/makefile-header-deps-mmd

Conversation

@Dhanya16

Copy link
Copy Markdown
Contributor

$(wildcard %.h) does not expand the pattern stem, so local headers were never prerequisites. Generate dependency files with -MMD/-MP, and use -MT for BPF objects so deps attach to the final .bpf.o rather than the temporary .tmp.bpf.o.

Fixes #275

Test plan

  • touch bootstrap.h && make bootstrap rebuilds BPF/skel/CC/binary
  • touch bootstrap.h && make .output/bootstrap.bpf.o rebuilds
  • .d files list bootstrap.h; BPF .d targets .bpf.o (not .tmp)

Before:

$ touch bootstrap.bpf.c
$ make bootstrap
  BPF      .output/bootstrap.bpf.o
  GEN-SKEL .output/bootstrap.skel.h
  CC       .output/bootstrap.o
  BINARY   bootstrap
$ touch bootstrap.c
$ make bootstrap
  CC       .output/bootstrap.o
  BINARY   bootstrap
$ touch bootstrap.h
$ make bootstrap
make: 'bootstrap' is up to date.
$ touch bootstrap.h
$ make .output/bootstrap.bpf.o
make: '.output/bootstrap.bpf.o' is up to date.

After:

$ touch bootstrap.h
$ make bootstrap
  BPF      .output/bootstrap.bpf.o
  GEN-SKEL .output/bootstrap.skel.h
  CC       .output/bootstrap.o
  BINARY   bootstrap
$ touch bootstrap.h
$ make .output/bootstrap.bpf.o
  BPF      .output/bootstrap.bpf.o

$(wildcard %.h) does not expand the pattern stem, so local headers
were never prerequisites. Generate dependency files with -MMD/-MP,
and use -MT for BPF objects so deps attach to the final .bpf.o
rather than the temporary .tmp.bpf.o.
Fixes libbpf#275

Signed-off-by: Dhanya16 <dhanyabailoor@gmail.com>
@Dhanya16
Dhanya16 force-pushed the fix/makefile-header-deps-mmd branch from 67b013d to 41ddbc6 Compare August 21, 2026 15:23
@danielocfb danielocfb self-assigned this Aug 25, 2026

@danielocfb danielocfb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me, thanks for the fix.

@danielocfb
danielocfb merged commit d853739 into libbpf:master Aug 25, 2026
23 of 24 checks passed
@danielocfb

Copy link
Copy Markdown
Collaborator

Btw, I think the CMake path has a similar issue, in case you feel like looking at that as well.

@Dhanya16

Copy link
Copy Markdown
Contributor Author

Thanks! I'll investigate the CMake side and send a follow-up PR.

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.

Make doesn't detect changes in the header files

2 participants