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