Makefile: automatically generate dependencies.
This uses a trick from scottmcpeak.com/autodepend/autodepend.html. It may seem like overkill for such a small codebase, but note that header modifications did not trigger rebuilds in the affected object files in the existing Makefile.
This commit is contained in:
parent
89e96e759a
commit
c9c370e466
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.o
|
||||
*.d
|
||||
ssd1306_bin
|
||||
|
14
Makefile
14
Makefile
@ -4,12 +4,22 @@ LDFLAGS=-static
|
||||
OBJS=main.o ssd1306.o linux_i2c.o
|
||||
BIN=ssd1306_bin
|
||||
|
||||
default: $(BIN)
|
||||
.PHONY: default clean
|
||||
|
||||
# Adapted from scottmcpeak.com/autodepend/autodepend.html
|
||||
-include $(OBJS:.o=.d)
|
||||
%.o: %.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
$(CC) -c $(CFLAGS) $< -o $*.o
|
||||
$(CC) -MM $(CFLAGS) $< > $*.d
|
||||
@cp -f $*.d $*.d.tmp
|
||||
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
|
||||
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
|
||||
@rm -f $*.d.tmp
|
||||
|
||||
$(BIN):$(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f ./*.o $(BIN)
|
||||
rm -f *.o *.d $(BIN)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user