CONFIG := DEFINE := INCLUDE := -Icommon CFLAGS := -Wall -Wextra -Werror -O2 $(EXTRA_CFLAGS) LDFLAGS := $(EXTRA_LDFLAGS) LIBS := -lBlinkenLib $(EXTRA_LIBS) TARGET := Blinker ifeq ($(CROSS_WIN),1) CXX := x86_64-w64-mingw32-g++ PLATFORM := windows TARGET := Blinker.exe else CXX := g++ PLATFORM := linux endif INCLUDE += -I$(PLATFORM) CFGS := $(wildcard config/*.cfg.sh) CFGS_BASE := $(patsubst %.cfg.sh,%,$(CFGS)) CFGS_MK := $(addsuffix .cfg.mk,$(CFGS_BASE)) SRCS := $(wildcard common/*.cpp) $(wildcard $(PLATFORM)/*.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 $@/$(PLATFORM) 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 -rf obj $(TARGET) distclean: clean rm -f config.mk $(CFGS_MK)