Skip to content

Instantly share code, notes, and snippets.

@waveacme
Created March 17, 2016 08:14
Show Gist options
  • Save waveacme/e45914e53e7499a43be5 to your computer and use it in GitHub Desktop.
Save waveacme/e45914e53e7499a43be5 to your computer and use it in GitHub Desktop.
general Makefile
CC=gcc
CFLAGS=-Wall -IDIR
LDFLAGS=-LDIR -lfoo
TARGET= a.out
#SOURCES=bar.c
SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:.c=.o)
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $^ -o $@ $(LDFLAGS)
clean:
-rm $(TARGET) *.o *.d *.d.*
.PHONY: clean
-include $(SOURCES:.c=.d)
%.d: %.c
@set -e; rm -f $@; \
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
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