From: Ladislav Michl <[email protected]>

Drop checks for things nothing uses: C++ compiler, headers, types and
functions (kconfig has no config.h), the #! test, the bison++ test,
and AC_CANONICAL_*.

Move the remaining runtime checks to the bootstrap, so both ways check
the same things. While there try to unify things a bit; every host
tool used ends linked, so that all host tools PTXdist depends on are
in one place, show up in the BSP report and trigger a rebuild of the
host tools when any of them vanishes.

patch keeps its special handling: GNU patch >= 2.1 is preferred
(gpatch, then patch). Anything else is used with a warning, as before;
Sun's patch is known to be buggy and patch 2.0 cannot create directories.

CC, CFLAGS, CPPFLAGS, LDFLAGS, LEX, YACC, PATCH and PKG_CONFIG can
still be passed to configure and end up in the bootstrap when running
make.

Signed-off-by: Ladislav Michl <[email protected]>
---
 Makefile.in                  |   2 +-
 configure.ac                 | 312 ++++-------------------------------
 scripts/ptxdist_bootstrap.sh | 111 +++++++++++--
 3 files changed, 130 insertions(+), 295 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 5eb7b407b..f16a3744f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -17,7 +17,7 @@ export SHELL
 all:
        @echo "preparing PTXdist host tools ..."
        @CC="@CC@" CFLAGS="@CFLAGS@" CPPFLAGS="@CPPFLAGS@" LDFLAGS="@LDFLAGS@" \
-               LEX="@LEX@" YACC="@YACC@" \
+               LEX="@LEX@" YACC="@YACC@" PATCH="@PATCH@" 
PKG_CONFIG="@PKG_CONFIG@" \
                "@BASH@" "$(abs_srcdir)/scripts/ptxdist_bootstrap.sh" 
"$(abs_builddir)"
        @echo "done."
 
diff --git a/configure.ac b/configure.ac
index 2590ebbed..17edbd769 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8,8 +8,6 @@ AC_INIT([ptxdist],
        [m4_esyscmd([scripts/kernel/setlocalversion .tarball-version])],
        [[email protected]])
 AC_CONFIG_AUX_DIR(scripts/autoconf)
-AC_CANONICAL_BUILD
-AC_CANONICAL_HOST
 
 dnl
 dnl Check if the user has extracted the patches archive
@@ -24,62 +22,8 @@ else
 fi
 
 dnl
-dnl Check for C and C++ compilers
+dnl Check for Bourne-Again Shell, needed to run anything else
 dnl
