build 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. [% IF c("var/linux-cross") -%]
  4. [% pc(c('var/compiler'), 'var/setup', {
  5. compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')),
  6. hardened_gcc => 0
  7. }) %]
  8. [% pc('gcc', 'var/setup', {
  9. compiler_tarfile => c('input_files_by_name/' _ 'gcc-host'),
  10. target => [ c('var/channel'), 'torbrowser-linux-x86_64' ],
  11. hardened_gcc => 0
  12. }) %]
  13. [% ELSE -%]
  14. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  15. [% END -%]
  16. distdir=/var/tmp/dist/[% project %]
  17. mkdir -p /var/tmp/build
  18. [% IF c("var/android") %]
  19. TORCONFIGDIR="$distdir/assets/common"
  20. libsdir=$distdir/jniLibs/[% c("var/abi") %]
  21. mkdir -p $libsdir $TORCONFIGDIR "$distdir/Tor"
  22. [% END %]
  23. [% IF c("var/linux") || c("var/windows") %]
  24. TORCONFIGDIR="$distdir/Data/Tor"
  25. mkdir -p $TORCONFIGDIR
  26. mkdir -p "$distdir/Tor"
  27. [% END %]
  28. [% IF c("var/osx") %]
  29. [% IF c("var/nightly") %]
  30. # We are compiling Tor with Rust enabled for nightlies.
  31. export TOR_RUST_TARGET=x86_64-apple-darwin
  32. [% END %]
  33. TORBINDIR="$distdir/Contents/MacOS/Tor"
  34. TORCONFIGDIR="$distdir/Contents/Resources/TorBrowser/Tor"
  35. mkdir -p $distdir/bin
  36. mkdir -p $TORBINDIR
  37. mkdir -p $TORCONFIGDIR
  38. [% END %]
  39. [% IF c("var/windows") || c("var/android") %]
  40. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zlib') %]
  41. zlibdir=/var/tmp/dist/zlib
  42. [% END %]
  43. [% IF c("var/android") %]
  44. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zstd') %]
  45. [% END %]
  46. [% IF !c("var/android") && c("var/nightly") %]
  47. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  48. export PATH=/var/tmp/dist/rust/bin:$PATH
  49. [% END %]
  50. tar -C /var/tmp/dist -xf [% c('input_files_by_name/openssl') %]
  51. tar -C /var/tmp/dist -xf [% c('input_files_by_name/libevent') %]
  52. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  53. libeventdir=/var/tmp/dist/libevent
  54. openssldir=/var/tmp/dist/openssl/openssl
  55. [% IF 0 && c("var/linux-cross") -%]
  56. # Work around missing libraries. Maybe there's a better way?
  57. crossdepsdir=/var/tmp/dist/cross-deps-chroot
  58. mkdir -p $crossdepsdir
  59. pushd $crossdepsdir
  60. apt-get --option "APT::Architecture=[% c("var/arch_debian") %]" download $(apt-rdepends zlib1g-dev:[% c("var/arch_debian") %]|grep -v "^ "|grep -v "libc-dev")
  61. for PACKAGE in ./*.deb; do
  62. dpkg -x $PACKAGE ./
  63. done
  64. popd
  65. cp --archive --no-clobber $crossdepsdir/usr/include/* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/include/
  66. cp --archive --no-clobber $crossdepsdir/usr/lib/[% c("var/crosstarget") %]/lib*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  67. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libz*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  68. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libz.so.1 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libz.so
  69. [% END -%]
  70. [% IF c("var/linux-arm") -%]
  71. [% IF c("var/nightly") %]
  72. # We are compiling Tor with Rust enabled for nightlies.
  73. export TOR_RUST_TARGET=armv7-unknown-linux-gnueabihf
  74. [% END %]
  75. [% END -%]
  76. [% IF c("var/linux-ppc64le") -%]
  77. [% IF c("var/nightly") %]
  78. # We are compiling Tor with Rust enabled for nightlies.
  79. export TOR_RUST_TARGET=powerpc64le-unknown-linux-gnu
  80. [% END %]
  81. [% END -%]
  82. [% IF c("var/windows") %]
  83. [% IF c("var/nightly") %]
  84. # We are compiling Tor with Rust enabled for nightlies.
  85. export TOR_RUST_TARGET=[% c("arch") %]-pc-windows-gnu
  86. [% END %]
  87. # XXX: It's a bit unfortunate but we need the pthread dll here as libevent
  88. # gets compiled with pthread support once it is enabled in GCC, which we need
  89. # to do as otherwise the Rust compilaton breaks.
  90. mingwlibs=/var/tmp/dist/mingw-w64/[% c("arch") %]-w64-mingw32/bin/
  91. cp $zlibdir/lib/*.dll $openssldir/bin/*.dll $libeventdir/bin/*.dll \
  92. $gcclibs/*.dll $mingwlibs/libwinpthread-1.dll $distdir/Tor/
  93. [% END %]
  94. [% IF c("var/linux-i686") && c("var/nightly") -%]
  95. export TOR_RUST_TARGET=i686-unknown-linux-gnu
  96. [% END -%]
  97. [% IF c("var/linux") %]
  98. mkdir -p "$distdir/Debug/Tor"
  99. cp $openssldir/lib/libssl.so.1.1 "$distdir/Tor/"
  100. cp $openssldir/lib/libcrypto.so.1.1 "$distdir/Tor/"
  101. cp $libeventdir/lib/libevent-2.1.so.7 "$distdir/Tor/"
  102. # We need to copy the libstdc++.so.6 for Tor Browser on older Linux distros.
  103. # Copying it into /Browser, which feels more natural, and amending
  104. # LD_LIBRARY_PATH breaks updates from a Tor Browser with the old
  105. # LD_LIBRARY_PATH value to the Tor Browser with the newer one. Thus, we copy
  106. # the libstdc++ into the directory with the libs tor depends on, too. See bug
  107. # 13359 for further details.
  108. mkdir -p "$distdir/Tor/libstdc++"
  109. cp [% c("var/libpath") %]/libstdc++.so.6 "$distdir/Tor/libstdc++/"
  110. [% IF c("var/asan") -%]
  111. cp [% c("var/libpath") %]/libasan.so.5 "$distdir/Tor/"
  112. cp [% c("var/libpath") %]/libubsan.so.1 "$distdir/Tor/"
  113. [% END -%]
  114. [% IF c("var/linux-cross") %]
  115. cp -a [% c("var/libpath") %]/libssp.so* "$distdir/Tor/"
  116. [% END %]
  117. chmod 700 "$distdir"/Tor/*.so*
  118. chmod 700 "$distdir"/Tor/libstdc++/*.so*
  119. # This is needed to make RPATH unavailable. See bug 9150.
  120. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$distdir/Tor/"
  121. [% IF c("var/linux-cross") -%]
  122. # Add libstdc++ to LD_LIBRARY_PATH to avoid rust link issue (bug 27101)
  123. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/var/tmp/dist/gcc/lib64/"
  124. [% END -%]
  125. [% END %]
  126. [% IF c("var/osx") %]
  127. cp $libeventdir/lib/libevent-*.dylib $TORBINDIR/
  128. # The target version needs to be set before the configure step.
  129. export MACOSX_DEPLOYMENT_TARGET=[% c("var/macosx_deployment_target") %]
  130. [% END %]
  131. cd /var/tmp/build/[% project %]-[% c('version') %]
  132. # add git hash to micro-revision.i for #24995
  133. echo '"[% c("abbrev", { abbrev_length => 16 }) %]"' > micro-revision.i
  134. ./autogen.sh
  135. find -type f -print0 | xargs -0 [% c("var/touch") %]
  136. [% IF !c("var/android") && c("var/nightly") %]TOR_RUST_DEPENDENCIES=`pwd`/src/ext/rust/crates[% END %] ./configure --disable-asciidoc --with-libevent-dir="$libeventdir" --with-openssl-dir="$openssldir" \
  137. [% IF c("var/asan") %]--enable-fragile-hardening[% END %] \
  138. [% IF c("var/windows") || c("var/android") %]--with-zlib-dir="$zlibdir"[% END %] \
  139. [% IF c("var/osx") %]--enable-static-openssl[% END %] \
  140. [% IF !c("var/android") && c("var/nightly") %]--enable-rust[% END %] \
  141. --prefix="$distdir" [% c("var/configure_opt") %]
  142. [% IF c("var/osx") -%]
  143. export LD_PRELOAD=[% c("var/faketime_path") %]
  144. export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
  145. [% END -%]
  146. make -j[% c("buildconf/num_procs") %]
  147. make install
  148. [% IF c("var/osx") -%]
  149. unset LD_PRELOAD
  150. [% END -%]
  151. cp $distdir/share/tor/geoip $TORCONFIGDIR
  152. cp $distdir/share/tor/geoip6 $TORCONFIGDIR
  153. [% IF c("var/osx") %]
  154. LIBEVENT_FILE=`basename $libeventdir/lib/libevent-*.dylib`
  155. cd $distdir
  156. cp bin/tor $TORBINDIR/
  157. cd $TORBINDIR/
  158. x86_64-apple-darwin11-install_name_tool -change $libeventdir/lib/$LIBEVENT_FILE @executable_path/$LIBEVENT_FILE tor
  159. [% END %]
  160. cd $distdir
  161. [% IF c("var/windows") %]
  162. install -s $distdir/bin/tor.exe $distdir/Tor/
  163. [% IF c("var/expert_bundle") %]
  164. install -s $distdir/bin/tor-gencert.exe $distdir/Tor/
  165. [% END %]
  166. [% END %]
  167. [% IF c("var/linux") %]
  168. [% IF c("var/linux-cross") -%]
  169. TARGET_OBJCOPY=/var/tmp/dist/gcc-cross/bin/[% c("var/crosstarget") %]-objcopy
  170. TARGET_STRIP=/var/tmp/dist/gcc-cross/bin/[% c("var/crosstarget") %]-strip
  171. [% ELSE -%]
  172. TARGET_OBJCOPY=objcopy
  173. TARGET_STRIP=strip
  174. [% END -%]
  175. # Strip and generate debuginfo for libs
  176. $TARGET_OBJCOPY --only-keep-debug $distdir/bin/tor $distdir/Debug/Tor/tor
  177. install -s --strip-program="$TARGET_STRIP" $distdir/bin/tor $distdir/Tor/
  178. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/Tor/tor $distdir/Tor/tor
  179. for i in $distdir/Tor/*so*
  180. do
  181. LIB=`basename $i`
  182. $TARGET_OBJCOPY --only-keep-debug $distdir/Tor/$LIB $distdir/Debug/Tor/$LIB
  183. $TARGET_STRIP $distdir/Tor/$LIB
  184. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/Tor/$LIB $distdir/Tor/$LIB
  185. done
  186. [% END %]
  187. [% IF c("var/android") %]
  188. install -s --strip-program=[% c("var/configure_host") %]-strip $distdir/bin/tor $libsdir/libTor.so
  189. [% END %]
  190. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  191. [%
  192. IF c("var/expert_bundle");
  193. SET win_arch = c('var/windows-x86_64') ? 'win64' : 'win32';
  194. c('zip', {
  195. zip_src => [ 'Data', 'Tor', ],
  196. zip_args => dest_dir _ '/' _ c('filename') _ '/tor-' _ win_arch _ '-' _ c("version") _ '.zip',
  197. });
  198. ELSE;
  199. IF c("var/osx");
  200. SET tarsrcdir = [ 'Contents' ];
  201. ELSIF c("var/android");
  202. SET tarsrcdir = [ 'assets', 'jniLibs' ];
  203. ELSE;
  204. SET tarsrcdir = [ 'Data', 'Tor', ];
  205. END;
  206. c('tar', {
  207. tar_src => tarsrcdir,
  208. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor.tar.gz',
  209. });
  210. END;
  211. %]
  212. [% IF c("var/linux") %]
  213. [% c('tar', {
  214. tar_src => [ 'Debug' ],
  215. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-debug.tar.xz',
  216. }) %]
  217. [% END %]