-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
372 lines (300 loc) · 16.9 KB
/
Copy pathMakefile
File metadata and controls
372 lines (300 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# Detect architecture and OS
ifeq ($(OS),Windows_NT)
ARCH ?= $(PROCESSOR_ARCHITECTURE)
NUM_CPUS ?= $(NUMBER_OF_PROCESSORS)
else
ARCH ?= $(shell uname -m)
OS := $(shell uname -s)
NUM_CPUS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
endif
# Set base commands based on architecture
ifeq ($(ARCH),powerpc)
BASE_RUN := cargo +nightly run -Z build-std
BASE_CHECK := cargo +nightly check -Z build-std --all-targets
else ifeq ($(ARCH),powerpc64)
BASE_RUN := cargo +nightly run -Z build-std
BASE_CHECK := cargo +nightly check -Z build-std --all-targets
else
BASE_RUN := cargo run
BASE_CHECK := cargo check --all-targets
endif
.PHONY: default check check-efi-64 check-efi-32 check-efi check-dos-real check-dos32a check-dos check-486 check-arm64 check-ppc check-ppc64 check-windows-gui-x64 check-windows-gui-32 check-windows-gui-arm64 check-windows-gui check-haiku-gui check-gui check-all check-riscv check-android lint fix fmt quality build build-debug build-release _cargo_cross _build-dos-tools build-dos-real _build-dos32a-tools _build-dos32a-rustid build-dos32a build-dos build-windows-gui-x64 build-windows-gui-32 build-windows-gui-arm64 build-windows-gui build-haiku-gui build-linux-gui build-appimage appimage build-arm64 build-ppc build-mac build-mac-arm build-486 build-efi-64 build-efi-32 build-efi build-486-musl clean clean-files run from-file run-dos test-dos run-efi-64 run-efi-32 test coverage test-all test-arm test-x86 check-ci
# Lists the available actions
default:
@echo "This is an $(ARCH) machine, running $(OS) on $(NUM_CPUS) cpus/cores/threads"
@rustup default
@just --list 2>/dev/null || echo "Install 'just' to see available commands"
ifeq ($(OS),Windows_NT)
_cargo_cross:
@where cargo-cross >/dev/null 2>&1 || cargo install cargo-cross
else
_cargo_cross:
@if ! command -v cargo-cross >/dev/null 2>&1; then cargo install cargo-cross; fi
endif
# Check code validity and style
check:
$(BASE_CHECK)
# Compile check for 64-bit x86 EFI application
check-efi-64:
@if ! rustup target list --installed | grep -q x86_64-unknown-uefi; then rustup target add x86_64-unknown-uefi; fi
cargo check --target x86_64-unknown-uefi --features efi-build --bin efi
# Compile check for 32-bit x86 EFI application
check-efi-32:
@if ! rustup target list --installed | grep -q i686-unknown-uefi; then rustup target add i686-unknown-uefi; fi
cargo check --target i686-unknown-uefi --features efi-build --bin efi
# Compile check for both 32-bit and 64-bit EFI
check-efi: check-efi-64 check-efi-32
# Compile check for DOS (real-mode EXE)
check-dos-real: _build-dos-tools
@RUSTFLAGS="-C link-arg=-Tbuild-config/link-exe.x" cargo +nightly check -Zjson-target-spec -Z build-std=core,alloc,panic_abort --target build-config/i486-dos.json --release --features dos-build --bin dos
# Compile check for DOS/32A (protected-mode LE)
check-dos32a: _build-dos32a-tools
@RUSTFLAGS="-C link-arg=-Tbuild-config/link-dos32a.x -C link-arg=--emit-relocs -C strip=none" cargo +nightly check -Zjson-target-spec -Z build-std=core,alloc,panic_abort --target build-config/i486-dos32a.json --features="dos32a-build" --bin dos --release
# Compile check for all DOS targets
check-dos: check-dos32a check-dos-real
# Compile check for Risc V
check-riscv:
@if ! rustup target list --installed | grep -q riscv64gc-unknown-linux-gnu; then rustup target add riscv64gc-unknown-linux-gnu; fi
cargo check --target riscv64gc-unknown-linux-gnu
# Compile check for Android ARM64
check-android:
@if ! rustup target list --installed | grep -q aarch64-linux-android; then rustup target add aarch64-linux-android; fi
cargo check --target aarch64-linux-android
# Compile check for 32-bit Linux 486
check-486:
@if ! rustup component list --installed --toolchain nightly | grep -q rust-src; then rustup component add rust-src --toolchain nightly; fi
cargo +nightly check -Zjson-target-spec -Z build-std=std,core,alloc,panic_abort --target build-config/i486-linux.json --release
# Compile check for linux arm64
check-arm64: _cargo_cross
@if ! rustup target list --installed | grep -q aarch64-unknown-linux-gnu; then rustup target add aarch64-unknown-linux-gnu; fi
cargo cross check --target aarch64-unknown-linux-gnu
# Compile check for linux powerpc
check-ppc: _cargo_cross
@if ! rustup target list --installed | grep -q powerpc-unknown-linux-gnu; then rustup target add powerpc-unknown-linux-gnu; fi
cargo cross +nightly check --target powerpc-unknown-linux-gnu -Z build-std
# Compile check for linux powerpc64
check-ppc64: _cargo_cross
@if ! rustup target list --installed | grep -q powerpc64-unknown-linux-gnu; then rustup target add powerpc64-unknown-linux-gnu; fi
cargo cross +nightly check --target powerpc64-unknown-linux-gnu -Z build-std
# Compile check for Windows GUI (64-bit x86 GNU)
check-windows-gui-x64:
@if ! rustup target list --installed | grep -q x86_64-pc-windows-gnu; then rustup target add x86_64-pc-windows-gnu; fi
cargo check --target x86_64-pc-windows-gnu --features gui --bin gui
# Compile check for Windows GUI (32-bit x86 GNU)
check-windows-gui-32:
@if ! rustup target list --installed | grep -q i686-pc-windows-gnu; then rustup target add i686-pc-windows-gnu; fi
cargo check --target i686-pc-windows-gnu --features gui --bin gui
# Compile check for Windows GUI (ARM64 GNU)
check-windows-gui-arm64:
@if ! rustup target list --installed | grep -q aarch64-pc-windows-gnullvm; then rustup target add aarch64-pc-windows-gnullvm; fi
cargo check --target aarch64-pc-windows-gnullvm --features gui --bin gui
# Compile check for all Windows GUI targets
check-windows-gui: check-windows-gui-32 check-windows-gui-x64 check-windows-gui-arm64
# Compile check for Haiku GUI
check-haiku-gui:
cargo check --features gui
# Compile check for Linux GUI
check-linux-gui:
cargo check --features gui --bin gui
# Compile check for all GUI targets
check-gui: check-windows-gui check-haiku-gui check-linux-gui
# Compile check for CI targets and platforms
check-ci: check check-efi check-dos check-riscv check-android check-486 check-windows-gui check-arm64
# Compile check for all supported targets and platforms
check-all: check-ci check-ppc check-ppc64
# More in-depth code style checking
lint:
cargo clippy --all-targets --all-features
# Fix linting errors
fix:
cargo fix --all-targets --all-features
# Automatic code formatting
fmt:
cargo fmt
# Run all the code quality stuff
quality: fmt check lint
# Build the app
build:
cargo build
# Build debug app
build-debug:
cargo build --features debug --bin debug
# Do an optimized, release build for the current platform
build-release:
cargo build --release
_build-dos-tools:
# Fetch required tools (if they aren't already installed)
@if ! rustup component list --installed --toolchain nightly | grep -q rust-src; then rustup component add rust-src --toolchain nightly; fi
# Build for DOS (EXE format)
build-dos-real: _build-dos-tools
@RUSTFLAGS="-C link-arg=-Tbuild-config/link-exe.x" cargo +nightly build -Zjson-target-spec -Z build-std=core,alloc,panic_abort --target build-config/i486-dos.json --release --features dos-build --bin dos
@cargo run --manifest-path tools/make_exe/Cargo.toml --quiet -- ./target/i486-dos/release/dos rust86.exe
@cargo test --test dos_binary_size_test --features dos-build
_build-dos32a-tools:
# Fetch required tools (if they aren't already installed)
@if ! rustup component list --installed --toolchain nightly | grep -q rust-src; then rustup component add rust-src --toolchain nightly; fi
_build-dos32a-rustid: _build-dos32a-tools
@RUSTFLAGS="-C link-arg=-Tbuild-config/link-dos32a.x -C link-arg=--emit-relocs -C strip=none" cargo +nightly build -Zjson-target-spec -Z build-std=core,alloc,panic_abort --target build-config/i486-dos32a.json --features="dos32a-build" --bin dos --release
@cargo run --manifest-path tools/elf2le/Cargo.toml --quiet -- ./target/i486-dos32a/release/dos rustid.le
@if command -v dosbox-x >/dev/null 2>&1; then \
dosbox-x -conf ./tools/dosbox-x.conf -fastlaunch -silent -exit -c "MOUNT C ." -c "C:" -c "COPY tools\dos32a\dos32a.exe ." -c "tools\dos32a\sb.exe /b /o /bnrustid.exe rustid.le" >/dev/null 2>&1 || true; \
elif [ -f "C:/DOSBox-X/dosbox-x.exe" ]; then \
"C:/DOSBox-X/dosbox-x.exe" -conf ./tools/dosbox-x.conf -fastlaunch -silent -exit -c "MOUNT C ." -c "C:" -c "COPY tools\dos32a\dos32a.exe ." -c "tools\dos32a\sb.exe /b /o /bnrustid.exe rustid.le" >/dev/null 2>&1 || true; \
fi
@if [ -f RUSTID.EXE ]; then mv RUSTID.EXE rustid.exe; fi
# Build for DOS/32A (LE format bound executable)
build-dos32a: clean-files _build-dos32a-tools _build-dos32a-rustid
# Build all dos binaries
build-dos: build-dos32a build-dos-real
# Build 64-bit Windows GUI using MinGW/GNU target (cross-compilable from Linux)
build-windows-gui-x64: _cargo_cross
@if ! rustup target list --installed | grep -q x86_64-pc-windows-gnu; then rustup target add x86_64-pc-windows-gnu; fi
cargo cross build --target x86_64-pc-windows-gnu --features gui --bin gui --release
ifeq ($(OS),Windows_NT)
@if not exist "target\dist" mkdir "target\dist"
@if exist "target\x86_64-pc-windows-gnu\release\gui.exe" copy /Y "target\x86_64-pc-windows-gnu\release\gui.exe" "target\dist\rustid_x86_64.exe" >/dev/null 2>&1
else
@mkdir -p target/dist
@cp target/x86_64-pc-windows-gnu/release/gui.exe target/dist/rustid_x86_64.exe 2>/dev/null || true
endif
# Build 32-bit Windows GUI using MinGW/GNU target (Pentium baseline, Windows 9x/ME/NT/2000/XP/7/10/11)
build-windows-gui-32: _cargo_cross
ifeq ($(OS),Windows_NT)
powershell -ExecutionPolicy Bypass -File build-config/build-windows-gui-32.ps1
else
bash build-config/build-windows-gui-32.sh
endif
# Build ARM64 Windows GUI using LLVM MinGW/GNU target
build-windows-gui-arm64:
ifeq ($(OS),Windows_NT)
powershell -ExecutionPolicy Bypass -File build-config/build-windows-gui-arm64.ps1
else
bash build-config/build-windows-gui-arm64.sh
endif
# Build all Windows GUI binaries (x86 32-bit, x86 64-bit, ARM64)
build-windows-gui: build-windows-gui-32 build-windows-gui-x64 build-windows-gui-arm64
# Build Haiku GUI application
build-haiku-gui:
cargo build --features gui --bin gui --release
@mkdir -p target/dist
@cp target/release/gui target/dist/rustid_haiku 2>/dev/null || true
@if command -v rc >/dev/null 2>&1 && command -v xres >/dev/null 2>&1; then \
rc -o target/dist/rustid.rsrc assets/haiku/rustid.rdef && \
xres -o target/dist/rustid_haiku target/dist/rustid.rsrc && \
xres -o target/release/gui target/dist/rustid.rsrc 2>/dev/null || true; \
(command -v mimeset >/dev/null 2>&1 && mimeset -f target/dist/rustid_haiku 2>/dev/null || true); \
echo "Attached Haiku icon and resources to rustid_haiku"; \
fi
# Build Linux GUI application
build-linux-gui:
cargo build --features gui --bin gui --release
@mkdir -p target/dist
@cp target/release/gui target/dist/rustid-gui 2>/dev/null || true
# Build Linux AppImage application
build-appimage:
bash build-config/build-appimage.sh
appimage: build-appimage
# Build for linux arm64
build-arm64: _cargo_cross
@if ! rustup target list --installed | grep -q aarch64-unknown-linux-gnu; then rustup target add aarch64-unknown-linux-gnu; fi
cargo cross build --target aarch64-unknown-linux-gnu
# Build for linux powerpc
build-ppc: _cargo_cross
@if ! rustup target list --installed | grep -q powerpc-unknown-linux-gnu; then rustup target add powerpc-unknown-linux-gnu; fi
cargo cross +nightly build --target powerpc-unknown-linux-gnu -Z build-std
# Build for x86 macs
build-mac: _cargo_cross
@if ! rustup target list --installed | grep -q x86_64-apple-darwin; then rustup target add x86_64-apple-darwin; fi
cargo cross build --target x86_64-apple-darwin --release
# Build for arm Macs
build-mac-arm: _cargo_cross
@if ! rustup target list --installed | grep -q aarch64-apple-darwin; then rustup target add aarch64-apple-darwin; fi
cargo cross build --target aarch64-apple-darwin --release
# Build for 32-bit Linux (should work on 486-class cpus)
build-486:
@if ! rustup component list --installed --toolchain nightly | grep -q rust-src; then rustup component add rust-src --toolchain nightly; fi
cargo +nightly build -Zjson-target-spec -Z build-std=std,core,alloc,panic_abort --target build-config/i486-linux.json --release
# Build 64-bit x86 EFI application
build-efi-64:
@if ! rustup target list --installed | grep -q x86_64-unknown-uefi; then rustup target add x86_64-unknown-uefi; fi
cargo build --target x86_64-unknown-uefi --features efi-build --bin efi --release
@mkdir -p target/efi-disk/EFI/BOOT
@cp target/x86_64-unknown-uefi/release/efi.efi target/efi-disk/EFI/BOOT/BOOTX64.EFI
# Build 32-bit x86 EFI application
build-efi-32:
@if ! rustup target list --installed | grep -q i686-unknown-uefi; then rustup target add i686-unknown-uefi; fi
cargo build --target i686-unknown-uefi --features efi-build --bin efi --release
@mkdir -p target/efi-disk/EFI/BOOT
@cp target/i686-unknown-uefi/release/efi.efi target/efi-disk/EFI/BOOT/BOOTIA32.EFI
# Build both 32-bit and 64-bit EFI binaries
build-efi: build-efi-64 build-efi-32
# Build for 32-bit Linux musl (works on 486-class cpus)
build-486-musl: _cargo_cross
bash build-config/build-486-musl.sh
# Remove build files
clean: clean-files
@cargo clean
# Remove various artifacts in root
clean-files:
@rm -f *.com
@rm -f *.exe
@rm -f *.EXE
@rm -f *.le
@rm -f *.lx
@rm -f *.LX
@rm -f *.bin
@rm -f *.log
# Build and run the app
run:
@$(BASE_RUN) -- $(ARG)
# Run rustid, but pull cpu information from a cpuid dump
from-file:
@$(BASE_RUN) file $(ARG)
ifeq ($(OS),Windows_NT)
# Run the dos build in DOSBox-X
run-dos: build-dos
"C:\DOSBox-X\dosbox-x.exe" . -fastlaunch -conf ./tools/dosbox-x.conf rustid.exe
# Run the dos build in DOSBox-x, and return the output to a file
test-dos: build-dos
"C:\DOSBox-X\dosbox-x.exe" . -fastlaunch -console -log-con -conf ./tools/dosbox-x.conf -time-limit 2 rustid.exe
else
# Run the dos build in DOSBox-X
run-dos: build-dos
dosbox-x . -fastlaunch rustid.exe
# Run the dos build in DOSBox-x, and return the output to a file
test-dos: build-dos
dosbox-x . -fastlaunch -conf ./tools/dosbox-x.conf -time-limit 2 -log-con rustid.exe
# Run 64-bit EFI build in QEMU
run-efi-64: build-efi-64
@CODE=$$(find /usr/share /usr/lib -name "*OVMF_CODE*.fd" -o -name "*ovmf_code*.fd" 2>/dev/null | grep -v 32 | grep -v -E "secboot|snakeoil|\.ms\." | head -n1); VARS=$$(find /usr/share /usr/lib -name "*OVMF_VARS*.fd" -o -name "*ovmf_vars*.fd" 2>/dev/null | grep -v 32 | grep -v -E "secboot|snakeoil|\.ms\." | head -n1); SINGLE=$$(find /usr/share /usr/lib -name "OVMF.fd" -o -name "ovmf.fd" 2>/dev/null | head -n1); if [ -n "$$CODE" ] && [ -n "$$VARS" ]; then cp "$$VARS" target/OVMF64_VARS.fd && qemu-system-x86_64 -drive if=pflash,format=raw,readonly=on,file="$$CODE" -drive if=pflash,format=raw,file=target/OVMF64_VARS.fd -drive file=fat:rw:target/efi-disk,format=raw -nographic -net none -no-reboot; elif [ -n "$$SINGLE" ]; then qemu-system-x86_64 -bios "$$SINGLE" -drive file=fat:rw:target/efi-disk,format=raw -nographic -net none -no-reboot; else echo "OVMF firmware not found"; exit 1; fi
# Run 32-bit EFI build in QEMU
run-efi-32: build-efi-32
@CODE=$$(find /usr/share /usr/lib -name "*OVMF32_CODE*.fd" -o -name "*ovmf32_code*.fd" 2>/dev/null | grep -v -E "secboot|snakeoil|\.ms\." | head -n1); VARS=$$(find /usr/share /usr/lib -name "*OVMF32_VARS*.fd" -o -name "*ovmf32_vars*.fd" 2>/dev/null | grep -v -E "secboot|snakeoil|\.ms\." | head -n1); SINGLE=$$(find /usr/share /usr/lib -name "*OVMF32.fd" -o -name "*ovmf32.fd" 2>/dev/null | head -n1); if [ -n "$$CODE" ] && [ -n "$$VARS" ]; then cp "$$VARS" target/OVMF32_VARS.fd && qemu-system-i386 -drive if=pflash,format=raw,readonly=on,file="$$CODE" -drive if=pflash,format=raw,file=target/OVMF32_VARS.fd -drive file=fat:rw:target/efi-disk,format=raw -nographic -net none -no-reboot; elif [ -n "$$SINGLE" ]; then qemu-system-i386 -bios "$$SINGLE" -drive file=fat:rw:target/efi-disk,format=raw -nographic -net none -no-reboot; else echo "OVMF32 firmware not found. On Debian/Ubuntu, install with: sudo apt install ovmf-ia32"; exit 1; fi
endif
# Run all the (native) tests
test:
cargo test
# Run tests and generate code coverage
coverage:
cargo llvm-cov --open
# Run 64 and 32 bit tests (on 64bit platform)
test-all: test test-x86 test-arm
ifeq ($(OS),Windows_NT)
# Run Windows arm tests
test-arm: _cargo_cross
@rustup target list --installed | findstr /c:"aarch64-pc-windows-msvc" >/dev/null || rustup target add aarch64-pc-windows-msvc
cargo cross test --target aarch64-pc-windows-gnu
# Run tests for 32-bit x86
test-x86:
@rustup target list --installed | findstr /c:"i686-pc-windows-msvc" >/dev/null || rustup target add i686-pc-windows-msvc
cargo test --target i686-pc-windows-msvc
else
# Run linux aarch64 tests
test-arm: _cargo_cross
@if ! rustup target list --installed | grep -q aarch64-unknown-linux-musl; then rustup target add aarch64-unknown-linux-musl; fi
cargo cross test --target aarch64-unknown-linux-musl
# Run tests for 32-bit x86 (musl target - no system dependencies)
test-x86: _cargo_cross
@if ! rustup target list --installed | grep -q i686-unknown-linux-musl; then rustup target add i686-unknown-linux-musl; fi
cargo cross test --target i686-unknown-linux-musl
endif