-AC_PROG_CC
-AC_PROG_CXX
-
-dnl
-dnl Check for pkg-config
-dnl
-PKG_PROG_PKG_CONFIG
-AS_IF([test -z "$PKG_CONFIG"], AC_MSG_ERROR([pkg-config not found.]))
-
-AC_CHECK_HEADERS([fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h 
stddef.h stdlib.h string.h sys/time.h unistd.h])
-
-AC_CHECK_HEADER([regex.h], [], AC_MSG_ERROR([Cannot find regex.h.]))
-
-PKG_CHECK_MODULES([MCONF], [ncursesw],, [
-       PKG_CHECK_MODULES([MCONF], [ncurses],, [
-               AC_MSG_ERROR([Cannot find ncurses library.])
-       ])
-])
-CFLAGS="${CFLAGS} ${MCONF_CFLAGS}"
-
-dnl
-dnl Checks for typedefs, structures, and compiler characteristics.
-dnl
-AC_CHECK_HEADER_STDBOOL
-AC_C_INLINE
-AC_TYPE_INT16_T
-AC_TYPE_INT32_T
-AC_TYPE_INT8_T
-AC_TYPE_OFF_T
-AC_TYPE_SIZE_T
-AC_TYPE_SSIZE_T
-AC_TYPE_UINT16_T
-AC_TYPE_UINT32_T
-AC_TYPE_UINT8_T
-
-dnl
-dnl Checks for library functions.
-dnl
-AC_FUNC_ALLOCA
-AC_FUNC_MALLOC
-AC_FUNC_REALLOC
-AC_CHECK_FUNCS([bzero gettimeofday memmove memset mkdir regcomp setlocale 
strcasecmp strchr strcspn strdup strncasecmp strpbrk strrchr strspn strtol 
strtoull uname])
-
-
-AC_SYS_INTERPRETER
-if test "$interpval" != yes ; then
-       AC_MSG_WARN([no
-
-bash scripts may not be invoked correctly due to problems with your
-systems implementation of #! being either broken or non-existant.
-])
-fi
-
-dnl Check for Bourne-Again Shell
 unset BASH  # bash sets this itself!
 AC_ARG_WITH(bash, AS_HELP_STRING([--with-bash],[name of the bash executable to 
use]),
     [
@@ -93,230 +37,42 @@ if test -z "$BASH" ; then
     AC_MSG_ERROR([Please specify the location of bash with the option 
'--with-bash'])
 fi
 
-# It would be nice not to have to use backticks, but too many retarded sh
-# implementations still don't support $( )
-# BEWARE:  There is a distinct possibility that we are currently running under
-# bash in this configure script (/bin/sh being a symlink to /bin/bash).  Even
-# though the result /could/ be available to us directly as $BASH_VERSION we
-# don't want to use, or trust it, incase the user is specifying a different
-# bash executable.
-if `$BASH -c '[[ "$BASH_VERSION" \< "4.2" ]]'` ; then
-    AC_MSG_ERROR([
-$PACKAGE_NAME requires at least version 4.2 of bash, you can download a current
-version of bash from ftp.gnu.org
-])
-fi
-
-
-dnl Check for sed >= 4.0
-AC_PATH_PROGS(SED, gsed sed,, $PATH)
-if test -z "$SED"; then
-       AC_MSG_ERROR([sed could not be found, please install])
-fi
-
-AC_MSG_CHECKING([sed version])
-SED_VERSION=`$SED --version 2>/dev/null | $SED -ne "1 
s/.*GNU.*\s\([[0-9\+\.]]\+\).*/\1/p"`
-case "$SED_VERSION" in
-3.*) AC_MSG_ERROR([we need at least GNU sed 4.x but found $SED_VERSION]) ;;
-4.*) ;;
-*)   AC_MSG_ERROR([we need at least GNU sed 4.x]) ;;
-esac
-AC_MSG_RESULT([$SED_VERSION])
-
-dnl check for gnu tools
-dnl   $1: tool to search for
-dnl   $2: package where the tool is (e.g. 'coreutils')
-AC_DEFUN([GNU_TOOL],
-       [AC_CACHE_CHECK([for GNU $1], [ac_cv_path_gnu_$1],
-               [AC_PATH_PROGS_FEATURE_CHECK([gnu_$1], [g$1 $1.gnu $1-gnu $1],
-                       [[out=`$ac_path_gnu_$1 --version 2>/dev/null | $SED -ne 
"s/.*\(GNU\) $2.*/\1/p"`
-                               test "x$out" = xGNU && 
ac_cv_path_gnu_$1=$ac_path_gnu_$1 ac_path_gnu_$1_found=:]],
-                       [AC_MSG_ERROR([could not find GNU $1])])])
-       AC_SUBST([GNU_$1], [$ac_cv_path_gnu_$1])])
-
-GNU_TOOL(cat, coreutils)
-GNU_TOOL(chmod, coreutils)
-GNU_TOOL(chown, coreutils)
-GNU_TOOL(cp, coreutils)
-GNU_TOOL(dirname, coreutils)
-GNU_TOOL(install, coreutils)
-GNU_TOOL(ln, coreutils)
-GNU_TOOL(md5sum, coreutils)
-GNU_TOOL(mkdir, coreutils)
-GNU_TOOL(mknod, coreutils)
-GNU_TOOL(mktemp, coreutils)
-GNU_TOOL(mv, coreutils)
-GNU_TOOL(readlink, coreutils)
-GNU_TOOL(realpath, coreutils)
-GNU_TOOL(rm, coreutils)
-GNU_TOOL(rmdir, coreutils)
-GNU_TOOL(sha256sum, coreutils)
-GNU_TOOL(sort, coreutils)
-GNU_TOOL(stat, coreutils)
-GNU_TOOL(touch, coreutils)
-GNU_TOOL(tty, coreutils)
-GNU_TOOL(tar, tar)
-GNU_TOOL(find, findutils)
-GNU_TOOL(xargs, findutils)
-
-dnl Check for awk
-AC_PROG_AWK
-AC_PATH_PROGS(AWK, ${AWK},)
-AC_MSG_CHECKING([awk version])
-AWK_VERSION=`$AWK --version 2>/dev/null | $SED -ne "s/GNU [[Aa]]wk 
\([[0-9\.]]*\)/\1/p"`
-case "$AWK_VERSION" in
-"") AC_MSG_ERROR([we need GNU awk]) ;;
-*)  ;;
-esac
-AC_MSG_RESULT([$AWK_VERSION])
-
-# fall back to 'false' for systems which do not provide a 'sysctl' tool
-AC_PATH_PROGS(SYSCTL, sysctl false,, $PATH)
-
-dnl Check for lex
-AC_PROG_LEX(noyywrap)
-AC_PATH_PROGS(LEX, ${LEX},, $PATH)
-if test -z "${LEX}"; then
-   AC_MSG_ERROR([(f)lex could not be found, please install])
-fi
-
-dnl Check for yacc
-AC_PROG_YACC
-AC_PATH_PROGS(YACC, ${YACC},, $PATH)
-if test -z "${YACC}"; then
-   AC_MSG_ERROR([yacc/bison could not be found, please install])
-fi
-
-
-AC_MSG_CHECKING([whether yacc is bison++])
-if $YACC --version 2>/dev/null | grep bison++ -q; then
-   AC_MSG_ERROR([your $YACC turns out to be bison++, please install plain 
bison])
-else
-   AC_MSG_RESULT([no, this is good])
-fi
-
-AC_MSG_CHECKING([yacc/bison version])
-YACC_VERSION=`$YACC --version 2>/dev/null | $SED -ne "s/.*GNU Bison.* 
\([[0-9.]]*\).*/\1/p"`
-case "${YACC_VERSION}" in
-     1.*)
-     AC_MSG_ERROR([$YACC_VERSION, your bison version is too old, install 2.3 
or sth. like that]) ;;
-     "")
-     AC_MSG_WARN([no GNU bison found, continuing anyway....]) ;;
-     *)
-     AC_MSG_RESULT([$YACC_VERSION]) ;;
-esac
-
-dnl Check for bunzip2
-AC_PATH_PROGS(BUNZIP2, bunzip2,, $PATH)
-if test -z "$BUNZIP2"; then
-       AC_MSG_ERROR([bunzip2 could not be found, please install])
-fi
-
-dnl Check for gunzip
-AC_PATH_PROGS(GUNZIP, gunzip,, $PATH)
-if test -z "$GUNZIP"; then
-       AC_MSG_ERROR([gunzip could not be found, please install])
-fi
-
-dnl Check for unzip
-AC_PATH_PROGS(UNZIP, unzip,, $PATH)
-if test -z "$UNZIP"; then
-       AC_MSG_ERROR([unzip could not be found, please install])
-fi
-
-dnl Check for xz
-AC_PATH_PROGS(XZ, xz,, $PATH)
-if test -z "$XZ"; then
-       AC_MSG_ERROR([xz could not be found, please install])
-fi
-
-dnl Check for wget
-AC_PATH_PROGS(WGET, wget,, $PATH)
-if test -z "$WGET"; then
-       AC_MSG_ERROR([wget could not be found, please install])
-fi
-
-AC_MSG_CHECKING([find version])
-FIND_VERSION=`$GNU_find --version 2>/dev/null | $SED -ne 
"s/.*\s\+\([[0-9]]\+\.[[0-9]]\+\.[[0-9]]\+\).*$/\1/p"`
-case "$FIND_VERSION" in
-4.*) ;;
-*)   AC_MSG_ERROR([we need at least GNU find 4.x]) ;;
-esac
-AC_MSG_RESULT([$FIND_VERSION])
-
-dnl Check for make
-AC_PATH_PROGS(MAKE, gmake gnumake make,, $PATH)
-if test -z "$MAKE"; then
-       AC_MSG_ERROR([make could not be found, please install])
-fi
-MAKE_VERSION=`$MAKE --version 2>/dev/null | $SED -ne "s/^GNU Make 
\([[0-9]]\+\.[[0-9.]]\+\).*$/\1/p"`
-MAJOR_MAKE_VERSION="${MAKE_VERSION%%.*}"
-MINOR_MAKE_VERSION="${MAKE_VERSION#*.}"
-MINOR_MAKE_VERSION="${MINOR_MAKE_VERSION%%.*}"
-if test -z "${MAJOR_MAKE_VERSION}"  -o -z "${MINOR_MAKE_VERSION}" ; then
-       AC_MSG_ERROR([could not parse make version. GNU make >= 3.81 required])
-fi
-if test $MAJOR_MAKE_VERSION -eq 3 -a $MINOR_MAKE_VERSION -lt 81 -o 
$MAJOR_MAKE_VERSION -lt 3 ; then
-       AC_MSG_ERROR([GNU make >= 3.81 required ($MAKE_VERSION found)])
-fi
-
-dnl Check for file
-AC_PATH_PROGS(FILE, file,, $PATH)
-if test -z "$FILE"; then
-       AC_MSG_ERROR([file could not be found, please install])
-fi
-AC_SUBST([PTXDIST_FILE], [$FILE])
-
-AC_PATH_PROG(SPHINX, sphinx-build,, $PATH)
-if test -z "$SPHINX"; then
-       AC_MSG_NOTICE([sphinx not found, required to build the documentation])
-       SPHINX=sphinx-build
+dnl
+dnl Everything else is checked by the bootstrap script, which reports all
+dnl missing tools at once. It is run again by 'make' to set things up.
+dnl
+AC_ARG_VAR([CC], [C compiler command for kconfig])
+AC_ARG_VAR([CFLAGS], [C compiler flags for kconfig])
+AC_ARG_VAR([CPPFLAGS], [C preprocessor flags for kconfig])
+AC_ARG_VAR([LDFLAGS], [linker flags for kconfig])
+AC_ARG_VAR([LEX], [lexer generator, default: flex])
+AC_ARG_VAR([YACC], [parser generator, default: bison])
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config])
+AC_ARG_VAR([PATCH], [patch executable to use, default: GNU patch from PATH])
+AC_ARG_WITH(patch, AS_HELP_STRING([--with-patch],[name of the patch executable 
to use, same as PATCH=]),
+       [PATCH="$withval"])
+
+AC_MSG_CHECKING([host tools])
+if CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" \
+       LEX="$LEX" YACC="$YACC" PATCH="$PATCH" PKG_CONFIG="$PKG_CONFIG" \
+       "$BASH" "$srcdir/scripts/ptxdist_bootstrap.sh" --check 
>&AS_MESSAGE_LOG_FD 2>config.bootstrap
+then
+       AC_MSG_RESULT([ok])
+       # warnings
+       cat config.bootstrap >&2
+       cat config.bootstrap >&AS_MESSAGE_LOG_FD
+       rm -f config.bootstrap
 else
