OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.4 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-config/pkgseldir_compile.sh
  6. # Copyright (C) 2008 - 2010 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. PKGSEL_LIST_VAR="$1"
  16. VAR_PREFIX="$2"
  17. OUT_PREFIX="$3"
  18. shift 3
  19. OUT_CONFIG="${OUT_PREFIX}config.in"
  20. OUT_PKGSEL="${OUT_PREFIX}pkgsel.in"
  21. OUT_PKGSELAWK="${OUT_PREFIX}pkgsel.awk"
  22. trap ' ' INT
  23. module_get_var()
  24. {
  25. echo "${VAR_PREFIX}${1}" | tr ' a-z-' '_A-Z_'
  26. }
  27. module_get_description()
  28. {
  29. sed -n -e 's/^#[ \t]*Description:[ \t]*\(.*\)/\1/p' "$1"
  30. }
  31. module_get_default()
  32. {
  33. sed -n -e 's/^# Default: \(.*\)/\1/p' "$1"
  34. }
  35. module_render()
  36. {
  37. local pkgseldir="$1" module_dir="$2" module_filename="$3" module_name="$4" module_type="$5"
  38. local file= var= desc= default=
  39. # recompose the full path to the module file
  40. file="$pkgseldir${module_dir:+/$module_dir}/$module_filename"
  41. var="$( module_get_var "$module_name" )"
  42. # print headers
  43. cat <<-EOT | tee -a "$OUT_CONFIG.$$" >> "$OUT_PKGSEL.$$"
  44. # BEGIN:$var ($module_filename)
  45. #
  46. EOT
  47. case "$module_type" in
  48. auto)
  49. cat <<-EOT >> "$OUT_PKGSEL.$$"
  50. $PKGSEL_LIST_VAR="\$$PKGSEL_LIST_VAR $file"
  51. EOT
  52. ;;
  53. boolean)
  54. desc="$( module_get_description "$file" )"
  55. default="$( module_get_default "$file" )"
  56. cat <<-EOT >> "$OUT_CONFIG.$$"
  57. bool '${desc:-${module_name//_/ }}' $var ${default:-0}
  58. EOT
  59. cat <<-EOT >> "$OUT_PKGSEL.$$"
  60. if [ "\$$var" = 1 ]; then
  61. $PKGSEL_LIST_VAR="\$$PKGSEL_LIST_VAR $file"
  62. fi
  63. EOT
  64. ;;
  65. esac
  66. # print footers
  67. cat <<-EOT | tee -a "$OUT_CONFIG.$$" >> "$OUT_PKGSEL.$$"
  68. # END:$var
  69. EOT
  70. }
  71. cat <<-EOT | tee "$OUT_CONFIG.$$" > "$OUT_PKGSEL.$$"
  72. # Generated by $0
  73. # ($( date ))
  74. # using: $@
  75. EOT
  76. for pkgseldir; do
  77. if [ ! -d "$pkgseldir" ]; then
  78. echo "$pkgseldir: Invalid pkgseldir." >&2
  79. continue
  80. else
  81. pkgseldir=$( cd "$pkgseldir"; pwd -P )
  82. fi
  83. bin/find "$pkgseldir" -name '*.all' -o -name '*.ask' | sort | while read module; do
  84. # simple parsing
  85. #
  86. module_dir="${module%/*}"
  87. module_filename="${module##*/}"
  88. module_file_ext="${module##*.}"
  89. case "$module_file_ext" in
  90. all) module_type=auto
  91. ;;
  92. ask) module_type=boolean
  93. ;;
  94. *) # not a module
  95. continue
  96. ;;
  97. esac
  98. # make $module_dir $pkgseldir relative
  99. if [ "$module_dir" = "$pkgseldir" ]; then
  100. module_dir=
  101. else
  102. module_dir="${module_dir#$pkgseldir/}"
  103. fi
  104. module_name="$( echo "${module_filename%.*}" | sed -e 's/^[0-9][0-9]-//' )"
  105. module_render "$pkgseldir" "$module_dir" "$module_filename" "$module_name" "$module_type"
  106. done
  107. done
  108. cat <<EOT >> "$OUT_PKGSEL.$$"
  109. # Update .awk file only if needed
  110. #
  111. if [ ! -s "$OUT_PKGSELAWK" -o "\$( cat "$OUT_PKGSELAWK.cache" 2> /dev/null)" != "\$$PKGSEL_LIST_VAR" ]; then
  112. echo "\$$PKGSEL_LIST_VAR" > $OUT_PKGSELAWK.cache
  113. cat <<-EOF > "$OUT_PKGSELAWK.\$\$"
  114. # Generated by \$0
  115. # \$( date )
  116. # using: \$$PKGSEL_LIST_VAR
  117. EOF
  118. lib/sde-config/pkgsel2awk.sh \$$PKGSEL_LIST_VAR >> "$OUT_PKGSELAWK.\$\$"
  119. mv "$OUT_PKGSELAWK.\$\$" "$OUT_PKGSELAWK"
  120. fi
  121. EOT
  122. for x in $OUT_CONFIG $OUT_PKGSEL; do
  123. mv "$x.$$" "$x"
  124. done