build 8.3 KB

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