stuff
This commit is contained in:
parent
9131431144
commit
7e19a1c169
97
build.c
97
build.c
@ -11,7 +11,7 @@ void Error(String msg)
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Compile command
|
||||
* Step
|
||||
* ========================== */
|
||||
|
||||
typedef struct StepListNode StepListNode;
|
||||
@ -68,6 +68,47 @@ void RcIncludeListAppend(Arena *arena, RcIncludeList *l, D_Tag tag, String rc_ty
|
||||
++l->count;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Depfile
|
||||
*
|
||||
* TODO: Migrate this to buildit
|
||||
* ========================== */
|
||||
|
||||
void AddDependenciesFromDepFile(Arena *arena, D_Tag file, D_Tag dep_file)
|
||||
{
|
||||
TempArena scratch = ScratchBegin(arena);
|
||||
|
||||
D_AddDependency(file, dep_file);
|
||||
{
|
||||
String dep_file_data = D_ReadAll(scratch.arena, dep_file);
|
||||
StringList patterns = { 0 };
|
||||
StringListAppend(scratch.arena, &patterns, Lit("\r\n"));
|
||||
StringListAppend(scratch.arena, &patterns, Lit("\n"));
|
||||
StringList lines = StringSplit(scratch.arena, dep_file_data, patterns);
|
||||
for (StringListNode *dn = lines.first; dn; dn = dn->next) {
|
||||
String line = dn->string;
|
||||
line = StringReplace(scratch.arena, line, Lit("\\ "), Lit(" "));
|
||||
if (StringEndsWith(line, Lit(" \\"))) {
|
||||
line.len -= 2;
|
||||
}
|
||||
if (StringBeginsWith(line, Lit(" "))) {
|
||||
line.len -= 2;
|
||||
line.text += 2;
|
||||
}
|
||||
if (!StringEndsWith(line, Lit(":"))) {
|
||||
D_Tag tag = D_FileTagFromPath(scratch.arena, line);
|
||||
if (!D_TagEqual(tag, file)) {
|
||||
String line_copy = StringCopy(arena, line);
|
||||
D_Tag tag_copy = D_FileTagFromPath(arena, line_copy);
|
||||
D_AddDependency(file, tag_copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScratchEnd(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Build
|
||||
* ========================== */
|
||||
@ -76,6 +117,8 @@ void OnBuild(StringList cli_args)
|
||||
{
|
||||
Arena arena = ArenaAlloc(Gigabyte(64));
|
||||
|
||||
OS_TimeStamp start = OS_GetTimeStamp();
|
||||
|
||||
/* ========================== *
|
||||
* Read args
|
||||
* ========================== */
|
||||
@ -126,6 +169,7 @@ void OnBuild(StringList cli_args)
|
||||
}
|
||||
|
||||
String hist_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/.dephist"), FmtStr(arg_outdir)));
|
||||
String out_dep_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/dep/"), FmtStr(arg_outdir)));
|
||||
String out_obj_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/obj/"), FmtStr(arg_outdir)));
|
||||
String out_inc_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/inc/"), FmtStr(arg_outdir)));
|
||||
String out_bin_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/bin/"), FmtStr(arg_outdir)));
|
||||
@ -232,16 +276,16 @@ void OnBuild(StringList cli_args)
|
||||
StringListAppend(&arena, &compile_args, StringF(&arena, Lit("/Fd\"%F\\\""), FmtStr(out_bin_dir_path)));
|
||||
} else {
|
||||
/* Clang */
|
||||
StringListAppend(&arena, &c_compile_args, Lit("clang -xc -std=c99 -c %F -o %F -MD"));
|
||||
StringListAppend(&arena, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c %F -o %F -MD"));
|
||||
StringListAppend(&arena, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c %F -o %F -MD"));
|
||||
StringListAppend(&arena, &pch_cpp_compile_args, Lit("clang -xc++-header -std=c++20 -c %F -o %F -MD"));
|
||||
StringListAppend(&arena, &c_compile_args, Lit("clang -xc -std=c99 -c \"%F\" -o \"%F\""));
|
||||
StringListAppend(&arena, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c \"%F\" -o \"%F\""));
|
||||
StringListAppend(&arena, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c \"%F\" -o \"%F\""));
|
||||
StringListAppend(&arena, &pch_cpp_compile_args, Lit("clang -xc++-header -std=c++20 -c \"%F\" -o \"%F\""));
|
||||
StringListAppend(&arena, &rc_compile_args, Lit("llvm-rc /fo\"%F\" \"%F\""));
|
||||
|
||||
#if 0
|
||||
StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_c_file.full_path)));
|
||||
StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_cpp_file.full_path)));
|
||||
#endif
|
||||
StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("-MD -MF \"%F\""), FmtStr(out_dep_dir_path)));
|
||||
StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("-MD -MF \"%F\""), FmtStr(out_dep_dir_path)));
|
||||
StringListAppend(&arena, &pch_c_compile_args, StringF(&arena, Lit("-MD -MF \"%F\""), FmtStr(out_dep_dir_path)));
|
||||
StringListAppend(&arena, &pch_cpp_compile_args, StringF(&arena, Lit("-MD -MF \"%F\""), FmtStr(out_dep_dir_path)));
|
||||
|
||||
|
||||
StringListAppend(&arena, &link_args, Lit("clang %F"));
|
||||
@ -475,32 +519,7 @@ void OnBuild(StringList cli_args)
|
||||
String dep_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension));
|
||||
dep_file = D_FileTagFromPath(&arena, dep_file_path);
|
||||
}
|
||||
D_AddDependency(file, dep_file);
|
||||
|
||||
{
|
||||
String dep_file_data = D_ReadAll(&arena, dep_file);
|
||||
StringList patterns = { 0 };
|
||||
StringListAppend(&arena, &patterns, Lit("\r\n"));
|
||||
StringListAppend(&arena, &patterns, Lit("\n"));
|
||||
StringList lines = StringSplit(&arena, dep_file_data, patterns);
|
||||
for (StringListNode *dn = lines.first; dn; dn = dn->next) {
|
||||
String line = dn->string;
|
||||
line = StringReplace(&arena, line, Lit("\\ "), Lit(" "));
|
||||
if (StringEndsWith(line, Lit(" \\"))) {
|
||||
line.len -= 2;
|
||||
}
|
||||
if (StringBeginsWith(line, Lit(" "))) {
|
||||
line.len -= 2;
|
||||
line.text += 2;
|
||||
}
|
||||
if (!StringEndsWith(line, Lit(":"))) {
|
||||
D_Tag tag = D_FileTagFromPath(&arena, line);
|
||||
if (!D_TagEqual(tag, file)) {
|
||||
D_AddDependency(file, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AddDependenciesFromDepFile(&arena, file, dep_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -665,10 +684,10 @@ void OnBuild(StringList cli_args)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SH_Print(Lit("Nothing to build"));
|
||||
SH_Print(Lit("No work to do\n"));
|
||||
}
|
||||
if (!success) {
|
||||
Error(Lit("Build failed"));
|
||||
Error(Lit("Build failed\n"));
|
||||
OS_Exit(1);
|
||||
}
|
||||
}
|
||||
@ -679,6 +698,10 @@ void OnBuild(StringList cli_args)
|
||||
|
||||
D_WriteStateToHistFile(hist_path);
|
||||
|
||||
OS_TimeStamp end = OS_GetTimeStamp();
|
||||
F64 seconds = OS_SecondsFromTimeStamp(end - start);
|
||||
SH_PrintF(Lit("Finished in %F seconds\n"), FmtF64P(seconds, 5));
|
||||
|
||||
#if 0
|
||||
#if Rtc
|
||||
getchar();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user