-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
98 lines (61 loc) · 1.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
.SUFFIXES:
.SUFFIXES: .c .h .o .so
# Output dynamic library
_OUT = groot
OUTDIR = .
OUT = $(OUTDIR)/lib$(_OUT).so
# Source code
_SRC = log.c
SDIR = src
SRC = $(patsubst %,$(SDIR)/%,$(_SRC))
# Header files
_DEPS = log.h
HDIR = include
DEPS = $(patsubst %,$(HDIR)/%,$(_DEPS))
# Object files
_OBJS = log.o
ODIR = obj
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
# Files to compile for testing/demonstration
TOUT = groot_demo
TDIR = test
TEST = $(TDIR)/groot_demo.c $(HDIR)/log.h
# Include directories
_IDIRS = include
IDIRS = $(patsubst %,-I%,$(_IDIRS))
# Compiler name
CC = gcc
# Compiler optimisation options
COPT = -O2
# Compiler options
CFLAGS = $(IDIRS) $(COPT) -fPIC -g -std=c99 -pedantic \
-Wall -Wextra -Wcast-align -Wcast-qual -Wdisabled-optimization -Wformat=2 \
-Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs \
-Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 \
-Wswitch-default -Wundef
# Linker name
LD = gcc
# Linker optimisation options
LDOPT = -O2
# Linker options
LDFLAGS = $(LDLIBS) $(LDOPT) -shared
.PHONY: all demo
all: $(OUT)
demo: $(TOUT)
# Compile source into object files
$(OBJS): $(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
@ mkdir -p $(ODIR)
$(CC) -c $< $(CFLAGS) -o $@
# Compile object files into dynamic library
$(OUT): $(OBJS)
$(LD) $(OBJS) $(LDFLAGS) -o $(OUT)
# Simple compile of demonstration script
$(TOUT): all
$(CC) $(TEST) -L$(OUTDIR) -Wl,-rpath=$(OUTDIR) -l$(_OUT) $(CFLAGS) -o $(TOUT)
.PHONY: clean-all clean clean-demo
# Remove object files and dynamic library
clean-all: clean clean-demo
clean:
rm -f $(OBJS) $(OUT)
clean-demo:
rm -f $(TOUT)