Skip to content

Commit

Permalink
C template: even better Makefile (with dependency management)
Browse files Browse the repository at this point in the history
  • Loading branch information
42LoCo42 committed Dec 10, 2023
1 parent b6726f7 commit 50cbdd5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion templates/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ CFLAGS += $(shell pkg-config --cflags $(DEPS))
LDFLAGS += $(shell pkg-config --libs $(DEPS))

SRCS := $(shell find -name '*.c')
INCS := $(patsubst %.c,build/%.d,$(SRCS))
OBJS := $(patsubst %.c,build/%.o,$(SRCS))
DIRS := $(sort $(shell dirname $(OBJS)))

$(shell mkdir -p $(DIRS))

all: $(NAME)

-include $(INCS)

build/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -c $< -MMD -o $@

$(NAME): $(OBJS)
$(CC) $(LDFLAGS) $^ -o $@
Expand Down

0 comments on commit 50cbdd5

Please sign in to comment.