cross.sh 5.2 KB

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