-       AC_MSG_NOTICE([sphinx found, run 'ptxdist docs-html' to get 
documentation])
+       AC_MSG_RESULT([failed])
+       cat config.bootstrap >&2
+       cat config.bootstrap >&AS_MESSAGE_LOG_FD
+       rm -f config.bootstrap
+       AC_MSG_ERROR([host check failed])
 fi
-AC_SUBST(SPHINX)
 
 AC_PATH_PROGS(RST2MAN, rst2man,, $PATH)
 AC_SUBST(RST2MAN)
 
-dnl Check for patch
-AC_ARG_WITH(patch, AS_HELP_STRING([--with-patch],[name of the patch executable 
to use]),
-    [
-       PATCH="$withval"
-       AC_SUBST(PATCH)
-       AC_MSG_NOTICE([Using patch executable $PATCH])
-    ],[
-       AC_PATH_PROG(PATCH, patch)
-    ])
-if test -z "$PATCH"; then
-    AC_MSG_ERROR([Please specify the location of the patch executable with the 
option '--with-patch'])
-fi
-
-# Sun's patch is a mess, issue a warning.  But we are going to continue with
-# the build because you might just be lucky.
-AC_MSG_CHECKING([whether $PATCH will work])
-if $PATCH -v 2>&1 | grep -q "Sun" >/dev/null 2>&1; then
-       AC_MSG_RESULT(no)
-       AC_MSG_WARN([
-Sorry, you have a Sun version of patch which is notoriously buggy.  
$PACKAGE_NAME
-may function correctly, or minor errors may occur due to Sun's patch tool.
-Please consider upgrading to GNU patch, if you already have GNU patch then you
-can supply its path with the '--with-patch=' option.
-])
-elif $PATCH --version 2>&1 | grep -q "patch 2.0" >/dev/null 2>&1; then
-       AC_MSG_RESULT(no)
-       AC_MSG_WARN([
-Sorry, the version of patch you are using can cause severe problems when a 
patch
-creates a directory.  $PACKAGE_NAME may well function correctly with this 
version
-of patch or small problems could creep in.
-Please consider upgrading your patch to a more recent version, if you already
-have a more recent version of patch then you can supply its path with the
-'--with-patch=' option.
-])
-else
-       AC_MSG_RESULT(yes)
-fi
-
 dnl check if bash completion is desired (adapted from 'source-highlight' by 
Lorenzo Bettini)
 dnl don't use sysconfdir! as bash_completion does not check multiple 
