build 7.4 KB

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