-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcompat.inc
169 lines (144 loc) · 4.2 KB
/
compat.inc
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
158
159
160
161
162
163
164
165
166
167
168
169
#
# Makefile compiler compatibility checks.
# Define flags for optional compiler flags or settings to keep most
# of the compiler version check jank out of the main Makefile.
#
#
# Assume GCC until proven wrong...
#
COMPILER := ${shell \
compiler="gcc"; \
command -v ${CC} >/dev/null || compiler="error"; \
tmp=`${CC} --version`; \
echo $$tmp | grep -qi "clang version" && compiler="clang"; \
echo $$tmp | grep -qi "LLVM version" && compiler="clang"; \
echo $$tmp | grep -qi "emcc" && compiler="clang"; \
echo $$compiler; }
ifeq (${COMPILER},error)
$(error CC not found: ${CC})
endif
#
# Get compiler version (GCC).
#
ifeq (${COMPILER},gcc)
GCC_VER := ${shell ${CC} -dumpfullversion -dumpversion |\
awk -F. '{print $$3+100*($$2+100*$$1)}'}
GCC_VER_GE_4 := ${shell test ${GCC_VER} -ge 40000; echo $$?}
endif
#
# Get compiler version (clang).
#
ifeq (${COMPILER},clang)
CLANG_VER_FLAG = "--version"
#
# Emscripten uses completely different version numbering and the easiest way
# to get the clang version is to run it with verbose sanity checks instead.
# Because of this, stderr needs to be redirected to stdout for this command.
#
ifeq (${CC},emcc)
CLANG_VER_FLAG = "-v"
endif
CLANG_VER := ${shell ${CC} ${CLANG_VER_FLAG} 2>&1 |\
grep -oi "version.* [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" |\
grep -o "[0-9][0-9]*.*" |\
awk -F. '{print $$3+100*($$2+100*$$1)}'}
COMPILERXX := ${shell \
compiler="gcc"; \
tmp=`${CXX} --version`; \
echo $$tmp | grep -qi "clang version" && compiler="clang"; \
echo $$tmp | grep -qi "LLVM version" && compiler="clang"; \
echo $$tmp | grep -qi "emcc" && compiler="clang"; \
echo $$compiler; }
ifneq (${COMPILERXX},clang)
$(warning CC is clang but CXX isn't clang++; disabling compiler-specific checks.)
COMPILER := unknown
endif
GCC_VER := 40201
GCC_VER_GE_4 := 0
endif
#
# Features requiring GCC 4 minimum and compatible with clang.
#
ifeq (${GCC_VER_GE_4},0)
HAS_PEDANTIC ?= 1
HAS_F_VISIBILITY ?= 1
HAS_W_NO_VARIADIC_MACROS ?= 1
GCC_VER_GE_4_1 := ${shell test ${GCC_VER} -ge 40100; echo $$?}
ifeq (${GCC_VER_GE_4_1},0)
HAS_F_STACK_PROTECTOR ?= 1
endif
GCC_VER_GE_4_3 := ${shell test ${GCC_VER} -ge 40300; echo $$?}
ifeq (${GCC_VER_GE_4_3},0)
HAS_W_MISSING_DECLARATIONS_CXX ?= 1
HAS_W_VLA ?= 1
endif
endif
#
# Features requiring higher versions of GCC.
#
ifeq (${COMPILER},gcc)
GCC_VER_GE_4_5 := ${shell test ${GCC_VER} -ge 40500; echo $$?}
ifeq ($(GCC_VER_GE_4_5),0)
HAS_F_LTO ?= 1
endif
GCC_VER_GE_4_6 := ${shell test ${GCC_VER} -ge 40600; echo $$?}
ifeq ($(GCC_VER_GE_4_6),0)
HAS_W_NO_UNUSED_BUT_SET_VARIABLE ?= 1
endif
GCC_VER_GE_4_9 := ${shell test ${GCC_VER} -ge 40900; echo $$?}
ifeq (${GCC_VER_GE_4_9},0)
HAS_F_STACK_PROTECTOR_STRONG ?= 1
endif
GCC_VER_GE_7 := ${shell test ${GCC_VER} -ge 70000; echo $$?}
ifeq ($(GCC_VER_GE_7),0)
HAS_W_NO_FORMAT_TRUNCATION ?= 1
HAS_W_NO_IMPLICIT_FALLTHROUGH ?= 1
endif
GCC_VER_GE_10 := ${shell test ${GCC_VER} -ge 100000; echo $$?}
ifeq (${GCC_VER_GE_10},0)
HAS_F_ANALYZER ?= 1
endif
endif
#
# C++11 support (GCC).
# C++11 is optional or unused for all core MegaZeux features, but may be
# required in the future for optional features (e.g. the network layer).
#
ifeq (${COMPILER},gcc)
GCC_VER_GE_4_8 := ${shell test ${GCC_VER} -ge 40800; echo $$?}
ifeq (${GCC_VER_GE_4_8},0)
HAS_CXX_11 ?= 1
#
# -Wmissing-field-initializers doesn't properly support C++11 value
# initialization in GCC versions prior to 5 and will emit spurious warnings.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61489
#
GCC_VER_GE_5 := ${shell test ${GCC_VER} -ge 50000; echo $$?}
ifneq (${GCC_VER_GE_5},0)
HAS_BROKEN_W_MISSING_FIELD_INITIALIZERS ?= 1
endif
endif
endif # GCC
#
# C++11 support (clang).
#
ifeq (${COMPILER},clang)
# Not clear when this was added but it's old.
HAS_F_LTO ?= 1
CLANG_VER_GE_3_3 := ${shell test "${CLANG_VER}" -ge 30300; echo $$?}
ifeq (${CLANG_VER_GE_3_3},0)
HAS_CXX_11 ?= 1
endif
CLANG_VER_GE_3_5 := ${shell test "${CLANG_VER}" -ge 30500; echo $$?}
ifeq (${CLANG_VER_GE_3_3},0)
HAS_F_STACK_PROTECTOR_STRONG ?= 1
endif
endif # clang
#
# Get pkgconf or pkg-config (prefer pkgconf).
#
PKGCONF ?= ${shell \
result=false; \
command -v pkg-config >/dev/null && result=pkg-config; \
command -v pkgconf >/dev/null && result=pkgconf; \
echo $$result; }