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
|
*.o
|
||||||
|
*.d
|
||||||
ssd1306_bin
|
ssd1306_bin
|
||||||
|
16
Makefile
16
Makefile
@ -4,12 +4,22 @@ LDFLAGS=-static
|
|||||||
OBJS=main.o ssd1306.o linux_i2c.o
|
OBJS=main.o ssd1306.o linux_i2c.o
|
||||||
BIN=ssd1306_bin
|
BIN=ssd1306_bin
|
||||||
|
|
||||||
%.o:%.c
|
default: $(BIN)
|
||||||
$(CC) -c -o $@ $< $(CFLAGS)
|
.PHONY: default clean
|
||||||
|
|
||||||
|
# Adapted from scottmcpeak.com/autodepend/autodepend.html
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
%.o: %.c
|
||||||
|
$(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)
|
$(BIN):$(OBJS)
|
||||||
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ./*.o $(BIN)
|
rm -f *.o *.d $(BIN)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user