File: genif.sh

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (53 lines) | stat: -rwxr-xr-x 1,260 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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 "$template"; then
  echo "Please supply template." >&2
  exit 1
fi

header_list=
olddir=$(pwd)

# Go to project root.
cd "$(CDPATH='' cd -- "$(dirname -- "$0")/../" && pwd -P)" || exit

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)

cd $olddir

cat $template | \
  sed \
    -e "s'@EXT_INCLUDE_CODE@'$includes'" \
    -e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
    -e 's/@NEWLINE@/\
/g'