diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-26 14:06:30 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-26 14:06:30 -0400 |
| commit | ffab48769be00a7f8b846df95c6598beb19a70f3 (patch) | |
| tree | a28f4efb71f8d6c3730e61957b15a47c88116f9c | |
| parent | 01ccc0e8acb2ff1e0ed2a9bbf687e27853ab645d (diff) | |
Rebuild files when build configuration (e.g. optimization level or C
compiler) changes
| -rw-r--r-- | src/tomo.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -80,6 +80,8 @@ static OptionalText_t optimization = Text("2"), cc = Text(DEFAULT_C_COMPILER); +static Text_t config_summary; + static void transpile_header(env_t *base_env, Path_t path); static void transpile_code(env_t *base_env, Path_t path); static void compile_object_file(Path_t path); @@ -211,6 +213,8 @@ int main(int argc, char *argv[]) if (show_codegen.length > 0 && Text$equal_values(show_codegen, Text("pretty"))) show_codegen = Text("{ sed '/^#line/d;/^$/d' | indent -o /dev/stdout | bat -l c -P; }"); + config_summary = Text$from_str(String(cc, " ", cflags, " -O", optimization)); + for (int64_t i = 0; i < uninstall.length; i++) { Text_t *u = (Text_t*)(uninstall.data + i*uninstall.stride); system(String("rm -rvf '"TOMO_HOME"'/installed/", *u, " '"TOMO_HOME"'/lib/lib", *u, SHARED_SUFFIX)); @@ -613,6 +617,13 @@ void compile_files(env_t *env, List_t to_compile, List_t *object_files, List_t * } } +static bool is_config_outdated(Path_t path) +{ + OptionalText_t config = Path$read(build_file(path, ".config")); + if (config.length < 0) return true; + return !Text$equal_values(config, config_summary); +} + void build_file_dependency_graph(Path_t path, Table_t *to_compile, Table_t *to_link) { if (Table$get(*to_compile, &path, Table$info(&Path$info, &Byte$info))) @@ -624,7 +635,8 @@ void build_file_dependency_graph(Path_t path, Table_t *to_compile, Table_t *to_l }; staleness.o = staleness.c || staleness.h || is_stale(build_file(path, ".o"), build_file(path, ".c")) - || is_stale(build_file(path, ".o"), build_file(path, ".h")); + || is_stale(build_file(path, ".o"), build_file(path, ".h")) + || is_config_outdated(path); Table$set(to_compile, &path, &staleness, Table$info(&Path$info, &Byte$info)); assert(Text$equal_values(Path$extension(path, true), Text("tm"))); @@ -783,6 +795,8 @@ void compile_object_file(Path_t path) if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) exit(EXIT_FAILURE); + Path$write(build_file(path, ".config"), config_summary, 0644); + if (!quiet) print("Compiled object:\t", obj_file); } |
