star-build

Automation tool for project installation
git clone git://git.meso-star.fr/star-build.git
Log | Files | Refs | README | LICENSE

build.sh (3465B)


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