build 7.5 KB

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