-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·158 lines (114 loc) · 4.96 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
.PHONY: all all_shared all_static all_8 all_16 all_32 shared_8 shared_16 shared_32 static_8 static_16 static_32 clean
###############################################################################
# Some overridable build settings
#compiler
CXX:=g++
#archiver - for static libs
AR:=ar rcs
#pkg-config
PKG_CONFIG:=pkg-config
# Set to "1" to disable C++11
WITHOUT_CPP11:=0
###############################################################################
# get flags from pkg-config, ignore errors here
PCRE_CFLAGS:=$(shell $(PKG_CONFIG) --cflags libpcre 2>/dev/null)
PCRE_LIBS:=$(shell $(PKG_CONFIG) --libs libpcre 2>/dev/null)
PCRE16_CFLAGS:=$(shell $(PKG_CONFIG) --cflags libpcre16 2>/dev/null)
PCRE16_LIBS:=$(shell pkg-config --libs libpcre16 2>/dev/null)
PCRE32_CFLAGS:=$(shell $(PKG_CONFIG) --cflags libpcre32 2>/dev/null)
PCRE32_LIBS:=$(shell $(PKG_CONFIG) --libs libpcre32 2>/dev/null)
CUMMON_LIBS:=
COMMON_CFLAGS=-fPIC
ifneq (1,$(WITHOUT_CPP11))
COMMON_CFLAGS+=-std=c++11 # recommended, but can do without
endif
COMMON_CFLAGS+=-O3 # Optimization level
COMMON_CFLAGS+=-g # debug symbols
COMMON_CFLAGS+=-Wall # all warnings
COMMON_CFLAGS+=-Werror # treat warnings as errors
PCRSCPP_VERSION:=0.0.1
PCRSCPP_SO_VERSION:=0
LIBPCRSCPP_shared=libpcrscpp.so.$(PCRSCPP_VERSION)
LIBPCRSCPP_static=libpcrscpp.a
LIBPCRSCPP16_shared=libpcrscpp16.so.$(PCRSCPP_VERSION)
LIBPCRSCPP16_static=libpcrscpp16.a
LIBPCRSCPP32_shared=libpcrscpp32.so.$(PCRSCPP_VERSION)
LIBPCRSCPP32_static=libpcrscpp32.a
#default target
all: all_shared all_static test test16 test32
@echo "All done"
shared_8: $(LIBPCRSCPP_shared)
shared_16: $(LIBPCRSCPP16_shared)
shared_32: $(LIBPCRSCPP32_shared)
all_shared: shared_8 shared_16 shared_32
static_8: $(LIBPCRSCPP_static)
static_16: $(LIBPCRSCPP16_static)
static_32: $(LIBPCRSCPP32_static)
all_static: static_8 static_16 static_32
$(LIBPCRSCPP_shared): obj/pcrscpp.o
rm -f $@
$(CXX) -shared -Wl,-soname,libpcrscpp.so.$(PCRSCPP_SO_VERSION) -o $@ $^ $(PCRE_LIBS) $(CUMMON_LIBS)
$(LIBPCRSCPP_static): obj/pcrscpp.o
rm -f $@
$(AR) $@ $^
$(LIBPCRSCPP16_shared): obj/pcrscpp16.o
rm -f $@
$(CXX) -shared -Wl,-soname,libpcrscpp16.so.$(PCRSCPP_SO_VERSION) -o $@ $^ $(PCRE16_LIBS) $(CUMMON_LIBS)
$(LIBPCRSCPP16_static): obj/pcrscpp16.o
rm -f $@
$(AR) $@ $^
$(LIBPCRSCPP32_shared): obj/pcrscpp32.o
rm -f $@
$(CXX) -shared -Wl,-soname,libpcrscpp32.so.$(PCRSCPP_SO_VERSION) -o $@ $^ $(PCRE32_LIBS) $(CUMMON_LIBS)
$(LIBPCRSCPP32_static): obj/pcrscpp32.o
rm -f $@
$(AR) $@ $^
obj:
@mkdir -p "$@"
obj/pcrscpp.o: src/pcrscpp.cpp src/pcrscpp_macros.h include/pcrscpp.h|obj
rm -f $@
@$(PKG_CONFIG) --version 2>&1 >/dev/null || \
(echo "Error: cannot find pkg-config. Try setting PKG_CONFIG make variable"; exit 1)
@$(PKG_CONFIG) libpcre 2>&1 >/dev/null || \
(echo "Error: $(PKG_CONFIG) cannot find libpcre"; exit 1)
$(CXX) -Iinclude $(PCRE_CFLAGS) $(COMMON_CFLAGS) -UPCRSCPP16 -UPCRSCPP32 -c src/pcrscpp.cpp -o $@
obj/pcrscpp16.o: src/pcrscpp.cpp src/pcrscpp_macros.h include/pcrscpp.h|obj
rm -f $@
@$(PKG_CONFIG) --version 2>&1 >/dev/null || \
(echo "Error: cannot find pkg-config. Try setting PKG_CONFIG make variable"; exit 1)
@$(PKG_CONFIG) libpcre16 2>&1 >/dev/null || \
(echo "Error: $(PKG_CONFIG) cannot find libpcre16"; exit 1)
$(CXX) -Iinclude $(PCRE16_CFLAGS) $(COMMON_CFLAGS) -DPCRSCPP16 -UPCRSCPP32 -c src/pcrscpp.cpp -o $@
obj/pcrscpp32.o: src/pcrscpp.cpp src/pcrscpp_macros.h include/pcrscpp.h|obj
rm -f $@
@$(PKG_CONFIG) --version 2>&1 >/dev/null || \
(echo "Error: cannot find pkg-config. Try setting PKG_CONFIG make variable"; exit 1)
@$(PKG_CONFIG) libpcre32 2>&1 >/dev/null || \
(echo "Error: $(PKG_CONFIG) cannot find libpcre32"; exit 1)
$(CXX) -Iinclude $(PCRE16_CFLAGS) $(COMMON_CFLAGS) -UPCRSCPP16 -DPCRSCPP32 -c src/pcrscpp.cpp -o $@
clean:
rm -f obj/pcrscpp.o obj/pcrscpp16.o obj/pcrscpp32.o \
$(LIBPCRSCPP_shared) $(LIBPCRSCPP_static) \
$(LIBPCRSCPP16_shared) $(LIBPCRSCPP16_static) \
$(LIBPCRSCPP32_shared) $(LIBPCRSCPP32_static) \
obj/test.o test obj/test16.o test16 obj/test32.o test32
obj/test.o: src/test.cpp $(LIBPCRSCPP_static)|obj
$(CXX) -Iinclude $(PCRE_CFLAGS) $(COMMON_CFLAGS) -c src/test.cpp -o obj/test.o
test: obj/test.o
$(CXX) $^ $(LIBPCRSCPP_static) $(PCRE_LIBS) $(CUMMON_LIBS) -o $@
obj/test16.o: src/test16.cpp $(LIBPCRSCPP16_static)|obj
ifneq (1,$(WITHOUT_CPP11))
$(CXX) -Iinclude $(PCRE16_CFLAGS) $(COMMON_CFLAGS) -c src/test16.cpp -o obj/test16.o
else
$(CXX) -Iinclude $(PCRE16_CFLAGS) $(filter-out -Werror,$(COMMON_CFLAGS)) -c src/test16.cpp -o obj/test16.o
endif
test16: obj/test16.o
$(CXX) $^ $(LIBPCRSCPP16_static) $(PCRE16_LIBS) $(CUMMON_LIBS) -o $@
obj/test32.o: src/test32.cpp $(LIBPCRSCPP16_static)|obj
ifneq (1,$(WITHOUT_CPP11))
$(CXX) -Iinclude $(PCRE32_CFLAGS) $(COMMON_CFLAGS) -c src/test32.cpp -o obj/test32.o
else
$(CXX) -Iinclude $(PCRE32_CFLAGS) $(filter-out -Werror,$(COMMON_CFLAGS)) -c src/test32.cpp -o obj/test32.o
endif
test32: obj/test32.o
$(CXX) $^ $(LIBPCRSCPP32_static) $(PCRE32_LIBS) $(CUMMON_LIBS) -o $@