build 8.5 KB

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