qments/Makefile

42 lines
870 B
Makefile
Raw Normal View History

STATIC_LIB ?= libqments.a
SHARED_LIB ?= libqments.so
2023-06-15 01:44:02 +03:00
BD ?= build
SRC_DIRS ?= src
INCLUDE_DIRS ?= include
SBD ?= $(BD)/shared
2023-06-15 01:44:02 +03:00
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))
CFLAGS ?= -O2 -ansi -pedantic
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)
2023-06-15 01:44:02 +03:00
mkdir -p $(@D)
ar rcs $@ $(OBJ_FILES)
$(SBD)/%.o: %.c
mkdir -p $(@D)
$(CC) $(CFLAGS) -fPIC -c $< -o $@ -I $(INCLUDE_DIRS)
2023-06-15 01:44:02 +03:00
$(BD)/%.o: %.c
mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@ -I $(INCLUDE_DIRS)
all: shared static
2023-06-15 01:44:02 +03:00
clean:
rm -rfI $(BD)/
.PHONY: all clean shared static