build 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 $distdir
  6. mkdir -p /var/tmp/build
  7. [% IF c("var/android") %]
  8. # We need to make sure our ZSTD dependencey is properly picked up.
  9. # --enable-zstd is not enough.
  10. export ZSTD_CFLAGS=-I/var/tmp/dist/zstd/include
  11. export ZSTD_LIBS=/var/tmp/dist/zstd/lib/libzstd.a
  12. [% END %]
  13. TORDATADIR="$distdir/data"
  14. TORBINDIR="$distdir/tor"
  15. mkdir $TORDATADIR
  16. mkdir $TORBINDIR
  17. [% IF c("var/windows") || c("var/android") %]
  18. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zlib') %]
  19. zlibdir=/var/tmp/dist/zlib
  20. [% END %]
  21. [% IF c("var/android") %]
  22. tar -C /var/tmp/dist -xf [% c('input_files_by_name/zstd') %]
  23. [% END %]
  24. tar -C /var/tmp/dist -xf [% c('input_files_by_name/openssl') %]
  25. tar -C /var/tmp/dist -xf [% c('input_files_by_name/libevent') %]
  26. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  27. libeventdir=/var/tmp/dist/libevent
  28. openssldir=/var/tmp/dist/openssl/openssl
  29. [% IF c("var/linux") %]
  30. TORDEBUGDIR="$distdir/debug"
  31. mkdir "$TORDEBUGDIR"
  32. cp $openssldir/lib/libssl.so.1.1 "$TORBINDIR"
  33. cp $openssldir/lib/libcrypto.so.1.1 "$TORBINDIR"
  34. cp $libeventdir/lib/libevent-2.1.so.7 "$TORBINDIR"
  35. # We need to copy the libstdc++.so.6 for Tor Browser on older Linux distros.
  36. # Copying it into /Browser, which feels more natural, and amending
  37. # LD_LIBRARY_PATH breaks updates from a Tor Browser with the old
  38. # LD_LIBRARY_PATH value to the Tor Browser with the newer one. Thus, we copy
  39. # the libstdc++ into the directory with the libs tor depends on, too. See bug
  40. # 13359 for further details.
  41. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libstdc++.so.6 "$TORBINDIR"
  42. [% IF c("var/asan") -%]
  43. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libasan.so.6 "$TORBINDIR"
  44. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libubsan.so.1 "$TORBINDIR"
  45. [% END -%]
  46. chmod 700 "$TORBINDIR"/*.so*
  47. # This is needed to make RPATH unavailable. See bug 9150.
  48. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TORBINDIR"
  49. [% END %]
  50. [% IF c("var/macos") %]
  51. cp $libeventdir/lib/libevent-*.dylib "$TORBINDIR"
  52. [% END %]
  53. [% IF c("var/windows") %]
  54. export CC=[% c("arch") %]-w64-mingw32-cc
  55. [% END %]
  56. cd /var/tmp/build/[% project %]-[% c('version') %]
  57. # add git hash to micro-revision.i for #24995
  58. echo '"[% c("abbrev", { abbrev_length => 16 }) %]"' > micro-revision.i
  59. ./autogen.sh
  60. find -type f -print0 | xargs -0 [% c("touch") %]
  61. ./configure --disable-asciidoc --with-libevent-dir="$libeventdir" --with-openssl-dir="$openssldir" \
  62. [% IF c("var/asan") %]--enable-fragile-hardening[% END %] \
  63. [% IF c("var/windows") || c("var/android") %]--with-zlib-dir="$zlibdir"[% END %] \
  64. [% IF c("var/macos") %]--enable-static-openssl[% END %] \
  65. [% IF c("var/windows") %]--enable-static-libevent --enable-static-openssl --enable-static-zlib[% END %] \
  66. --prefix="$distdir" [% c("var/configure_opt") %]
  67. [% IF c("var/macos") -%]
  68. export LD_PRELOAD=[% c("var/faketime_path") %]
  69. export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
  70. [% END -%]
  71. make -j[% c("num_procs") %]
  72. make install
  73. [% IF c("var/macos") -%]
  74. unset LD_PRELOAD
  75. [% END -%]
  76. cp $distdir/share/tor/geoip "$TORDATADIR"
  77. cp $distdir/share/tor/geoip6 "$TORDATADIR"
  78. [% IF c("var/macos") %]
  79. LIBEVENT_FILE=`basename $libeventdir/lib/libevent-*.dylib`
  80. cd $distdir
  81. cp bin/tor "$TORBINDIR"
  82. cd "$TORBINDIR"
  83. [% c("var/build_target") %]-install_name_tool -change "$libeventdir/lib/$LIBEVENT_FILE" "@executable_path/$LIBEVENT_FILE" tor
  84. [% END %]
  85. cd $distdir
  86. [% IF c("var/windows") %]
  87. install -s $distdir/bin/tor.exe "$TORBINDIR"
  88. install -s $distdir/bin/tor-gencert.exe "$TORBINDIR"
  89. [% END %]
  90. [% IF c("var/linux") %]
  91. # Strip and generate debuginfo for libs
  92. objcopy --only-keep-debug $distdir/bin/tor "$TORDEBUGDIR/tor"
  93. install -s $distdir/bin/tor "$TORBINDIR"
  94. objcopy --add-gnu-debuglink="$TORDEBUGDIR/tor" "$TORBINDIR/tor"
  95. for i in "$TORBINDIR"/*so*
  96. do
  97. LIB=`basename $i`
  98. if [ $LIB == 'libstdc++.so.6' ]; then
  99. # keeping this separate to maintain reproducibility; we can probably
  100. # treat this the same as the rest (though it seems libstdc++ doesn't come with
  101. # any useful debug symbols since we don't build it, so maybe we should figure
  102. # out how to package them
  103. strip "$TORBINDIR/$LIB"
  104. else
  105. objcopy --only-keep-debug "$TORBINDIR/$LIB" "$TORDEBUGDIR/$LIB"
  106. strip "$TORBINDIR/$LIB"
  107. objcopy --add-gnu-debuglink="$TORDEBUGDIR/$LIB" "$TORBINDIR/$LIB"
  108. fi
  109. done
  110. [% END %]
  111. [% IF c("var/android") %]
  112. install -s --strip-program=[% c("var/cross_prefix") %]-strip "$distdir/bin/tor" "$TORBINDIR/libTor.so"
  113. [% END %]
  114. [%
  115. SET tar_src = [ "tor", "data" ];
  116. IF c("var/linux");
  117. tar_src.push("debug");
  118. END;
  119. c('tar', {
  120. tar_src => tar_src,
  121. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  122. });
  123. %]