build 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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-secure-api \
  69. --enable-idl \
  70. --with-default-msvcrt=ucrt \
  71. --with-default-win32-winnt=$default_win32_winnt \
  72. --prefix=$distdir/[% c("arch") %]-w64-mingw32
  73. make -j[% c("buildconf/num_procs") %] install
  74. cd $builddir/mingw-w64-clang/mingw-w64-crt
  75. mkdir build && cd build
  76. ../configure --host=[% c("arch") %]-w64-mingw32 \
  77. $crt_flags \
  78. --with-default-msvcrt=ucrt \
  79. CC="$CC" \
  80. AR=llvm-ar \
  81. RANLIB=llvm-ranlib \
  82. DLLTOOL=llvm-dlltool \
  83. --prefix=$distdir/[% c("arch") %]-w64-mingw32
  84. make -j[% c("buildconf/num_procs") %]
  85. make -j[% c("buildconf/num_procs") %] install
  86. cd $builddir/mingw-w64-clang/mingw-w64-tools/widl
  87. mkdir build && cd build
  88. ../configure --target=[% c("arch") %]-w64-mingw32 --prefix=$distdir
  89. make -j[% c("buildconf/num_procs") %]
  90. make -j[% c("buildconf/num_procs") %] install
  91. # compiler-rt
  92. cd $builddir/compiler-rt
  93. mkdir build && cd build
  94. CLANG_VERSION=$(basename $(dirname $(dirname $(dirname $($CC --print-libgcc-file-name -rtlib=compiler-rt)))))
  95. cmake -DCMAKE_BUILD_TYPE=Release \
  96. -DCMAKE_C_COMPILER=$CC \
  97. -DCMAKE_SYSTEM_NAME=Windows \
  98. -DCMAKE_AR=$distdir/bin/llvm-ar \
  99. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  100. -DCMAKE_C_COMPILER_WORKS=1 \
  101. -DCMAKE_C_COMPILER_TARGET=$compiler_rt_machine-windows-gnu \
  102. -DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE \
  103. $builddir/compiler-rt/lib/builtins
  104. make -j[% c("buildconf/num_procs") %]
  105. mkdir -p $distdir/lib/clang/$CLANG_VERSION/lib/windows
  106. cp lib/windows/libclang_rt.builtins-$compiler_rt_machine.a $distdir/lib/clang/$CLANG_VERSION/lib/windows/
  107. # libunwind
  108. cd $builddir/libunwind
  109. mkdir build && cd build
  110. cmake -DCMAKE_BUILD_TYPE=Release \
  111. -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
  112. -DCMAKE_C_COMPILER=$CC \
  113. -DCMAKE_CXX_COMPILER=$CXX \
  114. -DCMAKE_CROSSCOMPILING=TRUE \
  115. -DCMAKE_SYSROOT=$distdir/[% c("arch") %]-w64-mingw32 \
  116. -DCMAKE_SYSTEM_NAME=Windows \
  117. -DCMAKE_C_COMPILER_WORKS=TRUE \
  118. -DCMAKE_CXX_COMPILER_WORKS=TRUE \
  119. -DLLVM_COMPILER_CHECKED=True \
  120. -DCMAKE_AR=$distdir/bin/llvm-ar \
  121. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  122. -DLLVM_NO_OLD_LIBSTDCXX=TRUE \
  123. -DCXX_SUPPORTS_CXX11=TRUE \
  124. -DCXX_SUPPORTS_CXX_STD=True \
  125. -DLIBUNWIND_USE_COMPILER_RT=TRUE \
  126. -DLIBUNWIND_ENABLE_THREADS=TRUE \
  127. -DLIBUNWIND_ENABLE_SHARED=FALSE \
  128. -DLIBUNWIND_ENABLE_CROSS_UNWINDING=FALSE \
  129. -DCMAKE_CXX_FLAGS="-Wno-dll-attribute-on-redeclaration -nostdinc++ -I$builddir/libcxx/include -DPSAPI_VERSION=2" \
  130. -DCMAKE_C_FLAGS="-Wno-dll-attribute-on-redeclaration" \
  131. $builddir/libunwind
  132. make -j[% c("buildconf/num_procs") %]
  133. make -j[% c("buildconf/num_procs") %] install
  134. # libcxxabi
  135. cd $builddir/libcxxabi
  136. mkdir build && cd build
  137. cmake -DCMAKE_BUILD_TYPE=Release \
  138. -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
  139. -DCMAKE_C_COMPILER=$CC \
  140. -DCMAKE_CXX_COMPILER=$CXX \
  141. -DCMAKE_CROSSCOMPILING=TRUE \
  142. -DCMAKE_SYSTEM_NAME=Windows \
  143. -DCMAKE_C_COMPILER_WORKS=TRUE \
  144. -DCMAKE_CXX_COMPILER_WORKS=TRUE \
  145. -DCMAKE_SYSROOT=$distdir/[% c("arch") %]-w64-mingw32 \
  146. -DLLVM_COMPILER_CHECKED=True \
  147. -DCMAKE_AR=$distdir/bin/llvm-ar \
  148. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  149. -DLIBCXXABI_USE_COMPILER_RT=ON \
  150. -DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
  151. -DLIBCXXABI_ENABLE_THREADS=ON \
  152. -DLIBCXXABI_TARGET_TRIPLE=[% c("arch") %]-w64-mingw32 \
  153. -DLIBCXXABI_ENABLE_SHARED=OFF \
  154. -DLIBCXXABI_LIBCXX_INCLUDES=$builddir/libcxx/include \
  155. -DLLVM_NO_OLD_LIBSTDCXX=TRUE \
  156. -DCXX_SUPPORTS_CXX11=TRUE \
  157. -DCXX_SUPPORTS_CXX_STD=True \
  158. -DCMAKE_CXX_FLAGS="-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HAS_THREAD_API_WIN32" \
  159. $builddir/libcxxabi
  160. make -j[% c("buildconf/num_procs") %] VERBOSE=1
  161. # libcxx
  162. cd $builddir/libcxx
  163. patch -p1 < $rootdir/sort.patch
  164. mkdir build && cd build
  165. cmake -DCMAKE_BUILD_TYPE=Release \
  166. -DCMAKE_INSTALL_PREFIX=$distdir/[% c("arch") %]-w64-mingw32 \
  167. -DCMAKE_C_COMPILER=$CC \
  168. -DCMAKE_CXX_COMPILER=$CXX \
  169. -DCMAKE_CROSSCOMPILING=TRUE \
  170. -DCMAKE_SYSTEM_NAME=Windows \
  171. -DCMAKE_C_COMPILER_WORKS=TRUE \
  172. -DCMAKE_CXX_COMPILER_WORKS=TRUE \
  173. -DLLVM_COMPILER_CHECKED=True \
  174. -DCMAKE_AR=$distdir/bin/llvm-ar \
  175. -DCMAKE_RANLIB=$distdir/bin/llvm-ranlib \
  176. -DLIBCXX_USE_COMPILER_RT=ON \
  177. -DLIBCXX_INSTALL_HEADERS=ON \
  178. -DLIBCXX_ENABLE_EXCEPTIONS=ON \
  179. -DLIBCXX_ENABLE_THREADS=ON \
  180. -DLIBCXX_HAS_WIN32_THREAD_API=ON \
  181. -DLIBCXX_ENABLE_MONOTONIC_CLOCK=ON \
  182. -DLIBCXX_ENABLE_SHARED=OFF \
  183. -DLIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG=TRUE \
  184. -DLIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB=TRUE \
  185. -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
  186. -DLIBCXX_ENABLE_FILESYSTEM=OFF \
  187. -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
  188. -DLIBCXX_CXX_ABI=libcxxabi \
  189. -DLIBCXX_CXX_ABI_INCLUDE_PATHS=$builddir/libcxxabi/include \
  190. -DLIBCXX_CXX_ABI_LIBRARY_PATH=$builddir/libcxxabi/build/lib \
  191. -DCMAKE_CXX_FLAGS="-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" \
  192. $builddir/libcxx
  193. make -j[% c("buildconf/num_procs") %] VERBOSE=1
  194. make -j[% c("buildconf/num_procs") %] install
  195. # libc++.a depends on libunwind.a. While the linker will automatically link to
  196. # libc++.a in C++ mode, it won't pick libunwind.a, requiring the caller to
  197. # explicitly pass -lunwind. To work around that, we merge libunwind.a into
  198. # libc++.a.
  199. merge_libs() {
  200. cat <<EOF |llvm-ar -M
  201. CREATE tmp.a
  202. ADDLIB $1
  203. ADDLIB $2
  204. SAVE
  205. END
  206. EOF
  207. llvm-ranlib tmp.a
  208. mv tmp.a $1
  209. }
  210. merge_libs $distdir/[% c("arch") %]-w64-mingw32/lib/libc++.a $distdir/[% c("arch") %]-w64-mingw32/lib/libunwind.a
  211. # Packaging up everything
  212. cd $distdir
  213. cd ..
  214. [% c('tar', {
  215. tar_src => [ project ],
  216. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  217. }) %]