Skip to content

Instantly share code, notes, and snippets.

@aprell
Created October 8, 2012 14:12
Show Gist options
  • Save aprell/3852743 to your computer and use it in GitHub Desktop.
Save aprell/3852743 to your computer and use it in GitHub Desktop.
Makefile dependency generation
# Dependency generation
# Project must define SRCS
DEPS = $(addprefix deps/,$(SRCS:.c=.d))
deps/%.d: %.c
$(CC) -MM $(CFLAGS) $(CPPFLAGS) -o $@ $<
sed -i "s/\($*.o\)/\1 deps\/$(notdir $@)/g" $@
# Prevent make from generating dependencies when running 'make clean'
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment