Skip to content

Commit bbf72f6

Browse files
authored
Merge pull request #1 from 7dog123/master
Add support for i586 target and optional i686 overlay; update compile script and README for legacy Windows compatibility
2 parents 417fe3a + 964995b commit bbf72f6

File tree

3 files changed

+180
-32
lines changed

3 files changed

+180
-32
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ jobs:
3737
3838
- name: Verify installed binaries
3939
run: |
40+
/opt/win32/bin/i586-w64-mingw32-gcc --version
41+
/opt/win32/bin/i586-w64-mingw32-g++ --version
4042
/opt/win32/bin/i686-w64-mingw32-gcc --version
43+
/opt/win32/bin/i686-w64-mingw32-g++ --version

README.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
# MinGW32 MSVCRT Toolchain
99

10-
`i686-w64-mingw32` cross-compiler toolchain using **MSVCRT** as default runtime. Ideal for compiling binaries compatible with Windows 9x, 2000, XP and other old systems, avoiding UCRT.
10+
cross-compiler toolchain using **MSVCRT** as default runtime.
11+
Default target: `i586-w64-mingw32`. Optional overlay: `i686-w64-mingw32`.
12+
13+
Ideal for compiling binaries compatible with **Windows 95/98/ME, 2000, XP** and other old systems, avoiding UCRT, while allowing **SSE2 and AVX** for modern CPUs when desired.
1114

1215
## 🎯 Objective
1316

@@ -20,6 +23,11 @@ Build a clean and minimalist MinGW32 toolchain with:
2023
- gcc (phase 2 - according to mingw32 to make Toolchains or Canadian Cross, is necessary to make GCC in two phases)
2124
- mingw-w64 tools (gendef, genidl, genpeimg, widl)
2225

26+
Supports:
27+
28+
- **Legacy Windows** (95/98/ME/NT4/2000/XP)
29+
- **Modern CPU features** (SSE2, AVX) for newer systems, selectable per-project.
30+
2331
## ✅ Prerequisites
2432

