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 21AWK=${AWK:-awk} 22template=$1 23shift 24extensions="$@" 25 26if test -z "$template"; then 27 echo "Please supply template." >&2 28 exit 1 29fi 30 31header_list= 32olddir=$(pwd) 33 34# Go to project root. 35cd "$(CDPATH='' cd -- "$(dirname -- "$0")/../" && pwd -P)" || exit 36 37module_ptrs="$(echo $extensions | $AWK -f ./build/order_by_dep.awk)" 38 39for ext in $extensions; do 40 ext_dir=$(echo "$ext" | cut -d ';' -f 2) 41 header_list="$header_list $ext_dir/*.h*" 42done 43 44includes=$($AWK -f ./build/print_include.awk $header_list) 45 46cd $olddir 47 48cat $template | \ 49 sed \ 50 -e "s'@EXT_INCLUDE_CODE@'$includes'" \ 51 -e "s'@EXT_MODULE_PTRS@'$module_ptrs'" \ 52 -e 's/@NEWLINE@/\ 53/g' 54