github.com/apptainer/singularity@v3.1.1+incompatible/mlocal/checks/basechecks.chk (about) 1 #!/bin/sh - 2 # Copyright (c) 2015-2018, Yannick Cote <yhcote@gmail.com>. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be found 4 # in the LICENSE file. 5 set -e 6 7 ######################## 8 # host compilers 9 ######################## 10 if [ "$hstcc" = "" ]; then 11 printf " checking: host C compiler... " 12 for cc in $hstcc_opts; do 13 if $cc -E -x c /dev/null >/dev/null 2>&1; then 14 hstcc="$cc" 15 break 16 fi 17 done 18 if [ "$hstcc" != "" ]; then 19 echo $hstcc 20 else 21 echo "not found!" 22 usage 23 exit 1 24 fi 25 else 26 printf " checking: host C compiler... " 27 if $hstcc -E -x c /dev/null >/dev/null 2>&1; then 28 echo $hstcc 29 else 30 echo "$hstcc cannot compile test code!" 31 usage 32 exit 1 33 fi 34 35 fi 36 if [ "$hstcxx" = "" ]; then 37 printf " checking: host C++ compiler... " 38 for cxx in $hstcxx_opts; do 39 if $cxx -E -x c++ /dev/null >/dev/null 2>&1; then 40 hstcxx="$cxx" 41 break 42 fi 43 done 44 if [ "$hstcxx" != "" ]; then 45 echo $hstcxx 46 else 47 echo "not found!" 48 fi 49 else 50 printf " checking: host C++ compiler... " 51 if $hstcxx -E -x c++ /dev/null >/dev/null 2>&1; then 52 echo $hstcxx 53 else 54 echo "$hstcxx cannot compile test code!" 55 fi 56 fi 57 58 ######################## 59 # host compilers options 60 ######################## 61 for opt in $cflags_opts; do 62 printf " checking: host C compiler option $opt... " 63 if $cc $opt -E -x c /dev/null >/dev/null 2>&1; then 64 echo "yes" 65 cflags="$cflags $opt" 66 else 67 echo "no" 68 fi 69 done 70 71 ######################## 72 # host tool paths 73 ######################## 74 printf " checking: host \`ar' path... " 75 if [ "$hstar" = "" ]; then 76 if test `dirname \`$hstcc -print-prog-name=ar\`` = "."; then 77 hstar="ar" 78 else 79 if ! hstar=`(cd \`dirname \\\`$hstcc -print-prog-name=ar\\\`\` 2>/dev/null && pwd -P)`/ar; then 80 echo "error: cannot find host \`ar' program" 81 exit 2 82 fi 83 fi 84 fi 85 echo "$hstar" 86 87 printf " checking: host \`ld' path... " 88 if [ "$hstld" = "" ]; then 89 if test `dirname \`$hstcc -print-prog-name=ld\`` = "."; then 90 hstld="ld" 91 else 92 if ! hstld=`(cd \`dirname \\\`$hstcc -print-prog-name=ld\\\`\` 2>/dev/null && pwd -P)`/ld; then 93 echo "error: cannot find host \`ld' program" 94 exit 2 95 fi 96 fi 97 fi 98 echo "$hstld" 99 100 printf " checking: host \`ranlib' path... " 101 if [ "$hstranlib" = "" ]; then 102 if test `dirname \`$hstcc -print-prog-name=ranlib\`` = "."; then 103 hstranlib="ranlib" 104 else 105 if ! hstranlib=`(cd \`dirname \\\`$hstcc -print-prog-name=ranlib\\\`\` 2>/dev/null && pwd -P)`/ranlib; then 106 echo "error: cannot find host \`ranlib' program" 107 exit 2 108 fi 109 fi 110 fi 111 echo "$hstranlib" 112 113 printf " checking: host \`objcopy' path... " 114 if [ "$hstobjcopy" = "" ]; then 115 if test `dirname \`$hstcc -print-prog-name=objcopy\`` = "."; then 116 hstobjcopy="objcopy" 117 else 118 if ! hstobjcopy=`(cd \`dirname \\\`$hstcc -print-prog-name=objcopy\\\`\` 2>/dev/null && pwd -P)`/objcopy; then 119 echo "error: cannot find host \`objcopy' program" 120 exit 2 121 fi 122 fi 123 fi 124 echo "$hstobjcopy" 125 126 127 ######################## 128 # target 129 ######################## 130 if [ "$tgtcc" = "" ]; then 131 tgtcc=$hstcc 132 fi 133 if [ "$tgtcxx" = "" ]; then 134 tgtcxx=$hstcxx 135 fi 136 137 138 ######################## 139 # target compilers 140 ######################## 141 printf " checking: target C compiler... " 142 if $tgtcc -E -x c /dev/null >/dev/null 2>&1; then 143 echo $tgtcc 144 else 145 echo "$tgtcc cannot compile test code!" 146 usage 147 exit 1 148 fi 149 printf " checking: target C++ compiler... " 150 if $tgtcxx -E -x c++ /dev/null >/dev/null 2>&1; then 151 echo $tgtcxx 152 else 153 echo "$tgtcxx cannot compile test code!" 154 fi 155 156 157 ######################## 158 # target tool paths 159 ######################## 160 printf " checking: target \`ar' path... " 161 if [ "$tgtar" = "" ]; then 162 if test `dirname \`$tgtcc -print-prog-name=ar\`` = "."; then 163 tgtar="ar" 164 else 165 if ! tgtar=`(cd \`dirname \\\`$tgtcc -print-prog-name=ar\\\`\` 2>/dev/null && pwd -P)`/ar; then 166 echo "error: cannot find target \`ar' program" 167 exit 2 168 fi 169 fi 170 fi 171 echo "$tgtar" 172 173 printf " checking: target \`ld' path... " 174 if [ "$tgtld" = "" ]; then 175 if test `dirname \`$tgtcc -print-prog-name=ld\`` = "."; then 176 tgtld="ld" 177 else 178 if ! tgtld=`(cd \`dirname \\\`$tgtcc -print-prog-name=ld\\\`\` 2>/dev/null && pwd -P)`/ld; then 179 echo "error: cannot find target \`ld' program" 180 exit 2 181 fi 182 fi 183 fi 184 echo "$tgtld" 185 186 printf " checking: target \`ranlib' path... " 187 if [ "$tgtranlib" = "" ]; then 188 if test `dirname \`$tgtcc -print-prog-name=ranlib\`` = "."; then 189 tgtranlib="ranlib" 190 else 191 if ! tgtranlib=`(cd \`dirname \\\`$tgtcc -print-prog-name=ranlib\\\`\` 2>/dev/null && pwd -P)`/ranlib; then 192 echo "error: cannot find target \`ranlib' program" 193 exit 2 194 fi 195 fi 196 fi 197 echo "$tgtranlib" 198 199 printf " checking: target \`objcopy' path... " 200 if [ "$tgtobjcopy" = "" ]; then 201 if test `dirname \`$tgtcc -print-prog-name=objcopy\`` = "."; then 202 tgtobjcopy="objcopy" 203 else 204 if ! tgtobjcopy=`(cd \`dirname \\\`$tgtcc -print-prog-name=objcopy\\\`\` 2>/dev/null && pwd -P)`/objcopy; then 205 echo "error: cannot find target \`objcopy' program" 206 exit 2 207 fi 208 fi 209 fi 210 echo "$tgtobjcopy" 211 212 213 ######################## 214 # static 215 ######################## 216 printf " checking: host compiles static binaries... " 217 if ! echo "int main(int args, char *argv[]) { return 0; }" | \ 218 $hstcc -x c -static -o /dev/null - >/dev/null 2>&1; then 219 hststatic=0 220 echo "no" 221 else 222 echo "yes" 223 fi 224 printf " checking: target compiles static binaries... " 225 if ! echo "int main(int args, char *argv[]) { return 0; }" | \ 226 $tgtcc -x c -static -o /dev/null - >/dev/null 2>&1; then 227 tgtstatic=0 228 echo "no" 229 else 230 echo "yes" 231 fi 232 233 234 ######################## 235 # host os 236 ######################## 237 printf " checking: host os type... " 238 host= 239 if echo | $hstcc -E -dM - | grep -qs -e __unix__ -e __unix -e unix; then 240 host="unix" 241 fi 242 if echo | $hstcc -E -dM - | grep -qs -e __APPLE__; then 243 host="darwin" 244 fi 245 if echo | $hstcc -E -dM - | grep -qs -e _WIN32 -e _WIN64 -e __WIN32 \ 246 -e __WIN64 -e __WINNT -e __WINNT__ -e __WIN32__ -e WINNT -e __WIN64__ \ 247 -e WIN32 -e WIN64; then 248 host="windows" 249 fi 250 if [ "$host" != "" ]; then 251 echo $host 252 else 253 echo "not found!" 254 usage 255 exit 1 256 fi 257 258 259 ######################## 260 # host architecture 261 ######################## 262 printf " checking: host architecture... " 263 hst_arch= 264 if echo | $hstcc -E -dM - | grep -qs -e __i386 -e __i386__ -e i386; then 265 hst_arch=i386 266 fi 267 if echo | $hstcc -E -dM - | grep -qs -e __amd64 -e __amd64__ -e __x86_64 \ 268 -e __x86_64__; then 269 hst_arch=x86_64 270 fi 271 if echo | $hstcc -E -dM - | grep -qs -e __arm__; then 272 hst_arch=arm 273 fi 274 if echo | $hstcc -E -dM - | grep -qs -e __aarch64 -e __aarch64__ -e __arm64 \ 275 -e __arm64__; then 276 hst_arch=aarch64 277 fi 278 if echo | $hstcc -E -dM - | grep -qs -e __ARCH_PPC64 -e __PPC64__; then 279 hst_arch=ppc64 280 fi 281 if [ "$hst_arch" != "" ]; then 282 echo $hst_arch 283 else 284 echo "not found!" 285 hst_arch=unknown 286 fi 287 288 289 ######################## 290 # target architecture 291 ######################## 292 printf " checking: target architecture... " 293 tgt_arch= 294 if echo | $tgtcc -E -dM - | grep -qs -e __i386 -e __i386__ -e i386; then 295 tgt_arch=i386 296 fi 297 if echo | $tgtcc -E -dM - | grep -qs -e __amd64 -e __amd64__ -e __x86_64 \ 298 -e __x86_64__; then 299 tgt_arch=x86_64 300 fi 301 if echo | $tgtcc -E -dM - | grep -qs -e __arm__; then 302 tgt_arch=arm 303 fi 304 if echo | $tgtcc -E -dM - | grep -qs -e __aarch64 -e __aarch64__ -e __arm64 \ 305 -e __arm64__; then 306 tgt_arch=aarch64 307 fi 308 if echo | $tgtcc -E -dM - | grep -qs -e __ARCH_PPC64 -e __PPC64__; then 309 tgt_arch=ppc64 310 fi 311 if [ "$tgt_arch" != "" ]; then 312 echo $tgt_arch 313 else 314 echo "not found!" 315 tgt_arch=unknown 316 fi 317 318 319 320 ######################## 321 # host wordsize 322 ######################## 323 printf " checking: host architecture word size... " 324 hst_word= 325 if echo | $hstcc -E -dM - | grep -qs -e __i386 -e __i386__ -e i386; then 326 hst_word=32 327 fi 328 if echo | $hstcc -E -dM - | grep -qs -e __amd64 -e __amd64__ -e __x86_64 \ 329 -e __x86_64__; then 330 hst_word=64 331 fi 332 if echo | $hstcc -E -dM - | grep -qs -e __arm__; then 333 hst_word=32 334 fi 335 if echo | $hstcc -E -dM - | grep -qs -e __aarch64 -e __aarch64__ -e __arm64 \ 336 -e __arm64__; then 337 hst_word=64 338 fi 339 if echo | $hstcc -E -dM - | grep -qs -e __ARCH_PPC64 -e __PPC64__; then 340 hst_word=64 341 fi 342 if [ "$hst_word" != "" ]; then 343 echo $hst_word 344 else 345 echo "not found!" 346 hst_word=unknown 347 fi 348 349 350 ######################## 351 # target wordsize 352 ######################## 353 printf " checking: target architecture word size... " 354 tgt_word= 355 if echo | $tgtcc -E -dM - | grep -qs -e __i386 -e __i386__ -e i386; then 356 tgt_word=32 357 fi 358 if echo | $tgtcc -E -dM - | grep -qs -e __amd64 -e __amd64__ -e __x86_64 \ 359 -e __x86_64__; then 360 tgt_word=64 361 fi 362 if echo | $tgtcc -E -dM - | grep -qs -e __arm__; then 363 tgt_word=32 364 fi 365 if echo | $tgtcc -E -dM - | grep -qs -e __aarch64 -e __aarch64__ -e __arm64 \ 366 -e __arm64__; then 367 tgt_word=64 368 fi 369 if echo | $tgtcc -E -dM - | grep -qs -e __ARCH_PPC64 -e __PPC64__; then 370 tgt_word=64 371 fi 372 if [ "$tgt_word" != "" ]; then 373 echo $tgt_word 374 else 375 echo "not found!" 376 tgt_word=unknown 377 fi 378 379 380 ######################## 381 # package version 382 ######################## 383 printf " checking: project version... " 384 if [ "$package_version" = "" ]; then 385 package_version=`(\ 386 git describe --match 'v[0-9]*' --dirty --always 2>/dev/null || \ 387 cat VERSION 2>/dev/null || echo "" \ 388 ) | \ 389 sed -e "s/^v//;s/-/_/g;s/_/-/;s/_/./g"` 390 fi 391 392 if [ "$package_version" != "" ]; then 393 echo $package_version 394 else 395 echo "not found!" 396 echo "error: unable to determine \$package_version variable" 397 echo "NOTE: Not in a git tree and VERSION file not found" 398 echo "NOTE: Try running ${0##*/} with [-V version]" 399 usage 400 exit 1 401 fi 402 403 printf " checking: project short version... " 404 if [ "$short_version" = "" ]; then 405 short_version=`(\ 406 git describe --abbrev=0 --match 'v[0-9]*' --always 2>/dev/null || \ 407 cat VERSION 2>/dev/null || echo ""\ 408 ) | \ 409 sed -e "s/^v//;s/-/_/g;s/_/-/;s/_/./g"` 410 fi 411 echo "$short_version" 412 413 printf " checking: golang compiler version... " 414 if [ "$go_version" = "" ]; then 415 go_version="`grep -A 1 ^go: .travis.yml 2>/dev/null|sed -n 's/.*- "//;s/"//p'`" 416 fi 417 echo "$go_version"