/work/compile_plugins.sh

http://github.com/tybor/Liberty · Shell · 131 lines · 95 code · 30 blank · 6 comment · 13 complexity · 1912d64604147bb5b180f8e5ef9f0151 MD5 · raw file

  1. #!/usr/bin/env bash
  2. cd ${0%/*}/..
  3. export LIBERTY_HOME=$(pwd)
  4. cd target
  5. export LOG=${LOG:-$LIBERTY_HOME/work/compile_plugins.log}
  6. . $LIBERTY_HOME/work/tools.sh
  7. eval `se -environment | grep -v '^#'`
  8. SE_SYS=${SE_SYS%/}
  9. export SE_SYS
  10. n1=$(find $SE_SYS/plugins -name c -type d | wc -l)
  11. n2=$(find $SE_SYS/runtime -name basic_\*.[ch] | sed 's/\.[ch]$//' | uniq | wc -l)
  12. n=$((n1+n2))
  13. i=0
  14. do_generate()
  15. {
  16. plugin_name="$1"
  17. plugin_h="$2"
  18. plugin_c="$3"
  19. plugin_so="$4"
  20. plugin_dir="$5"
  21. location="$6"
  22. plugin_pattern="$7"
  23. plugin_source="$8"
  24. test -d $plugin_dir || mkdir -p $plugin_dir
  25. progress 30 $((i*3)) $((n*3)) "Generating header file for $plugin_so"
  26. {
  27. cat <<EOF
  28. #ifndef __LIBERTY_PLUGIN__
  29. #define __LIBERTY_PLUGIN__
  30. #include "base.h"
  31. #include <errno.h>
  32. EOF
  33. if [ "$(echo ${plugin_pattern}*.h)" != "$plugin_pattern"'*.h' ]; then
  34. for f in ${plugin_pattern}*.h; do
  35. echo '#include "'${f##*/}'"'
  36. done
  37. fi
  38. echo
  39. find $path_liberty -name \*.e -exec grep -Hn 'location: "${sys}/'$location'"' {} \; | \
  40. awk -F: '{print $1}' | uniq | \
  41. xargs -n1 awk '/module_name: "'$plugin_name'"/ { i=1 } /feature_name: "[^"]*"/ { if (i) printf("%s %s\n", ARGV[1], $2); i=0 }' | \
  42. sed 's/"\([^"]*\)"/\1/g' | sort -u | \
  43. while read file symbol; do
  44. {
  45. cat $file | grep "$symbol" | grep ' is$'
  46. cat $file | grep -C3 'feature_name: "'$symbol'"'
  47. } | $LIBERTY_HOME/work/find_feature.py header $symbol ${file##*/}
  48. done | sort -u
  49. echo '#endif'
  50. } > $plugin_h
  51. progress 30 $((i*3+1)) $((n*3)) "Generating code file for $plugin_so"
  52. {
  53. cat <<EOF
  54. #include "${plugin_h##*/}"
  55. EOF
  56. if [ "$(echo ${plugin_pattern}*.c)" != "$plugin_pattern"'*.c' ]; then
  57. for f in ${plugin_pattern}*.c; do
  58. echo '#include "'${f##*/}'"'
  59. done
  60. fi
  61. echo
  62. find $path_liberty -name \*.e -exec grep -Hn 'location: "${sys}/'"$location"'"' {} \; | \
  63. awk -F: '{print $1}' | uniq | \
  64. xargs -n1 awk '/module_name: "'$plugin_name'"/ { i=1 } /feature_name: "[^"]*"/ { if (i) printf("%s %s\n", ARGV[1], $2); i=0 }' | \
  65. sed 's/"\([^"]*\)"/\1/g' | sort -u | \
  66. while read file symbol; do
  67. {
  68. cat $file | grep -E "^[[:space:]]*$symbol(|[:([:space:]].*) is$"
  69. cat $file | grep -C3 'feature_name: "'$symbol'"'
  70. } | $LIBERTY_HOME/work/find_feature.py code $symbol ${file##*/}
  71. done | sort -u
  72. } > $plugin_c
  73. progress 30 $((i*3+2)) $((n*3)) "Building $plugin_so"
  74. run gcc -iquote $SE_SYS/runtime/c -iquote $plugin_source -shared -fpic -fvisibility=hidden -o $plugin_so $plugin_c
  75. }
  76. find $SE_SYS/runtime -name basic_\*.[ch] | sed 's/\.[ch]$//' | uniq | while read basic_plugin; do
  77. plugin_dir=${basic_plugin#$SE_SYS/}
  78. plugin_dir=$(echo $plugin_dir | sed 's=/c/=/=')
  79. plugin_name=${plugin_dir##*/}
  80. plugin_h=${plugin_dir}~.h
  81. plugin_c=${plugin_dir}~.c
  82. plugin_so=${plugin_dir}.so
  83. plugin_dir=${plugin_dir%/*}
  84. do_generate "$plugin_name" "$plugin_h" "$plugin_c" "$plugin_so" "$plugin_dir" "runtime" "$basic_plugin" "$SE_SYS/runtime/c"
  85. cp -a $plugin_so ${basic_plugin}.so
  86. i=$((i+1))
  87. done
  88. find $SE_SYS/plugins -name c -type d | while read plugin; do
  89. plugin_dir=${plugin#$SE_SYS/}
  90. plugin_dir=${plugin_dir%/c}
  91. plugin_name=${plugin_dir##*/}
  92. plugin_so=${plugin_dir}.so
  93. plugin_h=${plugin_dir}~.h
  94. plugin_c=${plugin_dir}~.c
  95. plugin_dir=${plugin_dir%/*}
  96. do_generate "$plugin_name" "$plugin_h" "$plugin_c" "$plugin_so" "$plugin_dir" "plugins" "$plugin/" "$plugin"
  97. mkdir -p ${plugin%/c}/run
  98. cp -a $plugin_so ${plugin%/c}/run/${plugin_name}.so
  99. i=$((i+1))
  100. done
  101. progress 30 $n $n "done."