tiny change i found in my other sandbox
[tor/rransom.git] / contrib / cross.sh
bloba6085a400f0cb99209bc1ef813070039a393c362
1 #!/bin/bash
2 # Copyright 2006 Michael Mohr with modifications by Roger Dingledine
3 # See LICENSE for licensing information.
5 #######################################################################
6 # Tor-cross: a tool to help cross-compile Tor
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.
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.
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.
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.
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.
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.
44 # The target with which this script is tested is little-endian
45 # MIPS Linux, built on an Athlon-based Linux desktop.
47 #######################################################################
49 # disable the platform-specific tests in configure
50 export CROSS_COMPILE=yes
52 # for error conditions
53 EXITVAL=0
55 if [ ! -f autogen.sh ]
56 then
57 echo "Please run this script from the root of the Tor distribution"
58 exit -1
61 if [ ! -f configure ]
62 then
63 if [ -z $GEN_BUILD ]
64 then
65 echo "To automatically generate the build environment, set \$GEN_BUILD"
66 echo "to yes; for example,"
67 echo " export GEN_BUILD=yes"
68 EXITVAL=-1
72 if [ -z $PREFIX ]
73 then
74 echo "You must define \$PREFIX since you are cross-compiling."
75 echo "Select a non-system location (i.e. /tmp/tor-cross):"
76 echo " export PREFIX=/tmp/tor-cross"
77 EXITVAL=-1
80 if [ -z $CROSSPATH ]
81 then
82 echo "You must define the location of your cross-compiler's"
83 echo "directory using \$CROSSPATH; for example,"
84 echo " export CROSSPATH=/opt/cross/staging_dir_mipsel/bin"
85 EXITVAL=-1
88 if [ -z $HOST_TRIPLET ]
89 then
90 echo "You must define \$HOST_TRIPLET to continue. For example,"
91 echo "if you normally cross-compile applications using"
92 echo "mipsel-linux-uclibc-gcc, you would set \$HOST_TRIPLET like so:"
93 echo " export HOST_TRIPLET=mipsel-linux-uclibc-"
94 EXITVAL=-1
97 if [ -z $HOST ]
98 then
99 echo "You must specify a target processor with \$HOST; for example:"
100 echo " export HOST=mipsel-unknown-elf"
101 EXITVAL=-1
104 if [ -z $BUILD ]
105 then
106 echo "You should specify the host machine's type with \$BUILD; for example:"
107 echo " export BUILD=i686-pc-linux-gnu"
108 echo "If you wish to let configure autodetect the host, set \$BUILD to 'auto':"
109 echo " export BUILD=auto"
110 EXITVAL=-1
113 if [ ! -x $CROSSPATH/$HOST_TRIPLETgcc ]
114 then
115 echo "The specified toolchain does not contain an executable C compiler."
116 echo "Please double-check your settings and rerun cross.sh."
117 EXITVAL=-1
120 if [ $EXITVAL -ne 0 ]
121 then
122 echo "Remember, you can hard-code these values in cross.sh if needed."
123 exit $EXITVAL
126 if [ ! -z "$GEN_BUILD" -a ! -f configure ]
127 then
128 export NOCONF=yes
129 ./autogen.sh
132 # clean up any existing object files
133 if [ -f src/or/tor ]
134 then
135 make clean
138 # Set up the build environment and try to run configure
139 export PATH=$PATH:$CROSSPATH
140 export RANLIB=${HOST_TRIPLET}ranlib
141 export CC=${HOST_TRIPLET}gcc
143 if [ $BUILD == "auto" ]
144 then
145 ./configure \
146 --enable-debug \
147 --enable-eventdns \
148 --prefix=$PREFIX \
149 --host=$HOST
150 else
151 ./configure \
152 --enable-debug \
153 --enable-eventdns \
154 --prefix=$PREFIX \
155 --host=$HOST \
156 --build=$BUILD
159 # has a problem occurred?
160 if [ $? -ne 0 ]
161 then
162 echo ""
163 echo "A problem has been detected with configure."
164 echo "Please check the output above and rerun cross.sh"
165 echo ""
166 exit -1
169 # Now we're cookin'
171 make
173 # has a problem occurred?
174 if [ $? -ne 0 ]
175 then
176 echo ""
177 echo "A problem has been detected with make."
178 echo "Please check the output above and rerun make."
179 echo ""
180 exit -1
183 # if $STRIP has length (i.e. STRIP=yes), strip the binaries
184 if [ ! -z $STRIP ]
185 then
186 ${HOST_TRIPLET}strip \
187 src/or/tor \
188 src/test/test \
189 src/tools/tor-resolve
192 echo ""
193 echo "Tor should be compiled at this point. Now run 'make install' to"
194 echo "install to $PREFIX"
195 echo ""