build.sh (3496B)
1 #!/bin/sh 2 3 # Copyright (C) 2023-2026 |Méso|Star> (contact@meso-star.com) 4 # 5 # This file is part of Star-Build. 6 # 7 # Star-Build is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # Star-Build is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Star-Build. If not, see <http://www.gnu.org/licenses/>. 19 20 set -e 21 22 [ -n "${BUILD_SH}" ] && return 23 export BUILD_SH=1 24 25 # Check for use of SIMD instruction set 26 # Returns 0 if SIMD is enabled and >0 otherwise 27 use_simd() 28 { 29 if [ -z "${SIMD_WIDTH}" ]; then 30 return 1 31 fi 32 33 if [ "${SIMD_WIDTH}" = "128" ] \ 34 || [ "${SIMD_WIDTH}" = "256" ]; then 35 return 0 36 else 37 return 1 38 fi 39 } 40 41 # Check for conflicts between script versions of the same build 42 # Return 0 if version do not conflicts, and >0 otherwise 43 check_conflict() # name, version0, version 1 44 { 45 # Do not define local variables to avoid risk of updating variables 46 # defined in the calling's environment 47 48 if [ $# -lt 3 ]; then 49 >&2 printf 'usage: check_conflict name version0 version1\n' 50 return 1 51 fi 52 53 if [ "$2" != "$3" ]; then 54 >&2 printf '%s %s conflicts with %s %s\n' "$1" "$2" "$1" "$3" 55 return 1 56 fi 57 58 return 0 59 } 60 61 # Generate the targets for a git repository. The input variables are: 62 # - name : the name of the target (required) 63 # - url : the URL of the git repository (required) 64 # - tag : the tag/branch/commit to use (required) 65 # - dep : name of the targets on which this build depends (optional) 66 # - opt : the options passed when invoking make (optional) 67 git_repo() 68 { 69 sed \ 70 -e "s#@NAME@#${name}#g" \ 71 -e "s#@URL@#${url}#g" \ 72 -e "s#@TAG@#${tag}#g" \ 73 -e "s#@DEP@#${dep}#g" \ 74 -e "s#@OPT@#${opt}#g" \ 75 "misc/git.mk.in" 76 77 # Reset variables 78 name="" 79 url="" 80 tag="" 81 dep="" 82 opt="" 83 } 84 85 # Generate the targets for a Star-PKG binary. The input variables are: 86 # - name: the name of the target (required) 87 # - url: the URL of the package (required) 88 bin_spkg() 89 { 90 arch="${url##*/}" 91 arch="${arch%.*}" 92 path="${url%/*}" 93 94 sed \ 95 -e "s#@NAME@#${name}#g" \ 96 -e "s#@ARCH@#${arch}#g" \ 97 -e "s#@PATH@#${path}#g" \ 98 "misc/spkg.mk.in" 99 100 # Reset variables 101 name="" 102 url="" 103 } 104 105 # Generate the targets of a profile 106 profile() 107 { 108 sed -e "s#@NAME@#$1#g" "misc/profile.mk.in" 109 } 110 111 # Print the value of a variable in config.mk 112 showvar() 113 { 114 # To avoid messages from Make being displayed instead of the value of 115 # the queried variable, we redirect its output to /dev/null and open a 116 # new file descriptor to stdout to print the variable. 117 # 118 # The MAKEFLAGS environment variable is cleared to prevent make 119 # defining options which reserve the file descriptor used to print the 120 # variable, which would result in a ‘wrong file descriptor’ error. 121 # This can be the case with certain versions of GNU make which, when 122 # run in parallel, use pipe file descriptors to synchronise with the 123 # jobserver. 124 << EOF MAKEFLAGS="" ${MAKE:-make} -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$ 125 .POSIX: 126 include ../config.mk 127 showvar: 128 @1>&3 echo \$(${1}) 129 EOF 130 exec 3<&- # Close file descriptor 3 131 }