using bld to build on both linux and windows
This commit is contained in:
49
bld_file.cpp
49
bld_file.cpp
@@ -20,6 +20,7 @@ int CompileFiles(Strs files) {
|
|||||||
|
|
||||||
int Main() {
|
int Main() {
|
||||||
Strs files = ListDir("../test");
|
Strs files = ListDir("../test");
|
||||||
|
CompileFiles({"../test/main_core_as_header.cpp", "../core.c"});
|
||||||
For(files) {
|
For(files) {
|
||||||
if (S8_Find(it, "test_"_s, 0, 0)) {
|
if (S8_Find(it, "test_"_s, 0, 0)) {
|
||||||
CompileFiles(it);
|
CompileFiles(it);
|
||||||
@@ -67,4 +68,52 @@ int Main() {
|
|||||||
int error = Run(cc + objs + flags + link);
|
int error = Run(cc + objs + flags + link);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set DEBUG=-Od -RTC1 -D_DEBUG -MTd -fsanitize=address
|
||||||
|
set RELEASE=-O2 -MT -DNDEBUG -GL
|
||||||
|
set COMMON=-MP -FC -Z7 -GF -Gm- -Oi -Zo -EHa- -GR-
|
||||||
|
set WRN=-WX -W3 -wd4200 -diagnostics:column -nologo -D_CRT_SECURE_NO_WARNINGS
|
||||||
|
set LINK_DEBUG=-NODEFAULTLIB:LIBCMT
|
||||||
|
set LINK_RELEASE=-opt:ref -opt:icf -ltcg
|
||||||
|
|
||||||
|
set DEBUG_LINE=%DEBUG% %WRN% %COMMON% -link -incremental:no %LINK_DEBUG%
|
||||||
|
set RELEASE_LINE=%RELEASE% %WRN% %COMMON% -link -incremental:no %LINK_RELEASE%
|
||||||
|
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
|
||||||
|
cl.exe -Fe:bld.exe ../bld_main.cpp %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
bld.exe
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
|
||||||
|
cl.exe -Fe:test_arena.exe ../test/test_arena.cpp %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
test_arena.exe
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
|
||||||
|
cl.exe -Fe:test_table.exe ../test/test_table.cpp %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
test_table.exe
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
|
||||||
|
cl.exe -Fe:test_array.exe ../test/test_array.cpp %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
test_array.exe
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
|
||||||
|
cl.exe -Fe:cpp_debug.exe ../test/main.cpp %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
|
||||||
|
cl.exe -Fe:cpp_release.exe ../test/main.cpp %RELEASE_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
cl.exe -Fe:c_debug.exe ../test/main.c %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
cl.exe -Fe:main_core_as_header.exe ../core.c ../test/main_core_as_header.cpp %DEBUG_LINE%
|
||||||
|
if %errorlevel% neq 0 exit /b %errorlevel%
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
rem rtc1 - runtime error checks
|
||||||
|
rem gl - whole program optimizations
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
27
bld_lib.cpp
27
bld_lib.cpp
@@ -108,7 +108,7 @@ SRC_CacheEntry *SRC_HashFile(S8_String file, char *parent_file) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SRC_WasModified(S8_String file) {
|
bool SRC_WasModified(S8_String file, S8_String artifact_path) {
|
||||||
double time_start = OS_GetTime();
|
double time_start = OS_GetTime();
|
||||||
|
|
||||||
if (OS_FileExists(file) == false) {
|
if (OS_FileExists(file) == false) {
|
||||||
@@ -121,8 +121,9 @@ bool SRC_WasModified(S8_String file) {
|
|||||||
|
|
||||||
S8_String without_ext = S8_ChopLastPeriod(file);
|
S8_String without_ext = S8_ChopLastPeriod(file);
|
||||||
S8_String name_only = S8_SkipToLastSlash(without_ext);
|
S8_String name_only = S8_SkipToLastSlash(without_ext);
|
||||||
S8_String obj = S8_Format(Perm, "%.*s.%s", S8_Expand(name_only), IF_WINDOWS_ELSE("obj", "o"));
|
|
||||||
bool modified = OS_FileExists(obj) == false;
|
if (artifact_path.len == 0) artifact_path = S8_Format(Perm, "%.*s.%s", S8_Expand(name_only), IF_WINDOWS_ELSE("obj", "o"));
|
||||||
|
bool modified = OS_FileExists(artifact_path) == false;
|
||||||
|
|
||||||
SRC_CacheEntry *in_memory = SRC_HashFile(file, 0);
|
SRC_CacheEntry *in_memory = SRC_HashFile(file, 0);
|
||||||
IO_Assert(in_memory);
|
IO_Assert(in_memory);
|
||||||
@@ -150,6 +151,17 @@ struct Strs : Array<Str> {
|
|||||||
*this = {};
|
*this = {};
|
||||||
this->add(S8_MakeFromChar(str));
|
this->add(S8_MakeFromChar(str));
|
||||||
}
|
}
|
||||||
|
Strs(char *a, char *b) {
|
||||||
|
*this = {};
|
||||||
|
this->add(S8_MakeFromChar(a));
|
||||||
|
this->add(S8_MakeFromChar(b));
|
||||||
|
}
|
||||||
|
Strs(char *a, char *b, char *c) {
|
||||||
|
*this = {};
|
||||||
|
this->add(S8_MakeFromChar(a));
|
||||||
|
this->add(S8_MakeFromChar(b));
|
||||||
|
this->add(S8_MakeFromChar(c));
|
||||||
|
}
|
||||||
Strs(Str a) {
|
Strs(Str a) {
|
||||||
*this = {};
|
*this = {};
|
||||||
this->add(a);
|
this->add(a);
|
||||||
@@ -250,13 +262,14 @@ Str Merge(Strs list, Str separator = " "_s) {
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeWasModified(char *str) { return SRC_WasModified(S8_MakeFromChar(str)); }
|
|
||||||
bool CodeWasModified(S8_String str) { return SRC_WasModified(str); }
|
|
||||||
S8_String FilenameWithoutExt(S8_String it) { return S8_SkipToLastSlash(S8_ChopLastPeriod(it)); }
|
S8_String FilenameWithoutExt(S8_String it) { return S8_SkipToLastSlash(S8_ChopLastPeriod(it)); }
|
||||||
|
bool CodeWasModified(char *str, char *artifact = 0) { return SRC_WasModified(S8_MakeFromChar(str), S8_MakeFromChar(artifact)); }
|
||||||
|
bool CodeWasModified(S8_String str, S8_String artifact = {}) { return SRC_WasModified(str, artifact); }
|
||||||
Strs IfCodeWasModified(char *cfile, char *objfile) {
|
Strs IfCodeWasModified(char *cfile, char *objfile) {
|
||||||
Strs result = {};
|
Strs result = {};
|
||||||
S8_String s = S8_MakeFromChar(cfile);
|
S8_String s = S8_MakeFromChar(cfile);
|
||||||
if (SRC_WasModified(s)) {
|
S8_String o = S8_MakeFromChar(objfile);
|
||||||
|
if (SRC_WasModified(s, o)) {
|
||||||
return cfile;
|
return cfile;
|
||||||
}
|
}
|
||||||
return objfile;
|
return objfile;
|
||||||
@@ -278,7 +291,7 @@ Strs ListDir(char *dir) {
|
|||||||
#ifndef BLD_MAIN
|
#ifndef BLD_MAIN
|
||||||
int Main();
|
int Main();
|
||||||
int main() {
|
int main() {
|
||||||
SRC_InitCache(Perm, S8_Lit("buildfile.cache"));
|
SRC_InitCache(Perm, S8_Lit("bld_file.cache"));
|
||||||
int result = Main();
|
int result = Main();
|
||||||
if (result == 0) SRC_SaveCache();
|
if (result == 0) SRC_SaveCache();
|
||||||
}
|
}
|
||||||
|
|||||||
11
bld_main.cpp
11
bld_main.cpp
@@ -10,7 +10,7 @@ int main(int argument_count, char **arguments) {
|
|||||||
|
|
||||||
for (int i = 1; i < argument_count; i += 1) {
|
for (int i = 1; i < argument_count; i += 1) {
|
||||||
S8_String arg = S8_MakeFromChar(arguments[i]);
|
S8_String arg = S8_MakeFromChar(arguments[i]);
|
||||||
if (arg == "clear_cache"_s) OS_DeleteFile("bld.cache"_s);
|
if (arg == "clear_cache"_s) OS_DeleteFile("bld_tool.cache"_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
SRC_InitCache(Perm, S8_Lit("bld.cache"));
|
SRC_InitCache(Perm, S8_Lit("bld.cache"));
|
||||||
@@ -37,7 +37,7 @@ int main(int argument_count, char **arguments) {
|
|||||||
|
|
||||||
// @todo: add search path?
|
// @todo: add search path?
|
||||||
// Compile the build file only if code changed
|
// Compile the build file only if code changed
|
||||||
if (SRC_WasModified(build_file)) {
|
if (SRC_WasModified(build_file, exe_name)) {
|
||||||
double time = OS_GetTime();
|
double time = OS_GetTime();
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (cc == "cl"_s) {
|
if (cc == "cl"_s) {
|
||||||
@@ -48,8 +48,7 @@ int main(int argument_count, char **arguments) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IO_Assert(cc == "gcc"_s);
|
IO_Assert(cc == "gcc"_s);
|
||||||
if (result == 0) result = OS_SystemF("gcc -c -Wno-write-strings %Q -o %Q.o -g", build_file, b);
|
result = OS_SystemF("gcc -Wno-write-strings %Q -o %Q -g", build_file, exe_name);
|
||||||
if (result == 0) result = OS_SystemF("gcc -Wno-write-strings %Q.o -o %Q -g", b, exe_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
@@ -64,9 +63,9 @@ int main(int argument_count, char **arguments) {
|
|||||||
double time = OS_GetTime();
|
double time = OS_GetTime();
|
||||||
if (build_file.str) {
|
if (build_file.str) {
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
int result = OS_SystemF("%.*s", S8_Expand(exe_name));
|
int result = OS_SystemF("%Q", exe_name);
|
||||||
#else
|
#else
|
||||||
int result = OS_SystemF("./%.*s", S8_Expand(exe_name));
|
int result = OS_SystemF("./%Q", exe_name);
|
||||||
#endif
|
#endif
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
printf("FAILED execution of the build file!\n");
|
printf("FAILED execution of the build file!\n");
|
||||||
|
|||||||
44
build.bat
44
build.bat
@@ -1,49 +1,9 @@
|
|||||||
@echo off
|
@echo off
|
||||||
call ../misc/compile_setup.bat
|
call ../misc/compile_setup.bat
|
||||||
|
|
||||||
set DEBUG=-Od -RTC1 -D_DEBUG -MTd -fsanitize=address
|
|
||||||
set RELEASE=-O2 -MT -DNDEBUG -GL
|
|
||||||
set COMMON=-MP -FC -Z7 -GF -Gm- -Oi -Zo -EHa- -GR-
|
|
||||||
set WRN=-WX -W3 -wd4200 -diagnostics:column -nologo -D_CRT_SECURE_NO_WARNINGS
|
|
||||||
set LINK_DEBUG=-NODEFAULTLIB:LIBCMT
|
|
||||||
set LINK_RELEASE=-opt:ref -opt:icf -ltcg
|
|
||||||
|
|
||||||
set DEBUG_LINE=%DEBUG% %WRN% %COMMON% -link -incremental:no %LINK_DEBUG%
|
|
||||||
set RELEASE_LINE=%RELEASE% %WRN% %COMMON% -link -incremental:no %LINK_RELEASE%
|
|
||||||
|
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
|
cl -Fe:bld.exe ../bld_main.cpp -WX -W3 -wd4200 -diagnostics:column -nologo -Zi -D_CRT_SECURE_NO_WARNINGS
|
||||||
cl.exe -Fe:bld.exe ../bld_main.cpp %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
rem bld.exe
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
|
|
||||||
cl.exe -Fe:test_arena.exe ../test/test_arena.cpp %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
test_arena.exe
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
|
|
||||||
cl.exe -Fe:test_table.exe ../test/test_table.cpp %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
test_table.exe
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
|
|
||||||
cl.exe -Fe:test_array.exe ../test/test_array.cpp %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
test_array.exe
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
|
|
||||||
cl.exe -Fe:cpp_debug.exe ../test/main.cpp %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
|
|
||||||
cl.exe -Fe:cpp_release.exe ../test/main.cpp %RELEASE_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
cl.exe -Fe:c_debug.exe ../test/main.c %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
cl.exe -Fe:main_core_as_header.exe ../core.c ../test/main_core_as_header.cpp %DEBUG_LINE%
|
|
||||||
if %errorlevel% neq 0 exit /b %errorlevel%
|
|
||||||
cd ..
|
cd ..
|
||||||
|
build\bld.exe
|
||||||
|
|
||||||
rem rtc1 - runtime error checks
|
|
||||||
rem gl - whole program optimizations
|
|
||||||
|
|||||||
2
build.sh
2
build.sh
@@ -2,7 +2,7 @@
|
|||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
set -e
|
set -e
|
||||||
gcc -o bld ../bld_main.cpp -g -fno-exceptions -fno-rtti -Wno-write-strings
|
g++ -o bld ../bld_main.cpp -g
|
||||||
cd ..
|
cd ..
|
||||||
./build/bld
|
./build/bld
|
||||||
# gcc -o test_filesystem ../test/test_filesystem.c -Wno-write-strings
|
# gcc -o test_filesystem ../test/test_filesystem.c -Wno-write-strings
|
||||||
|
|||||||
14
clexer.c
14
clexer.c
@@ -107,7 +107,7 @@ CL_PRIVATE_FUNCTION void *CL__PushSizeZeroed(CL_Arena *arena, int size) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *CL_FixString[] = {
|
const char *CL_FixString[] = {
|
||||||
"",
|
"",
|
||||||
"SUFFIX_U",
|
"SUFFIX_U",
|
||||||
"SUFFIX_UL",
|
"SUFFIX_UL",
|
||||||
@@ -122,7 +122,7 @@ char *CL_FixString[] = {
|
|||||||
"PREFIX_L",
|
"PREFIX_L",
|
||||||
};
|
};
|
||||||
|
|
||||||
char *CL_KindString[] = {
|
const char *CL_KindString[] = {
|
||||||
"EOF",
|
"EOF",
|
||||||
"*",
|
"*",
|
||||||
"/",
|
"/",
|
||||||
@@ -242,7 +242,7 @@ char *CL_KindString[] = {
|
|||||||
"KEYWORD__GENERIC",
|
"KEYWORD__GENERIC",
|
||||||
};
|
};
|
||||||
|
|
||||||
char *CL_MessageKindString[] = {
|
const char *CL_MessageKindString[] = {
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"WARNING",
|
"WARNING",
|
||||||
"TRACE",
|
"TRACE",
|
||||||
@@ -317,12 +317,12 @@ CL_PRIVATE_FUNCTION CL_Token *CL_CopyToken(CL_Arena *arena, CL_Token *token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CL_API_FUNCTION void CL_StringifyMessage(char *buff, int buff_size, CL_Message *msg) {
|
CL_API_FUNCTION void CL_StringifyMessage(char *buff, int buff_size, CL_Message *msg) {
|
||||||
char *kind = CL_MessageKindString[msg->kind];
|
const char *kind = CL_MessageKindString[msg->kind];
|
||||||
CL_SNPRINTF(buff, buff_size, "%s:%d %15s %15s", msg->token.file, msg->token.line, kind, msg->string);
|
CL_SNPRINTF(buff, buff_size, "%s:%d %15s %15s", msg->token.file, msg->token.line, kind, msg->string);
|
||||||
}
|
}
|
||||||
|
|
||||||
CL_API_FUNCTION void CL_Stringify(char *buff, int buff_size, CL_Token *token) {
|
CL_API_FUNCTION void CL_Stringify(char *buff, int buff_size, CL_Token *token) {
|
||||||
char *token_kind = "UNKNOWN";
|
const char *token_kind = "UNKNOWN";
|
||||||
if (token->kind < CL_COUNT) token_kind = CL_KindString[token->kind];
|
if (token->kind < CL_COUNT) token_kind = CL_KindString[token->kind];
|
||||||
CL_SNPRINTF(buff, buff_size, "%s:%d %15s %15.*s", token->file, token->line, token_kind, token->len, token->str);
|
CL_SNPRINTF(buff, buff_size, "%s:%d %15s %15.*s", token->file, token->line, token_kind, token->len, token->str);
|
||||||
}
|
}
|
||||||
@@ -1499,7 +1499,7 @@ CL_API_FUNCTION void CL_DefaultTokenize(CL_LexResult *T, CL_Token *token) {
|
|||||||
default: {
|
default: {
|
||||||
CL_Message *result = CL_PushStruct(T->arena->other, CL_Message);
|
CL_Message *result = CL_PushStruct(T->arena->other, CL_Message);
|
||||||
result->kind = CLM_WARNING;
|
result->kind = CLM_WARNING;
|
||||||
result->string = "Unhandled character, skipping ...";
|
result->string = (char *)"Unhandled character, skipping ...";
|
||||||
CL_SLL_QUEUE_ADD(T->first_message, T->last_message, result);
|
CL_SLL_QUEUE_ADD(T->first_message, T->last_message, result);
|
||||||
result->token = *token;
|
result->token = *token;
|
||||||
token->kind = CL_COMMENT;
|
token->kind = CL_COMMENT;
|
||||||
@@ -1749,7 +1749,7 @@ CL_PRIVATE_FUNCTION char *CL_ChopLastSlash(CL_Arena *arena, char *str) {
|
|||||||
result = CL_PushStringCopy(arena, str, slash_pos);
|
result = CL_PushStringCopy(arena, str, slash_pos);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = "./";
|
result = (char *)"./";
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
2
clexer.h
2
clexer.h
@@ -410,7 +410,7 @@ CL_INLINE int CL_StringLength(char *string) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
CL_INLINE bool CL_StringsAreEqual(char *a, int64_t alen, char *b, int64_t blen) {
|
CL_INLINE bool CL_StringsAreEqual(char *a, int64_t alen, const char *b, int64_t blen) {
|
||||||
if (alen != blen) return false;
|
if (alen != blen) return false;
|
||||||
for (int i = 0; i < alen; i += 1) {
|
for (int i = 0; i < alen; i += 1) {
|
||||||
if (a[i] != b[i]) return false;
|
if (a[i] != b[i]) return false;
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#include "../core.c"
|
|
||||||
int main() {
|
|
||||||
MA_Arena arena = {0};
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#include "../core.c"
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
MA_Arena arena = {};
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
IO_Printf("test_filesystem.c - ");
|
IO_Printf("test_filesystem.c - ");
|
||||||
MA_Arena arena = {};
|
MA_Arena arena = {0};
|
||||||
S8_String read_file_path = S8_Lit("../test/data/read_file");
|
S8_String read_file_path = S8_Lit("../test/data/read_file");
|
||||||
|
|
||||||
// Read file test
|
// Read file test
|
||||||
|
|||||||
Reference in New Issue
Block a user