Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 3 | # Compile individual versions of each busybox applet. |
| 4 | |
| 5 | if [ $# -eq 0 ] |
| 6 | then |
| 7 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 8 | # Clear out the build directory. (Make clean should do this instead of here.) |
| 9 | |
| 10 | rm -rf build |
| 11 | mkdir build |
| 12 | |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 13 | # Make our prerequisites. |
| 14 | |
Bernhard Reutner-Fischer | 1d6fb6d | 2006-09-14 15:04:31 +0000 | [diff] [blame^] | 15 | make busybox.links include/bb_config.h $(pwd)/{libbb/libbb.a,archival/libunarchive/libunarchive.a,coreutils/libcoreutils/libcoreutils.a,networking/libiproute/libiproute.a} |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 16 | fi |
| 17 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 18 | # About 3/5 of the applets build from one .c file (with the same name as the |
| 19 | # corresponding applet), and all it needs to link against. However, to build |
| 20 | # them all we need more than that. |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 21 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 22 | # Figure out which applets need extra libraries added to their command line. |
| 23 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 24 | function substithing() |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 25 | { |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 26 | if [ "${1/ $3 //}" != "$1" ] |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 27 | then |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 28 | echo $2 |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 29 | fi |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 30 | } |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 31 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 32 | function extra_libraries() |
| 33 | { |
| 34 | # gzip needs gunzip.c (when gunzip is enabled, anyway). |
| 35 | substithing " gzip " "archival/gunzip.c archival/uncompress.c" "$1" |
| 36 | |
| 37 | # init needs init_shared.c |
| 38 | substithing " init " "init/init_shared.c" "$1" |
| 39 | |
| 40 | # ifconfig needs interface.c |
| 41 | substithing " ifconfig " "networking/interface.c" "$1" |
| 42 | |
| 43 | # Applets that need libunarchive.a |
| 44 | substithing " ar bunzip2 unlzma cpio dpkg gunzip rpm2cpio rpm tar uncompress unzip dpkg_deb gzip " "archival/libunarchive/libunarchive.a" "$1" |
| 45 | |
| 46 | # Applets that need libcoreutils.a |
| 47 | substithing " cp mv " "coreutils/libcoreutils/libcoreutils.a" "$1" |
| 48 | |
| 49 | # Applets that need libiproute.a |
| 50 | substithing " ip " "networking/libiproute/libiproute.a" "$1" |
| 51 | |
| 52 | # What needs -libm? |
| 53 | substithing " awk dc " "-lm" "$1" |
| 54 | |
| 55 | # What needs -lcrypt? |
| 56 | substithing " httpd vlock " "-lcrypt" "$1" |
| 57 | } |
| 58 | |
| 59 | # Query applets.h to figure out which applets need special treatment |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 60 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 61 | strange_names=`sed -rn -e 's/\#.*//' -e 's/.*APPLET_NOUSAGE\(([^,]*),([^,]*),.*/\1 \2/p' -e 's/.*APPLET_ODDNAME\(([^,]*),([^,]*),.*, *([^)]*).*/\1 \2@\3/p' include/applets.h` |
| 62 | |
| 63 | function bonkname() |
| 64 | { |
| 65 | while [ $# -gt 0 ] |
| 66 | do |
| 67 | if [ "$APPLET" == "$1" ] |
| 68 | then |
| 69 | APPFILT="${2/@*/}" |
| 70 | if [ "${APPFILT}" == "$2" ] |
| 71 | then |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 72 | HELPNAME='"nousage\n"' # These should be _fixed_. |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 73 | else |
| 74 | HELPNAME="${2/*@/}"_full_usage |
| 75 | fi |
| 76 | break |
| 77 | fi |
| 78 | shift 2 |
| 79 | done |
| 80 | #echo APPLET=${APPLET} APPFILT=${APPFILT} HELPNAME=${HELPNAME} 2=${2} |
| 81 | } |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 82 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 83 | # Iterate through every name in busybox.links |
| 84 | |
| 85 | function buildit () |
| 86 | { |
| 87 | export APPLET="$1" |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 88 | export APPFILT=${APPLET} |
| 89 | export HELPNAME=${APPLET}_full_usage |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 90 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 91 | bonkname $strange_names |
| 92 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 93 | j=`find archival console-tools coreutils debianutils editors findutils init loginutils miscutils modutils networking procps shell sysklogd util-linux -name "${APPFILT}.c"` |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 94 | if [ -z "$j" ] |
| 95 | then |
| 96 | echo no file for $APPLET |
| 97 | else |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 98 | echo "Building $APPLET" |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 99 | gcc -Os -o build/$APPLET applets/individual.c $j \ |
| 100 | `extra_libraries $APPFILT` libbb/libbb.a -Iinclude \ |
| 101 | -DBUILD_INDIVIDUAL \ |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 102 | '-Drun_applet_by_name(...)' '-Dfind_applet_by_name(...)=0' \ |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 103 | -DAPPLET_main=${APPFILT}_main -DAPPLET_full_usage=${HELPNAME} |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 104 | if [ $? -ne 0 ]; |
| 105 | then |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 106 | echo "Failed $APPLET" |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 107 | fi |
| 108 | fi |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | if [ $# -eq 0 ] |
| 112 | then |
| 113 | for APPLET in `sed 's .*/ ' busybox.links` |
| 114 | do |
| 115 | buildit "$APPLET" |
| 116 | done |
| 117 | else |
| 118 | buildit "$1" |
| 119 | fi |
| 120 | |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 121 | |
| 122 | strip build/* |