Teach md5sum and sha1sum to work the way other applets do so I don't have to
[oweals/busybox.git] / scripts / individual
1 #!/bin/sh
2
3 # Clear out the build directory.  (Make clean should do this instead of here.)
4
5 rm -rf build
6 mkdir build
7
8 # Make our prerequisites.
9
10 make busybox.links include/bb_config.h
11
12 # Adding "libbb/libbb.a" to the previous line doesn't work, nor does going
13 # "make libbb.a" in the libb directory.  The busybox makefile has layers and
14 # layers of overcomplicated brokenness...
15
16 cd libbb
17 make
18 cd ..
19
20 # Same problem.
21
22 cd archival/libunarchive
23 make
24 cd ../..
25
26 # About 3/5 of the applets build from one .c file (with the same name as the
27 # corresponding applet), and all it needs to link against.  However, to build
28 # them all we need more than that.
29
30 # Figure out which applets need extra libraries added to their command line.
31
32 function extra_libraries()
33 {
34   archival="ar bunzip2 unlzma cpio dpkg gunzip rpm2cpio rpm tar uncompress unzip dpkg_deb gzip "
35   if [ "${archival/$1 //}" != "${archival}" ]
36   then
37     echo "archival/libunarchive/libunarchive.a"
38   fi
39
40   # What needs -libm?
41
42   libm="awk dc "
43   if [ "${libm/$1 //}" != "${libm}" ]
44   then
45     echo "-lm"
46   fi
47 }
48
49 # Query applets.h to figure out which need something funky
50
51 strange_names=`sed -rn -e 's/\#.*//' -e 's/.*APPLET_NOUSAGE\(([^,]*),([^,]*),.*/\1 \2/p' -e 's/.*APPLET_ODDNAME\(([^,]*),([^,]*),.*, *([^)]*).*/\1 \2@\3/p' include/applets.h`
52
53 function bonkname()
54 {
55   while [ $# -gt 0 ]
56   do
57     if [ "$APPLET" == "$1" ]
58     then
59       APPFILT="${2/@*/}"
60       if [ "${APPFILT}" == "$2" ]
61       then
62         HELPNAME='"nousage\n"'
63       else
64         HELPNAME="${2/*@/}"_full_usage
65       fi
66       break
67     fi
68     shift 2
69   done
70 #echo APPLET=${APPLET} APPFILT=${APPFILT} HELPNAME=${HELPNAME} 2=${2}
71 }
72
73 for APPLET in `sed 's .*/  ' busybox.links`
74 do
75   export APPLET
76   export APPFILT=${APPLET}
77   export HELPNAME=${APPLET}_full_usage
78   bonkname $strange_names
79
80   j=`find . -name "${APPFILT}.c"`
81   if [ -z "$j" ]
82   then
83     echo no file for $APPLET
84   else
85     echo "Building $APPLET"
86     gcc -Os -o build/$APPLET applets/individual.c $j \
87         `extra_libraries $APPFILT` libbb/libbb.a -Iinclude \
88         -DBUILD_INDIVIDUAL \
89         "-Drun_applet_by_name(...)" "-Dfind_applet_by_name(...) 0" \
90         -DAPPLET_main=${APPFILT}_main -DAPPLET_full_usage=${HELPNAME}
91     if [ $? -ne 0 ];
92     then
93       echo "Failed $APPLET"
94     fi
95   fi
96 done
97
98 strip build/*