directories, we use the system default
 
@@ -347,12 +103,6 @@ dnl Print results
 AC_MSG_RESULT([$PACKAGE_NAME version $PACKAGE_VERSION configured.])
 AC_MSG_RESULT([Using '$prefix' for installation prefix.])
 
-# we don't need to see this just for the backup-files command
-# but we may as well spec it for the future
-#AC_MSG_RESULT([Using '$CC' for C compiler.])
-#AC_MSG_RESULT([Building with '$CFLAGS' for C compiler flags.])
-#AC_MSG_RESULT([Building with '$LIBS' for linker flags.])
-
 AC_MSG_RESULT([])
 AC_MSG_RESULT([Report bugs to $PACKAGE_BUGREPORT])
 AC_MSG_RESULT([])
diff --git a/scripts/ptxdist_bootstrap.sh b/scripts/ptxdist_bootstrap.sh
index b9f4c7a5c..081bace1a 100755
--- a/scripts/ptxdist_bootstrap.sh
+++ b/scripts/ptxdist_bootstrap.sh
@@ -9,9 +9,12 @@
 # left to the package build.
 #
 # usage: ptxdist_bootstrap.sh <builddir>
+#        ptxdist_bootstrap.sh --check
 #
-# CC, CFLAGS, CPPFLAGS, LDFLAGS, LEX, YACC and PKG_CONFIG from the
-# environment are used if set.
+# With --check, only the prerequisites are checked and nothing is built.
+#
+# CC, CFLAGS, CPPFLAGS, LDFLAGS, LEX, YACC, PATCH and PKG_CONFIG from
+# the environment are used if set and not empty.
 #
 
 PTXDIST_LOG_PROMPT="ptxdist: "
