commit 0f55d457104a07920245bfa06ab38c461b0ed359
parent 7da3f726fd6e9c0732b1321acc296722ed85b96d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 14 Oct 2022 12:36:24 +0200
Improve Makefile configuration step
Adds the configure.sh script which verifies that the programs and
dependencies needed to build the project exist.
Diffstat:
| M | Makefile | | | 21 | ++++++--------------- |
| A | configure.sh | | | 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 98 insertions(+), 15 deletions(-)
diff --git a/Makefile b/Makefile
@@ -57,17 +57,8 @@ sgs: $(OBJ)
@echo "LD $@"
@$(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS)
-.config: config.mk
- @echo "Find packages"; rm -f $@
- @$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys \
- || (echo "RSys $(RSYS_VERSION) not found" >&2; exit 1)
- @$(PKG_CONFIG) --atleast-version $(STAR-3D_VERSION) s3d \
- || (echo "Star-3D $(STAR-3D_VERSION) not found" >&2; exit 1)
- @$(PKG_CONFIG) --atleast-version $(STAR-SP_VERSION) star-sp \
- || (echo "Star-SP $(STAR-SP_VERSION) not found" >&2; exit 1)
- @$(PKG_CONFIG) --atleast-version $(STAR-MC_VERSION) smc \
- || (echo "Star-MC $(STAR-MC_VERSION) not found" >&2; exit 1)
- @echo "config done" > $@
+.config: config.mk configure.sh
+ @$(SHELL) configure.sh && echo "config done" > $@ || exit 1
.SUFFIXES: .c .d .o
.c.d:
@@ -83,7 +74,7 @@ sgs: $(OBJ)
################################################################################
pdf: $(DOC).pdf
-$(DOC).pdf: $(TEX) $(DOC).bbl
+$(DOC).pdf: .config $(TEX) $(DOC).bbl
$(LATEX) src/$(DOC).tex && $(LATEX) src/$(DOC).tex
$(DOC).bbl: $(TEX) src/biblio.bib
@@ -109,9 +100,9 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/share/doc/star-gs/README.md
clean:
- @rm -f $(OBJ) $(TEX) sgs .config ./*.aux ./*.bbl ./*.idx ./*.log ./*.dvi \
- ./*.glo ./*.lof ./*.toc ./*.out ./*.blg ./*.bbl ./*.nav ./*.snm ./*.vrb \
- weave* $(DOC).pdf
+ @rm -f $(OBJ) $(TEX) sgs .config ./*.aux ./*.bbl ./*.idx ./*.log ./*.dvi\
+ ./*.glo ./*.lof ./*.toc ./*.out ./*.blg ./*.bbl ./*.nav ./*.snm ./*.vrb\
+ weave* $(DOC).pdf
distclean: clean
@rm -f $(DEP)
diff --git a/configure.sh b/configure.sh
@@ -0,0 +1,92 @@
+#!/bin/sh -e
+
+# Copyright (C) 2021, 2022 Centre National de la Recherche Scientifique
+# Copyright (C) 2021, 2022 Institut Mines Télécom Albi-Carmaux
+# Copyright (C) 2021, 2022 |Méso|Star> (contact@meso-star.com)
+# Copyright (C) 2021, 2022 Université Clermont Auvergne
+# Copyright (C) 2021, 2022 Université de Lorraine
+# Copyright (C) 2021, 2022 Université de Lyon
+# Copyright (C) 2021, 2022 Université de Toulouse
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This script checks that the commands expected by the build process exist
+
+# Print the value of a variable in config.mk
+showvar()
+{
+ # We want to avoid various make messages being displayed (eg "Entering
+ # directory..." with GNU Make). However, we still want to display the value
+ # of the variable printed by the Makefile. To correct this contradiction, we
+ # print the variable in stderr which we then redirect to stdout while stdout
+ # is redirected to /dev/null
+ make -f 2>&1 1>/dev/null - << EOF
+.POSIX:
+include config.mk
+showvar:
+ @1>&2 echo \$(${1})
+EOF
+}
+
+################################################################################
+# Check required programs
+################################################################################
+bibtex=$(showvar BIBTEX)
+latex=$(showvar LATEX)
+cc=$(showvar CC)
+pkg_config=$(showvar PKG_CONFIG)
+
+programs="\
+ ${bibtex}
+ ${cc}
+ cpif
+ ${latex}
+ notangle
+ noweave
+ ${pkg_config}"
+
+printf "%s\n" "${programs}" | while read -r i; do
+ if ! command -v "${i}" > /dev/null; then
+ printf "\e[1;31merror\e[0m:%s: program is missing\n" "${i}"
+ exit 1
+ fi
+done || exit $?
+
+################################################################################
+# Check required dependencies
+################################################################################
+rsys_version=$(showvar RSYS_VERSION)
+s3d_version=$(showvar STAR-3D_VERSION)
+smc_version=$(showvar STAR-MC_VERSION)
+ssp_version=$(showvar STAR-MC_VERSION)
+
+deps="\
+ RSys rsys ${rsys_version}
+ Star-3D s3d ${s3d_version}
+ Star-MonteCarlo smc ${smc_version}
+ Star-SamPling star-sp ${ssp_version}"
+
+printf "%s\n" "${deps}" | while read -r i; do
+ name=$(printf "%s" "${i}" | awk '{print $1}')
+ pc=$(printf "%s" "${i}" | awk '{print $2}')
+ version=$(printf "%s" "${i}" | awk '{print $3}')
+
+ if ! "${pkg_config}" --atleast-version "${version}" "${pc}"; then
+ >&2 printf "\e[1;31merror\e[0m:%s %s: dependency is missing\n" \
+ "${name}" "${version}"
+ exit 1
+ fi
+done || exit $?
+
+printf "configure done\n"