Files
nt-lite/build.bat
T

249 lines
9.3 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set ROOT=%~dp0.
set SRC=%ROOT%\code
set VHD=%~dp0disk.vhd
if not exist "%VHD%" (
call mkimage.bat
)
if exist "obj" rd /s /q "obj"
if exist "bin" rd /s /q "bin"
mkdir "obj\boot" 2>nul
mkdir "obj\kernel" 2>nul
mkdir "obj\hal" 2>nul
mkdir "obj\syscall" 2>nul
mkdir "obj\win32" 2>nul
mkdir "obj\posix" 2>nul
mkdir "obj\drivers" 2>nul
mkdir "obj\init" 2>nul
mkdir "obj\shell_win32" 2>nul
mkdir "obj\shell_posix" 2>nul
mkdir "obj\shell_native" 2>nul
mkdir "obj\async_apc" 2>nul
mkdir "obj\async_cancel" 2>nul
mkdir "obj\doom" 2>nul
mkdir "obj\video" 2>nul
mkdir "bin" 2>nul
set CFLAGS=/nologo /W3 /WX /Od /GS- /Gs999999 /Gz /Gy /EHsc- /GR- /Oi /Zi /std:c17 /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /I"%SRC%\kernel" /I"%SRC%\hal" /I"%SRC%\syscall"
set LFLAGS=/nologo /NODEFAULTLIB /DEBUG
:: ---- Assemble ASM files ----
echo Assembling...
ml64 /nologo /c /Fo"obj\kernel\ke_switch.obj" "%SRC%\kernel\ke_switch.asm" || exit /b 1
ml64 /nologo /c /Fo"obj\kernel\ke_syscall_asm.obj" "%SRC%\kernel\ke_syscall.asm" || exit /b 1
ml64 /nologo /c /Fo"obj\kernel\ke_gdt_reload.obj" "%SRC%\kernel\ke_gdt_reload.asm" || exit /b 1
ml64 /nologo /c /Fo"obj\syscall\stubs.obj" "%SRC%\syscall\syscall_stubs.asm" || exit /b 1
:: ---- Compile libc ----
cl /nologo /c /Fo"obj\libc.obj" "%SRC%\libc.c" || exit /b 1
:: ---- Compile printf ----
cl %CFLAGS% /c /Fo"obj\printf.obj" "%SRC%\printf.c" || exit /b 1
:: ---- Compile ini parser ----
cl %CFLAGS% /c /Fo"obj\ini_parser.obj" "%SRC%\ini_parser.c" || exit /b 1
:: ---- Compile bootloader ----
echo Compiling bootloader...
for %%f in (%SRC%\boot\*.c) do (
cl %CFLAGS% /c /I"%SRC%\boot\include" /Fo"obj\boot\%%~nf.obj" "%%f" || exit /b 1
)
:: ---- Link bootloader ----
echo Linking bootx64.efi...
link %LFLAGS% /SUBSYSTEM:EFI_APPLICATION /ENTRY:UefiMain /OUT:"bin\bootx64.efi" ^
/PDB:"bin\bootx64.pdb" %SRC%\boot\efilib.lib obj\ini_parser.obj obj\libc.obj obj\boot\*.obj || exit /b 1
:: ---- Compile HAL ----
echo Compiling hal...
for %%f in (%SRC%\hal\*.c) do (
cl %CFLAGS% /c /Fo"obj\hal\%%~nf.obj" "%%f" || exit /b 1
)
:: ---- Link hal.dll ----
echo Linking hal.dll...
link %LFLAGS% /DLL /OUT:"bin\hal.dll" /ENTRY:HalInitialize /IGNORE:4216 obj\printf.obj obj\libc.obj obj\hal\*.obj || exit /b 1
:: ---- Compile kernel ----
echo Compiling kernel...
for %%f in (%SRC%\kernel\*.c) do (
cl %CFLAGS% /c /Fo"obj\kernel\%%~nf.obj" "%%f" || exit /b 1
)
:: ---- Link kernel.exe ----
echo Linking kernel.exe...
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:KernelMain /OUT:"bin\kernel.exe" /PDB:"bin\kernel.pdb" ^
bin\hal.lib obj\ini_parser.obj obj\printf.obj obj\libc.obj obj\kernel\*.obj || exit /b 1
:: ---- Compile syscall.dll ----
echo Compiling syscall.dll...
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\syscall.dll" obj\syscall\stubs.obj || exit /b 1
:: ---- Compile win32.dll ----
echo Compiling win32.dll...
for %%f in (%SRC%\win32\*.c) do (
cl %CFLAGS% /c /Fo"obj\win32\%%~nf.obj" "%%f" || exit /b 1
)
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\win32.dll" bin\syscall.lib obj\libc.obj obj\win32\*.obj || exit /b 1
:: ---- Compile posix.dll ----
echo Compiling posix.dll...
for %%f in (%SRC%\posix\*.c) do (
cl %CFLAGS% /c /Fo"obj\posix\%%~nf.obj" "%%f" || exit /b 1
)
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\posix.dll" bin\syscall.lib obj\libc.obj obj\posix\*.obj || exit /b 1
:: ---- Compile drivers ----
echo Compiling drivers...
cl %CFLAGS% /I"%SRC%\hal" /c /Fo"obj\drivers\ide.obj" "%SRC%\drivers\ide\ide.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\ide.sys" /ENTRY:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\ide.obj || exit /b 1
cl %CFLAGS% /I"%SRC%\hal" /c /Fo"obj\drivers\ahci.obj" "%SRC%\drivers\ahci\ahci.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\ahci.sys" /ENTRY:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\ahci.obj || exit /b 1
cl %CFLAGS% /I"%SRC%\fat32" /c /Fo"obj\drivers\fat32.obj" "%SRC%\drivers\fat32\fat32.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\fat32.sys" /ENTRY:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\fat32.obj || exit /b 1
cl %CFLAGS% /I"%SRC%\usb" /c /Fo"obj\drivers\usb.obj" "%SRC%\drivers\usb\usb.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\usb.sys" /ENTRY:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\usb.obj || exit /b 1
:: ---- Compile init ----
echo Compiling init...
for %%f in (%SRC%\init\*.c) do (
cl %CFLAGS% /c /Fo"obj\init\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:_start ^
/OUT:"bin\init.exe" /PDB:"bin\init.pdb" bin\syscall.lib obj\libc.obj obj\init\init.obj || exit /b 1
:: ---- Compile shell_win32 ----
echo Compiling shell_win32...
for %%f in (%SRC%\shell_win32\*.c) do (
cl %CFLAGS% /c /Fo"obj\shell_win32\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\shell_win32.exe" /PDB:"bin\shell_win32.pdb" bin\win32.lib obj\libc.obj obj\shell_win32\*.obj || exit /b 1
:: ---- Compile shell_posix ----
echo Compiling shell_posix...
for %%f in (%SRC%\shell_posix\*.c) do (
cl %CFLAGS% /c /Fo"obj\shell_posix\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\shell_posix.exe" /PDB:"bin\shell_posix.pdb" bin\posix.lib obj\libc.obj obj\shell_posix\*.obj || exit /b 1
:: ---- Compile shell_native ----
echo Compiling shell_native...
for %%f in (%SRC%\shell_native\*.c) do (
cl %CFLAGS% /c /Fo"obj\shell_native\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\shell_native.exe" /PDB:"bin\shell_native.pdb" bin\syscall.lib obj\libc.obj obj\shell_native\*.obj || exit /b 1
:: ---- Compile async_apc ----
echo Compiling async_apc...
for %%f in (%SRC%\async_apc\*.c) do (
cl %CFLAGS% /c /Fo"obj\async_apc\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\async_apc.exe" /PDB:"bin\async_apc.pdb" bin\syscall.lib obj\libc.obj obj\async_apc\*.obj || exit /b 1
:: ---- Compile async_cancel ----
echo Compiling async_cancel...
for %%f in (%SRC%\async_cancel\*.c) do (
cl %CFLAGS% /c /Fo"obj\async_cancel\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\async_cancel.exe" /PDB:"bin\async_cancel.pdb" bin\syscall.lib obj\libc.obj obj\async_cancel\*.obj || exit /b 1
:: ---- Compile doom ----
echo Compiling doom...
for %%f in (%SRC%\doom\*.c) do (
cl %CFLAGS% /c /Fo"obj\doom\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\doom.exe" /PDB:"bin\doom.pdb" bin\syscall.lib obj\libc.obj obj\doom\*.obj || exit /b 1
:: ---- Compile video player ----
echo Compiling video...
for %%f in (%SRC%\video\*.c) do (
cl %CFLAGS% /c /Fo"obj\video\%%~nf.obj" "%%f" || exit /b 1
)
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\video.exe" /PDB:"bin\video.pdb" bin\win32.lib obj\libc.obj %SRC%\video\bink2w64.lib obj\video\*.obj || exit /b 1
:: ---- Mount disk image ----
echo Mounting disk.vhd as Z: ...
set DPS=%TEMP%\ntlite_mnt_%RANDOM%.txt
(
echo select vdisk file="%VHD%"
echo attach vdisk
echo select partition 1
echo format fs=fat32 quick
echo assign letter=Z
echo exit
) > "%DPS%"
diskpart /s "%DPS%"
del "%DPS%"
if not exist "Z:\" (
echo ERROR: Could not mount disk.vhd as Z:
echo If Z: is already in use, change the letter in build.bat and mkimage.bat.
exit /b 1
)
set DEST=Z:
:: ---- Copy to ESP layout ----
echo Assembling ESP...
mkdir "%DEST%\apps" 2>nul
mkdir "%DEST%\system" 2>nul
mkdir "%DEST%\drivers" 2>nul
mkdir "%DEST%\EFI\BOOT" 2>nul
copy /y "bin\bootx64.efi" "%DEST%\EFI\BOOT\"
copy /y "bin\kernel.exe" "%DEST%\system\colonel.exe"
copy /y "bin\hal.dll" "%DEST%\system\"
copy /y "bin\syscall.dll" "%DEST%\system\"
copy /y "bin\win32.dll" "%DEST%\system\"
copy /y "bin\posix.dll" "%DEST%\system\"
copy /y "bin\ide.sys" "%DEST%\drivers\"
copy /y "bin\ahci.sys" "%DEST%\drivers\"
copy /y "bin\fat32.sys" "%DEST%\drivers\"
copy /y "bin\usb.sys" "%DEST%\drivers\"
copy /y "bin\init.exe" "%DEST%\system\"
copy /y "bin\shell_win32.exe" "%DEST%\apps\"
copy /y "bin\shell_posix.exe" "%DEST%\apps\"
copy /y "bin\shell_native.exe" "%DEST%\apps\"
copy /y "bin\async_apc.exe" "%DEST%\apps\"
copy /y "bin\async_cancel.exe" "%DEST%\apps\"
copy /y "bin\doom.exe" "%DEST%\apps\"
copy /y "bin\video.exe" "%DEST%\apps\"
copy /y "%SRC%\boot.ini" "%DEST%\"
copy /y "%SRC%\drivers\drivers.ini" "%DEST%\drivers\"
if exist "%SRC%\video\bink2w64.dll" copy /y "%SRC%\video\bink2w64.dll" "%DEST%\apps\"
if exist "%SRC%\video\video.bk2" copy /y "%SRC%\video\video.bk2" "%DEST%\apps\"
if exist "%SRC%\doom\doom1.wad" copy /y "%SRC%\doom\doom1.wad" "%DEST%\apps\"
:: ---- Unmount disk image ----
echo Unmounting disk.vhd...
set DPS=%TEMP%\ntlite_umnt_%RANDOM%.txt
(
echo select vdisk file="%VHD%"
echo detach vdisk
echo exit
) > "%DPS%"
diskpart /s "%DPS%"
del "%DPS%"
echo.
echo Build complete.