blob: 8ad7a7406375aadfaea551894a522ba3be9e0950 [file] [log] [blame]
Denys Vlasenko10c01a72016-12-23 13:39:22 +01001#!/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
9makeopts="-j9"
10
11# The list of all applet config symbols
12test -f include/applets.h || { echo "No include/applets.h file"; exit 1; }
13apps="`
14grep ^IF_ include/applets.h \
15| grep -v ^IF_FEATURE_ \
16| sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
Denys Vlasenko10c01a72016-12-23 13:39:22 +010017| sort | uniq
18`"
19
20# Take existing config
21test -f .config || { echo "No .config file"; exit 1; }
22cfg="`cat .config`"
23
24# Make a config with all applet symbols off
25allno="$cfg"
26for app in $apps; do
27 allno="`echo "$allno" | sed "s/^CONFIG_${app}=y\$/# CONFIG_${app} is not set/"`"
28done
Denys Vlasenko0b883582016-12-23 16:49:07 +010029#echo "$allno" >.config_allno
Denys Vlasenko10c01a72016-12-23 13:39:22 +010030
Denys Vlasenkoe7b54d02017-01-09 16:31:21 +010031trap 'test -f .config.SV && mv .config.SV .config && touch .config' EXIT
32
Denys Vlasenkob8935d02017-01-15 20:16:27 +010033
Denys Vlasenko10c01a72016-12-23 13:39:22 +010034# Turn on each applet individually and build single-applet executable
Denys Vlasenkob8935d02017-01-15 20:16:27 +010035# (give config names on command line to build only those)
36test $# = 0 && set -- $apps
Denys Vlasenko10c01a72016-12-23 13:39:22 +010037fail=0
Denys Vlasenkob8935d02017-01-15 20:16:27 +010038for app; do
Denys Vlasenko10c01a72016-12-23 13:39:22 +010039 # Only if it was indeed originally enabled...
40 { echo "$cfg" | grep -q "^CONFIG_${app}=y\$"; } || continue
41
42 echo "Making ${app}..."
43 mv .config .config.SV
44 echo "CONFIG_${app}=y" >.config
45 echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config
Denys Vlasenko0b883582016-12-23 16:49:07 +010046
Denys Vlasenko7d5c8812016-12-23 19:42:53 +010047 if test x"${app}" != x"SH_IS_ASH" && test x"${app}" != x"SH_IS_HUSH"; then
48 # $allno has all choices for "sh" aliasing set to off.
Denys Vlasenko0b883582016-12-23 16:49:07 +010049 # "sh" aliasing defaults to "ash", not none.
50 # without this fix, "make oldconfig" sets it wrong,
Denys Vlasenko7d5c8812016-12-23 19:42:53 +010051 # resulting in NUM_APPLETS = 2 (the second applet is "sh")
Denys Vlasenko0b883582016-12-23 16:49:07 +010052 sed '/CONFIG_SH_IS_NONE/d' -i .config
53 echo "CONFIG_SH_IS_NONE=y" >>.config
54 fi
55
Denys Vlasenko10c01a72016-12-23 13:39:22 +010056 if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
57 : $((fail++))
58 echo "Config error for ${app}"
59 mv .config busybox_config_${app}
Denys Vlasenko7d5c8812016-12-23 19:42:53 +010060 elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
Denys Vlasenko10c01a72016-12-23 13:39:22 +010061 : $((fail++))
Denys Vlasenkoe7b54d02017-01-09 16:31:21 +010062 grep -i -e error: -e warning: busybox_make_${app}.log
Denys Vlasenko10c01a72016-12-23 13:39:22 +010063 echo "Build error for ${app}"
64 mv .config busybox_config_${app}
Denys Vlasenkoa1cd0d92016-12-23 15:12:27 +010065 elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
Denys Vlasenkoe7b54d02017-01-09 16:31:21 +010066 grep -i -e error: -e warning: busybox_make_${app}.log
Denys Vlasenkoa1cd0d92016-12-23 15:12:27 +010067 mv busybox busybox_${app}
68 : $((fail++))
69 echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
70 mv .config busybox_config_${app}
Denys Vlasenko10c01a72016-12-23 13:39:22 +010071 else
Denys Vlasenkoe7b54d02017-01-09 16:31:21 +010072 grep -i -e error: -e warning: busybox_make_${app}.log \
73 || rm busybox_make_${app}.log
Denys Vlasenko10c01a72016-12-23 13:39:22 +010074 mv busybox busybox_${app}
Denys Vlasenkoe7b54d02017-01-09 16:31:21 +010075 #mv .config busybox_config_${app}
Denys Vlasenko10c01a72016-12-23 13:39:22 +010076 fi
77 mv .config.SV .config
78 #exit
79done
Denys Vlasenkoa1cd0d92016-12-23 15:12:27 +010080touch .config # or else next "make" can be confused
Denys Vlasenko10c01a72016-12-23 13:39:22 +010081echo "Failures: $fail"
82test $fail = 0 # set exitcode