build 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.5 "$distdir/Tor/"
  77. cp [% c("var/libpath") %]/libubsan.so.1 "$distdir/Tor/"
  78. [% END -%]
  79. [% IF c("var/linux-cross") %]
  80. cp -a /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libssp.so* "$distdir/Tor/"
  81. # Required for libevent
  82. export LDFLAGS="$LDFLAGS -Wl,-rpath-link=/var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib"
  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. [% IF c("var/linux-cross") -%]
  98. # Add libstdc++ to LD_LIBRARY_PATH to avoid rust link issue (bug 27101)
  99. # TODO: Can this be removed since Rust is no longer used?
  100. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/var/tmp/dist/gcc/lib64/"
  101. [% END -%]
  102. [% END %]
  103. [% IF c("var/osx") %]
  104. cp $libeventdir/lib/libevent-*.dylib $TORBINDIR/
  105. [% END %]
  106. cd /var/tmp/build/[% project %]-[% c('version') %]
  107. # add git hash to micro-revision.i for #24995
  108. echo '"[% c("abbrev", { abbrev_length => 16 }) %]"' > micro-revision.i
  109. ./autogen.sh
  110. find -type f -print0 | xargs -0 [% c("var/touch") %]
  111. ./configure --disable-asciidoc --with-libevent-dir="$libeventdir" --with-openssl-dir="$openssldir" \
  112. [% IF c("var/asan") %]--enable-fragile-hardening[% END %] \
  113. [% IF c("var/windows") || c("var/android") %]--with-zlib-dir="$zlibdir"[% END %] \
  114. [% IF c("var/osx") %]--enable-static-openssl[% END %] \
  115. --prefix="$distdir" [% c("var/configure_opt") %]
  116. [% IF c("var/osx") -%]
  117. export LD_PRELOAD=[% c("var/faketime_path") %]
  118. export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
  119. [% END -%]
  120. make -j[% c("buildconf/num_procs") %]
  121. make install
  122. [% IF c("var/osx") -%]
  123. unset LD_PRELOAD
  124. [% END -%]
  125. cp $distdir/share/tor/geoip $TORCONFIGDIR
  126. cp $distdir/share/tor/geoip6 $TORCONFIGDIR
  127. [% IF c("var/osx") %]
  128. LIBEVENT_FILE=`basename $libeventdir/lib/libevent-*.dylib`
  129. cd $distdir
  130. cp bin/tor $TORBINDIR/
  131. cd $TORBINDIR/
  132. x86_64-apple-darwin-install_name_tool -change $libeventdir/lib/$LIBEVENT_FILE @executable_path/$LIBEVENT_FILE tor
  133. [% END %]
  134. cd $distdir
  135. [% IF c("var/windows") %]
  136. install -s $distdir/bin/tor.exe $distdir/Tor/
  137. [% IF c("var/expert_bundle") %]
  138. install -s $distdir/bin/tor-gencert.exe $distdir/Tor/
  139. [% END %]
  140. [% END %]
  141. [% IF c("var/linux") %]
  142. # Strip and generate debuginfo for libs
  143. $TARGET_OBJCOPY --only-keep-debug $distdir/bin/tor $distdir/Debug/Tor/tor
  144. install -s --strip-program="$TARGET_STRIP" $distdir/bin/tor $distdir/Tor/
  145. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/Tor/tor $distdir/Tor/tor
  146. for i in $distdir/Tor/*so*
  147. do
  148. LIB=`basename $i`
  149. $TARGET_OBJCOPY --only-keep-debug $distdir/Tor/$LIB $distdir/Debug/Tor/$LIB
  150. $TARGET_STRIP $distdir/Tor/$LIB
  151. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/Tor/$LIB $distdir/Tor/$LIB
  152. done
  153. [% END %]
  154. [% IF c("var/android") %]
  155. install -s --strip-program=[% c("var/cross_prefix") %]-strip $distdir/bin/tor $libsdir/libTor.so
  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. ELSIF c("var/android");
  169. SET tarsrcdir = [ 'assets', 'jniLibs' ];
  170. ELSE;
  171. SET tarsrcdir = [ 'Data', 'Tor', ];
  172. END;
  173. c('tar', {
  174. tar_src => tarsrcdir,
  175. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor.tar.gz',
  176. });
  177. END;
  178. %]
  179. [% IF c("var/linux") %]
  180. [% c('tar', {
  181. tar_src => [ 'Debug' ],
  182. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-debug.tar.xz',
  183. }) %]
  184. [% END %]