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 | |
| 15 | make busybox.links include/bb_config.h |
| 16 | |
| 17 | # Adding "libbb/libbb.a" to the previous line doesn't work, nor does going |
| 18 | # "make libbb.a" in the libb directory. The busybox makefile has layers and |
| 19 | # layers of overcomplicated brokenness... |
| 20 | |
| 21 | cd libbb |
| 22 | make |
| 23 | cd .. |
| 24 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 25 | # Same problem. |
| 26 | |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 27 | cd archival/libunarchive |
| 28 | make |
| 29 | cd ../.. |
| 30 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 31 | # And again |
| 32 | |
| 33 | cd coreutils/libcoreutils |
| 34 | make |
| 35 | cd ../.. |
| 36 | |
| 37 | # Sensing a pattern here? |
| 38 | |
| 39 | #cd networking/libiproute |
| 40 | #make |
| 41 | #cd ../.. |
| 42 | |
| 43 | fi |
| 44 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 45 | # About 3/5 of the applets build from one .c file (with the same name as the |
| 46 | # corresponding applet), and all it needs to link against. However, to build |
| 47 | # them all we need more than that. |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 48 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 49 | # Figure out which applets need extra libraries added to their command line. |
| 50 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 51 | function substithing() |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 52 | { |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 53 | if [ "${1/ $3 //}" != "$1" ] |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 54 | then |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 55 | echo $2 |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 56 | fi |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 57 | } |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 58 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 59 | function extra_libraries() |
| 60 | { |
| 61 | # gzip needs gunzip.c (when gunzip is enabled, anyway). |
| 62 | substithing " gzip " "archival/gunzip.c archival/uncompress.c" "$1" |
| 63 | |
| 64 | # init needs init_shared.c |
| 65 | substithing " init " "init/init_shared.c" "$1" |
| 66 | |
| 67 | # ifconfig needs interface.c |
| 68 | substithing " ifconfig " "networking/interface.c" "$1" |
| 69 | |
| 70 | # Applets that need libunarchive.a |
| 71 | substithing " ar bunzip2 unlzma cpio dpkg gunzip rpm2cpio rpm tar uncompress unzip dpkg_deb gzip " "archival/libunarchive/libunarchive.a" "$1" |
| 72 | |
| 73 | # Applets that need libcoreutils.a |
| 74 | substithing " cp mv " "coreutils/libcoreutils/libcoreutils.a" "$1" |
| 75 | |
| 76 | # Applets that need libiproute.a |
| 77 | substithing " ip " "networking/libiproute/libiproute.a" "$1" |
| 78 | |
| 79 | # What needs -libm? |
| 80 | substithing " awk dc " "-lm" "$1" |
| 81 | |
| 82 | # What needs -lcrypt? |
| 83 | substithing " httpd vlock " "-lcrypt" "$1" |
| 84 | } |
| 85 | |
| 86 | # Query applets.h to figure out which applets need special treatment |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 87 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 88 | strange_names=`sed -rn -e 's/\#.*//' -e 's/.*APPLET_NOUSAGE\(([^,]*),([^,]*),.*/\1 \2/p' -e 's/.*APPLET_ODDNAME\(([^,]*),([^,]*),.*, *([^)]*).*/\1 \2@\3/p' include/applets.h` |
| 89 | |
| 90 | function bonkname() |
| 91 | { |
| 92 | while [ $# -gt 0 ] |
| 93 | do |
| 94 | if [ "$APPLET" == "$1" ] |
| 95 | then |
| 96 | APPFILT="${2/@*/}" |
| 97 | if [ "${APPFILT}" == "$2" ] |
| 98 | then |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 99 | HELPNAME='"nousage\n"' # These should be _fixed_. |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 100 | else |
| 101 | HELPNAME="${2/*@/}"_full_usage |
| 102 | fi |
| 103 | break |
| 104 | fi |
| 105 | shift 2 |
| 106 | done |
| 107 | #echo APPLET=${APPLET} APPFILT=${APPFILT} HELPNAME=${HELPNAME} 2=${2} |
| 108 | } |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 109 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 110 | # Iterate through every name in busybox.links |
| 111 | |
| 112 | function buildit () |
| 113 | { |
| 114 | export APPLET="$1" |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 115 | export APPFILT=${APPLET} |
| 116 | export HELPNAME=${APPLET}_full_usage |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 117 | |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 118 | bonkname $strange_names |
| 119 | |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 120 | 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] | 121 | if [ -z "$j" ] |
| 122 | then |
| 123 | echo no file for $APPLET |
| 124 | else |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 125 | echo "Building $APPLET" |
Rob Landley | affb7a6 | 2006-08-05 00:41:39 +0000 | [diff] [blame] | 126 | gcc -Os -o build/$APPLET applets/individual.c $j \ |
| 127 | `extra_libraries $APPFILT` libbb/libbb.a -Iinclude \ |
| 128 | -DBUILD_INDIVIDUAL \ |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 129 | '-Drun_applet_by_name(...)' '-Dfind_applet_by_name(...)=0' \ |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 130 | -DAPPLET_main=${APPFILT}_main -DAPPLET_full_usage=${HELPNAME} |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 131 | if [ $? -ne 0 ]; |
| 132 | then |
Rob Landley | 236c675 | 2006-08-06 02:13:36 +0000 | [diff] [blame] | 133 | echo "Failed $APPLET" |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 134 | fi |
| 135 | fi |
Rob Landley | 519d7df | 2006-08-09 20:56:23 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if [ $# -eq 0 ] |
| 139 | then |
| 140 | for APPLET in `sed 's .*/ ' busybox.links` |
| 141 | do |
| 142 | buildit "$APPLET" |
| 143 | done |
| 144 | else |
| 145 | buildit "$1" |
| 146 | fi |
| 147 | |
Rob Landley | cb376ee | 2006-08-04 21:05:33 +0000 | [diff] [blame] | 148 | |
| 149 | strip build/* |