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