1#!/bin/sh 2# 3# BLIS 4# An object-based framework for developing high-performance BLAS-like 5# libraries. 6# 7# Copyright (C) 2015, The University of Texas at Austin 8# 9# Redistribution and use in source and binary forms, with or without 10# modification, are permitted provided that the following conditions are 11# met: 12# - Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# - Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# - Neither the name(s) of the copyright holder(s) nor the names of its 18# contributors may be used to endorse or promote products derived 19# from this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32# 33# 34 35# 36# auto-detect.sh 37# 38# Zhang Xianyi 39# 40 41 42main() 43{ 44 if [ clang -v > /dev/null 2>&1 ]; then 45 CC=clang 46 else 47 CC=gcc 48 fi 49 CPUID_SRC=cpuid_x86.c 50 CPUID_BIN=blis_cpu_detect 51 ARCH=generic 52 53 # The name of the script, stripped of any preceeding path. 54 script_name=${0##*/} 55 56 # The path to the script. We need this to find the top-level directory 57 # of the source distribution in the event that the user has chosen to 58 # build elsewhere. 59 dist_path=${0%/${script_name}} 60 61 # The path to the directory in which we are building. We do this to 62 # make explicit that we distinguish between the top-level directory 63 # of the distribution and the directory in which we are building. 64 cur_dirpath="." 65 66 # 67 # Detect architecture by predefined macros 68 # 69 70 out1=`$CC -E ${dist_path}/arch_detect.c` 71 72 ARCH=`echo $out1 | grep -o "ARCH_[a-zA-Z0-9_]*" | head -n1` 73 74 if [ $ARCH = "ARCH_X86_64" ]; then 75 CPUID_SRC=cpuid_x86.c 76 elif [ $ARCH = "ARCH_X86" ]; then 77 CPUID_SRC=cpuid_x86.c 78 elif [ $ARCH = "ARCH_ARM" ]; then 79 CPUID_SRC=cpuid_arm.c 80 elif [ $ARCH = "ARCH_AARCH64" ]; then 81 # Only support armv8 now 82 echo "armv8a" 83 return 0 84 else 85 echo "generic" 86 return 0 87 fi 88 89 # 90 # Detect CPU cores 91 # 92 93 $CC -o ${cur_dirpath}/$CPUID_BIN ${dist_path}/$CPUID_SRC 94 ${cur_dirpath}/$CPUID_BIN 95 rm -rf ${cur_dirpath}/$CPUID_BIN 96 97 # Exit peacefully. 98 return 0 99} 100 101 102# The script's main entry point, passing all parameters given. 103main "$@" 104