3
0

gen_build_files.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/sh
  2. # Note: was using sed OPTS CMD -- FILES
  3. # but users complain that many sed implementations
  4. # are misinterpreting --.
  5. test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
  6. # cd to objtree
  7. cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
  8. # In separate objtree build, include/ might not exist yet
  9. mkdir include 2>/dev/null
  10. srctree="$1"
  11. status() { printf ' %-8s%s\n' "$1" "$2"; }
  12. gen() { status "GEN" "$@"; }
  13. chk() { status "CHK" "$@"; }
  14. generate()
  15. {
  16. # NB: data to be inserted at INSERT line is coming on stdin
  17. src="$1"
  18. dst="$2"
  19. header="$3"
  20. #chk "${dst}"
  21. {
  22. # Need to use printf: different shells have inconsistent
  23. # rules re handling of "\n" in echo params.
  24. printf "%s\n" "${header}"
  25. # print everything up to INSERT line
  26. sed -n '/^INSERT$/ q; p' "${src}"
  27. # copy stdin to stdout
  28. cat
  29. # print everything after INSERT line
  30. sed -n '/^INSERT$/ {
  31. :l
  32. n
  33. p
  34. bl
  35. }' "${src}"
  36. } >"${dst}.tmp"
  37. if ! cmp -s "${dst}" "${dst}.tmp"; then
  38. gen "${dst}"
  39. mv "${dst}.tmp" "${dst}"
  40. else
  41. rm -f "${dst}.tmp"
  42. fi
  43. }
  44. # (Re)generate include/applets.h
  45. sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
  46. | generate \
  47. "$srctree/include/applets.src.h" \
  48. "include/applets.h" \
  49. "/* DO NOT EDIT. This file is generated from applets.src.h */"
  50. # (Re)generate include/usage.h
  51. # We add line continuation backslash after each line,
  52. # and insert empty line before each line which doesn't start
  53. # with space or tab
  54. TAB="$(printf '\tX')"
  55. TAB="${TAB%X}"
  56. LF="$(printf '\nX')"
  57. LF="${LF%X}"
  58. sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \
  59. -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \
  60. "$srctree"/*/*.c "$srctree"/*/*/*.c \
  61. | generate \
  62. "$srctree/include/usage.src.h" \
  63. "include/usage.h" \
  64. "/* DO NOT EDIT. This file is generated from usage.src.h */"
  65. # (Re)generate */Kbuild and */Config.in
  66. # We skip .dotdirs - makes git/svn/etc users happier
  67. { cd -- "$srctree" && find . -type d ! '(' -name '.?*' -prune ')'; } \
  68. | while read -r d; do
  69. d="${d#./}"
  70. src="$srctree/$d/Kbuild.src"
  71. dst="$d/Kbuild"
  72. if test -f "$src"; then
  73. mkdir -p -- "$d" 2>/dev/null
  74. sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
  75. | generate \
  76. "${src}" "${dst}" \
  77. "# DO NOT EDIT. This file is generated from Kbuild.src"
  78. fi
  79. src="$srctree/$d/Config.src"
  80. dst="$d/Config.in"
  81. if test -f "$src"; then
  82. mkdir -p -- "$d" 2>/dev/null
  83. sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
  84. | generate \
  85. "${src}" "${dst}" \
  86. "# DO NOT EDIT. This file is generated from Config.src"
  87. fi
  88. done
  89. # Last read failed. This is normal. Don't exit with its error code:
  90. exit 0