| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Compiler detection |
| 4 |
# Sets: |
| 5 |
# CC, CXX, CFLAGS, CPPFLAGS, LDFLAGS, ARFLAGS, PKG_CONFIG, INSTALL, MBITS |
| 6 |
|
| 7 |
|
| 8 |
mkl_require host |
| 9 |
|
| 10 |
function checks { |
| 11 |
|
| 12 |
# C compiler |
| 13 |
mkl_meta_set "ccenv" "name" "C compiler from CC env" |
| 14 |
if ! mkl_command_check "ccenv" "WITH_CC" cont "$CC --version"; then |
| 15 |
if mkl_command_check "gcc" "WITH_GCC" cont "gcc --version"; then |
| 16 |
CC=gcc |
| 17 |
elif mkl_command_check "clang" "WITH_CLANG" cont "clang --version"; then |
| 18 |
CC=clang |
| 19 |
elif mkl_command_check "cc" "WITH_CC" fail "cc --version"; then |
| 20 |
CC=cc |
| 21 |
fi |
| 22 |
fi |
| 23 |
export CC="${CC}" |
| 24 |
mkl_mkvar_set CC CC "$CC" |
| 25 |
|
| 26 |
if [[ $MKL_CC_WANT_CXX == 1 ]]; then |
| 27 |
# C++ compiler |
| 28 |
mkl_meta_set "cxxenv" "name" "C++ compiler from CXX env" |
| 29 |
if ! mkl_command_check "cxxenv" "WITH_CXX" cont "$CXX --version" ; then |
| 30 |
mkl_meta_set "gxx" "name" "C++ compiler (g++)" |
| 31 |
mkl_meta_set "clangxx" "name" "C++ compiler (clang++)" |
| 32 |
mkl_meta_set "cxx" "name" "C++ compiler (c++)" |
| 33 |
if mkl_command_check "gxx" "WITH_GXX" cont "g++ --version"; then |
| 34 |
CXX=g++ |
| 35 |
elif mkl_command_check "clangxx" "WITH_CLANGXX" cont "clang++ --version"; then |
| 36 |
CXX=clang++ |
| 37 |
elif mkl_command_check "cxx" "WITH_CXX" fail "c++ --version"; then |
| 38 |
CXX=c++ |
| 39 |
fi |
| 40 |
fi |
| 41 |
export CXX="${CXX}" |
| 42 |
mkl_mkvar_set "CXX" CXX "$CXX" |
| 43 |
fi |
| 44 |
|
| 45 |
# Handle machine bits, if specified. |
| 46 |
if [[ ! -z "$MBITS" ]]; then |
| 47 |
mkl_meta_set mbits_m name "mbits compiler flag (-m$MBITS)" |
| 48 |
if mkl_compile_check mbits_m "" fail CC "-m$MBITS"; then |
| 49 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-m$MBITS" |
| 50 |
mkl_mkvar_append LDFLAGS LDFLAGS "-m$MBITS" |
| 51 |
fi |
| 52 |
if [[ -z "$ARFLAGS" && $MBITS == 64 && $MKL_DISTRO == "sunos" ]]; then |
| 53 |
# Turn on 64-bit archives on SunOS |
| 54 |
mkl_mkvar_append ARFLAGS ARFLAGS "S" |
| 55 |
fi |
| 56 |
fi |
| 57 |
|
| 58 |
# Provide prefix and checks for various other build tools. |
| 59 |
local t= |
| 60 |
for t in LD:ld NM:nm OBJDUMP:objdump STRIP:strip LIBTOOL:libtool RANLIB:ranlib ; do |
| 61 |
local tenv=${t%:*} |
| 62 |
t=${t#*:} |
| 63 |
local tval="${!tenv}" |
| 64 |
|
| 65 |
[[ -z $tval ]] && tval="$t" |
| 66 |
|
| 67 |
if mkl_prog_check "$t" "" disable "$tval" ; then |
| 68 |
if [[ $tval != ${!tenv} ]]; then |
| 69 |
export "$tenv"="$tval" |
| 70 |
fi |
| 71 |
mkl_mkvar_set $tenv $tenv "$tval" |
| 72 |
fi |
| 73 |
done |
| 74 |
|
| 75 |
# Compiler and linker flags |
| 76 |
[[ ! -z $CFLAGS ]] && mkl_mkvar_set "CFLAGS" "CFLAGS" "$CFLAGS" |
| 77 |
[[ ! -z $CPPFLAGS ]] && mkl_mkvar_set "CPPFLAGS" "CPPFLAGS" "$CPPFLAGS" |
| 78 |
[[ ! -z $CXXFLAGS ]] && mkl_mkvar_set "CXXFLAGS" "CXXFLAGS" "$CXXFLAGS" |
| 79 |
[[ ! -z $LDFLAGS ]] && mkl_mkvar_set "LDFLAGS" "LDFLAGS" "$LDFLAGS" |
| 80 |
[[ ! -z $ARFLAGS ]] && mkl_mkvar_set "ARFLAGS" "ARFLAGS" "$ARFLAGS" |
| 81 |
|
| 82 |
if [[ $MKL_NO_DEBUG_SYMBOLS != "y" ]]; then |
| 83 |
# Add debug symbol flag (-g) |
| 84 |
# OSX 10.9 requires -gstrict-dwarf for some reason. |
| 85 |
mkl_meta_set cc_g_dwarf name "debug symbols compiler flag (-g...)" |
| 86 |
if [[ $MKL_DISTRO == "osx" ]]; then |
| 87 |
if mkl_compile_check cc_g_dwarf "" cont CC "-gstrict-dwarf"; then |
| 88 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-gstrict-dwarf" |
| 89 |
else |
| 90 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-g" |
| 91 |
fi |
| 92 |
else |
| 93 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-g" |
| 94 |
fi |
| 95 |
fi |
| 96 |
|
| 97 |
|
| 98 |
# pkg-config |
| 99 |
if [ -z "$PKG_CONFIG" ]; then |
| 100 |
PKG_CONFIG=pkg-config |
| 101 |
fi |
| 102 |
|
| 103 |
if mkl_command_check "pkgconfig" "WITH_PKGCONFIG" cont "$PKG_CONFIG --version"; then |
| 104 |
export PKG_CONFIG |
| 105 |
fi |
| 106 |
mkl_mkvar_set "pkgconfig" PKG_CONFIG $PKG_CONFIG |
| 107 |
|
| 108 |
[[ ! -z "$append_PKG_CONFIG_PATH" ]] && mkl_env_append PKG_CONFIG_PATH "$append_PKG_CONFIG_PATH" ":" |
| 109 |
|
| 110 |
# install |
| 111 |
if [ -z "$INSTALL" ]; then |
| 112 |
if [[ $MKL_DISTRO == "sunos" ]]; then |
| 113 |
mkl_meta_set ginstall name "GNU install" |
| 114 |
if mkl_command_check ginstall "" ignore "ginstall --version"; then |
| 115 |
INSTALL=$(which ginstall) |
| 116 |
else |
| 117 |
INSTALL=$(which install) |
| 118 |
fi |
| 119 |
else |
| 120 |
INSTALL=$(which install) |
| 121 |
fi |
| 122 |
fi |
| 123 |
|
| 124 |
if mkl_command_check "install" "WITH_INSTALL" cont "$INSTALL --version"; then |
| 125 |
export INSTALL |
| 126 |
fi |
| 127 |
mkl_mkvar_set "install" INSTALL $INSTALL |
| 128 |
|
| 129 |
|
| 130 |
# Enable profiling if desired |
| 131 |
if [[ $WITH_PROFILING == y ]]; then |
| 132 |
mkl_allvar_set "" "WITH_PROFILING" "y" |
| 133 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-pg" |
| 134 |
mkl_mkvar_append LDFLAGS LDFLAGS "-pg" |
| 135 |
fi |
| 136 |
|
| 137 |
# Optimization |
| 138 |
if [[ $WITHOUT_OPTIMIZATION == n ]]; then |
| 139 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-O2" |
| 140 |
else |
| 141 |
mkl_mkvar_append CPPFLAGS CPPFLAGS "-O0" |
| 142 |
fi |
| 143 |
|
| 144 |
# Static linking |
| 145 |
if [[ $WITH_STATIC_LINKING == y ]]; then |
| 146 |
# LDFLAGS_STATIC is the LDFLAGS needed to enable static linking |
| 147 |
# of sub-sequent libraries, while |
| 148 |
# LDFLAGS_DYNAMIC is the LDFLAGS needed to enable dynamic linking. |
| 149 |
if [[ $MKL_DISTRO != "osx" ]]; then |
| 150 |
mkl_mkvar_set staticlinking LDFLAGS_STATIC "-Wl,-Bstatic" |
| 151 |
mkl_mkvar_set staticlinking LDFLAGS_DYNAMIC "-Wl,-Bdynamic" |
| 152 |
mkl_mkvar_set staticlinking HAS_LDFLAGS_STATIC y |
| 153 |
else |
| 154 |
# OSX linker can't enable/disable static linking so we'll |
| 155 |
# need to find the .a through STATIC_LIB_libname env var |
| 156 |
mkl_mkvar_set staticlinking HAS_LDFLAGS_STATIC n |
| 157 |
# libtool -static supported |
| 158 |
mkl_mkvar_set staticlinking HAS_LIBTOOL_STATIC y |
| 159 |
fi |
| 160 |
fi |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
mkl_option "Compiler" "env:CC" "--cc=CC" "Build using C compiler CC" "\$CC" |
| 165 |
mkl_option "Compiler" "env:CXX" "--cxx=CXX" "Build using C++ compiler CXX" "\$CXX" |
| 166 |
mkl_option "Compiler" "ARCH" "--arch=ARCH" "Build for architecture" "$(uname -m)" |
| 167 |
mkl_option "Compiler" "CPU" "--cpu=CPU" "Build and optimize for specific CPU" "generic" |
| 168 |
mkl_option "Compiler" "MBITS" "--mbits=BITS" "Machine bits (32 or 64)" "" |
| 169 |
|
| 170 |
for n in CFLAGS CPPFLAGS CXXFLAGS LDFLAGS ARFLAGS; do |
| 171 |
mkl_option "Compiler" "mk:$n" "--$n=$n" "Add $n flags" |
| 172 |
done |
| 173 |
|
| 174 |
mkl_option "Compiler" "env:append_PKG_CONFIG_PATH" "--pkg-config-path=EXTRA_PATHS" "Extra paths for pkg-config" |
| 175 |
|
| 176 |
mkl_option "Compiler" "WITH_PROFILING" "--enable-profiling" "Enable profiling" |
| 177 |
mkl_option "Compiler" "WITH_STATIC_LINKING" "--enable-static" "Enable static linking" |
| 178 |
mkl_option "Compiler" "WITHOUT_OPTIMIZATION" "--disable-optimization" "Disable optimization flag to compiler" "n" |
| 179 |
mkl_option "Compiler" "env:MKL_NO_DEBUG_SYMBOLS" "--disable-debug-symbols" "Disable debugging symbols" "n" |
| 180 |
mkl_option "Compiler" "env:MKL_WANT_WERROR" "--enable-werror" "Enable compiler warnings as errors" "n" |
| 181 |
mkl_option "Compiler" "WITH_STRIP" "--enable-strip" "Strip libraries when installing" "n" |