php-src/build/genif.sh
Hans Krentel (hakre) c075546320
Fail early in *nix configuration build script
Adding two exit early safeguards in the *nix configuration build script:

1) Given the initial cd into the build tree fails (the project root),
   the `buildconf` script exits with non-zero status (failure).
2) Given the grep command does not exist or `configure.ac` AC_INIT [1]
   expectations are unmet, the buildconf script exits non-zero.

Additionally quoting the pathname to cd into and the empty CD_PATH
parameter for portability, also for systems that are using a
non-portable pathname [2] for the build tree.

The initial CD safeguard has been applied to the `buildconf` and
four more scripts:

- build/genif.sh
- scripts/dev/credits
- scripts/dev/genfiles
- scripts/dev/makedist

Rationale:

Cd-ing into the project root should always prematurely exit w/ FAILURE
as a required precondition for its invocation has not been met. This
should never go unnoticed as it always requires user intervention.

Similar and more specifically to the PHP build on *nix systems, the
grep command is required early to obtain the `php_extra_version` from
configure.ac.  Previously, if the grep command is missing (or failing
due to not matching the line with the AC_INIT macro [1]), the internal
dev parameter would always be zero (0) which can easily result in the
situation that the configure script is not being rebuilt. This is
cumbersome as the rebuild of a configure script is more likely required
with checked-out dev versions under change rather than an already
properly set-up build environment on a dedicated build or release
system. Missing the fact that either the grep utility is missing or
the expectation of having the AC_INIT macro in configure.ac is unmet
should never go unnoticed as it always requires user intervention.

[1]: https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Initializing-configure.html
[2]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271

Closes GH-16717.
2024-11-09 14:03:04 +01:00

54 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
#
# Generate internal functions file content based on the provided extensions.
#
# SYNOPSIS:
# genif.sh <template> <extensions>
#
# ARGUMENTS:
# template Path to internal functions template file.
# extensions Space delimited list of provided extensions and their locations.
#
# ENVIRONMENT:
# The following optional variables are supported:
#
# AWK Path to the awk program or its command name.
# AWK=/path/to/awk genif.sh ...
#
# USAGE EXAMPLE:
# AWK=nawk ./build/genif.sh ./main/internal_functions.c.in "date;ext/date spl;ext/spl" > ./main/internal_functions.c
AWK=${AWK:-awk}
template=$1
shift
extensions="$@"
if test -z "$template"; then
echo "Please supply template." >&2
exit 1
fi
header_list=
olddir=$(pwd)
# Go to project root.
cd "$(CDPATH='' cd -- "$(dirname -- "$0")/../" && pwd -P)" || exit
module_ptrs="$(echo $extensions | $AWK -f ./build/order_by_dep.awk)"
for ext in $extensions; do
ext_dir=$(echo "$ext" | cut -d ';' -f 2)
header_list="$header_list $ext_dir/*.h*"
done
includes=$($AWK -f ./build/print_include.awk $header_list)
cd $olddir
cat $template | \
sed \
-e "s'@EXT_INCLUDE_CODE@'$includes'" \
-e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
-e 's/@NEWLINE@/\
/g'