-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (75 loc) · 2.06 KB
/
Makefile
File metadata and controls
116 lines (75 loc) · 2.06 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
.SUFFIXES:
.SUFFIXES: .c .h .o .so
# Output dynamic library
_OUT = percy
OUTDIR = .
OUT = $(OUTDIR)/lib$(_OUT).so
# Source code
_SRC = parser.c
SDIR = src
SRC = $(patsubst %,$(SDIR)/%,$(_SRC))
# Header files
_DEPS = parser.h
HDIR = include
DEPS = $(patsubst %,$(HDIR)/%,$(_DEPS))
# Object files
_OBJS = parser.o
ODIR = obj
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
# Files to compile for testing/demonstration
TOUT = percy_demo
TDIR = test
TEST = $(TDIR)/percy_demo.c $(HDIR)/parser.h
# Include directories
_IDIRS = include
IDIRS = $(patsubst %,-I%,$(_IDIRS))
# Libraries to be linked with `-l`
_LDLIBS = m
LDLIBS = $(patsubst %,-l%,$(_LDLIBS))
# multiple-precision libraries to be linked with `-l`
_LDLIBS_MP = mpc mpfr gmp
LDLIBS_MP = $(patsubst %,-l%,$(_LDLIBS_MP))
# 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 demomp mp
# Build with standard-precision
all: $(OUT)
demo: $(TOUT)
demomp: mp
demomp: CFLAGS += -D"MP_PREC" -lmpc -lmpfr -lgmp
demomp: $(TOUT)
# Build with multiple-precision extension
mp: CFLAGS += -D"MP_PREC"
mp: LDFLAGS += $(LDLIBS_MP)
mp: $(OUT)
# 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): $(OUT)
$(CC) $(TEST) -L$(OUTDIR) -Wl,-rpath=$(OUTDIR) -l$(_OUT) -lm $(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)