cross.sh 4.8 KB

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