blob: 1463e0fc48ba8802aaff3e0e17cc974e68b047b4 [file] [log] [blame]
Rob Landleycb376ee2006-08-04 21:05:33 +00001#!/bin/sh
2
Rob Landley519d7df2006-08-09 20:56:23 +00003# Compile individual versions of each busybox applet.
4
5if [ $# -eq 0 ]
6then
7
Rob Landley236c6752006-08-06 02:13:36 +00008# Clear out the build directory. (Make clean should do this instead of here.)
9
10rm -rf build
11mkdir build
12
Rob Landleycb376ee2006-08-04 21:05:33 +000013# Make our prerequisites.
14
15make 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
21cd libbb
22make
23cd ..
24
Rob Landley236c6752006-08-06 02:13:36 +000025# Same problem.
26
Rob Landleyaffb7a62006-08-05 00:41:39 +000027cd archival/libunarchive
28make
29cd ../..
30
Rob Landley519d7df2006-08-09 20:56:23 +000031# And again
32
33cd coreutils/libcoreutils
34make
35cd ../..
36
37# Sensing a pattern here?
38
39#cd networking/libiproute
40#make
41#cd ../..
42
43fi
44
Rob Landley236c6752006-08-06 02:13:36 +000045# 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 Landleyaffb7a62006-08-05 00:41:39 +000048
Rob Landley236c6752006-08-06 02:13:36 +000049# Figure out which applets need extra libraries added to their command line.
50
Rob Landley519d7df2006-08-09 20:56:23 +000051function substithing()
Rob Landleyaffb7a62006-08-05 00:41:39 +000052{
Rob Landley519d7df2006-08-09 20:56:23 +000053 if [ "${1/ $3 //}" != "$1" ]
Rob Landleyaffb7a62006-08-05 00:41:39 +000054 then
Rob Landley519d7df2006-08-09 20:56:23 +000055 echo $2
Rob Landley236c6752006-08-06 02:13:36 +000056 fi
Rob Landleyaffb7a62006-08-05 00:41:39 +000057}
Rob Landleyaffb7a62006-08-05 00:41:39 +000058
Rob Landley519d7df2006-08-09 20:56:23 +000059function 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 Landleycb376ee2006-08-04 21:05:33 +000087
Rob Landley236c6752006-08-06 02:13:36 +000088strange_names=`sed -rn -e 's/\#.*//' -e 's/.*APPLET_NOUSAGE\(([^,]*),([^,]*),.*/\1 \2/p' -e 's/.*APPLET_ODDNAME\(([^,]*),([^,]*),.*, *([^)]*).*/\1 \2@\3/p' include/applets.h`
89
90function bonkname()
91{
92 while [ $# -gt 0 ]
93 do
94 if [ "$APPLET" == "$1" ]
95 then
96 APPFILT="${2/@*/}"
97 if [ "${APPFILT}" == "$2" ]
98 then
Rob Landley519d7df2006-08-09 20:56:23 +000099 HELPNAME='"nousage\n"' # These should be _fixed_.
Rob Landley236c6752006-08-06 02:13:36 +0000100 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 Landleyaffb7a62006-08-05 00:41:39 +0000109
Rob Landley519d7df2006-08-09 20:56:23 +0000110# Iterate through every name in busybox.links
111
112function buildit ()
113{
114 export APPLET="$1"
Rob Landley236c6752006-08-06 02:13:36 +0000115 export APPFILT=${APPLET}
116 export HELPNAME=${APPLET}_full_usage
Rob Landley519d7df2006-08-09 20:56:23 +0000117
Rob Landley236c6752006-08-06 02:13:36 +0000118 bonkname $strange_names
119
Rob Landley519d7df2006-08-09 20:56:23 +0000120 j=`find archival console-tools coreutils debianutils editors findutils init loginutils miscutils modutils networking procps shell sysklogd util-linux -name "${APPFILT}.c"`
Rob Landleycb376ee2006-08-04 21:05:33 +0000121 if [ -z "$j" ]
122 then
123 echo no file for $APPLET
124 else
Rob Landley236c6752006-08-06 02:13:36 +0000125 echo "Building $APPLET"
Rob Landleyaffb7a62006-08-05 00:41:39 +0000126 gcc -Os -o build/$APPLET applets/individual.c $j \
127 `extra_libraries $APPFILT` libbb/libbb.a -Iinclude \
128 -DBUILD_INDIVIDUAL \
Rob Landley519d7df2006-08-09 20:56:23 +0000129 '-Drun_applet_by_name(...)' '-Dfind_applet_by_name(...)=0' \
Rob Landley236c6752006-08-06 02:13:36 +0000130 -DAPPLET_main=${APPFILT}_main -DAPPLET_full_usage=${HELPNAME}
Rob Landleycb376ee2006-08-04 21:05:33 +0000131 if [ $? -ne 0 ];
132 then
Rob Landley236c6752006-08-06 02:13:36 +0000133 echo "Failed $APPLET"
Rob Landleycb376ee2006-08-04 21:05:33 +0000134 fi
135 fi
Rob Landley519d7df2006-08-09 20:56:23 +0000136}
137
138if [ $# -eq 0 ]
139then
140 for APPLET in `sed 's .*/ ' busybox.links`
141 do
142 buildit "$APPLET"
143 done
144else
145 buildit "$1"
146fi
147
Rob Landleycb376ee2006-08-04 21:05:33 +0000148
149strip build/*