build 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. hardened_gcc => 0 }) %]
  5. [% IF c("var/linux-cross") -%]
  6. [% pc('gcc', 'var/setup', {
  7. compiler_tarfile => c('input_files_by_name/' _ 'gcc-host'),
  8. hardened_gcc => 0,
  9. target => [ c('var/channel'), 'torbrowser-linux-x86_64' ]
  10. }) %]
  11. # GCC's cc1 expects Jessie libmpfr; we feed it a symlink to Buster's instead
  12. # as a stupid compat cludge. TODO: Maybe copy in the actual Jessie version
  13. # from the GCC build container?
  14. mkdir -p /var/tmp/dist/libmpfr
  15. ln -s -T /usr/lib/x86_64-linux-gnu/libmpfr.so.6 /var/tmp/dist/libmpfr/libmpfr.so.4
  16. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/var/tmp/dist/libmpfr"
  17. [% END -%]
  18. distdir=/var/tmp/dist/[% project %]
  19. mkdir -p /var/tmp/build
  20. [% IF c("var/android") %]
  21. TORCONFIGDIR="$distdir/assets/common"
  22. libsdir=$distdir/jniLibs/[% c("var/abi") %]
  23. mkdir -p $libsdir $TORCONFIGDIR "$distdir/Tor"
  24. # We need to make sure our ZSTD dependencey is properly picked up.
  25. # --enable-zstd is not enough.
  26. export ZSTD_CFLAGS=-I/var/tmp/dist/zstd/include
  27. export ZSTD_LIBS=/var/tmp/dist/zstd/lib/libzstd.a
  28. [% END %]
  29. [% IF c("var/linux") || c("var/windows") %]
  30. TORCONFIGDIR="$distdir/Data/Tor"
  31. mkdir -p $TORCONFIGDIR
  32. mkdir -p "$distdir/Tor"
  33. [% END %]
  34. [% IF c("var/osx") %]
  35. TORBINDIR="$distdir/Contents/MacOS/Tor"
  36. TORCONFIGDIR="$distdir/Contents/Resources/TorBrowser/Tor"
  37. mkdir -p $distdir/bin
  38. mkdir -p $TORBINDIR
  39. mkdir -p $TORCONFIGDIR
  40. [% END %]
  41. [% IF c("var/windows") || c("var/android") %]
  42. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zlib') %]
  43. zlibdir=/var/tmp/dist/zlib
  44. [% END %]
  45. [% IF c("var/android") %]
  46. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zstd') %]
  47. [% END %]
  48. tar -C /var/tmp/dist -xf [% c('input_files_by_name/openssl') %]
  49. tar -C /var/tmp/dist -xf [% c('input_files_by_name/libevent') %]
  50. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  51. libeventdir=/var/tmp/dist/libevent
  52. openssldir=/var/tmp/dist/openssl/openssl
  53. [% IF c("var/windows") %]
  54. # XXX: It's a bit unfortunate but we need the pthread dll here as libevent
  55. # gets compiled with pthread support once it is enabled in GCC, which we need
  56. # to do as otherwise the Rust compilaton breaks.
  57. mingwlibs=/var/tmp/dist/mingw-w64/[% c("arch") %]-w64-mingw32/bin/
  58. cp $zlibdir/lib/*.dll $openssldir/bin/*.dll $libeventdir/bin/*.dll \
  59. $gcclibs/*.dll $mingwlibs/libwinpthread-1.dll $distdir/Tor/
  60. [% END %]
  61. [% IF c("var/linux") %]
  62. mkdir -p "$distdir/Debug/Tor"
  63. cp $openssldir/lib/libssl.so.1.1 "$distdir/Tor/"
  64. cp $openssldir/lib/libcrypto.so.1.1 "$distdir/Tor/"
  65. cp $libeventdir/lib/libevent-2.1.so.7 "$distdir/Tor/"
  66. # We need to copy the libstdc++.so.6 for Tor Browser on older Linux distros.
  67. # Copying it into /Browser, which feels more natural, and amending
  68. # LD_LIBRARY_PATH breaks updates from a Tor Browser with the old
  69. # LD_LIBRARY_PATH value to the Tor Browser with the newer one. Thus, we copy
  70. # the libstdc++ into the directory with the libs tor depends on, too. See bug
  71. # 13359 for further details.
  72. libstdc_dir="$distdir/Tor/libstdc++"
  73. mkdir -p $libstdc_dir
  74. cp [% c("var/libpath") %]/libstdc++.so.6 $libstdc_dir/
  75. [% IF c("var/asan") -%]
  76. cp [% c("var/libpath") %]/libasan.so.6 "$distdir/Tor/"
  77. cp [% c("var/libpath") %]/libubsan.so.1 "$distdir/Tor/"
  78. [% END -%]
  79. [% IF c("var/linux-cross") %]
  80. cp -a [% c("var/libpath") %]/libssp.so* "$distdir/Tor/"
  81. # Required for libevent
  82. export LDFLAGS="$LDFLAGS -Wl,-rpath-link=[% c('var/libpath') %]"
  83. # Required for zlib
  84. export LDFLAGS="$LDFLAGS -L/usr/lib/[% c('var/crosstarget') %]"
  85. cp -a /usr/include/zconf.h /usr/include/zlib.h /var/tmp/dist/gcc-cross/[% c('var/crosstarget') %]/include
  86. TARGET_OBJCOPY=/var/tmp/dist/gcc-cross/bin/[% c("var/crosstarget") %]-objcopy
  87. TARGET_STRIP=/var/tmp/dist/gcc-cross/bin/[% c("var/crosstarget") %]-strip
  88. [% ELSE %]
  89. TARGET_OBJCOPY=objcopy
  90. TARGET_STRIP=strip
  91. [% END %]
  92. chmod 700 "$distdir"/Tor/*.so*
  93. chmod 700 $libstdc_dir/libstdc++.so.6
  94. $TARGET_STRIP $libstdc_dir/libstdc++.so.6
  95. # This is needed to make RPATH unavailable. See bug 9150.
  96. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$distdir/Tor/"
  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. ./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") || c("var/android") %]--with-zlib-dir="$zlibdir"[% END %] \
  109. [% IF c("var/osx") %]--enable-static-openssl[% END %] \
  110. --prefix="$distdir" [% c("var/configure_opt") %]
  111. [% IF c("var/osx") -%]
  112. export LD_PRELOAD=[% c("var/faketime_path") %]
  113. export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
  114. [% END -%]
  115. make -j[% c("buildconf/num_procs") %]
  116. make install
  117. [% IF c("var/osx") -%]
  118. unset LD_PRELOAD
  119. [% END -%]
  120. cp $distdir/share/tor/geoip $TORCONFIGDIR
  121. cp $distdir/share/tor/geoip6 $TORCONFIGDIR
  122. [% IF c("var/osx") %]
  123. LIBEVENT_FILE=`basename $libeventdir/lib/libevent-*.dylib`
  124. cd $distdir
  125. cp bin/tor $TORBINDIR/
  126. cd $TORBINDIR/
  127. x86_64-apple-darwin-install_name_tool -change $libeventdir/lib/$LIBEVENT_FILE @executable_path/$LIBEVENT_FILE tor
  128. [% END %]
  129. cd $distdir
  130. [% IF c("var/windows") %]
  131. install -s $distdir/bin/tor.exe $distdir/Tor/
  132. [% IF c("var/expert_bundle") %]
  133. install -s $distdir/bin/tor-gencert.exe $distdir/Tor/
  134. [% END %]
  135. [% END %]
  136. [% IF c("var/linux") %]
  137. # Strip and generate debuginfo for libs
  138. $TARGET_OBJCOPY --only-keep-debug $distdir/bin/tor $distdir/Debug/Tor/tor
  139. install -s --strip-program="$TARGET_STRIP" $distdir/bin/tor $distdir/Tor/
  140. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/Tor/tor $distdir/Tor/tor
  141. for i in $distdir/Tor/*so*
  142. do
  143. LIB=`basename $i`
  144. $TARGET_OBJCOPY --only-keep-debug $distdir/Tor/$LIB $distdir/Debug/Tor/$LIB
  145. $TARGET_STRIP $distdir/Tor/$LIB
  146. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/Tor/$LIB $distdir/Tor/$LIB
  147. done
  148. [% END %]
  149. [% IF c("var/android") %]
  150. install -s --strip-program=[% c("var/cross_prefix") %]-strip $distdir/bin/tor $libsdir/libTor.so
  151. [% END %]
  152. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  153. [%
  154. IF c("var/expert_bundle");
  155. SET win_arch = c('var/windows-x86_64') ? 'win64' : 'win32';
  156. c('zip', {
  157. zip_src => [ 'Data', 'Tor', ],
  158. zip_args => dest_dir _ '/' _ c('filename') _ '/tor-' _ win_arch _ '-' _ c("version") _ '.zip',
  159. });
  160. ELSE;
  161. IF c("var/osx");
  162. SET tarsrcdir = [ 'Contents' ];
  163. ELSIF c("var/android");
  164. SET tarsrcdir = [ 'assets', 'jniLibs' ];
  165. ELSE;
  166. SET tarsrcdir = [ 'Data', 'Tor', ];
  167. END;
  168. c('tar', {
  169. tar_src => tarsrcdir,
  170. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor.tar.gz',
  171. });
  172. END;
  173. %]
  174. [% IF c("var/linux") %]
  175. [% c('tar', {
  176. tar_src => [ 'Debug' ],
  177. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-debug.tar.xz',
  178. }) %]
  179. [% END %]