gen_build_files.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. local src="$1" dst="$2" header="$3"
  18. #chk "${dst}"
  19. {
  20. # Need to use printf: different shells have inconsistent
  21. # rules re handling of "\n" in echo params.
  22. printf "%s\n" "${header}"
  23. # print everything up to INSERT line
  24. sed -n '/^INSERT$/ q; p' "${src}"
  25. # copy stdin to stdout
  26. cat
  27. # print everything after INSERT line
  28. sed -n '/^INSERT$/ { :l; n; p; bl }' "${src}"
  29. } >"${dst}.tmp"
  30. if ! cmp -s "${dst}" "${dst}.tmp"; then
  31. gen "${dst}"
  32. mv "${dst}.tmp" "${dst}"
  33. else
  34. rm -f "${dst}.tmp"
  35. fi
  36. }
  37. # (Re)generate include/applets.h
  38. sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
  39. | generate \
  40. "$srctree/include/applets.src.h" \
  41. "include/applets.h" \
  42. "/* DO NOT EDIT. This file is generated from applets.src.h */"
  43. # (Re)generate include/usage.h
  44. # We add line continuation backslash after each line,
  45. # and insert empty line before each line which doesn't start
  46. # with space or tab
  47. sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\@p' \
  48. "$srctree"/*/*.c "$srctree"/*/*/*.c \
  49. | generate \
  50. "$srctree/include/usage.src.h" \
  51. "include/usage.h" \
  52. "/* DO NOT EDIT. This file is generated from usage.src.h */"
  53. # (Re)generate */Kbuild and */Config.in
  54. # We skip .dotdirs - makes git/svn/etc users happier
  55. { cd -- "$srctree" && find . -type d -not '(' -name '.?*' -prune ')'; } \
  56. | while read -r d; do
  57. d="${d#./}"
  58. src="$srctree/$d/Kbuild.src"
  59. dst="$d/Kbuild"
  60. if test -f "$src"; then
  61. mkdir -p -- "$d" 2>/dev/null
  62. sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
  63. | generate \
  64. "${src}" "${dst}" \
  65. "# DO NOT EDIT. This file is generated from Kbuild.src"
  66. fi
  67. src="$srctree/$d/Config.src"
  68. dst="$d/Config.in"
  69. if test -f "$src"; then
  70. mkdir -p -- "$d" 2>/dev/null
  71. sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
  72. | generate \
  73. "${src}" "${dst}" \
  74. "# DO NOT EDIT. This file is generated from Config.src"
  75. fi
  76. done
  77. # Last read failed. This is normal. Don't exit with its error code:
  78. exit 0