Skip to content

Instantly share code, notes, and snippets.

@JayKickliter
Last active September 7, 2024 21:12
Show Gist options
  • Save JayKickliter/3119fce6eee578990e8686aa98aee639 to your computer and use it in GitHub Desktop.
Save JayKickliter/3119fce6eee578990e8686aa98aee639 to your computer and use it in GitHub Desktop.
GNU Make: force recompile when flags change
# Make OBJS depend on CPP/C/CXX/LD flags
$(OBJS): $(BUILDDIR)/flags.txt
# Creates a new flags.txt file when flags change
# make will detect this change and force a rebuild of
# all the sources
.PHONY: flags
$(BUILDDIR)/flags.txt: flags
$(Q){ \
TMP=`mktemp`; \
echo 'CPPFLAGS: $(CPPFLAGS)' >> $$TMP; \
echo 'CFLAGS: $(CFLAGS)' >> $$TMP; \
echo 'CXXFLAGS: $(CXXFLAGS)' >> $$TMP; \
echo 'LDFLAGS: $(LDFLAGS)' >> $$TMP; \
cmp -s $$TMP $@ || mv -f $$TMP $@; \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment