|
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 |
12 | 23 | shift
|
| 24 | +extensions="$@" |
13 | 25 |
|
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 |
17 | 29 | fi
|
18 | 30 |
|
19 | 31 | 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) |
22 | 36 |
|
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)" |
24 | 38 |
|
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*" |
28 | 42 | done
|
29 | 43 |
|
30 |
| -includes=`$awk -f ./build/print_include.awk $header_list` |
| 44 | +includes=$($AWK -f ./build/print_include.awk $header_list) |
31 | 45 |
|
32 | 46 | cd $olddir
|
33 | 47 |
|
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@/\ |
39 | 53 | /g'
|
0 commit comments