Skip to content

Commit 900de30

Browse files
committed
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
1 parent 392398b commit 900de30

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

build/genif.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
1-
#! /bin/sh
2-
3-
# replacement for genif.pl
4-
5-
infile=$1
6-
shift
7-
srcdir=$1
8-
shift
9-
extra_module_ptrs=$1
10-
shift
11-
awk=$1
1+
#!/bin/sh
2+
#
3+
# Generate internal functions file content based on the provided extensions.
4+
#
5+
# SYNOPSIS:
6+
# genif.sh <template> <extensions>
7+
#
8+
# ARGUMENTS:
9+
# template Path to internal functions template file.
10+
# extensions Space delimited list of provided extensions and their locations.
11+
#
12+
# ENVIRONMENT:
13+
# The following optional variables are supported:
14+
#
15+
# AWK Path to the awk program or its command name.
16+
# AWK=/path/to/awk genif.sh ...
17+
#
18+
# USAGE EXAMPLE:
19+
# AWK=nawk ./build/genif.sh ./main/internal_functions.c.in "date;ext/date spl;ext/spl" > ./main/internal_functions.c
20+
21+
AWK=${AWK:-awk}
22+
template=$1
1223
shift
24+
extensions="$@"
1325

14-
if test -z "$infile" || test -z "$srcdir"; then
15-
echo "please supply infile and srcdir" >&2
16-
exit 1
26+
if test -z "$template"; then
27+
echo "Please supply template." >&2
28+
exit 1
1729
fi
1830

1931
header_list=
20-
olddir=`pwd`
21-
cd $srcdir
32+
olddir=$(pwd)
33+
34+
# Go to project root.
35+
cd $(CDPATH= cd -- "$(dirname -- "$0")/../" && pwd -P)
2236

23-
module_ptrs="$extra_module_ptrs`echo $@ | $awk -f ./build/order_by_dep.awk`"
37+
module_ptrs="$(echo $extensions | $AWK -f ./build/order_by_dep.awk)"
2438

25-
for ext in ${1+"$@"} ; do
26-
ext_dir=`echo "$ext" | cut -d ';' -f 2`
27-
header_list="$header_list $ext_dir/*.h*"
39+
for ext in $extensions; do
40+
ext_dir=$(echo "$ext" | cut -d ';' -f 2)
41+
header_list="$header_list $ext_dir/*.h*"
2842
done
2943

30-
includes=`$awk -f ./build/print_include.awk $header_list`
44+
includes=$($AWK -f ./build/print_include.awk $header_list)
3145

3246
cd $olddir
3347

34-
cat $infile | \
35-
sed \
36-
-e "s'@EXT_INCLUDE_CODE@'$includes'" \
37-
-e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
38-
-e 's/@NEWLINE@/\
48+
cat $template | \
49+
sed \
50+
-e "s'@EXT_INCLUDE_CODE@'$includes'" \
51+
-e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
52+
-e 's/@NEWLINE@/\
3953
/g'

configure.ac

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,12 +1620,10 @@ FEO
16201620
dnl Run this only when generating all the files.
16211621
if test -n "\$REDO_ALL"; then
16221622
echo "creating main/internal_functions.c"
1623-
extensions="$EXT_STATIC"
1624-
sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in $srcdir "$EXTRA_MODULE_PTRS" $AWK \$extensions > main/internal_functions.c
1623+
AWK="$AWK" sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in "$EXT_STATIC" > main/internal_functions.c
16251624
16261625
echo "creating main/internal_functions_cli.c"
1627-
cli_extensions="$EXT_CLI_STATIC"
1628-
sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in $srcdir "$EXTRA_MODULE_PTRS" $AWK \$cli_extensions > main/internal_functions_cli.c
1626+
AWK="$AWK" sh $srcdir/build/genif.sh $srcdir/main/internal_functions.c.in "$EXT_CLI_STATIC" > main/internal_functions_cli.c
16291627
16301628
if test "$PHP_SAPI" = "apache2handler"; then
16311629
if test "$APACHE_VERSION" -ge 2004001; then

0 commit comments

Comments
 (0)