gen_build_files.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. # (Re)generate include/applets.h
  9. src="$srctree/include/applets.src.h"
  10. dst="include/applets.h"
  11. s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
  12. old=`cat "$dst" 2>/dev/null`
  13. # Why "IFS='' read -r REPLY"??
  14. # This atrocity is needed to read lines without mangling.
  15. # IFS='' prevents whitespace trimming,
  16. # -r suppresses backslash handling.
  17. new=`echo "/* DO NOT EDIT. This file is generated from applets.src.h */"
  18. while IFS='' read -r REPLY; do
  19. test x"$REPLY" = x"INSERT" && REPLY="$s"
  20. printf "%s\n" "$REPLY"
  21. done <"$src"`
  22. if test x"$new" != x"$old"; then
  23. echo " GEN $dst"
  24. printf "%s\n" "$new" >"$dst"
  25. fi
  26. # (Re)generate include/usage.h
  27. src="$srctree/include/usage.src.h"
  28. dst="include/usage.h"
  29. # We add line continuation backslash after each line,
  30. # and insert empty line before each line which doesn't start
  31. # with space or tab
  32. # (note: we need to use \\\\ because of ``)
  33. s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
  34. old=`cat "$dst" 2>/dev/null`
  35. new=`echo "/* DO NOT EDIT. This file is generated from usage.src.h */"
  36. while IFS='' read -r REPLY; do
  37. test x"$REPLY" = x"INSERT" && REPLY="$s"
  38. printf "%s\n" "$REPLY"
  39. done <"$src"`
  40. if test x"$new" != x"$old"; then
  41. echo " GEN $dst"
  42. printf "%s\n" "$new" >"$dst"
  43. fi
  44. # (Re)generate */Kbuild and */Config.in
  45. { cd -- "$srctree" && find -type d; } | while read -r d; do
  46. d="${d#./}"
  47. src="$srctree/$d/Kbuild.src"
  48. dst="$d/Kbuild"
  49. if test -f "$src"; then
  50. mkdir -p -- "$d" 2>/dev/null
  51. #echo " CHK $dst"
  52. s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
  53. old=`cat "$dst" 2>/dev/null`
  54. new=`echo "# DO NOT EDIT. This file is generated from Kbuild.src"
  55. while IFS='' read -r REPLY; do
  56. test x"$REPLY" = x"INSERT" && REPLY="$s"
  57. printf "%s\n" "$REPLY"
  58. done <"$src"`
  59. if test x"$new" != x"$old"; then
  60. echo " GEN $dst"
  61. printf "%s\n" "$new" >"$dst"
  62. fi
  63. fi
  64. src="$srctree/$d/Config.src"
  65. dst="$d/Config.in"
  66. if test -f "$src"; then
  67. mkdir -p -- "$d" 2>/dev/null
  68. #echo " CHK $dst"
  69. s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
  70. old=`cat "$dst" 2>/dev/null`
  71. new=`echo "# DO NOT EDIT. This file is generated from Config.src"
  72. while IFS='' read -r REPLY; do
  73. test x"$REPLY" = x"INSERT" && REPLY="$s"
  74. printf "%s\n" "$REPLY"
  75. done <"$src"`
  76. if test x"$new" != x"$old"; then
  77. echo " GEN $dst"
  78. printf "%s\n" "$new" >"$dst"
  79. fi
  80. fi
  81. done
  82. # Last read failed. This is normal. Don't exit with its error code:
  83. exit 0