-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
77 lines (58 loc) · 1.9 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Compiler
ifeq ($(OS), Windows_NT)
$(error Windows is not supported)
endif
CC = gcc
SRC_DIR = src
BUILD_DIR = build
BIN_DIR = bin
LDFLAGS = -lssl -lcrypto -lsqlite3 -ljansson
CFLAGS = -O2 -Wall -Werror -Wextra -I$(SRC_DIR) -I./include -pthread -g
ifeq ($(shell uname), Darwin)
HOMEBREW_PREFIX := $(shell brew --prefix openssl@3)
JANSSON_PREFIX := $(shell brew --prefix jansson)
ifeq ($(HOMEBREW_PREFIX),)
$(error openssl@3 is not installed, make sure its installed with `brew install openssl@3`)
endif
ifeq ($(JANSSON_PREFIX),)
$(error jansson is not installed, make sure its installed with `brew install jansson`)
endif
CFLAGS += -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/jansson/include -fsanitize=thread,undefined
LDFLAGS += -L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/jansson/lib
endif
# Export dynamic symbols on Linux
ifeq ($(shell uname), Linux)
CFLAGS += -Wl,--export-dynamic -fsanitize=thread,undefined,bounds
endif
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
TARGET = $(BIN_DIR)/cweb
# Library
LIB_DIR = libs
LIB_SRCS = libs/module.c src/map.c
LIB_OBJS = $(patsubst $(LIB_DIR)/%.c, $(BUILD_DIR)/%.o, $(LIB_SRCS))
LIB_TARGET = $(LIB_DIR)/libmodule.so
all: $(LIB_TARGET) $(TARGET)
$(TARGET): $(OBJS) ${LIB_DIR}/libevent.so
@mkdir -p $(BIN_DIR)
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(LIB_TARGET): $(LIB_OBJS)
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) -I./include -fPIC -shared -o $@ $^
$(BUILD_DIR)/%.o: $(LIB_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
${LIB_DIR}/libevent.so: ${LIB_DIR}/libevent.c
$(CC) $(CFLAGS) -fPIC -shared -o $@ $^
clean:
rm -rf $(BUILD_DIR) $(BIN_DIR)
rm -f $(LIB_TARGET) libs/libevent.so
purge:
rm -rf ./modules/*.so
rm -rf ./modules/routes.dat
run: all
$(TARGET)
.PHONY: all clean run