-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
64 lines (47 loc) · 1.48 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
MKDIR := mkdir -p --
INCLUDE := ./include
SRC := ./src
SRCS := $(wildcard $(SRC)/*.c)
BIN := ./bin
OUT := $(BIN)/libutf8encoder.a
SO_OUT := $(BIN)/libutf8encoder.so
OBJ := ./obj
OBJS := $(patsubst $(SRC)/%.c,$(OBJ)/%.o,$(SRCS))
SO_OBJ := ./soobj
SO_OBJS := $(patsubst $(SRC)/%.c,$(SO_OBJ)/%.o,$(SRCS))
TESTSRC := ./tests
TESTSRCS := $(wildcard $(TESTSRC)/*.c)
TESTOUT := $(BIN)/test
SOTESTOUT := $(BIN)/sotest
WARNINGS := -Wall -Wextra -Wfloat-equal -Wundef
ERRORS := -Werror=implicit-int -Werror=implicit-function-declaration
CFLAGS := $(WARNINGS) $(ERRORS) -std=c99
DEBUGCFLAGS := -g3
RELEASECFLAGS := -O3
SO_C_FLAGS := -fPIC
SO_LD_FLAGS := -shared
.PHONY: static shared test sharedtest clean
$(OBJ)/%.o: $(SRC)/%.c
$(MKDIR) $(OBJ)
$(CC) $(CFLAGS) $(RELEASECFLAGS) -I$(INCLUDE) -c $^ -o $@
$(OUT): $(OBJS)
$(MKDIR) $(BIN)
ar rcvs $@ $^
static: $(OUT)
$(SO_OBJ)/%.o: $(SRC)/%.c
$(MKDIR) $(SO_OBJ)
$(CC) $(SO_C_FLAGS) $(RELEASECFLAGS) -I$(INCLUDE) -c $^ -o $@
$(SO_OUT): $(SO_OBJS)
mkdir -p -- $(BIN)
$(CC) $(SO_LD_FLAGS) $^ -o $@
shared: $(SO_OUT)
$(TESTOUT): clean $(OUT) $(TESTSRCS)
$(MKDIR) $(BIN)
$(CC) $(CFLAGS) $(DEBUGCFLAGS) $(TESTSRCS) -L$(BIN) -lutf8encoder -I$(INCLUDE) -o $@
$(SOTESTOUT): clean $(SO_OUT) $(TESTSRCS)
$(MKDIR) $(BIN)
$(CC) $(CFLAGS) $(DEBUGCFLAGS) $(TESTSRCS) -L$(BIN) -lutf8encoder -Wl,-rpath=$(BIN) -I$(INCLUDE) -o $@
test: $(TESTOUT)
sharedtest: $(SOTESTOUT)
clean:
rm -Rf -- $(BIN) $(OBJ) $(SO_OBJ)