BD ?= build SD ?= src LIBS_DIR ?= libs LIBS ?= $(wildcard $(LIBS_DIR)/*) CGI_EXECS ?= view_comments.cgi new_client.cgi EXEC_TARGETS := $(patsubst %.cgi,$(BD)/%.cgi,$(CGI_EXECS)) LDFLAGS ?= -L$(BD)/ -lcgic -lqments -lhiredis -ltomcrypt -luuid SRC_FILES := $(shell find $(SD) -name *.c) EXEC_OBJS := $(patsubst %.cgi,$(BD)/%.o,$(CGI_EXECS)) OBJ_FILES := $(filter-out $(EXEC_OBJS),$(patsubst $(SD)/%.c,$(BD)/%.o,$(SRC_FILES))) INCLUDE_DIRS = -Ilibs/qments/include -Ilibs/cgic LIB_TARGETS = $(patsubst $(LIBS_DIR)/%,$(BD)/lib%.a,$(LIBS)) CFLAGS ?= -O2 -std=c99 -pedantic $(BD)/libcgic.a: $(MAKE) -C $(LIBS_DIR)/cgic mkdir -p $(@D) cp $(LIBS_DIR)/cgic/libcgic.a $(BD) $(BD)/libqments.a: $(MAKE) -C $(LIBS_DIR)/qments static cp $(LIBS_DIR)/qments/$(BD)/libqments.a $(BD) $(BD)/%.cgi: $(BD)/%.o $(OBJ_FILES) mkdir -p $(@D) $(CC) $(INCLUDE_DIRS) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(BD)/%.o: $(SD)/%.c $(LIB_TARGETS) mkdir -p $(@D) $(CC) $(INCLUDE_DIRS) $(CFLAGS) -c $< -o $@ $(LDFLAGS) all: $(EXEC_TARGETS) clean: rm -rfI $(BD)/ .PHONY: all clean