star-gs

Literate program for a geometric sensitivity calculation
git clone git://git.meso-star.fr/star-gs.git
Log | Files | Refs | README | LICENSE

configure.sh (3158B)


      1 #!/bin/sh -e
      2 
      3 # Copyright (C) 2021-2023 Centre National de la Recherche Scientifique
      4 # Copyright (C) 2021-2023 INSA Lyon
      5 # Copyright (C) 2021-2023 Institut Mines Télécom Albi-Carmaux
      6 # Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com)
      7 # Copyright (C) 2021-2023 Institut Pascal
      8 # Copyright (C) 2021-2023 PhotonLyX (info@photonlyx.com)
      9 # Copyright (C) 2021-2023 Université de Lorraine
     10 # Copyright (C) 2021-2023 Université Paul Sabatier
     11 # Copyright (C) 2021-2023 Université Toulouse - Jean Jaurès
     12 #
     13 # This program is free software: you can redistribute it and/or modify
     14 # it under the terms of the GNU General Public License as published by
     15 # the Free Software Foundation, either version 3 of the License, or
     16 # (at your option) any later version.
     17 #
     18 # This program is distributed in the hope that it will be useful,
     19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     21 # GNU General Public License for more details.
     22 #
     23 # You should have received a copy of the GNU General Public License
     24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     25 
     26 # Print the value of a variable in config.mk
     27 showvar()
     28 {
     29   # To avoid messages from Make being displayed instead of the value of the
     30   # queried variable, we redirect its output to /dev/null and open a new file
     31   # descriptor to stdout to print the variable
     32 << EOF make -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$
     33 .POSIX:
     34 include config.mk
     35 showvar:
     36 	@1>&3 echo \$(${1})
     37 EOF
     38   exec 3<&- # Close file descriptor 3
     39 }
     40 
     41 check_programs()
     42 {
     43   for i in "$@"; do
     44     if ! command -v "${i}" > /dev/null; then
     45       printf "\e[1;31merror\e[0m:%s: program is missing\n" "${i}"
     46       exit 1
     47     fi
     48   done
     49 }
     50 
     51 ################################################################################
     52 # Configure the program
     53 ################################################################################
     54 program()
     55 {
     56   cc=$(showvar CC)
     57   pkg_config=$(showvar PKG_CONFIG)
     58   check_programs "${cc}" "${pkg_config}"
     59 
     60   rsys_version=$(showvar RSYS_VERSION)
     61   s3d_version=$(showvar STAR-3D_VERSION)
     62   smc_version=$(showvar STAR-MC_VERSION)
     63   ssp_version=$(showvar STAR-SP_VERSION)
     64   dependencies="\
     65     RSys rsys ${rsys_version}
     66     Star-3D s3d ${s3d_version}
     67     Star-MonteCarlo smc ${smc_version}
     68     Star-SamPling star-sp ${ssp_version}"
     69 
     70   printf "%s\n" "${dependencies}" | while read -r i; do
     71     name=$(printf "%s" "${i}" | awk '{print $1}')
     72     pc=$(printf "%s" "${i}" | awk '{print $2}')
     73     version=$(printf "%s" "${i}" | awk '{print $3}')
     74 
     75     if ! "${pkg_config}" --atleast-version "${version}" "${pc}"; then
     76       >&2 printf "\e[1;31merror\e[0m:%s %s: dependency is missing\n" \
     77         "${name}" "${version}"
     78       exit 1
     79     fi
     80   done || exit $?
     81 }
     82 
     83 ################################################################################
     84 # Configure the document
     85 ################################################################################
     86 document()
     87 {
     88   bibtex=$(showvar BIBTEX)
     89   latex=$(showvar LATEX)
     90   tangle=$(showvar TANGLE)
     91   weave=$(showvar WEAVE)
     92   check_programs "${bibtex}" cpif "${latex}" "${tangle}" "${weave}"
     93 }
     94 
     95 "$@"