107 lines
2.6 KiB
C
107 lines
2.6 KiB
C
#include <stdio.h>
|
|
#define NOB_IMPLEMENTATION
|
|
#define NOB_STRIP_PREFIX
|
|
#include "nob.h"
|
|
|
|
#define BUILD_FOLDER "build/"
|
|
#define SRC_FOLDER "src/"
|
|
|
|
#define len NOB_ARRAY_LEN
|
|
|
|
const char *sources[] = {
|
|
"comp", "wayland",
|
|
"glfw", "vulkan",
|
|
"kitty", "string",
|
|
"gpu_allocator", "hashmap",
|
|
"util", "io",
|
|
"matrix", "paw_da",
|
|
"image", "types",
|
|
"paw_allocator", "paw_log",
|
|
"paw_object", "register",
|
|
"lang/ast", "lang/vstack",
|
|
"lang/ast_disc", "lang/functable",
|
|
"lang/glue", "Wayland/xdg-shell-protocol",
|
|
};
|
|
const char *cflags[] = {"-g", "-rdynamic", "-lm", "-lwayland-client",
|
|
"-lxkbcommon", "-lvulkan", "-lglfw"};
|
|
|
|
bool discover_build() {
|
|
Nob_File_Paths src_paths = {0};
|
|
if (!read_entire_dir(SRC_FOLDER, &src_paths)) {
|
|
exit(1);
|
|
}
|
|
|
|
for (int i = 0; i < src_paths.count; i++) {
|
|
if (*src_paths.items[i] == '.') {
|
|
continue;
|
|
}
|
|
char *path = temp_sprintf("%s%s", SRC_FOLDER, src_paths.items[i]);
|
|
printf("%s\n", path);
|
|
switch (get_file_type(path)) {
|
|
case NOB_FILE_REGULAR:
|
|
break;
|
|
case NOB_FILE_DIRECTORY:;
|
|
if (!mkdir_if_not_exists(
|
|
temp_sprintf("%s%s", BUILD_FOLDER, src_paths.items[i]))) {
|
|
return 1;
|
|
}
|
|
break;
|
|
case NOB_FILE_SYMLINK:
|
|
nob_log(ERROR, "symlink");
|
|
exit(1);
|
|
case NOB_FILE_OTHER:
|
|
nob_log(ERROR, "other");
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
NOB_GO_REBUILD_URSELF(argc, argv);
|
|
|
|
/* if (!discover_build()) { */
|
|
/* return 1; */
|
|
/* } */
|
|
/* return 0; */
|
|
|
|
if (!mkdir_if_not_exists(BUILD_FOLDER)) {
|
|
return 1;
|
|
}
|
|
|
|
if (!mkdir_if_not_exists(BUILD_FOLDER "lang/")) {
|
|
return 1;
|
|
}
|
|
if (!mkdir_if_not_exists(BUILD_FOLDER "Wayland/")) {
|
|
return 1;
|
|
}
|
|
|
|
Procs procs = {0};
|
|
Cmd cmd = {0};
|
|
|
|
for (int i = 0; i < len(sources); i++) {
|
|
cmd_append(&cmd, "cc", "-c");
|
|
for (int j = 0; j < len(cflags); j++) {
|
|
cmd_append(&cmd, cflags[j]);
|
|
}
|
|
cmd_append(&cmd, "-o",
|
|
temp_sprintf("%s%s%s", BUILD_FOLDER, sources[i], ".o"),
|
|
temp_sprintf("%s%s%s", SRC_FOLDER, sources[i], ".c"));
|
|
da_append(&procs, cmd_run_async_and_reset(&cmd));
|
|
}
|
|
|
|
if (!procs_wait_and_reset(&procs)) {
|
|
return 1;
|
|
}
|
|
|
|
cmd_append(&cmd, "cc");
|
|
for (int j = 0; j < len(cflags); j++) {
|
|
cmd_append(&cmd, cflags[j]);
|
|
}
|
|
cmd_append(&cmd, "-o", BUILD_FOLDER "main", "main.c");
|
|
for (int i = 0; i < len(sources); i++) {
|
|
cmd_append(&cmd, temp_sprintf("%s%s%s", BUILD_FOLDER, sources[i], ".o"));
|
|
}
|
|
cmd_run_sync_and_reset(&cmd);
|
|
|
|
return 0;
|
|
}
|