Skip to content

Commit

Permalink
Add auto-dependency generation to Makefile
Browse files Browse the repository at this point in the history
Add automatic dependency generation to the Makefile. Previously, changes
to any of the header files would cause a re-link, but not a rebuild of
the source code files that include those headers.

Signed-off-by: Stefan Reinauer <[email protected]>
  • Loading branch information
reinauer committed Nov 21, 2020
1 parent e556c12 commit ea8131f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*.o
.deps
dpcmd
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@ LDFLAGS ?=
LDFLAGS += -lpthread
LDFLAGS += $(shell $(PKG_CONFIG) --libs libusb-1.0)

PROGRAMMER_OBJS += dpcmd.o usbdriver.o FlashCommand.o SerialFlash.o parse.o board.o project.o IntelHexFile.o MotorolaFile.o
DEPDIR := .deps
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d

$(PROGRAM): $(PROGRAMMER_OBJS) *.h Makefile
$(CC) $(CFLAGS) -o $(PROGRAM) $(PROGRAMMER_OBJS) $(LDFLAGS)
SRCS = dpcmd.c usbdriver.c FlashCommand.c SerialFlash.c parse.c board.c project.c IntelHexFile.c MotorolaFile.c

PROGRAMMER_OBJS := $(SRCS:%.c=%.o)

$(PROGRAM): $(PROGRAMMER_OBJS)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ $(LDFLAGS)

%.o : %.c
%.o : %.c $(DEPDIR)/%.d | $(DEPDIR)
$(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

$(DEPDIR): ; @mkdir -p $@

DEPFILES := $(SRCS:%.c=$(DEPDIR)/%.d)
$(DEPFILES):

include $(wildcard $(DEPFILES))

clean:
@rm -vf $(PROGRAM) $(PROGRAM).exe *.o *.d
rm -vf $(PROGRAM) $(PROGRAM).exe *.o
rm -rvf $(DEPDIR)

install: $(PROGRAM)
@[ $(shell id -u) -eq 0 ] || (echo "Error: install needs root privileges" && false)
Expand Down

0 comments on commit ea8131f

Please sign in to comment.