├── .github └── workflows │ └── build-mingw.yml ├── .gitignore ├── README.md └── build.sh /.github/workflows/build-mingw.yml: -------------------------------------------------------------------------------- 1 | 2 | name: build-mingw 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-24.04 12 | strategy: 13 | matrix: 14 | arch: [i686, x86_64] 15 | 16 | outputs: 17 | GCC_VERSION: ${{ steps.build.outputs.GCC_VERSION }} 18 | MINGW_VERSION: ${{ steps.build.outputs.MINGW_VERSION }} 19 | GDB_VERSION: ${{ steps.build.outputs.GDB_VERSION }} 20 | MAKE_VERSION: ${{ steps.build.outputs.MAKE_VERSION }} 21 | 22 | steps: 23 | 24 | - name: checkout 25 | uses: actions/checkout@v4 26 | 27 | - name: install dependencies 28 | run: | 29 | sudo apt-get install --no-install-recommends -y \ 30 | ca-certificates \ 31 | libgmp-dev \ 32 | libmpc-dev \ 33 | libmpfr-dev \ 34 | libisl-dev \ 35 | xz-utils \ 36 | texinfo \ 37 | patch \ 38 | p7zip \ 39 | cmake \ 40 | make \ 41 | curl \ 42 | m4 \ 43 | gcc \ 44 | g++ 45 | 46 | - name: build 47 | id: build 48 | run: ./build.sh ${{ matrix.arch }} 49 | 50 | - name: upload artifacts 51 | uses: actions/upload-artifact@v4 52 | with: 53 | name: gcc-v${{ steps.build.outputs.GCC_VERSION }}-mingw-v${{ steps.build.outputs.MINGW_VERSION }}-${{ matrix.arch }} 54 | path: gcc-v${{ steps.build.outputs.GCC_VERSION }}-mingw-v${{ steps.build.outputs.MINGW_VERSION }}-${{ matrix.arch }}.7z 55 | if-no-files-found: error 56 | compression-level: 0 57 | 58 | release: 59 | runs-on: ubuntu-24.04 60 | needs: build 61 | permissions: 62 | contents: write 63 | env: 64 | GH_TOKEN: ${{ github.token }} 65 | steps: 66 | 67 | - name: release 68 | run: | 69 | echo 'GCC v${{ needs.build.outputs.GCC_VERSION }}' >>notes.txt 70 | echo 'MinGW-w64 v${{ needs.build.outputs.MINGW_VERSION }}' >>notes.txt 71 | echo 'GDB v${{ needs.build.outputs.GDB_VERSION }}' >>notes.txt 72 | echo 'Make v${{ needs.build.outputs.MAKE_VERSION }}' >>notes.txt 73 | gh release create gcc-v${{ needs.build.outputs.GCC_VERSION }}-mingw-v${{ needs.build.outputs.MINGW_VERSION }} -R "${GITHUB_REPOSITORY}" -t 'gcc-v${{ needs.build.outputs.GCC_VERSION }}-mingw-v${{ needs.build.outputs.MINGW_VERSION }}' -F notes.txt 74 | 75 | - name: get artifacts 76 | uses: actions/download-artifact@v4 77 | with: 78 | pattern: gcc-v${{ needs.build.outputs.GCC_VERSION }}-mingw-v${{ needs.build.outputs.MINGW_VERSION }}-* 79 | merge-multiple: true 80 | 81 | - name: upload artifacts 82 | run: gh release upload 'gcc-v${{ needs.build.outputs.GCC_VERSION }}-mingw-v${{ needs.build.outputs.MINGW_VERSION }}' gcc-v${{ needs.build.outputs.GCC_VERSION }}-mingw-v${{ needs.build.outputs.MINGW_VERSION }}-*.7z -R "${GITHUB_REPOSITORY}" 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.7z 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Automatic 32-bit and 64-bit Windows build of [gcc][] compiler, [mingw-w64][] runtime, [gdb][] debugger and [make][]. 2 | 3 | Builds are linked statically to their dependencies and provide only static runtime libraries (libstdc++, libgomp, libwinpthread and others). 4 | 5 | Download binary build as 7z archive from [latest release][] page. 6 | 7 | To build binaries locally run `build.sh`. Make sure you have installed all necessary dependencies. 8 | 9 | To build binaries using Docker, run: 10 | 11 | docker run -ti --rm -v `pwd`:/output -e OUTPUT=/output -w /mnt ubuntu:24.04 12 | apt update 13 | DEBIAN_FRONTEND=noninteractive apt install --no-install-recommends -y \ 14 | ca-certificates libgmp-dev libmpc-dev libmpfr-dev libisl-dev xz-utils texinfo patch bzip2 p7zip cmake make curl m4 gcc g++ 15 | /output/build.sh i686 16 | /output/build.sh x86_64 17 | exit 18 | 19 | [gcc]: https://gcc.gnu.org/ 20 | [mingw-w64]: http://mingw-w64.org/ 21 | [gdb]: https://www.gnu.org/software/gdb/ 22 | [make]: https://www.gnu.org/software/make/ 23 | [latest release]: https://github.com/mmozeiko/build-gcc-mingw/releases/latest 24 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eux 4 | 5 | ZSTD_VERSION=1.5.7 6 | GMP_VERSION=6.3.0 7 | MPFR_VERSION=4.2.2 8 | MPC_VERSION=1.3.1 9 | ISL_VERSION=0.26 10 | EXPAT_VERSION=2.7.1 11 | BINUTILS_VERSION=2.44 12 | GCC_VERSION=15.1.0 13 | MINGW_VERSION=12.0.0 14 | MAKE_VERSION=4.4.1 15 | GDB_VERSION=16.3 16 | 17 | ARCH=${1:-x86_64} 18 | NAME=gcc-v${GCC_VERSION}-mingw-v${MINGW_VERSION}-${ARCH} 19 | TARGET=${ARCH}-w64-mingw32 20 | if [ "${ARCH}" == "i686" ]; then 21 | EXTRA_CRT_ARGS=--disable-lib64 22 | EXTRA_GCC_ARGS="--disable-sjlj-exceptions --with-dwarf2" 23 | elif [ "${ARCH}" == "x86_64" ]; then 24 | EXTRA_CRT_ARGS=--disable-lib32 25 | EXTRA_GCC_ARGS= 26 | else 27 | exit 1 28 | fi 29 | 30 | function get() 31 | { 32 | mkdir -p ${SOURCE} && pushd ${SOURCE} 33 | FILE="${1##*/}" 34 | if [ ! -f "${FILE}" ]; then 35 | curl -fL "$1" -o ${FILE} 36 | case "${1##*.}" in 37 | gz|tgz) 38 | tar --warning=none -xzf ${FILE} 39 | ;; 40 | bz2) 41 | tar --warning=none -xjf ${FILE} 42 | ;; 43 | xz) 44 | tar --warning=none -xJf ${FILE} 45 | ;; 46 | *) 47 | exit 1 48 | ;; 49 | esac 50 | fi 51 | popd 52 | } 53 | 54 | # by default place output in current folder 55 | OUTPUT="${OUTPUT:-`pwd`}" 56 | 57 | # place where source code is downloaded & unpacked 58 | SOURCE=`pwd`/source 59 | 60 | # place where build for specific target is done 61 | BUILD=`pwd`/build/${TARGET} 62 | 63 | # place where bootstrap compiler is built 64 | BOOTSTRAP=`pwd`/bootstrap/${TARGET} 65 | 66 | # place where build dependencies are installed 67 | PREFIX=`pwd`/prefix/${TARGET} 68 | 69 | # final installation folder 70 | FINAL=`pwd`/${NAME} 71 | 72 | get https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/zstd-${ZSTD_VERSION}.tar.gz 73 | get https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.xz 74 | get https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.xz 75 | get https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz 76 | get https://libisl.sourceforge.io/isl-${ISL_VERSION}.tar.xz 77 | get https://github.com/libexpat/libexpat/releases/download/R_${EXPAT_VERSION//./_}/expat-${EXPAT_VERSION}.tar.xz 78 | get https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz 79 | get https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz 80 | get https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v${MINGW_VERSION}.tar.bz2 81 | get https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.xz 82 | get https://ftp.gnu.org/gnu/make/make-${MAKE_VERSION}.tar.gz 83 | 84 | mkdir -p ${BUILD}/x-binutils && pushd ${BUILD}/x-binutils 85 | ${SOURCE}/binutils-${BINUTILS_VERSION}/configure \ 86 | --prefix=${BOOTSTRAP} \ 87 | --with-sysroot=${BOOTSTRAP} \ 88 | --target=${TARGET} \ 89 | --disable-plugins \ 90 | --disable-nls \ 91 | --disable-shared \ 92 | --disable-multilib \ 93 | --disable-werror 94 | make -j`nproc` 95 | make install 96 | popd 97 | 98 | mkdir -p ${BUILD}/x-mingw-w64-headers && pushd ${BUILD}/x-mingw-w64-headers 99 | ${SOURCE}/mingw-w64-v${MINGW_VERSION}/mingw-w64-headers/configure \ 100 | --prefix=${BOOTSTRAP} \ 101 | --host=${TARGET} 102 | make -j`nproc` 103 | make install 104 | ln -sTf ${BOOTSTRAP} ${BOOTSTRAP}/mingw 105 | popd 106 | 107 | mkdir -p ${BUILD}/x-gcc && pushd ${BUILD}/x-gcc 108 | ${SOURCE}/gcc-${GCC_VERSION}/configure \ 109 | --prefix=${BOOTSTRAP} \ 110 | --with-sysroot=${BOOTSTRAP} \ 111 | --target=${TARGET} \ 112 | --enable-static \ 113 | --disable-shared \ 114 | --disable-lto \ 115 | --disable-nls \ 116 | --disable-multilib \ 117 | --disable-werror \ 118 | --disable-libgomp \ 119 | --enable-languages=c,c++ \ 120 | --enable-threads=posix \ 121 | --enable-checking=release \ 122 | --enable-large-address-aware \ 123 | --disable-libstdcxx-pch \ 124 | --disable-libstdcxx-verbose \ 125 | ${EXTRA_GCC_ARGS} 126 | make -j`nproc` all-gcc 127 | make install-gcc 128 | popd 129 | 130 | export PATH=${BOOTSTRAP}/bin:$PATH 131 | 132 | mkdir -p ${BUILD}/x-mingw-w64-crt && pushd ${BUILD}/x-mingw-w64-crt 133 | ${SOURCE}/mingw-w64-v${MINGW_VERSION}/mingw-w64-crt/configure \ 134 | --prefix=${BOOTSTRAP} \ 135 | --with-sysroot=${BOOTSTRAP} \ 136 | --host=${TARGET} \ 137 | --disable-dependency-tracking \ 138 | --enable-warnings=0 \ 139 | ${EXTRA_CRT_ARGS} 140 | make -j`nproc` 141 | make install 142 | popd 143 | 144 | mkdir -p ${BUILD}/x-mingw-w64-winpthreads && pushd ${BUILD}/x-mingw-w64-winpthreads 145 | ${SOURCE}/mingw-w64-v${MINGW_VERSION}/mingw-w64-libraries/winpthreads/configure \ 146 | --prefix=${BOOTSTRAP} \ 147 | --with-sysroot=${BOOTSTRAP} \ 148 | --host=${TARGET} \ 149 | --disable-dependency-tracking \ 150 | --enable-static \ 151 | --disable-shared 152 | make -j`nproc` 153 | make install 154 | popd 155 | 156 | pushd ${BUILD}/x-gcc 157 | make -j`nproc` 158 | make install 159 | popd 160 | 161 | mkdir -p ${BUILD}/zstd && pushd ${BUILD}/zstd 162 | cmake ${SOURCE}/zstd-${ZSTD_VERSION}/build/cmake \ 163 | -DCMAKE_BUILD_TYPE=Release \ 164 | -DCMAKE_SYSTEM_NAME=Windows \ 165 | -DCMAKE_INSTALL_PREFIX=${PREFIX} \ 166 | -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \ 167 | -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ 168 | -DCMAKE_C_COMPILER=${TARGET}-gcc \ 169 | -DCMAKE_CXX_COMPILER=${TARGET}-g++ \ 170 | -DZSTD_BUILD_STATIC=ON \ 171 | -DZSTD_BUILD_SHARED=OFF \ 172 | -DZSTD_BUILD_PROGRAMS=OFF \ 173 | -DZSTD_BUILD_CONTRIB=OFF \ 174 | -DZSTD_BUILD_TESTS=OFF 175 | make -j`nproc` 176 | make install 177 | popd 178 | 179 | mkdir -p ${BUILD}/gmp && pushd ${BUILD}/gmp 180 | ${SOURCE}/gmp-${GMP_VERSION}/configure \ 181 | --prefix=${PREFIX} \ 182 | --host=${TARGET} \ 183 | --disable-shared \ 184 | --enable-static \ 185 | --enable-fat \ 186 | CC=${TARGET}-gcc \ 187 | CFLAGS="-O2 -std=gnu17" 188 | make -j`nproc` 189 | make install 190 | popd 191 | 192 | mkdir -p ${BUILD}/mpfr && pushd ${BUILD}/mpfr 193 | ${SOURCE}/mpfr-${MPFR_VERSION}/configure \ 194 | --prefix=${PREFIX} \ 195 | --host=${TARGET} \ 196 | --disable-shared \ 197 | --enable-static \ 198 | --with-gmp-build=${BUILD}/gmp 199 | make -j`nproc` 200 | make install 201 | popd 202 | 203 | mkdir -p ${BUILD}/mpc && pushd ${BUILD}/mpc 204 | ${SOURCE}/mpc-${MPC_VERSION}/configure \ 205 | --prefix=${PREFIX} \ 206 | --host=${TARGET} \ 207 | --disable-shared \ 208 | --enable-static \ 209 | --with-{gmp,mpfr}=${PREFIX} 210 | make -j`nproc` 211 | make install 212 | popd 213 | 214 | mkdir -p ${BUILD}/isl && pushd ${BUILD}/isl 215 | ${SOURCE}/isl-${ISL_VERSION}/configure \ 216 | --prefix=${PREFIX} \ 217 | --host=${TARGET} \ 218 | --disable-shared \ 219 | --enable-static \ 220 | --with-gmp-prefix=${PREFIX} 221 | make -j`nproc` 222 | make install 223 | popd 224 | 225 | mkdir -p ${BUILD}/expat && pushd ${BUILD}/expat 226 | ${SOURCE}/expat-${EXPAT_VERSION}/configure \ 227 | --prefix=${PREFIX} \ 228 | --host=${TARGET} \ 229 | --disable-shared \ 230 | --enable-static \ 231 | --without-examples \ 232 | --without-tests 233 | make -j`nproc` 234 | make install 235 | popd 236 | 237 | mkdir -p ${BUILD}/binutils && pushd ${BUILD}/binutils 238 | ${SOURCE}/binutils-${BINUTILS_VERSION}/configure \ 239 | --prefix=${FINAL} \ 240 | --with-sysroot=${FINAL} \ 241 | --host=${TARGET} \ 242 | --target=${TARGET} \ 243 | --enable-lto \ 244 | --enable-plugins \ 245 | --enable-64-bit-bfd \ 246 | --disable-nls \ 247 | --disable-multilib \ 248 | --disable-werror \ 249 | --with-{gmp,mpfr,mpc,isl}=${PREFIX} 250 | make -j`nproc` 251 | make install 252 | popd 253 | 254 | mkdir -p ${BUILD}/mingw-w64-headers && pushd ${BUILD}/mingw-w64-headers 255 | ${SOURCE}/mingw-w64-v${MINGW_VERSION}/mingw-w64-headers/configure \ 256 | --prefix=${FINAL}/${TARGET} \ 257 | --host=${TARGET} 258 | make -j`nproc` 259 | make install 260 | ln -sTf ${FINAL}/${TARGET} ${FINAL}/mingw 261 | popd 262 | 263 | mkdir -p ${BUILD}/mingw-w64-crt && pushd ${BUILD}/mingw-w64-crt 264 | ${SOURCE}/mingw-w64-v${MINGW_VERSION}/mingw-w64-crt/configure \ 265 | --prefix=${FINAL}/${TARGET} \ 266 | --with-sysroot=${FINAL}/${TARGET} \ 267 | --host=${TARGET} \ 268 | --disable-dependency-tracking \ 269 | --enable-warnings=0 \ 270 | ${EXTRA_CRT_ARGS} 271 | make -j`nproc` 272 | make install 273 | popd 274 | 275 | mkdir -p ${BUILD}/gcc && pushd ${BUILD}/gcc 276 | ${SOURCE}/gcc-${GCC_VERSION}/configure \ 277 | --prefix=${FINAL} \ 278 | --with-sysroot=${FINAL} \ 279 | --target=${TARGET} \ 280 | --host=${TARGET} \ 281 | --disable-dependency-tracking \ 282 | --disable-nls \ 283 | --disable-multilib \ 284 | --disable-werror \ 285 | --disable-shared \ 286 | --enable-static \ 287 | --enable-lto \ 288 | --enable-languages=c,c++,lto \ 289 | --enable-libgomp \ 290 | --enable-threads=posix \ 291 | --enable-checking=release \ 292 | --enable-mingw-wildcard \ 293 | --enable-large-address-aware \ 294 | --disable-libstdcxx-pch \ 295 | --disable-libstdcxx-verbose \ 296 | --disable-win32-registry \ 297 | --with-tune=intel \ 298 | ${EXTRA_GCC_ARGS} \ 299 | --with-{gmp,mpfr,mpc,isl,zstd}=${PREFIX} 300 | make -j`nproc` 301 | make install 302 | popd 303 | 304 | mkdir -p ${BUILD}/mingw-w64-winpthreads && pushd ${BUILD}/mingw-w64-winpthreads 305 | ${SOURCE}/mingw-w64-v${MINGW_VERSION}/mingw-w64-libraries/winpthreads/configure \ 306 | --prefix=${FINAL}/${TARGET} \ 307 | --with-sysroot=${FINAL}/${TARGET} \ 308 | --host=${TARGET} \ 309 | --disable-dependency-tracking \ 310 | --disable-shared \ 311 | --enable-static 312 | make -j`nproc` 313 | make install 314 | popd 315 | 316 | mkdir -p ${BUILD}/gdb && pushd ${BUILD}/gdb 317 | ${SOURCE}/gdb-${GDB_VERSION}/configure \ 318 | --prefix=${FINAL} \ 319 | --host=${TARGET} \ 320 | --enable-64-bit-bfd \ 321 | --disable-werror \ 322 | --disable-source-highlight \ 323 | --with-static-standard-libraries \ 324 | --with-libexpat-prefix=${PREFIX} \ 325 | --with-{gmp,mpfr,mpc,isl,zstd}=${PREFIX} \ 326 | CFLAGS="-O2 -std=gnu17" \ 327 | CXXFLAGS="-O2 -D_WIN32_WINNT=0x0600" 328 | make -j`nproc` 329 | cp gdb/.libs/gdb.exe gdbserver/gdbserver.exe ${FINAL}/bin/ 330 | popd 331 | 332 | mkdir -p ${BUILD}/make && pushd ${BUILD}/make 333 | ${SOURCE}/make-${MAKE_VERSION}/configure \ 334 | --prefix=${FINAL} \ 335 | --host=${TARGET} \ 336 | --disable-nls \ 337 | --disable-rpath \ 338 | --enable-case-insensitive-file-system \ 339 | CFLAGS="-O2 -std=gnu17" 340 | make -j`nproc` 341 | make install 342 | popd 343 | 344 | rm -rf ${FINAL}/bin/${TARGET}-* 345 | rm -rf ${FINAL}/bin/ld.bfd.exe ${FINAL}/${TARGET}/bin/ld.bfd.exe 346 | rm -rf ${FINAL}/lib/bfd-plugins/libdep.dll.a 347 | rm -rf ${FINAL}/share 348 | 349 | find ${FINAL} -name '*.exe' -print0 | xargs -0 -n 8 -P 2 ${TARGET}-strip --strip-unneeded 350 | find ${FINAL} -name '*.dll' -print0 | xargs -0 -n 8 -P 2 ${TARGET}-strip --strip-unneeded 351 | find ${FINAL} -name '*.o' -print0 | xargs -0 -n 8 -P 2 ${TARGET}-strip --strip-unneeded 352 | find ${FINAL} -name '*.a' -print0 | xargs -0 -n 8 -P `nproc` ${TARGET}-strip --strip-unneeded 353 | 354 | rm ${FINAL}/mingw 355 | 7zr a -mx9 -mqs=on -mmt=on ${OUTPUT}/${NAME}.7z ${FINAL} 356 | 357 | if [[ -v GITHUB_OUTPUT ]]; then 358 | echo "GCC_VERSION=${GCC_VERSION}" >>${GITHUB_OUTPUT} 359 | echo "MINGW_VERSION=${MINGW_VERSION}" >>${GITHUB_OUTPUT} 360 | echo "GDB_VERSION=${GDB_VERSION}" >>${GITHUB_OUTPUT} 361 | echo "MAKE_VERSION=${MAKE_VERSION}" >>${GITHUB_OUTPUT} 362 | fi 363 | --------------------------------------------------------------------------------