STATIC_LIB ?= libqments.a SHARED_LIB ?= libqments.so BD ?= build SRC_DIRS ?= src INCLUDE_DIRS ?= include SBD ?= $(BD)/shared SRC_FILES := $(shell find $(SRC_DIRS) -name *.c) OBJ_FILES := $(patsubst %.c,$(BD)/%.o,$(SRC_FILES)) OBJ_FILES := $(patsubst %.c,$(BD)/%.o,$(SRC_FILES)) SHARED_OBJ_FILES := $(patsubst %.c,$(SBD)/%.o,$(SRC_FILES)) shared: $(SBD)/$(SHARED_LIB) static: $(BD)/$(STATIC_LIB) $(SBD)/$(SHARED_LIB): $(SHARED_OBJ_FILES) $(CC) $(CFLAGS) -shared -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(BD)/$(STATIC_LIB): $(OBJ_FILES) mkdir -p $(@D) ar rcs $@ $(OBJ_FILES) $(SBD)/%.o: %.c mkdir -p $(@D) $(CC) $(CFLAGS) -fPIC -c $< -o $@ -I $(INCLUDE_DIRS) $(BD)/%.o: %.c mkdir -p $(@D) $(CC) $(CFLAGS) -c $< -o $@ -I $(INCLUDE_DIRS) all: shared static clean: rm -rfI $(BD)/ .PHONY: all clean shared static