blob: d5f7b9488eb3b00271d138025c6f56707f7ac2dc [file] [log] [blame]
Denys Vlasenko3015a132010-05-17 01:59:16 +02001#!/bin/sh
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02002
Denys Vlasenkoc3dadba2011-04-16 17:59:34 +02003# Note: was using sed OPTS CMD -- FILES
4# but users complain that many sed implementations
5# are misinterpreting --.
6
Denys Vlasenko572b9a32010-05-09 16:20:52 +02007test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02008
9# cd to objtree
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020010cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko1883cb12010-07-09 01:25:36 +020011# In separate objtree build, include/ might not exist yet
12mkdir include 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020013
14srctree="$1"
15
Mike Frysingerf718e3a2010-11-16 07:29:12 -050016status() { printf ' %-8s%s\n' "$1" "$2"; }
17gen() { status "GEN" "$@"; }
18chk() { status "CHK" "$@"; }
19
maxwen27116ba2015-08-14 21:41:28 +020020# On OSX the sed implementation is not compatible with some of the
21# features in this script, so this uses gsed and warns the user if
22# it does not exist.
23UNAME=$(uname -sm)
24case "$UNAME" in
25*Darwin*|*Macintosh*)
26 SED_IMPL=$(which gsed)
27 if [ $? != 0 ]; then
28 echo "GNU sed is required for Darwin builds, please install and add 'gsed' to the path"
29 exit 1;
30 fi
31 ;;
32*)
33 SED_IMPL=sed
34esac
35
Mike Frysingerf718e3a2010-11-16 07:29:12 -050036generate()
37{
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020038 # NB: data to be inserted at INSERT line is coming on stdin
39 local src="$1" dst="$2" header="$3"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050040 #chk "${dst}"
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020041 {
Denys Vlasenko7a3f8e22010-11-25 06:55:18 +010042 # Need to use printf: different shells have inconsistent
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020043 # rules re handling of "\n" in echo params.
Denys Vlasenko749e3052010-11-24 15:06:49 +010044 printf "%s\n" "${header}"
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020045 # print everything up to INSERT line
maxwen27116ba2015-08-14 21:41:28 +020046 $SED_IMPL -n '/^INSERT$/ q; p' "${src}"
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020047 # copy stdin to stdout
48 cat
49 # print everything after INSERT line
maxwen27116ba2015-08-14 21:41:28 +020050 $SED_IMPL -n '/^INSERT$/ { :l; n; p; bl }' "${src}"
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020051 } >"${dst}.tmp"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050052 if ! cmp -s "${dst}" "${dst}.tmp"; then
53 gen "${dst}"
54 mv "${dst}.tmp" "${dst}"
55 else
56 rm -f "${dst}.tmp"
57 fi
58}
59
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020060# (Re)generate include/applets.h
maxwen27116ba2015-08-14 21:41:28 +020061$SED_IMPL -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020062| generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050063 "$srctree/include/applets.src.h" \
64 "include/applets.h" \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020065 "/* DO NOT EDIT. This file is generated from applets.src.h */"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020066
Denys Vlasenkof0f94702010-06-06 01:53:38 +020067# (Re)generate include/usage.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020068# We add line continuation backslash after each line,
69# and insert empty line before each line which doesn't start
70# with space or tab
maxwen27116ba2015-08-14 21:41:28 +020071$SED_IMPL -n -e 's@^//usage:\([ \t].*\)$@\1 \\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\@p' \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020072 "$srctree"/*/*.c "$srctree"/*/*/*.c \
73| generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050074 "$srctree/include/usage.src.h" \
75 "include/usage.h" \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020076 "/* DO NOT EDIT. This file is generated from usage.src.h */"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020077
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020078# (Re)generate */Kbuild and */Config.in
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020079# We skip .dotdirs - makes git/svn/etc users happier
80{ cd -- "$srctree" && find . -type d -not '(' -name '.?*' -prune ')'; } \
81| while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020082 d="${d#./}"
Denys Vlasenko1883cb12010-07-09 01:25:36 +020083
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020084 src="$srctree/$d/Kbuild.src"
85 dst="$d/Kbuild"
86 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030087 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020088
maxwen27116ba2015-08-14 21:41:28 +020089 $SED_IMPL -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020090 | generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050091 "${src}" "${dst}" \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020092 "# DO NOT EDIT. This file is generated from Kbuild.src"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020093 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020094
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020095 src="$srctree/$d/Config.src"
96 dst="$d/Config.in"
97 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030098 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020099
maxwen27116ba2015-08-14 21:41:28 +0200100 $SED_IMPL -n 's@^//config:@@p' "$srctree/$d"/*.c \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +0200101 | generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -0500102 "${src}" "${dst}" \
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +0200103 "# DO NOT EDIT. This file is generated from Config.src"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200104 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200105done
106
Denys Vlasenkof9d09132010-11-21 22:10:07 +0100107# Last read failed. This is normal. Don't exit with its error code:
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200108exit 0