summaryrefslogtreecommitdiff
path: root/scripts/individual
blob: 35c44e87eb660c482ababdb9e1a89f1b5f8df8e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh

# Clear out the build directory.  (Make clean should do this instead of here.)

rm -rf build
mkdir build

# Make our prerequisites.

make busybox.links include/bb_config.h

# Adding "libbb/libbb.a" to the previous line doesn't work, nor does going
# "make libbb.a" in the libb directory.  The busybox makefile has layers and
# layers of overcomplicated brokenness...

cd libbb
make
cd ..

# Same problem.

cd archival/libunarchive
make
cd ../..

# About 3/5 of the applets build from one .c file (with the same name as the
# corresponding applet), and all it needs to link against.  However, to build
# them all we need more than that.

# Figure out which applets need extra libraries added to their command line.

function extra_libraries()
{
  archival="ar bunzip2 unlzma cpio dpkg gunzip rpm2cpio rpm tar uncompress unzip dpkg_deb gzip "
  if [ "${archival/$1 //}" != "${archival}" ]
  then
    echo "archival/libunarchive/libunarchive.a"
  fi

  # What needs -libm?

  libm="awk dc "
  if [ "${libm/$1 //}" != "${libm}" ]
  then
    echo "-lm"
  fi
}

# Query applets.h to figure out which need something funky

strange_names=`sed -rn -e 's/\#.*//' -e 's/.*APPLET_NOUSAGE\(([^,]*),([^,]*),.*/\1 \2/p' -e 's/.*APPLET_ODDNAME\(([^,]*),([^,]*),.*, *([^)]*).*/\1 \2@\3/p' include/applets.h`

function bonkname()
{
  while [ $# -gt 0 ]
  do
    if [ "$APPLET" == "$1" ]
    then
      APPFILT="${2/@*/}"
      if [ "${APPFILT}" == "$2" ]
      then
        HELPNAME='"nousage\n"'
      else
        HELPNAME="${2/*@/}"_full_usage
      fi
      break
    fi
    shift 2
  done
#echo APPLET=${APPLET} APPFILT=${APPFILT} HELPNAME=${HELPNAME} 2=${2}
}

for APPLET in `sed 's .*/  ' busybox.links`
do
  export APPLET
  export APPFILT=${APPLET}
  export HELPNAME=${APPLET}_full_usage
  bonkname $strange_names

  j=`find . -name "${APPFILT}.c"`
  if [ -z "$j" ]
  then
    echo no file for $APPLET
  else
    echo "Building $APPLET"
    gcc -Os -o build/$APPLET applets/individual.c $j \
	`extra_libraries $APPFILT` libbb/libbb.a -Iinclude \
	-DBUILD_INDIVIDUAL \
	"-Drun_applet_by_name(...)" "-Dfind_applet_by_name(...) 0" \
	-DAPPLET_main=${APPFILT}_main -DAPPLET_full_usage=${HELPNAME}
    if [ $? -ne 0 ];
    then
      echo "Failed $APPLET"
    fi
  fi
done

strip build/*