@@ -39,14 +42,26 @@ esac
 set +o posix
 
 topdir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" || exit
-builddir="${1}"
-if [ -z "${builddir}" ]; then
-       echo "usage: ${0} <builddir>" >&2
+case "${1}" in
+"")
+       echo "usage: ${0} <builddir>|--check" >&2
        exit 1
-fi
+       ;;
+--check)
+       check_only=true
+       ;;
+*)
+       builddir="${1}"
+       ;;
+esac
+
+# empty means unset, e.g. when passed from configure
+for var in CC CFLAGS CPPFLAGS LDFLAGS LEX YACC PATCH PKG_CONFIG; do
+       [ -n "${!var}" ] || unset "${var}"
+done
 
 declare -A links
-declare -a missing
+declare -a missing warnings
 
 #
 # $1: version found, $2: version required
@@ -95,7 +110,7 @@ find_gnu() {
 }
 
 for tool in cat chmod chown cp dirname install ln md5sum mkdir mknod \
-               mktemp mv readlink realpath rm rmdir sort stat tty; do
+               mktemp mv readlink realpath rm rmdir sha256sum sort stat touch 
tty; do
        find_gnu "${tool}" "GNU coreutils" "" coreutils "g${tool}" "${tool}"
 done
 find_gnu tar   "GNU tar"       ""      tar             gtar tar
