individual 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/sh
  2. # Compile individual versions of each busybox applet.
  3. if [ $# -eq 0 ]
  4. then
  5. # Clear out the build directory. (Make clean should do this instead of here.)
  6. rm -rf build
  7. mkdir build
  8. # Make our prerequisites.
  9. make busybox.links include/bb_config.h $(pwd)/{libbb/libbb.a,archival/libunarchive/libunarchive.a,coreutils/libcoreutils/libcoreutils.a,networking/libiproute/libiproute.a}
  10. else
  11. # Could very well be that we want to build an individual applet but have no
  12. # 'build' dir yet..
  13. test -d ./build || mkdir build
  14. fi
  15. # About 3/5 of the applets build from one .c file (with the same name as the
  16. # corresponding applet), and all it needs to link against. However, to build
  17. # them all we need more than that.
  18. # Figure out which applets need extra libraries added to their command line.
  19. function substithing()
  20. {
  21. if [ "${1/ $3 //}" != "$1" ]
  22. then
  23. echo $2
  24. fi
  25. }
  26. function extra_libraries()
  27. {
  28. # gzip needs gunzip.c (when gunzip is enabled, anyway).
  29. substithing " gzip " "archival/gunzip.c archival/uncompress.c" "$1"
  30. # init needs init_shared.c
  31. substithing " init " "init/init_shared.c" "$1"
  32. # ifconfig needs interface.c
  33. substithing " ifconfig " "networking/interface.c" "$1"
  34. # Applets that need libunarchive.a
  35. substithing " ar bunzip2 unlzma cpio dpkg gunzip rpm2cpio rpm tar uncompress unzip dpkg_deb gzip " "archival/libunarchive/libunarchive.a" "$1"
  36. # Applets that need libcoreutils.a
  37. substithing " cp mv " "coreutils/libcoreutils/libcoreutils.a" "$1"
  38. # Applets that need libiproute.a
  39. substithing " ip " "networking/libiproute/libiproute.a" "$1"
  40. # What needs -libm?
  41. substithing " awk dc " "-lm" "$1"
  42. # What needs -lcrypt?
  43. substithing " httpd vlock " "-lcrypt" "$1"
  44. }
  45. # Query applets.h to figure out which applets need special treatment
  46. strange_names=`sed -rn -e 's/\#.*//' -e 's/.*APPLET_NOUSAGE\(([^,]*),([^,]*),.*/\1 \2/p' -e 's/.*APPLET_ODDNAME\(([^,]*),([^,]*),.*, *([^)]*).*/\1 \2@\3/p' include/applets.h`
  47. function bonkname()
  48. {
  49. while [ $# -gt 0 ]
  50. do
  51. if [ "$APPLET" == "$1" ]
  52. then
  53. APPFILT="${2/@*/}"
  54. if [ "${APPFILT}" == "$2" ]
  55. then
  56. HELPNAME='"nousage\n"' # These should be _fixed_.
  57. else
  58. HELPNAME="${2/*@/}"_full_usage
  59. fi
  60. break
  61. fi
  62. shift 2
  63. done
  64. #echo APPLET=${APPLET} APPFILT=${APPFILT} HELPNAME=${HELPNAME} 2=${2}
  65. }
  66. # Iterate through every name in busybox.links
  67. function buildit ()
  68. {
  69. export APPLET="$1"
  70. export APPFILT=${APPLET}
  71. export HELPNAME=${APPLET}_full_usage
  72. bonkname $strange_names
  73. j=`find archival console-tools coreutils debianutils editors findutils init loginutils miscutils modutils networking procps shell sysklogd util-linux -name "${APPFILT}.c"`
  74. if [ -z "$j" ]
  75. then
  76. echo no file for $APPLET
  77. else
  78. echo "Building $APPLET"
  79. gcc -Os -o build/$APPLET applets/individual.c $j \
  80. `extra_libraries $APPFILT` libbb/libbb.a -Iinclude \
  81. -DBUILD_INDIVIDUAL \
  82. '-Drun_applet_by_name(...)' '-Dfind_applet_by_name(...)=0' \
  83. -DAPPLET_main=${APPFILT}_main -DAPPLET_full_usage=${HELPNAME}
  84. if [ $? -ne 0 ];
  85. then
  86. echo "Failed $APPLET"
  87. fi
  88. fi
  89. }
  90. if [ $# -eq 0 ]
  91. then
  92. for APPLET in `sed 's .*/ ' busybox.links`
  93. do
  94. buildit "$APPLET"
  95. done
  96. else
  97. buildit "$1"
  98. fi
  99. strip build/*