cross.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, $HOST_TRIPLET, $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. # for error conditions
  51. EXITVAL=0
  52. if [ ! -f autogen.sh ]
  53. then
  54. echo "Please run this script from the root of the Tor distribution"
  55. exit -1
  56. fi
  57. if [ ! -f configure ]
  58. then
  59. if [ -z $GEN_BUILD ]
  60. then
  61. echo "To automatically generate the build environment, set \$GEN_BUILD"
  62. echo "to yes; for example,"
  63. echo " export GEN_BUILD=yes"
  64. EXITVAL=-1
  65. fi
  66. fi
  67. if [ -z $PREFIX ]
  68. then
  69. echo "You must define \$PREFIX since you are cross-compiling."
  70. echo "Select a non-system location (i.e. /tmp/tor-cross):"
  71. echo " export PREFIX=/tmp/tor-cross"
  72. EXITVAL=-1
  73. fi
  74. if [ -z $CROSSPATH ]
  75. then
  76. echo "You must define the location of your cross-compiler's"
  77. echo "directory using \$CROSSPATH; for example,"
  78. echo " export CROSSPATH=/opt/cross/staging_dir_mipsel/bin"
  79. EXITVAL=-1
  80. fi
  81. if [ -z $HOST_TRIPLET ]
  82. then
  83. echo "You must define \$HOST_TRIPLET to continue. For example,"
  84. echo "if you normally cross-compile applications using"
  85. echo "mipsel-linux-uclibc-gcc, you would set \$HOST_TRIPLET like so:"
  86. echo " export HOST_TRIPLET=mipsel-linux-uclibc-"
  87. EXITVAL=-1
  88. fi
  89. if [ -z $HOST ]
  90. then
  91. echo "You must specify a target processor with \$HOST; for example:"
  92. echo " export HOST=mipsel-unknown-elf"
  93. EXITVAL=-1
  94. fi
  95. if [ -z $BUILD ]
  96. then
  97. echo "You should specify the host machine's type with \$BUILD; for example:"
  98. echo " export BUILD=i686-pc-linux-gnu"
  99. echo "If you wish to let configure autodetect the host, set \$BUILD to 'auto':"
  100. echo " export BUILD=auto"
  101. EXITVAL=-1
  102. fi
  103. if [ ! -x $CROSSPATH/$HOST_TRIPLETgcc ]
  104. then
  105. echo "The specified toolchain does not contain an executable C compiler."
  106. echo "Please double-check your settings and rerun cross.sh."
  107. EXITVAL=-1
  108. fi
  109. if [ $EXITVAL -ne 0 ]
  110. then
  111. echo "Remember, you can hard-code these values in cross.sh if needed."
  112. exit $EXITVAL
  113. fi
  114. if [ ! -z "$GEN_BUILD" -a ! -f configure ]
  115. then
  116. export NOCONF=yes
  117. ./autogen.sh
  118. fi
  119. # clean up any existing object files
  120. if [ -f src/or/tor ]
  121. then
  122. make clean
  123. fi
  124. # Set up the build environment and try to run configure
  125. export PATH=$PATH:$CROSSPATH
  126. export RANLIB=${HOST_TRIPLET}ranlib
  127. export CC=${HOST_TRIPLET}gcc
  128. if [ $BUILD == "auto" ]
  129. then
  130. ./configure \
  131. --enable-debug \
  132. --enable-eventdns \
  133. --prefix=$PREFIX \
  134. --host=$HOST
  135. else
  136. ./configure \
  137. --enable-debug \
  138. --enable-eventdns \
  139. --prefix=$PREFIX \
  140. --host=$HOST \
  141. --build=$BUILD
  142. fi
  143. # has a problem occurred?
  144. if [ $? -ne 0 ]
  145. then
  146. echo ""
  147. echo "A problem has been detected with configure."
  148. echo "Please check the output above and rerun cross.sh"
  149. echo ""
  150. exit -1
  151. fi
  152. # Now we're cookin'
  153. make
  154. # has a problem occurred?
  155. if [ $? -ne 0 ]
  156. then
  157. echo ""
  158. echo "A problem has been detected with make."
  159. echo "Please check the output above and rerun make."
  160. echo ""
  161. exit -1
  162. fi
  163. # if $STRIP has length (i.e. STRIP=yes), strip the binaries
  164. if [ ! -z $STRIP ]
  165. then
  166. ${HOST_TRIPLET}strip \
  167. src/or/tor \
  168. src/or/test \
  169. src/tools/tor-resolve
  170. fi
  171. echo ""
  172. echo "Tor should be compiled at this point. Now run 'make install' to"
  173. echo "install to $PREFIX"
  174. echo ""