Skip to content

Refactor genif.sh #4372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions build/genif.sh
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 2 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1629,12 +1629,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
Expand Down