2533
- Linux with:
@@ -78,16 +86,57 @@ export PATH=$PREFIX/bin:$PATH
7886
edit accordingly your PREFIX configuration
7987
```
8088

81-
Example of compilation:
89+
⚡ Using the Compiler:
90+
91+
## Legacy-safe builds (Win9x/98/ME/NT4) - default, nothing speial:
92+
93+
```bash
94+
i586-w64-mingw32-gcc main.c -o main.exe
95+
```
96+
97+
## Win2000+:
98+
```bash
99+
i586-w64-mingw32-gcc main.c -o main.exe -DWINVER=0x500 -D_WIN32_WINNT=0x500
100+
```
101+
102+
## WinXP+"
103+
```bash
104+
i586-w64-mingw32-gcc main.c -o main.exe -DWINVER=0x501 -D_WIN32_WINNT=0x501
105+
```
106+
107+
## Enable SSE2 (Pentium 4+):
108+
```bash
109+
i586-w64-mingw32-gcc main.c -o main.exe -msse2 -mfpmath=sse
110+
```
111+
(Will **not** run on 9x/NT4-era hardware.)
112+
113+
# Enable AVX (Sandy Bridge+ and OS support):
114+
115+
```bash
116+
i586-w64-mingw32-gcc main.c -o main.exe -mavx
117+
```
118+
AVX needs an OS that saves/restores YMM state. **Windows XP does not**; think Windows 7 SP1+.
119+
120+
# C++ small/static Runtime if desired:
121+
```bash
122+
i586-w64-mingw32-g++ main.cpp -o main.exe -static-libgcc -static-libstd++
123+
```
82124

125+
# i686 overlay builds:
83126
```bash
84-
i686-w64-mingw32-gcc -nostdlib -static-libgcc -lmingw32 hello.c -o hello.exe
127+
i686-w64-mingw32-gcc main.c -o main.exe
128+
```
129+
**Uses `--with-arch=pentiumpro` internally for i686 optimizations**
130+
131+
Example with Legacy flags:
132+
```bash
133+
i586-w64-mingw32-gcc -nostdlib -static-libgcc -lmingw32 hello.c -o hello.exe
85134
```
86135

87136
## 🖼️ Compatibility
88137

89138
- Generate code for Windows 95/98/ME/2k/XP
90-
- Compatible with Windows NT 4.0/2k/XP
139+
- Compatible with Windows NT4/2000/XP
91140
- Don't Work with UCRT (but you have to test it)
92141
- Works with MSVCRT (tested)
93142

@@ -98,3 +147,13 @@ This project only automates compilations of GNU tools under their respective lic
98147
## 📄 Note
99148

100149
This repository is part of a complex project comming soon early
150+
151+
## 🗂️ Feature Matrix
152+
153+
| Target Windows | Compiler Flag | CPU Features | Notes |
154+
|----------------|---------------|--------------|-------|
155+
| Windows 95/98/ME | `i586-w64-mingw32-gcc` | Pentium / MMX | Legacy safe |
156+
| Windows NT4/2000 | `-DWINVER=0x0500 -D_WIN32_WINNT=0x0500` | SSE optional | Modern CPUs can enable SSE2 |
157+
| Windows XP | `-DWINVER=0x0501 -D_WIN32_WINNT=0x0501` | SSE2 default | Works on most XP-era CPUs |
158+
| Windows 7+ | `-DWINVER=0x0601 -D_WIN32_WINNT=0x0601` | SSE2 / AVX optional | Enable AVX with `-mavx` |
159+
| Modern CPUs | `-msse2 -mavx` | SSE2 / AVX | Only for CPUs that support it, may break legacy Windows |

compile-mingw32.sh

Lines changed: 114 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ THREADS="--enable-threads=win32"
1313
TC_ARCH="win32"
1414
BUILD_DIR="/opt/$TC_ARCH"
1515
PREFIX="$BUILD_DIR"
16-
TARGET="i686-w64-mingw32"
16+
TARGET="i586-w64-mingw32" # Pentium baseline (safe for Win95/NT4)
17+
I686_TARGET="i686-w64-mingw32" # i686 overlay for 200/XP+
1718
JOBS="$(nproc)"
1819
SOURCE="src-$TC_ARCH"
1920

21+
###########################################################################
22+
# Default to NT4/Win95 headersl override per-project of you need 2000/XP+ #
23+
###########################################################################
24+
CFLAGS+="-DWINVER=0x0400 -D_WIN32_WINNT=0x0400"
25+
CXXFLAGS+="$CFLAGS"
26+
2027
#########################
2128
# URLs of sources files #
2229
#########################
@@ -129,7 +136,13 @@ HOST=$(~/$SOURCE/gcc-13.1.0/config.guess)
129136
echo "Starting Binutils build..."
130137
cd binutils-${BINUTILS_VER}
131138
mkdir -p build && cd build
132-
../configure --target=$TARGET --host=$HOST --prefix=$PREFIX --with-sysroot=$PREFIX --disable-multilib --disable-nls
139+
../configure \
140+
--target=$TARGET \
141+
--host=$HOST \
142+
--prefix=$PREFIX \
143+
--with-sysroot=$PREFIX \
144+
--disable-multilib \
145+
--disable-nls
133146
make -j$JOBS
134147
make install
135148

@@ -147,12 +160,18 @@ mkdir -p build && cd build
147160
# as per Mingw/GCC documentation for Toolchain #
148161
################################################
149162

150-
../configure --prefix=$PREFIX/$TARGET --host=$TARGET --with-sysroot=$PREFIX --enable-sdk=all --enable-idl --with-default-msvcrt=msvcrt
163+
../configure \
164+
--prefix=$PREFIX/$TARGET \
165+
--host=$TARGET \
166+
--with-sysroot=$PREFIX \
167+
--enable-sdk=all \
168+
--enable-idl \
169+
--with-default-msvcrt=msvcrt
151170
make install
152171

153172
echo "Creating Symlinks"
154-
ln -s $PREFIX/$TARGET $PREFIX/mingw
155-
ln -s $PREFIX/$TARGET/lib $PREFIX/$TARGET/lib64
173+
ln -sf $PREFIX/$TARGET $PREFIX/mingw
174+
ln -sf $PREFIX/$TARGET/lib $PREFIX/$TARGET/lib64
156175
echo ""
157176
echo "Now mingw and lib64 is symlinked"
158177
echo "to correct paths accepted by GCC"
@@ -176,15 +195,28 @@ cd ~/$SOURCE/gcc-${GCC_VER}
176195
# Download GCC Pre Requisites
177196
echo "Downloading GCC Pre Requisites"
178197
./contrib/download_prerequisites
179-
mkdir -p build && cd build
198+
mkdir -p build-phase-1 && cd build-phase-1
180199

181200
##########################################
182201
# Configure GGC for Phase 1 #
183202
# as per GCC documentation for Toolchain #
184203
##########################################
185204
echo "Building GCC ${GCC_VERSION} with C only"
186-
# Building with c++ cause errors about SSE2 and AVX, help to fix that is appreciated
187-
../configure --target=$TARGET --host=$HOST --prefix=$PREFIX --with-sysroot=$PREFIX --disable-multilib --enable-languages=c --disable-nls --without-headers --with-default-msvcrt=msvcrt --disable-shared $THREADS
205+
../configure \
206+
--target=$TARGET \
207+
--host=$HOST \
208+
--prefix=$PREFIX \
209+
--with-sysroot=$PREFIX \
210+
--disable-multilib \
211+
--enable-languages=c \
212+
--disable-nls \
213+
--without-headers \
214+
--with-default-msvcrt=msvcrt \
215+
--disable-shared \
216+
--with-arch=pentium \
217+
--with-tune=generic \
218+
--enable-sjlj-exceptions \
219+
$THREADS
188220
make all-gcc -j$JOBS
189221
make install-gcc
190222

@@ -202,15 +234,33 @@ mkdir -p build && cd build
202234
# as per Mingw/GCC documentation for Toolchain #
203235
################################################
204236

205-
../configure --host=$TARGET --prefix=$PREFIX/$TARGET --with-sysroot=$PREFIX --with-default-msvcrt=msvcrt
237+
../configure \
238+
--host=$TARGET \
239+
--prefix=$PREFIX/$TARGET \
240+
--with-sysroot=$PREFIX \
241+
--with-default-msvcrt=msvcrt
206242
make -j$JOBS
207243
make install
208244

209245
############################################
210246
# Built GCC Phase 2 (Continues the Phase 1 #
211247
############################################
212248
echo "Building GCC ${GCC_VER} Phase 2"
213-
cd ~/$SOURCE/gcc-13.1.0/build
249+
cd ~/$SOURCE/gcc-13.1.0
250+
mkdir -p build-phase-2 && cd build-phase-2
251+
../configure \
252+
--target=$TARGET \
253+
--host=$HOST \
254+
--prefix=$PREFIX \
255+
--with-sysroot=$PREFIX \
256+
--disable-multilib \
257+
--enable-languages=c,c++ \
258+
--disable-nls \
259+
--disable-shared \
260+
--with-arch=pentium \
261+
--with-tune=generic \
262+
--enable-sjlj-exceptions \
263+
$THREADS
214264

215265
##########################################
216266
# Configure GGC for Phase 2 #
@@ -230,29 +280,65 @@ make install
230280

231281
echo "Building Mingw-w64 tools"
232282

233-
echo "Building gendef"
234-
cd ~/$SOURCE/mingw-w64-v12.0.0/mingw-w64-tools/gendef
235-
./configure
236-
make -j$JOBS
237-
make install
283+
build_tool() {
284+
local tool=$1
285+
echo "Building $tool"
286+
287+
cd ~/$SOURCE/mingw-w64-v12.0.0/mingw-w64-tools/$tool
288+
if [ "$tool" == "widl" ]; then
289+
./configure --target=$TARGET --prefix=$PREFIX --bindir=$PREFIX/bin
290+
else
291+
./configure
292+
fi
293+
make -j$JOBS
294+
make install
295+
}
238296

239-
echo "Building genidl"
240-
cd ~/$SOURCE/mingw-w64-v12.0.0/mingw-w64-tools/genidl
241-
./configure
242-
make -j$JOBS
243-
make install
297+
build_tool gendef
298+
build_tool genidl
299+
build_tool genpeimg
300+
build_tool widl
244301

245-
echo "Building genpeimg"
246-
cd ~/$SOURCE/mingw-w64-v12.0.0/mingw-w64-tools/genpeimg
247-
./configure
248-
make -j$JOBS
249-
make install
302+
#########################
303+
# Optional i686 overlay #
304+
#########################
250305

251-
echo "Building widl"
252-
cd ~/$SOURCE/mingw-w64-v12.0.0/mingw-w64-tools/widl
253-
./configure --target=$TARGET --prefix=$PREFIX --bindir=$PREFIX/bin
306+
################################################
307+
# Build and install Binutils 2.40 i686 overlay #
308+
################################################
309+
echo "Starting Binutils i686 build..."
310+
cd ~/$SOURCE/binutils-${BINUTILS_VER}
311+
mkdir -p build-i686 && cd build-i686
312+
../configure \
313+
--target=$I686_TARGET \
314+
--host=$HOST \
315+
--prefix=$PREFIX \
316+
--disable-multilib \
317+
--disable-nls
254318
make -j$JOBS
255319
make install
256320

321+
#############################################
322+
# Build and install GCC 13.1.0 i686 overlay #
323+
#############################################
324+
echo "Starting GCC ${GCC_VER} i686 build ..."
325+
cd ~/$SOURCE/gcc-${GCC_VER}
326+
mkdir build-i686 && cd build-i686
327+
../configure \
328+
--target=$I686_TARGET \
329+
--host=$HOST \
330+
--prefix=$PREFIX \
331+
--with-sysroot=$PREFIX \
332+
--disable-multilib \
333+
--enable-languages=c,c++ \
334+
--disable-nls \
335+
--disable-shared \
336+
--with-arch=pentiumpro \
337+
--with-tune=generic \
338+
--enable-sjlj-exceptions \
339+
$THREADS
340+
make all-gcc -j$JOBS
341+
make install-gcc
342+
257343
echo "Built all done! Toolchain is located in $TARGET"
258344
echo "Don't forget to add the $TARGET in PATH to use"

0 commit comments

Comments
 (0)