Skip to content

Instantly share code, notes, and snippets.

@xieyunzi
Last active August 8, 2018 06:52
Show Gist options
  • Save xieyunzi/9666aea9af17eacee3d8c7f1fe1efb35 to your computer and use it in GitHub Desktop.
Save xieyunzi/9666aea9af17eacee3d8c7f1fe1efb35 to your computer and use it in GitHub Desktop.
makefile for c
CFLAGS= -I../include
# https://stackoverflow.com/questions/22551167/using-a-result-of-shells-find-as-a-target-in-a-makefile
sources = $(shell find . -maxdepth 1 -name '*.c')
include $(sources:.c=.d)
# http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html
# generate dependencies
%.d: %.c
@set -e; rm -f $@; \
$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment