TARGET := Blinker CXX := g++ CONFIG := DEFINE := INCLUDE := -Icommon -Ilinux CFLAGS := -Wall -Wextra -Werror -O2 LDFLAGS := LIBS := -lBlinkenLib CFGS := $(wildcard config/*.cfg.sh) CFGS_BASE := $(patsubst %.cfg.sh,%,$(CFGS)) CFGS_MK := $(addsuffix .cfg.mk,$(CFGS_BASE)) SRCS := $(wildcard common/*.cpp) $(wildcard linux/*.cpp) SRCS_BASE := $(patsubst %.cpp,%,$(SRCS)) DEPS := $(addprefix obj/,$(addsuffix .d,$(SRCS_BASE))) OBJS := $(addprefix obj/,$(addsuffix .o,$(SRCS_BASE))) .PHONY: all clean distclean .SUFFIXES: .SECONDARY: all: $(DEPS) $(TARGET) ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) include config.mk -include $(DEPS) endif endif DEFINE += -DBLINKER_CONFIG="\"$(CONFIG)\"" config.mk: $(CFGS_MK) cat /dev/null $^ >$@ %.cfg.mk: %.cfg.sh sh $< >$@ obj: mkdir $@ $@/common $@/linux obj/%.d: %.cpp Makefile config.mk | obj $(CXX) $(DEFINE) $(INCLUDE) $(CFLAGS) -MM -MT $(@:.d=.o) -o $@ $< obj/%.o: %.cpp Makefile | obj $(CXX) $(DEFINE) $(INCLUDE) $(CFLAGS) -c -o $@ $< $(TARGET): $(OBJS) $(CXX) $(LDFLAGS) -o $@ $+ $(LIBS) clean: rm -f obj $(TARGET) distclean: clean rm -f config.mk $(CFGS_MK)