bc: prepare for char-by-char input handling
[oweals/busybox.git] / make_single_applets.sh
1 #!/bin/sh
2 # This script expects that the tree was built with the desired .config:
3 # in particular, it expects that include/applets.h is generated already.
4 #
5 # The script will try to rebuild each enabled applet in isolation.
6 # All other options which chose general bbox config, applet features, etc,
7 # are not modified for the builds.
8
9 makeopts="-j9"
10
11 # The list of all applet config symbols
12 test -f include/applets.h || { echo "No include/applets.h file"; exit 1; }
13 apps="`
14 grep ^IF_ include/applets.h \
15 | grep -v '^IF_FEATURE_' \
16 | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
17 | grep -v '^BUSYBOX$' \
18 | sort | uniq
19 `"
20
21 # Take existing config
22 test -f .config || { echo "No .config file"; exit 1; }
23 cfg="`cat .config`"
24
25 # Make a config with all applet symbols off
26 allno="$cfg"
27 for app in $apps; do
28         allno="`echo "$allno" | sed "s/^CONFIG_${app}=y\$/# CONFIG_${app} is not set/"`"
29 done
30 # remove "busybox" as well
31 allno="`echo "$allno" | sed "s/^CONFIG_BUSYBOX=y\$/# CONFIG_BUSYBOX is not set/"`"
32 #echo "$allno" >.config_allno
33
34 trap 'test -f .config.SV && mv .config.SV .config && touch .config' EXIT
35
36
37 # Turn on each applet individually and build single-applet executable
38 # (give config names on command line to build only those)
39 test $# = 0 && set -- $apps
40 fail=0
41 for app; do
42         # Only if it was indeed originally enabled...
43         { echo "$cfg" | grep -q "^CONFIG_${app}=y\$"; } || continue
44
45         echo "Making ${app}..."
46         mv .config .config.SV
47         echo "CONFIG_${app}=y" >.config
48         echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config
49
50         if test x"${app}" != x"SH_IS_ASH" && test x"${app}" != x"SH_IS_HUSH"; then
51                 # $allno has all choices for "sh" aliasing set to off.
52                 # "sh" aliasing defaults to "ash", not none.
53                 # without this fix, "make oldconfig" sets it wrong,
54                 # resulting in NUM_APPLETS = 2 (the second applet is "sh")
55                 sed '/CONFIG_SH_IS_NONE/d' -i .config
56                 echo "CONFIG_SH_IS_NONE=y" >>.config
57         fi
58
59         if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
60                 fail=$((fail+1))
61                 echo "Config error for ${app}"
62                 mv .config busybox_config_${app}
63         elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
64                 fail=$((fail+1))
65                 grep -i -e error: -e warning: busybox_make_${app}.log
66                 echo "Build error for ${app}"
67                 mv .config busybox_config_${app}
68         elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
69                 grep -i -e error: -e warning: busybox_make_${app}.log
70                 mv busybox busybox_${app}
71                 fail=$((fail+1))
72                 echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
73                 mv .config busybox_config_${app}
74         else
75                 grep -i -e error: -e warning: busybox_make_${app}.log \
76                 || rm busybox_make_${app}.log
77                 mv busybox busybox_${app}
78                 #mv .config busybox_config_${app}
79         fi
80         mv .config.SV .config
81         #exit
82 done
83 touch .config # or else next "make" can be confused
84 echo "Failures: $fail"
85 test $fail = 0 # set exitcode