busybox/make_single_applets.sh
<<
>>
Prefs
   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
   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/' \
  17| grep -v '^BUSYBOX$' \
  18| sort | uniq
  19`"
  20
  21# Take existing config
  22test -f .config || { echo "No .config file"; exit 1; }
  23cfg="`cat .config`"
  24
  25# Make a config with all applet symbols off
  26allno="$cfg"
  27for app in $apps; do
  28        allno="`echo "$allno" | sed "s/^CONFIG_${app}=y\$/# CONFIG_${app} is not set/"`"
  29done
  30#echo "$allno" >.config_allno
  31
  32trap 'test -f .config.SV && mv .config.SV .config && touch .config' EXIT
  33
  34
  35# Turn on each applet individually and build single-applet executable
  36# (give config names on command line to build only those)
  37test $# = 0 && set -- $apps
  38fail=0
  39for app; do
  40        # Only if it was indeed originally enabled...
  41        { echo "$cfg" | grep -q "^CONFIG_${app}=y\$"; } || continue
  42
  43        echo "Making ${app}..."
  44        mv .config .config.SV
  45        echo "CONFIG_${app}=y" >.config
  46        echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config
  47
  48        if test x"${app}" != x"SH_IS_ASH" && test x"${app}" != x"SH_IS_HUSH"; then
  49                # $allno has all choices for "sh" aliasing set to off.
  50                # "sh" aliasing defaults to "ash", not none.
  51                # without this fix, "make oldconfig" sets it wrong,
  52                # resulting in NUM_APPLETS = 2 (the second applet is "sh")
  53                sed '/CONFIG_SH_IS_NONE/d' -i .config
  54                echo "CONFIG_SH_IS_NONE=y" >>.config
  55        fi
  56
  57        if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
  58                fail=$((fail+1))
  59                echo "Config error for ${app}"
  60                mv .config busybox_config_${app}
  61        elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
  62                fail=$((fail+1))
  63                grep -i -e error: -e warning: busybox_make_${app}.log
  64                echo "Build error for ${app}"
  65                mv .config busybox_config_${app}
  66        elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
  67                grep -i -e error: -e warning: busybox_make_${app}.log
  68                mv busybox busybox_${app}
  69                fail=$((fail+1))
  70                echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
  71                mv .config busybox_config_${app}
  72        else
  73                grep -i -e error: -e warning: busybox_make_${app}.log \
  74                || rm busybox_make_${app}.log
  75                mv busybox busybox_${app}
  76                #mv .config busybox_config_${app}
  77        fi
  78        mv .config.SV .config
  79        #exit
  80done
  81touch .config # or else next "make" can be confused
  82echo "Failures: $fail"
  83test $fail = 0 # set exitcode
  84