cross.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/bash
  2. # $Id$
  3. # Copyright 2006 Michael Mohr with modifications by Roger Dingledine
  4. # See LICENSE for licensing information.
  5. #######################################################################
  6. # Tor-cross: a tool to help cross-compile Tor
  7. #
  8. # The purpose of a cross-compiler is to produce an executable for
  9. # one system (CPU) on another. This is useful, for example, when
  10. # the target system does not have a native compiler available.
  11. # You might, for example, wish to cross-compile a program on your
  12. # host (the computer you're working on now) for a target such as
  13. # a router or handheld computer.
  14. #
  15. # A number of environment variables must be set in order for this
  16. # script to work:
  17. # $PREFIX, $CROSSPATH, $ARCH_PREFIX, $HOST,
  18. # and (optionally) $BUILD
  19. # Please run the script for a description of each one. If automated
  20. # builds are desired, the above variables can be exported at the top
  21. # of this script.
  22. #
  23. # Recent releases of Tor include test programs in configure. Normally
  24. # this is a good thing, since it catches a number of problems.
  25. # However, this also presents a problem when cross compiling, since
  26. # you can't run binary images for the target system on the host.
  27. #
  28. # Tor-cross assumes that you know what you're doing and removes a
  29. # number of checks known to cause problems with this process.
  30. # Note that this does not guarantee that the program will run or
  31. # even compile; it simply allows configure to generate the Makefiles.
  32. #
  33. # Stripping the binaries should almost always be done for an
  34. # embedded environment where space is at an exacting premium.
  35. # However, the default is NOT to strip them since they are useful for
  36. # debugging. If you do not plan to do any debugging and you
  37. # don't care about the debugging symbols, set $STRIP to "yes" before
  38. # running this script.
  39. #
  40. # Tor-cross was written by Michael Mohr. He can be contacted at
  41. # m(dot)mohr(at)laposte(dot)net. Comments are appreciated, but
  42. # flames go to /dev/null.
  43. #
  44. # The target with which this script is tested is little-endian
  45. # MIPS Linux, built on an Athlon-based Linux desktop.
  46. #
  47. #######################################################################
  48. # disable the platform-specific tests in configure
  49. export CROSS_COMPILE=yes
  50. if [ ! -f configure ]
  51. then
  52. echo "Please run this script from the root of the Tor distribution."
  53. exit -1
  54. fi
  55. if [ -z $PREFIX ]
  56. then
  57. echo "You must define \$PREFIX since you are cross-compiling."
  58. echo "Select a non-system location (i.e. /tmp/tor-cross):"
  59. echo " export PREFIX=/tmp/tor-cross"
  60. exit -1
  61. fi
  62. if [ -z $CROSSPATH ]
  63. then
  64. echo "You must define the location of your cross-compiler's"
  65. echo "directory using \$CROSSPATH; for example,"
  66. echo " export CROSSPATH=/opt/cross/staging_dir_mipsel/bin"
  67. exit -1
  68. fi
  69. if [ -z $ARCH_PREFIX ]
  70. then
  71. echo "You must define \$ARCH_PREFIX to continue. For example,"
  72. echo "if you normally cross-compile applications using"
  73. echo "mipsel-linux-uclibc-gcc, you would set \$ARCH_PREFIX like so:"
  74. echo " export ARCH_PREFIX=mipsel-linux-uclibc-"
  75. exit -1
  76. fi
  77. if [ -z $HOST ]
  78. then
  79. echo "You must specify a target processor with \$HOST; for example:"
  80. echo " export HOST=mipsel-unknown-elf"
  81. exit -1
  82. fi
  83. if [ -z $BUILD ]
  84. then
  85. echo "You should specify the host machine's type with \$BUILD; for example:"
  86. echo " export BUILD=i686-pc-linux-gnu"
  87. echo "If you wish to let configure autodetect the host, set \$BUILD to 'auto':"
  88. echo " export BUILD=auto"
  89. exit -1
  90. fi
  91. # clean up any existing object files
  92. if [ -f src/or/tor ]
  93. then
  94. make clean
  95. fi
  96. # Set up the build environment and try to run configure
  97. export PATH=$PATH:$CROSSPATH
  98. export RANLIB=${ARCH_PREFIX}ranlib
  99. export CC=${ARCH_PREFIX}gcc
  100. if [ $BUILD == "auto" ]
  101. then
  102. ./configure \
  103. --prefix=$PREFIX \
  104. --host=$HOST
  105. else
  106. ./configure \
  107. --prefix=$PREFIX \
  108. --host=$HOST \
  109. --build=$BUILD
  110. fi
  111. # has a problem occurred?
  112. if [ $? -ne 0 ]
  113. then
  114. echo ""
  115. echo "A problem has been detected with configure."
  116. echo "Please check the output above and rerun cross.sh"
  117. echo ""
  118. exit -1
  119. fi
  120. # Now we're cookin'
  121. make
  122. # if $STRIP has length (i.e. STRIP=yes), strip the binaries
  123. if [ ! -z $STRIP ]
  124. then
  125. ${ARCH_PREFIX}strip \
  126. src/or/tor \
  127. src/or/test \
  128. src/tools/tor-resolve
  129. fi
  130. echo ""
  131. echo "Tor should be compiled at this point. Now run 'make install' to"
  132. echo "install to $PREFIX"
  133. echo ""