diff options
author | Peter Kokot <peterkokot@gmail.com> | 2019-07-08 14:58:26 +0200 |
---|---|---|
committer | Peter Kokot <peterkokot@gmail.com> | 2019-07-08 14:58:26 +0200 |
commit | 900de30b0f40a254e19082d3e2b696d58e338b43 (patch) | |
tree | 6c7045a7072e10e5010e2bab2bfd153be20e1291 /build | |
parent | 392398bfe63b43288a0fbd301491b564eb24dfe9 (diff) | |
download | php-git-900de30b0f40a254e19082d3e2b696d58e338b43.tar.gz |
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
Diffstat (limited to 'build')
-rwxr-xr-x | build/genif.sh | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/build/genif.sh b/build/genif.sh index a6eb627b0c..697bef9591 100755 --- a/build/genif.sh +++ b/build/genif.sh @@ -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' |