From dbe7ba827a7650a5f2fcedcb961723989e260490 Mon Sep 17 00:00:00 2001 From: Mark Reuter <13319190+reutermj@users.noreply.github.com> Date: Sun, 11 Aug 2024 12:37:26 -0700 Subject: [PATCH] Add amalgamate-path to project.json Add field amalgamate-path to project.json to configure the output subdirectory of project path for the amalgamted source and header. --- drivers/amalgamate/src/main.c | 21 +++++++++++++++------ include/bake/project.h | 1 + src/project.c | 3 +++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/amalgamate/src/main.c b/drivers/amalgamate/src/main.c index 4e6bf7c..95af663 100644 --- a/drivers/amalgamate/src/main.c +++ b/drivers/amalgamate/src/main.c @@ -324,24 +324,32 @@ void generate( target_path = project_obj->generate_path; } + char *output_path; + if (project_obj->amalgamate_path) { + output_path = ut_asprintf("%s/%s", target_path, project_obj->amalgamate_path); + ut_mkdir(output_path); + } else { + output_path = ut_asprintf("%s", target_path); + } + /* Create output file strings & check when they were last modified */ - char *include_file_out = ut_asprintf("%s/%s.h", target_path, project); - char *include_file_tmp = ut_asprintf("%s/%s.h.tmp", target_path, project); + char *include_file_out = ut_asprintf("%s/%s.h", output_path, project); + char *include_file_tmp = ut_asprintf("%s/%s.h.tmp", output_path, project); time_t include_modified = 0; if (ut_file_test(include_file_out) == 1) { include_modified = ut_lastmodified(include_file_out); } - char *src_file_out = ut_asprintf("%s/%s.c", target_path, project); - char *src_file_tmp = ut_asprintf("%s/%s.c.tmp", target_path, project); + char *src_file_out = ut_asprintf("%s/%s.c", output_path, project); + char *src_file_tmp = ut_asprintf("%s/%s.c.tmp", output_path, project); time_t src_modified = 0; if (ut_file_test(src_file_out) == 1) { src_modified = ut_lastmodified(src_file_out); } /* In case project contains Objective C files */ - char *m_file_out = ut_asprintf("%s/%s_objc.m", target_path, project); - char *m_file_tmp = ut_asprintf("%s/%s_objc.m.tmp", target_path, project); + char *m_file_out = ut_asprintf("%s/%s_objc.m", output_path, project); + char *m_file_tmp = ut_asprintf("%s/%s_objc.m.tmp", output_path, project); time_t m_modified = 0; if (ut_file_test(m_file_out) == 1) { m_modified = ut_lastmodified(m_file_out); @@ -489,6 +497,7 @@ void generate( free(src_file_tmp); free(src_path); free(include_path); + free(output_path); ut_rb_free(files_parsed); ut_rb_free(objc_files_parsed); diff --git a/include/bake/project.h b/include/bake/project.h index d0be3cc..9612a4b 100644 --- a/include/bake/project.h +++ b/include/bake/project.h @@ -90,6 +90,7 @@ struct bake_project { bool public; /* Is package public or private */ bool coverage; /* Include in coverage analysis (default = true) */ bool amalgamate; /* Generate amalgamated source (default = false) */ + char *amalgamate_path; /* Output subdirectory project path for amalgamated source (default = .) */ bool standalone; /* Copy amalgamated sources from dependencies (default = false) */ bool recursive; /* Is this project recursively built */ ut_ll use; /* Project dependencies */ diff --git a/src/project.c b/src/project.c index 29c84b0..c9e18c2 100644 --- a/src/project.c +++ b/src/project.c @@ -376,6 +376,9 @@ int16_t bake_project_parse_value( if (!strcmp(member, "amalgamate")) { ut_try (bake_json_set_boolean(&p->amalgamate, member, v), NULL); } else + if (!strcmp(member, "amalgamate_path") || !strcmp(member, "amalgamate-path")) { + ut_try (bake_json_set_string(&p->amalgamate_path, member, v), NULL); + } else if (!strcmp(member, "standalone") || !strcmp(member, "standalone")) { ut_try (bake_json_set_boolean(&p->standalone, member, v), NULL); } else