@@ -107,11 +122,69 @@ find_gnu make     "GNU Make"      3.81    make            
gmake gnumake make
 
 links[bash]="${BASH}"
 
-if path="$(type -P file)"; then
-       links[file]="${path}"
-else
-       missing+=( "'file' (package: file)" )
-fi
+#
+# find a tool, any implementation will do, and register a link for it
+#
+# $1: tool, $2: package that provides it
+#
+find_tool() {
+       local path
+
+       if path="$(type -P "${1}")"; then
+               links[${1}]="${path}"
+       else
+               missing+=( "'${1}' (package: ${2})" )
+       fi
+}
+
+find_tool file file
+find_tool bzip2        bzip2
+find_tool gzip gzip
+find_tool xz   xz
+find_tool unzip        unzip
+find_tool wget wget
+
+#
+# patch: any implementation works in principle, but some are known to
+# be broken, e.g. Sun's patch or patch 2.0, which cannot create
+# directories. Prefer GNU patch and warn about anything else.
+#
+find_patch() {
+       local -a names=( gpatch patch )
+       local name path version
+
+       if [ -n "${PATCH}" ]; then
+               names=( "${PATCH}" )
+       fi
+
+       for name in "${names[@]}"; do
+               path="$(type -P "${name}")" || continue
+               version="$("${path}" --version 2>/dev/null | head -n 1)"
+               if [[ "${version}" =~ ^(GNU )?patch\ ([0-9]+(\.[0-9]+)+) ]] &&
+                       version_ge "${BASH_REMATCH[2]}" 2.1; then
+                       links[patch]="${path}"
+                       return
+               fi
+       done
+
+       # no GNU patch, take what is there
+       for name in "${names[@]}"; do
+               path="$(type -P "${name}")" && break
+       done
+       if [ -z "${path}" ]; then
+               missing+=( "'${names[-1]}' (package: patch)" )
+               return
+       fi
+       links[patch]="${path}"
+       if "${path}" -v 2>&1 | grep -q Sun; then
+               warnings+=( "'${path}' is Sun's patch, which is notoriously 
buggy." )
+       else
+               warnings+=( "'${path}' is not GNU patch >= 2.1, it may not work 
correctly." )
+       fi
+       warnings+=( "Please consider installing GNU patch (package: patch) or 
set PATCH." )
+}
+
+find_patch
 
 # optional
 links[sysctl]="$(type -P sysctl || type -P false)"
@@ -188,6 +261,14 @@ if type -P "${CC%% *}" > /dev/null; then
        fi
 fi
 
+if [ ${#warnings[@]} -gt 0 ]; then
+       {
+               echo
+               printf "${PTXDIST_LOG_PROMPT}warning: %s\n" "${warnings[@]}"
+               echo
+       } >&2
+fi
+
 if [ ${#missing[@]} -gt 0 ]; then
        {
                echo
@@ -199,6 +280,10 @@ if [ ${#missing[@]} -gt 0 ]; then
        exit 1
 fi
 
+if [ -n "${check_only}" ]; then
+       exit 0
+fi
+
 #
 # all prerequisites are there, set up the build directory
 #
-- 
2.47.3


Reply via email to