-
Notifications
You must be signed in to change notification settings - Fork 102
/
nob.c
112 lines (100 loc) · 5.16 KB
/
nob.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#define NOB_IMPLEMENTATION
#include "./nob.h"
#define CONFIG_PATH "./build/config.h"
void generate_default_config(Nob_String_Builder *content)
{
nob_sb_append_cstr(content, "//// Build target. Pick only one!\n");
#ifdef _WIN32
# if defined(_MSC_VER)
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_LINUX\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MINGW\n");
nob_sb_append_cstr(content, "#define MUSIALIZER_TARGET_WIN64_MSVC\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_MACOS\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_OPENBSD\n");
# else
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_LINUX\n");
nob_sb_append_cstr(content, "#define MUSIALIZER_TARGET_WIN64_MINGW\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MSVC\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_MACOS\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_OPENBSD\n");
# endif
#elif defined (__APPLE__) || defined (__MACH__)
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_LINUX\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MINGW\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MSVC\n");
nob_sb_append_cstr(content, "#define MUSIALIZER_TARGET_MACOS\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_OPENBSD\n");
#elif defined(__OpenBSD__)
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_LINUX\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MINGW\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MSVC\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_MACOS\n");
nob_sb_append_cstr(content, "#define MUSIALIZER_TARGET_OPENBSD\n");
#else
nob_sb_append_cstr(content, "#define MUSIALIZER_TARGET_LINUX\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MINGW\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_WIN64_MSVC\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_MACOS\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_TARGET_OPENBSD\n");
#endif
nob_sb_append_cstr(content, "\n");
nob_sb_append_cstr(content, "//// Moves everything in src/plug.c to a separate \"DLL\" so it can be hotreloaded. Works only for Linux right now\n");
// TODO: FIX ASAP! This requires bootstrapping nob with additional flags which goes against its philosophy!
#ifdef MUSIALIZER_HOTRELOAD
nob_sb_append_cstr(content, "#define MUSIALIZER_HOTRELOAD\n");
#else
nob_sb_append_cstr(content, "// #define MUSIALIZER_HOTRELOAD\n");
#endif
nob_sb_append_cstr(content, "\n");
nob_sb_append_cstr(content, "//// Don't bundle resources/ folder with the executable and load the resources directly from the folder.\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_UNBUNDLE\n");
nob_sb_append_cstr(content, "\n");
nob_sb_append_cstr(content, "//// Unfinished feature that enables capturing sound from the mic.\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_MICROPHONE\n");
nob_sb_append_cstr(content, "\n");
nob_sb_append_cstr(content, "//// Activate UI buttons on Press instead of Release just as John Carmack explained https://twitter.com/ID_AA_Carmack/status/1787850053912064005\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_ACT_ON_PRESS\n");
}
int main(int argc, char **argv)
{
NOB_GO_REBUILD_URSELF(argc, argv);
const char *program = nob_shift_args(&argc, &argv);
const char *build_conf_path = "./build/build.conf";
int build_conf_exists = nob_file_exists(build_conf_path);
if (build_conf_exists < 0) return 1;
if (build_conf_exists) {
// @backcomp
nob_log(NOB_ERROR, "We found %s. That means your build folder has an old schema.", build_conf_path);
nob_log(NOB_ERROR, "Instead of %s you are suppose to use %s to configure the build now.", build_conf_path, CONFIG_PATH);
nob_log(NOB_ERROR, "Remove your ./build/ folder and run %s again to regenerate the folder with the new schema.", program);
return 1;
}
nob_log(NOB_INFO, "--- STAGE 1 ---");
if (!nob_mkdir_if_not_exists("build")) return 1;
int config_exists = nob_file_exists(CONFIG_PATH);
if (config_exists < 0) return 1;
if (config_exists == 0) {
nob_log(NOB_INFO, "Generating %s", CONFIG_PATH);
Nob_String_Builder content = {0};
generate_default_config(&content);
if (!nob_write_entire_file(CONFIG_PATH, content.items, content.count)) return 1;
} else {
nob_log(NOB_INFO, "file `%s` already exists", CONFIG_PATH);
}
Nob_Cmd cmd = {0};
const char *configured_binary = "build/nob.configured";
nob_cmd_append(&cmd, NOB_REBUILD_URSELF(configured_binary, "./src_build/nob_configured.c"));
if (!nob_cmd_run_sync(cmd)) return 1;
cmd.count = 0;
nob_cmd_append(&cmd, configured_binary);
nob_da_append_many(&cmd, argv, argc);
if (!nob_cmd_run_sync(cmd)) return 1;
return 0;
}