From 3dba3a64aa17470e42444158acfdb4b20b9eda6b Mon Sep 17 00:00:00 2001 From: bumbread Date: Tue, 7 Jun 2022 00:17:14 +1100 Subject: [PATCH] Different build script --- bake.cmd | 63 ++++++++++++++++++------ {platform/win32 => code/os/win}/entry.c | 0 {platform/win32 => code/os/win}/env.c | 0 {platform/win32 => code/os/win}/memory.c | 1 + {platform/win32 => code/os/win}/win32.h | 0 5 files changed, 48 insertions(+), 16 deletions(-) rename {platform/win32 => code/os/win}/entry.c (100%) rename {platform/win32 => code/os/win}/env.c (100%) rename {platform/win32 => code/os/win}/memory.c (99%) rename {platform/win32 => code/os/win}/win32.h (100%) diff --git a/bake.cmd b/bake.cmd index 028e8c1..15e4ac2 100644 --- a/bake.cmd +++ b/bake.cmd @@ -1,23 +1,54 @@ @echo off setlocal enabledelayedexpansion -set CIABATTA_OPTIONS=-Iinc -Wall -g -gcodeview -nodefaultlibs -D_CRT_SECURE_NO_WARNINGS -set PLATFORM=win32 -if NOT "%1"=="fast" ( - - del ciabatta.lib - for /R code %%F in (*.c) do ( - echo %%F - clang -c -o build\%%~nF.obj %%F %CIABATTA_OPTIONS% - ) - for /R platform\%PLATFORM% %%F in (*.c) do ( - echo %%F - clang -c -o build\%%~nF.obj %%F %CIABATTA_OPTIONS% - ) - llvm-ar rc ciabatta.lib build\*.obj - del build\*.obj +:: Make sure that if I ctrl+c out of the script the dir is popped +:: If there's anything that requires user input, this script will break +:: in that case I recommend you removing the 'echo y' part. +:: although you will have to confirm termination of the script twice +if "%~1" neq "_start_" ( + pushd %~pd0 + echo y | cmd /c "%~f0" _start_ %* + popd + exit /b ) +shift /1 +set CIABATTA_OPTIONS=-Iinc -Wall -g -gcodeview -nodefaultlibs -D_CRT_SECURE_NO_WARNINGS +set PLATFORM=win + +if "%1"=="fast" ( + goto :skip_crt_compilation +) +:: For each C file in code/ we check whether it's OS-dependent. +:: If so, we check whether the platform is the chosen one. If not, we ignore +:: that file (set ok=0). Otherwise we compile it. +:: Man, batch files are sure scary, when you try to do something serious +:: it took me a lot of time to figure out how to write this if it breaks +:: im gonna be seriously disappointed :kekw: +del ciabatta.lib 2> nul +for /R code %%F in (*.c) do ( + set ok=1 + set os_dependent=0 + set is_cur_os=0 + echo %%F | findstr /c:"%~pd0code\os" > nul + if !errorlevel! neq 1 ( + set os_dependent=1 + ) + echo %%F | findstr /c:"%~pd0code\os\%PLATFORM%" > nul + if !errorlevel! neq 1 ( + set is_cur_os=1 + ) + if "!os_dependent!"=="1" if "!is_cur_os!"=="0" ( + set ok=0 + ) + if "!ok!"=="1" ( + echo %%F + clang -c -o build\%%~nF.obj %%F %CIABATTA_OPTIONS% + ) +) +llvm-ar rc ciabatta.lib build\*.obj +del build\*.obj + +:skip_crt_compilation echo Compiling test.. clang test\test.c ciabatta.lib -std=c11 -lkernel32 -luser32 -lshell32 -nostdlib %CIABATTA_OPTIONS% - diff --git a/platform/win32/entry.c b/code/os/win/entry.c similarity index 100% rename from platform/win32/entry.c rename to code/os/win/entry.c diff --git a/platform/win32/env.c b/code/os/win/env.c similarity index 100% rename from platform/win32/env.c rename to code/os/win/env.c diff --git a/platform/win32/memory.c b/code/os/win/memory.c similarity index 99% rename from platform/win32/memory.c rename to code/os/win/memory.c index 0514767..0b218bc 100644 --- a/platform/win32/memory.c +++ b/code/os/win/memory.c @@ -72,3 +72,4 @@ void *realloc(void *ptr, size_t size) { void *buffer = HeapReAlloc(_heap, 0, ptr, size); return buffer; } + diff --git a/platform/win32/win32.h b/code/os/win/win32.h similarity index 100% rename from platform/win32/win32.h rename to code/os/win/win32.h