build 8.2 KB

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