gen_build_files.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/sh
  2. test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
  3. # cd to objtree
  4. cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
  5. # In separate objtree build, include/ might not exist yet
  6. mkdir include 2>/dev/null
  7. srctree="$1"
  8. status() { printf ' %-8s%s\n' "$1" "$2"; }
  9. gen() { status "GEN" "$@"; }
  10. chk() { status "CHK" "$@"; }
  11. generate()
  12. {
  13. local src="$1" dst="$2" header="$3" insert="$4"
  14. #chk "${dst}"
  15. (
  16. printf "%s\n" "${header}"
  17. if grep -qs '^INSERT$' "${src}"; then
  18. sed -n '1,/^INSERT$/p' "${src}"
  19. printf "%s\n" "${insert}"
  20. sed -n '/^INSERT$/,$p' "${src}"
  21. else
  22. if [ -n "${insert}" ]; then
  23. printf "%s\n" "ERROR: INSERT line missing in: ${src}" 1>&2
  24. fi
  25. cat "${src}"
  26. fi
  27. ) | sed '/^INSERT$/d' > "${dst}.tmp"
  28. if ! cmp -s "${dst}" "${dst}.tmp"; then
  29. gen "${dst}"
  30. mv "${dst}.tmp" "${dst}"
  31. else
  32. rm -f "${dst}.tmp"
  33. fi
  34. }
  35. # (Re)generate include/applets.h
  36. s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
  37. generate \
  38. "$srctree/include/applets.src.h" \
  39. "include/applets.h" \
  40. "/* DO NOT EDIT. This file is generated from applets.src.h */" \
  41. "${s}"
  42. # (Re)generate include/usage.h
  43. # We add line continuation backslash after each line,
  44. # and insert empty line before each line which doesn't start
  45. # with space or tab
  46. # (note: we need to use \\\\ because of ``)
  47. s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
  48. generate \
  49. "$srctree/include/usage.src.h" \
  50. "include/usage.h" \
  51. "/* DO NOT EDIT. This file is generated from usage.src.h */" \
  52. "${s}"
  53. # (Re)generate */Kbuild and */Config.in
  54. { cd -- "$srctree" && find . -type d; } | while read -r d; do
  55. d="${d#./}"
  56. src="$srctree/$d/Kbuild.src"
  57. dst="$d/Kbuild"
  58. if test -f "$src"; then
  59. mkdir -p -- "$d" 2>/dev/null
  60. s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
  61. generate \
  62. "${src}" "${dst}" \
  63. "# DO NOT EDIT. This file is generated from Kbuild.src" \
  64. "${s}"
  65. fi
  66. src="$srctree/$d/Config.src"
  67. dst="$d/Config.in"
  68. if test -f "$src"; then
  69. mkdir -p -- "$d" 2>/dev/null
  70. s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
  71. generate \
  72. "${src}" "${dst}" \
  73. "# DO NOT EDIT. This file is generated from Config.src" \
  74. "${s}"
  75. fi
  76. done
  77. # Last read failed. This is normal. Don't exit with its error code:
  78. exit 0