2019-07-08 20:58:26 +08:00
|
|
|
#!/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
|
2000-12-21 00:29:07 +08:00
|
|
|
shift
|
2019-07-08 20:58:26 +08:00
|
|
|
extensions="$@"
|
1999-05-07 04:52:19 +08:00
|
|
|
|
2019-07-08 20:58:26 +08:00
|
|
|
if test -z "$template"; then
|
|
|
|
echo "Please supply template." >&2
|
|
|
|
exit 1
|
1999-05-07 04:52:19 +08:00
|
|
|
fi
|
|
|
|
|
2002-03-22 18:22:41 +08:00
|
|
|
header_list=
|
2019-07-08 20:58:26 +08:00
|
|
|
olddir=$(pwd)
|
|
|
|
|
|
|
|
# Go to project root.
|
2024-11-08 04:00:23 +08:00
|
|
|
cd "$(CDPATH='' cd -- "$(dirname -- "$0")/../" && pwd -P)" || exit
|
1999-09-04 01:46:39 +08:00
|
|
|
|
2019-07-08 20:58:26 +08:00
|
|
|
module_ptrs="$(echo $extensions | $AWK -f ./build/order_by_dep.awk)"
|
2005-06-21 21:47:38 +08:00
|
|
|
|
2019-07-08 20:58:26 +08:00
|
|
|
for ext in $extensions; do
|
|
|
|
ext_dir=$(echo "$ext" | cut -d ';' -f 2)
|
|
|
|
header_list="$header_list $ext_dir/*.h*"
|
1999-05-09 05:44:12 +08:00
|
|
|
done
|
|
|
|
|
2019-07-08 20:58:26 +08:00
|
|
|
includes=$($AWK -f ./build/print_include.awk $header_list)
|
2000-12-21 00:29:07 +08:00
|
|
|
|
1999-09-04 01:46:39 +08:00
|
|
|
cd $olddir
|
|
|
|
|
2019-07-08 20:58:26 +08:00
|
|
|
cat $template | \
|
|
|
|
sed \
|
|
|
|
-e "s'@EXT_INCLUDE_CODE@'$includes'" \
|
|
|
|
-e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \
|
|
|
|
-e 's/@NEWLINE@/\
|
1999-05-09 06:00:02 +08:00
|
|
|
/g'
|