Refactor genif.sh

Changes:
- Coding style fixes
- ${1+"$@"} replaced with "$@" [1]
- EXTRA_MODULE_PTRS variable is not used anymore
- awk tool defined via environment variable
- srcdir determined automatically from the genif.sh location

[1] https://www.in-ulm.de/~mascheck/various/bourne_args/

Closes GH-4372
This commit is contained in:
Peter Kokot 2019-07-08 14:58:26 +02:00
parent 392398bfe6
commit 900de30b0f
2 changed files with 42 additions and 30 deletions

View File

@ -1,39 +1,53 @@
#! /bin/sh
#!/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
# replacement for genif.pl
AWK=${AWK:-awk}
template=$1
shift
extensions="$@"
infile=$1
shift
srcdir=$1
shift
extra_module_ptrs=$1
shift
awk=$1
shift
if test -z "$infile" || test -z "$srcdir"; then
echo "please supply infile and srcdir" >&2
exit 1
if test -z "$template"; then
echo "Please supply template." >&2
exit 1
fi
header_list=
olddir=`pwd`
cd $srcdir
olddir=$(pwd)
module_ptrs="$extra_module_ptrs`echo $@ | $awk -f ./build/order_by_dep.awk`"
# Go to project root.
cd $(CDPATH= cd -- "$(dirname -- "$0")/../" && pwd -P)
for ext in ${1+"$@"} ; do
ext_dir=`echo "$ext" | cut -d ';' -f 2`
header_list="$header_list $ext_dir/*.h*"
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`
includes=$($AWK -f ./build/print_include.awk $header_list)
cd $olddir
cat $infile | \
sed \
-e "s'@EXT_INCLUDE_CODE@'$includes'" \
-e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
-e 's/@NEWLINE@/\
cat $template | \
sed \
-e "s'@EXT_INCLUDE_CODE@'$includes'" \
-e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
-e 's/@NEWLINE@/\
/g'

View File

@ -1620,12 +1620,10 @@ FEO
dnl Run this only when generating all the files.
if test -n "\$REDO_ALL"; then
echo "creating main/internal_functions.c"
extensions="$EXT_STATIC"
sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in $srcdir "$EXTRA_MODULE_PTRS" $AWK \$extensions > main/internal_functions.c
AWK="$AWK" sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in "$EXT_STATIC" > main/internal_functions.c
echo "creating main/internal_functions_cli.c"
cli_extensions="$EXT_CLI_STATIC"
sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in $srcdir "$EXTRA_MODULE_PTRS" $AWK \$cli_extensions > main/internal_functions_cli.c
AWK="$AWK" sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in "$EXT_CLI_STATIC" > main/internal_functions_cli.c
if test "$PHP_SAPI" = "apache2handler"; then
if test "$APACHE_VERSION" -ge 2004001; then