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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
#!/bin/bash
#
# Compiler detection
# Sets:
# CC, CXX, CFLAGS, CPPFLAGS, LDFLAGS, ARFLAGS, PKG_CONFIG, INSTALL, MBITS
mkl_require host
function checks {
# C compiler
mkl_meta_set "ccenv" "name" "C compiler from CC env"
if ! mkl_command_check "ccenv" "WITH_CC" cont "$CC --version"; then
if mkl_command_check "gcc" "WITH_GCC" cont "gcc --version"; then
CC=gcc
elif mkl_command_check "clang" "WITH_CLANG" cont "clang --version"; then
CC=clang
elif mkl_command_check "cc" "WITH_CC" fail "cc --version"; then
CC=cc
fi
fi
export CC="${CC}"
mkl_mkvar_set CC CC "$CC"
if [[ $MKL_CC_WANT_CXX == 1 ]]; then
# C++ compiler
mkl_meta_set "cxxenv" "name" "C++ compiler from CXX env"
if ! mkl_command_check "cxxenv" "WITH_CXX" cont "$CXX --version" ; then
mkl_meta_set "gxx" "name" "C++ compiler (g++)"
mkl_meta_set "clangxx" "name" "C++ compiler (clang++)"
mkl_meta_set "cxx" "name" "C++ compiler (c++)"
if mkl_command_check "gxx" "WITH_GXX" cont "g++ --version"; then
CXX=g++
elif mkl_command_check "clangxx" "WITH_CLANGXX" cont "clang++ --version"; then
CXX=clang++
elif mkl_command_check "cxx" "WITH_CXX" fail "c++ --version"; then
CXX=c++
fi
fi
export CXX="${CXX}"
mkl_mkvar_set "CXX" CXX "$CXX"
fi
# Handle machine bits, if specified.
if [[ ! -z "$MBITS" ]]; then
mkl_meta_set mbits_m name "mbits compiler flag (-m$MBITS)"
if mkl_compile_check mbits_m "" fail CC "-m$MBITS"; then
mkl_mkvar_append CPPFLAGS CPPFLAGS "-m$MBITS"
mkl_mkvar_append LDFLAGS LDFLAGS "-m$MBITS"
fi
if [[ -z "$ARFLAGS" && $MBITS == 64 && $MKL_DISTRO == "sunos" ]]; then
# Turn on 64-bit archives on SunOS
mkl_mkvar_append ARFLAGS ARFLAGS "S"
fi
fi
# Provide prefix and checks for various other build tools.
local t=
for t in LD:ld NM:nm OBJDUMP:objdump STRIP:strip LIBTOOL:libtool RANLIB:ranlib ; do
local tenv=${t%:*}
t=${t#*:}
local tval="${!tenv}"
[[ -z $tval ]] && tval="$t"
if mkl_prog_check "$t" "" disable "$tval" ; then
if [[ $tval != ${!tenv} ]]; then
export "$tenv"="$tval"
fi
mkl_mkvar_set $tenv $tenv "$tval"
fi
done
# Compiler and linker flags
[[ ! -z $CFLAGS ]] && mkl_mkvar_set "CFLAGS" "CFLAGS" "$CFLAGS"
[[ ! -z $CPPFLAGS ]] && mkl_mkvar_set "CPPFLAGS" "CPPFLAGS" "$CPPFLAGS"
[[ ! -z $CXXFLAGS ]] && mkl_mkvar_set "CXXFLAGS" "CXXFLAGS" "$CXXFLAGS"
[[ ! -z $LDFLAGS ]] && mkl_mkvar_set "LDFLAGS" "LDFLAGS" "$LDFLAGS"
[[ ! -z $ARFLAGS ]] && mkl_mkvar_set "ARFLAGS" "ARFLAGS" "$ARFLAGS"
if [[ $MKL_NO_DEBUG_SYMBOLS != "y" ]]; then
# Add debug symbol flag (-g)
# OSX 10.9 requires -gstrict-dwarf for some reason.
mkl_meta_set cc_g_dwarf name "debug symbols compiler flag (-g...)"
if [[ $MKL_DISTRO == "osx" ]]; then
if mkl_compile_check cc_g_dwarf "" cont CC "-gstrict-dwarf"; then
mkl_mkvar_append CPPFLAGS CPPFLAGS "-gstrict-dwarf"
else
mkl_mkvar_append CPPFLAGS CPPFLAGS "-g"
fi
else
mkl_mkvar_append CPPFLAGS CPPFLAGS "-g"
fi
fi
# pkg-config
if [ -z "$PKG_CONFIG" ]; then
PKG_CONFIG=pkg-config
fi
if mkl_command_check "pkgconfig" "WITH_PKGCONFIG" cont "$PKG_CONFIG --version"; then
export PKG_CONFIG
fi
mkl_mkvar_set "pkgconfig" PKG_CONFIG $PKG_CONFIG
[[ ! -z "$append_PKG_CONFIG_PATH" ]] && mkl_env_append PKG_CONFIG_PATH "$append_PKG_CONFIG_PATH" ":"
# install
if [ -z "$INSTALL" ]; then
if [[ $MKL_DISTRO == "sunos" ]]; then
mkl_meta_set ginstall name "GNU install"
if mkl_command_check ginstall "" ignore "ginstall --version"; then
INSTALL=$(which ginstall)
else
INSTALL=$(which install)
fi
else
INSTALL=$(which install)
fi
fi
if mkl_command_check "install" "WITH_INSTALL" cont "$INSTALL --version"; then
export INSTALL
fi
mkl_mkvar_set "install" INSTALL $INSTALL
# Enable profiling if desired
if [[ $WITH_PROFILING == y ]]; then
mkl_allvar_set "" "WITH_PROFILING" "y"
mkl_mkvar_append CPPFLAGS CPPFLAGS "-pg"
mkl_mkvar_append LDFLAGS LDFLAGS "-pg"
fi
# Optimization
if [[ $WITHOUT_OPTIMIZATION == n ]]; then
mkl_mkvar_append CPPFLAGS CPPFLAGS "-O2"
else
mkl_mkvar_append CPPFLAGS CPPFLAGS "-O0"
fi
# Static linking
if [[ $WITH_STATIC_LINKING == y ]]; then
# LDFLAGS_STATIC is the LDFLAGS needed to enable static linking
# of sub-sequent libraries, while
# LDFLAGS_DYNAMIC is the LDFLAGS needed to enable dynamic linking.
if [[ $MKL_DISTRO != "osx" ]]; then
mkl_mkvar_set staticlinking LDFLAGS_STATIC "-Wl,-Bstatic"
mkl_mkvar_set staticlinking LDFLAGS_DYNAMIC "-Wl,-Bdynamic"
mkl_mkvar_set staticlinking HAS_LDFLAGS_STATIC y
else
# OSX linker can't enable/disable static linking so we'll
# need to find the .a through STATIC_LIB_libname env var
mkl_mkvar_set staticlinking HAS_LDFLAGS_STATIC n
# libtool -static supported
mkl_mkvar_set staticlinking HAS_LIBTOOL_STATIC y
fi
fi
# Check for GNU ar (which has the -M option)
mkl_meta_set "gnuar" "name" "GNU ar"
mkl_command_check "gnuar" "HAS_GNU_AR" disable \
"ar -V 2>/dev/null | grep -q GNU"
}
mkl_option "Compiler" "env:CC" "--cc=CC" "Build using C compiler CC" "\$CC"
mkl_option "Compiler" "env:CXX" "--cxx=CXX" "Build using C++ compiler CXX" "\$CXX"
mkl_option "Compiler" "ARCH" "--arch=ARCH" "Build for architecture" "$(uname -m)"
mkl_option "Compiler" "CPU" "--cpu=CPU" "Build and optimize for specific CPU" "generic"
mkl_option "Compiler" "MBITS" "--mbits=BITS" "Machine bits (32 or 64)" ""
for n in CFLAGS CPPFLAGS CXXFLAGS LDFLAGS ARFLAGS; do
mkl_option "Compiler" "mk:$n" "--$n=$n" "Add $n flags"
done
mkl_option "Compiler" "env:append_PKG_CONFIG_PATH" "--pkg-config-path=EXTRA_PATHS" "Extra paths for pkg-config"
mkl_option "Compiler" "WITH_PROFILING" "--enable-profiling" "Enable profiling"
mkl_option "Compiler" "WITH_STATIC_LINKING" "--enable-static" "Enable static linking"
mkl_option "Compiler" "WITHOUT_OPTIMIZATION" "--disable-optimization" "Disable optimization flag to compiler" "n"
mkl_option "Compiler" "env:MKL_NO_DEBUG_SYMBOLS" "--disable-debug-symbols" "Disable debugging symbols" "n"
mkl_option "Compiler" "env:MKL_WANT_WERROR" "--enable-werror" "Enable compiler warnings as errors" "n"
mkl_option "Compiler" "WITH_STRIP" "--enable-strip" "Strip libraries when installing" "n"
|