genif.sh 1.2 KB

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