]> granicus.if.org Git - php/commitdiff
Refactor genif.sh
authorPeter Kokot <peterkokot@gmail.com>
Mon, 8 Jul 2019 12:58:26 +0000 (14:58 +0200)
committerPeter Kokot <peterkokot@gmail.com>
Mon, 8 Jul 2019 12:58:26 +0000 (14:58 +0200)
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

build/genif.sh
configure.ac

index a6eb627b0c5ff194e717a4eeb3c1dfe0327fe0a4..697bef95912e46f8bc8e6c7759de4322c94eaa34 100755 (executable)
@@ -1,39 +1,53 @@
-#! /bin/sh
-
-# replacement for genif.pl
-
-infile=$1
-shift
-srcdir=$1
-shift
-extra_module_ptrs=$1
-shift
-awk=$1
+#!/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 "$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)
+
+# Go to project root.
+cd $(CDPATH= cd -- "$(dirname -- "$0")/../" && pwd -P)
 
-module_ptrs="$extra_module_ptrs`echo $@ | $awk -f ./build/order_by_dep.awk`"
+module_ptrs="$(echo $extensions | $AWK -f ./build/order_by_dep.awk)"
 
-for ext in ${1+"$@"} ; do
-       ext_dir=`echo "$ext" | cut -d ';' -f 2`
-       header_list="$header_list $ext_dir/*.h*"
+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'
index 36bfc9e020459f995a3f93fa565d90a71b21d6c7..9ca763b2713325f3e1bd6fff0b8d178a5cfaf6db 100644 (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