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