2024-07-16 10:20:28 +00:00
|
|
|
# Build type (debug, sanitize, or release)
|
|
|
|
BUILD_TYPE := debug
|
|
|
|
|
|
|
|
COMMON_CFLAGS = -Wall -Wextra -Wpedantic -std=c11 -fPIC -I.
|
|
|
|
CFLAGS_DEBUG = $(COMMON_CFLAGS) -Og -g -DSPARSEMAP_DIAGNOSTIC -DDEBUG
|
|
|
|
CFLAGS_SANITIZE = $(COMMON_CFLAGS) -Og -g -DSPARSEMAP_DIAGNOSTIC -DDEBUG -fsanitize=address,leak,object-size,pointer-compare,pointer-subtract,null,return,bounds,pointer-overflow,undefined -fsanitize-address-use-after-scope -std=c11
|
|
|
|
CFLAGS_RELEASE = $(COMMON_CFLAGS) -Ofast
|
|
|
|
CFLAGS_TEST = $(COMMON_CFLAGS) -Og -g -DDEBUG -I. -Itest
|
|
|
|
CFLAGS := $(if $(filter debug,$(BUILD_TYPE)),$(CFLAGS_DEBUG), \
|
|
|
|
$(if $(filter release,$(BUILD_TYPE)),$(CFLAGS_RELEASE), \
|
|
|
|
$(if $(filter sanitize,$(BUILD_TYPE)),$(CFLAGS_SANITIZE), \
|
|
|
|
$(error Unknown build type: $(BUILD_TYPE)))))
|
|
|
|
|
|
|
|
LDFLAGS = -lm
|
|
|
|
LDFLAGS_VERBOSE = -Wl,-v
|
|
|
|
|
|
|
|
SRCS = $(wildcard *.c)
|
|
|
|
OBJS = $(SRCS:.c=.o)
|
2024-04-10 20:13:48 +00:00
|
|
|
STATIC_LIB = libsparsemap.a
|
|
|
|
SHARED_LIB = libsparsemap.so
|
2024-07-16 10:20:28 +00:00
|
|
|
TEST_TARGETS = test/test test/soak test/ex_1 test/ex_2 test/ex_3 test/ex_4
|
|
|
|
TEST_SRCS = $(filter-out $(wildcard test/ex_*) test/midl.c $(TEST_TARGETS:=.c), $(wildcard test/*.c))
|
|
|
|
TEST_OBJS = $(TEST_SRCS:.c=.o)
|
|
|
|
TEST_DEPS = $(filter-out $(TEST_TARGETS:=.h), $(TEST_SRCS:.c=.h))
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
# Targets
|
|
|
|
all: $(STATIC_LIB) $(SHARED_LIB)
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
info:
|
|
|
|
$(info TEST_SRCS: $(TEST_SRCS))
|
|
|
|
$(info TEST_OBJS: $(TEST_OBJS))
|
|
|
|
$(info TEST_DEPS: $(TEST_DEPS))
|
2024-04-10 20:13:48 +00:00
|
|
|
|
|
|
|
$(STATIC_LIB): $(OBJS)
|
2024-07-16 10:20:28 +00:00
|
|
|
ar rcs libsparsemap.a $(OBJS)
|
2024-04-10 20:13:48 +00:00
|
|
|
|
|
|
|
$(SHARED_LIB): $(OBJS)
|
2024-07-16 10:20:28 +00:00
|
|
|
$(CC) -shared -o libsparsemap.so $(OBJS) $(LDFLAGS)
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
check: $(TEST_TARGETS)
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
test/test: $(TEST_OBJS) $(STATIC_LIB) test/test.o
|
|
|
|
$(CC) $^ $(LDFLAGS) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
test/soak: $(TEST_OBJS) $(STATIC_LIB) test/soak.o
|
|
|
|
$(CC) $^ $(LDFLAGS) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
test/ex_1: test/ex_1.o $(STATIC_LIB)
|
|
|
|
$(CC) $^ $(LDFLAGS) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
test/ex_2: test/ex_2.o $(STATIC_LIB)
|
|
|
|
$(CC) $^ $(LDFLAGS) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
test/ex_3: test/ex_3.o $(STATIC_LIB)
|
|
|
|
$(CC) $^ $(LDFLAGS) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
test/ex_4: test/ex_4.o $(STATIC_LIB)
|
|
|
|
$(CC) $^ $(LDFLAGS) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
$(TEST_OBJS): $(TEST_SRCS) $(TEST_DEPS)
|
|
|
|
$(CC) $(CFLAGS_TEST) -c $(subst .o,.c,$@) -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
$(OBJS): $(SRCS)
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
2024-04-10 20:13:48 +00:00
|
|
|
|
2024-07-16 10:20:28 +00:00
|
|
|
clean:
|
|
|
|
rm -f libsparsemap.a libsparsemap.so $(OBJS) $(TEST_OBJS) \
|
|
|
|
test/test test/soak test/ex_1 test/ex_2 test/ex_3 test/ex_4
|