build 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. builddir=/var/tmp/build
  4. distdir=/var/tmp/dist/mingw-w64-clang
  5. mkdir -p $distdir
  6. cd /var/tmp/dist
  7. tar -xf $rootdir/[% c('input_files_by_name/clang') %]
  8. mv clang/* mingw-w64-clang/
  9. tar -xf $rootdir/[% c('input_files_by_name/cmake') %]
  10. mkdir -p $builddir
  11. cd $builddir
  12. tar -xf $rootdir/mingw-w64-clang-[% c('version') %].tar.gz
  13. mv mingw-w64-clang-[% c('version') %] mingw-w64-clang
  14. tar -xf $rootdir/[% c('input_files_by_name/libcxx') %]
  15. mv libcxx-* libcxx
  16. tar -xf $rootdir/[% c('input_files_by_name/libcxxabi') %]
  17. mv libcxxabi-* libcxxabi
  18. tar -xf $rootdir/[% c('input_files_by_name/libunwind') %]
  19. mv libunwind-* libunwind
  20. tar -xf $rootdir/[% c('input_files_by_name/compiler-rt') %]
  21. mv compiler-rt-* compiler-rt
  22. tar -xf $rootdir/[% c('input_files_by_name/llvm-mingw') %]
  23. # Adding the wrappers and symlinks we need
  24. cd $distdir/bin
  25. exception_flags=""
  26. [% IF c("var/windows-i686") %]
  27. exception_flags="-fsjlj-exceptions"
  28. [% END -%]
  29. compiler_flags="--sysroot \$DIR/../[% c("arch") %]-w64-mingw32 -rtlib=compiler-rt -stdlib=libc++ -fuse-ld=lld $exception_flags -fuse-cxa-atexit -Qunused-arguments"
  30. cat <<EOF >[% c("arch") %]-w64-mingw32-clang
  31. #!/bin/sh
  32. DIR="\$(cd "\$(dirname "\$0")" && pwd)"
  33. \$DIR/clang -target [% c("arch") %]-w64-mingw32 $compiler_flags "\$@"
  34. EOF
  35. chmod +x [% c("arch") %]-w64-mingw32-clang
  36. cat <<EOF >[% c("arch") %]-w64-mingw32-clang++
  37. #!/bin/sh
  38. DIR="\$(cd "\$(dirname "\$0")" && pwd)"
  39. \$DIR/clang -target [% c("arch") %]-w64-mingw32 --driver-mode=g++ $compiler_flags "\$@"
  40. EOF
  41. chmod +x [% c("arch") %]-w64-mingw32-clang++
  42. ln -s llvm-nm [% c("arch") %]-w64-mingw32-nm
  43. ln -s llvm-strip [% c("arch") %]-w64-mingw32-strip
  44. ln -s llvm-readobj [% c("arch") %]-w64-mingw32-readobj
  45. ln -s llvm-objcopy [% c("arch") %]-w64-mingw32-objcopy
  46. ./clang $builddir/llvm-mingw/wrappers/windres-wrapper.c -O2 -Wl,-s -o [% c("arch") %]-w64-mingw32-windres
  47. # Building mingw-w64
  48. export PATH="$distdir/bin:/var/tmp/dist/cmake/bin:$PATH"
  49. CC="[% c("arch") %]-w64-mingw32-clang"
  50. CXX="[% c("arch") %]-w64-mingw32-clang++"
  51. # This is the default value of _WIN32_WINNT. Gecko configure script explicitly
  52. # sets this, so this is not used to build Gecko itself. We default to 0x601,
  53. # which is Windows 7.
  54. default_win32_winnt=0x601
  55. [% IF c("var/windows-i686") %]
  56. crt_flags="--enable-lib32 --disable-lib64"
  57. compiler_rt_machine="i386"
  58. [% ELSE -%]
  59. crt_flags="--disable-lib32 --enable-lib64"
  60. compiler_rt_machine="x86_64"
  61. [% END -%]
  62. cd $builddir/mingw-w64-clang
  63. patch -p1 < $rootdir/mingw-winrt.patch
  64. cd mingw-w64-headers
  65. mkdir build && cd build
  66. ../configure --host=[% c("arch") %]-w64-mingw32 \
  67. --enable-sdk=all \
  68. --enable-idl \
  69. --with-default-msvcrt=ucrt \
  70. --with-default-win32-winnt=$default_win32_winnt \
  71. --prefix=$distdir/[% c("arch") %]-w64-mingw32
  72. make -j[% c("buildconf/num_procs") %] install
  73. cd $builddir/mingw-w64-clang/mingw-w64-crt
  74. mkdir build && cd build
  75. ../configure --host=[% c("arch") %]-w64-mingw32 \
  76. $crt_flags \
  77. --with-default-msvcrt=ucrt \
  78. CC="$CC" \
  79. AR=llvm-ar \
  80. RANLIB=llvm-ranlib \
  81. DLLTOOL=llvm-dlltool \
  82. --prefix=$distdir/[% c("arch") %]-w64-mingw32
  83. make -j[% c("buildconf/num_procs") %]
  84. make -j[% c("buildconf/num_procs") %] install
  85. cd $builddir/mingw-w64-clang/mingw-w64-tools/widl
  86. mkdir build && cd build
  87. ../configure --target=[% c("arch") %]-w64-mingw32 --prefix=$distdir
  88. make -j[% c("buildconf/num_procs") %]
  89. make -j[% c("buildconf/num_procs") %] install
  90. # compiler-rt
  91. cd $builddir/compiler-rt
  92. mkdir build && cd build
  93. CLANG_VERSION=$(basename $(dirname $(dirname $(dirname $($CC --print-libgcc-file-name -rtlib=compiler-rt)))))
  94. cmake -DCMAKE_BUILD_TYPE=Release \
  95. -DCMAKE_C_COMPILER=$CC \
  96. -DCMAKE_SYSTEM_NAME=Windows \
  97. -DCMAKE_AR=$distdir/bin/llvm-ar \
  98. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  99. -DCMAKE_C_COMPILER_WORKS=1 \
  100. -DCMAKE_C_COMPILER_TARGET=$compiler_rt_machine-windows-gnu \
  101. -DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE \
  102. $builddir/compiler-rt/lib/builtins
  103. make -j[% c("buildconf/num_procs") %]
  104. mkdir -p $distdir/lib/clang/$CLANG_VERSION/lib/windows
  105. cp lib/windows/libclang_rt.builtins-$compiler_rt_machine.a $distdir/lib/clang/$CLANG_VERSION/lib/windows/
  106. # libunwind
  107. cd $builddir/libunwind
  108. mkdir build && cd build
  109. cmake -DCMAKE_BUILD_TYPE=Release \
  110. -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
  111. -DCMAKE_C_COMPILER=$CC \
  112. -DCMAKE_CXX_COMPILER=$CXX \
  113. -DCMAKE_CROSSCOMPILING=TRUE \
  114. -DCMAKE_SYSROOT=$distdir/[% c("arch") %]-w64-mingw32 \
  115. -DCMAKE_SYSTEM_NAME=Windows \
  116. -DCMAKE_C_COMPILER_WORKS=TRUE \
  117. -DCMAKE_CXX_COMPILER_WORKS=TRUE \
  118. -DLLVM_COMPILER_CHECKED=True \
  119. -DCMAKE_AR=$distdir/bin/llvm-ar \
  120. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  121. -DLLVM_NO_OLD_LIBSTDCXX=TRUE \
  122. -DCXX_SUPPORTS_CXX11=TRUE \
  123. -DCXX_SUPPORTS_CXX_STD=True \
  124. -DLIBUNWIND_USE_COMPILER_RT=TRUE \
  125. -DLIBUNWIND_ENABLE_THREADS=TRUE \
  126. -DLIBUNWIND_ENABLE_SHARED=FALSE \
  127. -DLIBUNWIND_ENABLE_CROSS_UNWINDING=FALSE \
  128. -DCMAKE_CXX_FLAGS="-Wno-dll-attribute-on-redeclaration -nostdinc++ -I$builddir/libcxx/include -DPSAPI_VERSION=2" \
  129. -DCMAKE_C_FLAGS="-Wno-dll-attribute-on-redeclaration" \
  130. $builddir/libunwind
  131. make -j[% c("buildconf/num_procs") %]
  132. make -j[% c("buildconf/num_procs") %] install
  133. # libcxxabi
  134. cd $builddir/libcxxabi
  135. mkdir build && cd build
  136. cmake -DCMAKE_BUILD_TYPE=Release \
  137. -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
  138. -DCMAKE_C_COMPILER=$CC \
  139. -DCMAKE_CXX_COMPILER=$CXX \
  140. -DCMAKE_CROSSCOMPILING=TRUE \
  141. -DCMAKE_SYSTEM_NAME=Windows \
  142. -DCMAKE_C_COMPILER_WORKS=TRUE \
  143. -DCMAKE_CXX_COMPILER_WORKS=TRUE \
  144. -DCMAKE_SYSROOT=$distdir/[% c("arch") %]-w64-mingw32 \
  145. -DLLVM_COMPILER_CHECKED=True \
  146. -DCMAKE_AR=$distdir/bin/llvm-ar \
  147. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  148. -DLIBCXXABI_USE_COMPILER_RT=ON \
  149. -DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
  150. -DLIBCXXABI_ENABLE_THREADS=ON \
  151. -DLIBCXXABI_TARGET_TRIPLE=[% c("arch") %]-w64-mingw32 \
  152. -DLIBCXXABI_ENABLE_SHARED=OFF \
  153. -DLIBCXXABI_LIBCXX_INCLUDES=$builddir/libcxx/include \
  154. -DLLVM_NO_OLD_LIBSTDCXX=TRUE \
  155. -DCXX_SUPPORTS_CXX11=TRUE \
  156. -DCXX_SUPPORTS_CXX_STD=True \
  157. -DCMAKE_CXX_FLAGS="-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HAS_THREAD_API_WIN32" \
  158. $builddir/libcxxabi
  159. make -j[% c("buildconf/num_procs") %] VERBOSE=1
  160. # libcxx
  161. cd $builddir/libcxx
  162. patch -p1 < $rootdir/sort.patch
  163. mkdir build && cd build
  164. cmake -DCMAKE_BUILD_TYPE=Release \
  165. -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
  166. -DCMAKE_C_COMPILER=$CC \
  167. -DCMAKE_CXX_COMPILER=$CXX \
  168. -DCMAKE_CROSSCOMPILING=TRUE \
  169. -DCMAKE_SYSTEM_NAME=Windows \
  170. -DCMAKE_C_COMPILER_WORKS=TRUE \
  171. -DCMAKE_CXX_COMPILER_WORKS=TRUE \
  172. -DLLVM_COMPILER_CHECKED=True \
  173. -DCMAKE_AR=$distdir/bin/llvm-ar \
  174. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  175. -DLIBCXX_USE_COMPILER_RT=ON \
  176. -DLIBCXX_INSTALL_HEADERS=ON \
  177. -DLIBCXX_ENABLE_EXCEPTIONS=ON \
  178. -DLIBCXX_ENABLE_THREADS=ON \
  179. -DLIBCXX_HAS_WIN32_THREAD_API=ON \
  180. -DLIBCXX_ENABLE_MONOTONIC_CLOCK=ON \
  181. -DLIBCXX_ENABLE_SHARED=OFF \
  182. -DLIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG=TRUE \
  183. -DLIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB=TRUE \
  184. -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
  185. -DLIBCXX_ENABLE_FILESYSTEM=OFF \
  186. -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
  187. -DLIBCXX_CXX_ABI=libcxxabi \
  188. -DLIBCXX_CXX_ABI_INCLUDE_PATHS=$builddir/libcxxabi/include \
  189. -DLIBCXX_CXX_ABI_LIBRARY_PATH=$builddir/libcxxabi/build/lib \
  190. -DCMAKE_CXX_FLAGS="-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" \
  191. $builddir/libcxx
  192. make -j[% c("buildconf/num_procs") %] VERBOSE=1
  193. make -j[% c("buildconf/num_procs") %] install
  194. # libc++.a depends on libunwind.a. While the linker will automatically link to
  195. # libc++.a in C++ mode, it won't pick libunwind.a, requiring the caller to
  196. # explicitly pass -lunwind. To work around that, we merge libunwind.a into
  197. # libc++.a.
  198. merge_libs() {
  199. cat <<EOF |llvm-ar -M
  200. CREATE tmp.a
  201. ADDLIB $1
  202. ADDLIB $2
  203. SAVE
  204. END
  205. EOF
  206. llvm-ranlib tmp.a
  207. mv tmp.a $1
  208. }
  209. merge_libs $distdir/[% c("arch") %]-w64-mingw32/lib/libc++.a $distdir/[% c("arch") %]-w64-mingw32/lib/libunwind.a
  210. # Packaging up everything
  211. cd $distdir
  212. cd ..
  213. [% c('tar', {
  214. tar_src => [ project ],
  215. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  216. }) %]