INSTALLING 64-BIT AND 32-BIT GCC 9.3.1 EXECUTABLES THAT CAN COMPILE TO 64-BIT AND 32-BIT
MS WINDOWS CODE, RESPECTIVELY (MY FOLDER STRUCTURE).

Apr 21, 2020 
------------
Building MinGW-64 gcc yourself!
-------------------------------
After having an on-line discussion with LHMouse from this thread, I was able to write
my own script to build gcc direcltly from the MinGW git repositories using MSYS2, and
I'm pretty excited about that--no more waiting for somebody to post a distribution.
Here is my build script if you want to try it yourself.  Be warned that on a pretty
fast system (core i9-9900 with SSD's), the build takes about 4 hours.  It also requires
several GB of disk space.  You'll need my imerge.exe program to merge the two system
include folders into one.  And if you want my favorite make program, you need
make.exe and rsxnt.dll.

MSYS-2 repository:  repo.msys2.org/mingw/x86_64/

But you don't have to build your own if you just want to download my build directly.  My
goal is to have a minimalistic, straightforward folder structure that I use to compile
all my C/C++ code.  This distro also includes pthreads, ada, objective C, Fortran 95.

1. Download my gcc 9.3.1 distro.

2. Create your install folder, e.g. d:\mingw931, and extract my package into that folder.

   The package structure is like so:

        d:\mingw931
           +- include
           +- lib
              +- x64
              +- x32
           +- bin
              +- x64
              +- x32
              +- lib

3. Optimizations

   a. One-pass max:  -Ofast -flto -fomit-frame-pointer -momit-leaf-frame-pointer
                     -fgraphite-identity -floop-interchange -floop-block
                     -floop-parallelize-all -ftree-loop-distribution
                     -ftree-parallelize-loops=2 -pthread -m64 -Wall

   b. Profile generate:  -Ofast -flto -fomit-frame-pointer -momit-leaf-frame-pointer
                         -fgraphite-identity -floop-interchange -floop-block -pthread
                         -floop-parallelize-all -ftree-parallelize-loops=4
                         -ftree-loop-distribution -march=native -m64 -Wall
                         -fprofile-generate=d:\gcc_profiles

   c. Profile use:  -Ofast -flto -fomit-frame-pointer -momit-leaf-frame-pointer
                    -fgraphite-identity -floop-interchange -floop-block -pthread
                    -floop-parallelize-all -ftree-parallelize-loops=4
                    -ftree-loop-distribution -march=native -m64 -Wall
                    -fprofile-use=d:\gcc_profiles

4. Script mingw.bat to set environment/path.  Usage:  mingw 64  or   mingw 32

    @echo off
    if not "%1"=="" goto envset
    echo "Usage:  mingw 32|64"
    goto end
    :envset
    set MINGW=c:\mingw931
    set MYINCLUDE=d:\my_include
    set MYLIB=d:\my_lib\mingw%1
    set GCCVER=9.3.1
    rem
    rem Remove all other C compilers from path.  You can remove the -u swithces
    rem if you are not using any other C compilers.  Change the drive letters to
    rem match your system
    rem
    repath -u c:\mingw* -u d:\mingw* -e %MINGW%\bin\x%1
    call _repath.bat
    del _repath.bat
    set c_include_dir=%MYINCLUDE%
    set c_include_path=%MYINCLUDE%;%MINGW%\include\x%1;%MINGW%\include;%MINGW%\include\ddk
    set cplus_include_path=%MYINCLUDE%;%MINGW%\include\x%1\c++;%MINGW%\include\c++;%MINGW%\include\c++\backward;%MINGW%\include\x%1;%MINGW%\include
    set library_path=%MYLIB%;%MINGW%\lib\x%1
    set libdir=
    set exedir=c:\bin%1
    set cc=gcc
    set cpp=g++
    set f77=gcc
    set cflags=-Ofast -m%1 -Wall
    gcc -v
    :end