Repository: lucy Updated Branches: refs/heads/master 6f1efa315 -> c0e4d81d8
Switch to new Charmonizer Make API Rework the Charmonizer fragment to use the new API to build binaries. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/68e4662f Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/68e4662f Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/68e4662f Branch: refs/heads/master Commit: 68e4662ff725e5ec94732afaba4f04d41210872c Parents: 6f1efa3 Author: Nick Wellnhofer <[email protected]> Authored: Wed Jul 6 13:15:04 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Wed Jul 6 13:23:08 2016 +0200 ---------------------------------------------------------------------- common/charmonizer.main | 305 ++++++++++++++++--------------------------- 1 file changed, 110 insertions(+), 195 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/68e4662f/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/common/charmonizer.main b/common/charmonizer.main index cbc6c5b..1b676ce 100644 --- a/common/charmonizer.main +++ b/common/charmonizer.main @@ -38,8 +38,9 @@ #include "Charmonizer/Core/ConfWriterRuby.h" typedef struct lucy_MakeFile { - chaz_MakeFile *makefile; - chaz_CLI *cli; + chaz_CLI *cli; + chaz_MakeFile *makefile; + chaz_MakeBinary *lib; /* Directories. */ const char *base_dir; @@ -54,21 +55,15 @@ typedef struct lucy_MakeFile { char *snowstop_dir; char *ucd_dir; char *utf8proc_dir; + char *json_dir; /* Files. */ char *autogen_target; const char **autogen_src_files; - char *json_parser; /* Clownfish library. */ char *cfish_lib_dir; const char *cfish_lib_name; - - /* Lucy libraries. */ - chaz_Lib *shared_lib; - chaz_Lib *static_lib; - char *shared_lib_filename; - char *static_lib_filename; } lucy_MakeFile; typedef struct SourceFileContext { @@ -97,9 +92,6 @@ static void lucy_MakeFile_write_c_test_rules(lucy_MakeFile *self); static void -S_c_file_callback(const char *dir, char *file, void *context); - -static void S_cfh_file_callback(const char *dir, char *file, void *context); static int @@ -174,11 +166,6 @@ int main(int argc, const char **argv) { if (chaz_CLI_defined(cli, "enable-makefile")) { lucy_MakeFile *mf = lucy_MakeFile_new(cli); lucy_MakeFile_write(mf); - /* Export filenames. */ - chaz_ConfWriter_add_def("SHARED_LIB_FILENAME", - mf->shared_lib_filename); - chaz_ConfWriter_add_def("STATIC_LIB_FILENAME", - mf->static_lib_filename); lucy_MakeFile_destroy(mf); } @@ -229,9 +216,6 @@ S_add_compiler_flags(struct chaz_CLI *cli) { } } - chaz_CFlags_add_define(extra_cflags, "CFP_LUCY", NULL); - chaz_CFlags_add_define(extra_cflags, "CFP_TESTLUCY", NULL); - chaz_CFlags_hide_symbols(extra_cflags); } @@ -242,8 +226,9 @@ lucy_MakeFile_new(chaz_CLI *cli) { lucy_MakeFile *self = malloc(sizeof(lucy_MakeFile)); - self->makefile = chaz_MakeFile_new(); self->cli = cli; + self->makefile = chaz_MakeFile_new(); + self->lib = NULL; /* Initialize directories. */ self->base_dir = ".."; @@ -276,31 +261,31 @@ lucy_MakeFile_new(chaz_CLI *cli) { self->utf8proc_dir = chaz_Util_join(dir_sep, self->modules_dir, "unicode", "utf8proc", NULL); + self->json_dir + = chaz_Util_join(dir_sep, self->core_dir, "Lucy", "Util", "Json", + NULL); /* Initialize file names. */ if (chaz_CLI_defined(cli, "enable-perl")) { static const char *perl_autogen_src_files[] = { - "boot", - "callbacks", - "lucy_parcel", - "testlucy_parcel", + "boot.c", + "callbacks.c", + "lucy_parcel.c", + "testlucy_parcel.c", NULL }; self->autogen_src_files = perl_autogen_src_files; } else { static const char *c_autogen_src_files[] = { - "lucy_parcel", - "testlucy_parcel", + "lucy_parcel.c", + "testlucy_parcel.c", NULL }; self->autogen_src_files = c_autogen_src_files; } self->autogen_target = chaz_Util_join(dir_sep, "autogen", "hierarchy.json", NULL); - self->json_parser - = chaz_Util_join(dir_sep, self->core_dir, "Lucy", "Util", "Json", - "JsonParser", NULL); /* Clownfish library. */ if (cfish_prefix) { @@ -317,13 +302,6 @@ lucy_MakeFile_new(chaz_CLI *cli) { self->cfish_lib_name = "cfish"; } - /* Lucy libraries. */ - self->shared_lib = chaz_Lib_new_shared("lucy", lucy_version, - lucy_major_version); - self->static_lib = chaz_Lib_new_static("lucy"); - self->shared_lib_filename = chaz_Lib_filename(self->shared_lib); - self->static_lib_filename = chaz_Lib_filename(self->static_lib); - return self; } @@ -341,34 +319,27 @@ lucy_MakeFile_destroy(lucy_MakeFile *self) { free(self->snowstop_dir); free(self->ucd_dir); free(self->utf8proc_dir); + free(self->json_dir); free(self->autogen_target); - free(self->json_parser); free(self->cfish_lib_dir); - chaz_Lib_destroy(self->shared_lib); - chaz_Lib_destroy(self->static_lib); - free(self->shared_lib_filename); - free(self->static_lib_filename); - free(self); } static void lucy_MakeFile_write(lucy_MakeFile *self) { - SourceFileContext sfc; - const char *dir_sep = chaz_OS_dir_sep(); - const char *obj_ext = chaz_CC_obj_ext(); + const char *host = chaz_CLI_strval(self->cli, "host"); const char *math_lib = chaz_Floats_math_library(); chaz_MakeVar *var; chaz_MakeRule *rule; - chaz_MakeRule *clean_rule; chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags(); chaz_CFlags *makefile_cflags; + chaz_CFlags *compile_flags; chaz_CFlags *link_flags; char *scratch; @@ -389,7 +360,6 @@ lucy_MakeFile_write(lucy_MakeFile *self) { chaz_CFlags_enable_optimization(makefile_cflags); chaz_CFlags_enable_debugging(makefile_cflags); chaz_CFlags_disable_strict_aliasing(makefile_cflags); - chaz_CFlags_compile_shared_library(makefile_cflags); if (chaz_CLI_defined(self->cli, "enable-coverage")) { chaz_CFlags_enable_code_coverage(makefile_cflags); } @@ -408,105 +378,96 @@ lucy_MakeFile_write(lucy_MakeFile *self) { chaz_CFlags_destroy(makefile_cflags); - /* Object files */ + /* Binary. */ - var = chaz_MakeFile_add_var(self->makefile, "LUCY_OBJS", NULL); - sfc.var = var; + if (strcmp(host, "c") == 0 || strcmp(host, "perl") == 0) { + chaz_MakeFile_add_rule(self->makefile, "all", "$(LUCY_SHARED_LIB)"); - chaz_Make_list_files(self->host_src_dir, "c", S_c_file_callback, &sfc); - chaz_Make_list_files(self->core_dir, "c", S_c_file_callback, &sfc); - chaz_Make_list_files(self->snowstem_dir, "c", S_c_file_callback, &sfc); - chaz_Make_list_files(self->snowstop_dir, "c", S_c_file_callback, &sfc); - chaz_Make_list_files(self->utf8proc_dir, "c", S_c_file_callback, &sfc); + self->lib + = chaz_MakeFile_add_shared_lib(self->makefile, NULL, "lucy", + lucy_version, lucy_major_version); + rule = chaz_MakeFile_add_rule(self->makefile, + "$(LUCY_SHARED_LIB_OBJS)", + self->autogen_target); + /* + * The dependency is actually on JsonParser.h, but make doesn't cope + * well with multiple output files. + */ + scratch = chaz_Util_join(dir_sep, self->json_dir, "JsonParser.c", + NULL); + chaz_MakeRule_add_prereq(rule, scratch); + free(scratch); - scratch = chaz_Util_join("", self->json_parser, obj_ext, NULL); - chaz_MakeVar_append(var, scratch); - free(scratch); + link_flags = chaz_MakeBinary_get_link_flags(self->lib); + chaz_CFlags_enable_debugging(link_flags); + if (self->cfish_lib_dir) { + chaz_CFlags_add_library_path(link_flags, self->cfish_lib_dir); + } + if (math_lib) { + chaz_CFlags_add_external_lib(link_flags, math_lib); + } + chaz_CFlags_add_external_lib(link_flags, self->cfish_lib_name); + if (chaz_HeadCheck_check_header("pcre.h")) { + chaz_CFlags_add_external_lib(link_flags, "pcre"); + } + if (chaz_CLI_defined(self->cli, "enable-coverage")) { + chaz_CFlags_enable_code_coverage(link_flags); + } + } + else { + chaz_MakeFile_add_rule(self->makefile, "static", "$(LUCY_STATIC_LIB)"); - for (i = 0; self->autogen_src_files[i] != NULL; ++i) { - char *path = chaz_Util_join("", self->autogen_src_dir, dir_sep, - self->autogen_src_files[i], obj_ext, NULL); - chaz_MakeVar_append(var, path); - free(path); + self->lib + = chaz_MakeFile_add_static_lib(self->makefile, NULL, "lucy"); + rule = chaz_MakeFile_add_rule(self->makefile, + "$(LUCY_STATIC_LIB_OBJS)", + self->autogen_target); + scratch = chaz_Util_join(dir_sep, self->json_dir, "JsonParser.c", + NULL); + chaz_MakeRule_add_prereq(rule, scratch); + free(scratch); } - /* Rules */ + chaz_MakeBinary_add_src_dir(self->lib, self->host_src_dir); + chaz_MakeBinary_add_src_dir(self->lib, self->core_dir); + chaz_MakeBinary_add_src_dir(self->lib, self->snowstem_dir); + chaz_MakeBinary_add_src_dir(self->lib, self->snowstop_dir); + chaz_MakeBinary_add_src_dir(self->lib, self->utf8proc_dir); - scratch = chaz_Util_join(" ", self->shared_lib_filename, - self->static_lib_filename, NULL); - chaz_MakeFile_add_rule(self->makefile, "all", scratch); - free(scratch); + chaz_MakeBinary_add_src_file(self->lib, self->json_dir, "JsonParser.c"); + + for (i = 0; self->autogen_src_files[i] != NULL; ++i) { + chaz_MakeBinary_add_src_file(self->lib, self->autogen_src_dir, + self->autogen_src_files[i]); + } + + compile_flags = chaz_MakeBinary_get_compile_flags(self->lib); + chaz_CFlags_add_define(compile_flags, "CFP_LUCY", NULL); + chaz_CFlags_add_define(compile_flags, "CFP_TESTLUCY", NULL); - chaz_MakeFile_add_rule(self->makefile, "static", self->static_lib_filename); + /* Additional rules. */ chaz_MakeFile_add_lemon_exe(self->makefile, self->lemon_dir); - chaz_MakeFile_add_lemon_grammar(self->makefile, self->json_parser); + scratch = chaz_Util_join(dir_sep, self->json_dir, "JsonParser", NULL); + chaz_MakeFile_add_lemon_grammar(self->makefile, scratch); + free(scratch); - if (!chaz_CLI_defined(self->cli, "enable-perl")) { + if (strcmp(host, "c") == 0) { lucy_MakeFile_write_c_cfc_rules(self); + lucy_MakeFile_write_c_test_rules(self); } /* Needed for parallel builds. */ for (i = 0; self->autogen_src_files[i] != NULL; ++i) { char *path = chaz_Util_join("", self->autogen_src_dir, dir_sep, - self->autogen_src_files[i], ".c", NULL); + self->autogen_src_files[i], NULL); rule = chaz_MakeFile_add_rule(self->makefile, path, self->autogen_target); free(path); } - rule = chaz_MakeFile_add_rule(self->makefile, "$(LUCY_OBJS)", - self->autogen_target); - /* - * The dependency is actually on JsonParser.h, but make doesn't cope - * well with multiple output files. - */ - scratch = chaz_Util_join(".", self->json_parser, "c", NULL); - chaz_MakeRule_add_prereq(rule, scratch); - free(scratch); - - link_flags = chaz_CC_new_cflags(); - chaz_CFlags_enable_debugging(link_flags); - if (self->cfish_lib_dir) { - chaz_CFlags_add_library_path(link_flags, self->cfish_lib_dir); - } - if (math_lib) { - chaz_CFlags_add_external_library(link_flags, math_lib); - } - chaz_CFlags_add_external_library(link_flags, self->cfish_lib_name); - if (chaz_HeadCheck_check_header("pcre.h")) { - chaz_CFlags_add_external_library(link_flags, "pcre"); - } - if (chaz_CLI_defined(self->cli, "enable-coverage")) { - chaz_CFlags_enable_code_coverage(link_flags); - } - rule = chaz_MakeFile_add_shared_lib(self->makefile, self->shared_lib, - "$(LUCY_OBJS)", link_flags); - chaz_CFlags_destroy(link_flags); - chaz_MakeFile_add_static_lib(self->makefile, self->static_lib, "$(LUCY_OBJS)"); - - if (!chaz_CLI_defined(self->cli, "enable-perl")) { - lucy_MakeFile_write_c_test_rules(self); - } - - clean_rule = chaz_MakeFile_clean_rule(self->makefile); - - if (chaz_Make_shell_type() == CHAZ_OS_CMD_EXE) { - /* - * The length of the command would exceed the limit of 8191 - * characters. As a work-around, delete all .obj files in BASE_DIR - * using 'del /s /q'. - */ - scratch = chaz_Util_join("", "del /s /q ", self->base_dir, "\\*", - obj_ext, NULL); - chaz_MakeRule_add_command(clean_rule, scratch); - free(scratch); - } - else { - chaz_MakeRule_add_rm_command(clean_rule, "$(LUCY_OBJS)"); - } - - chaz_MakeRule_add_recursive_rm_command(clean_rule, "autogen"); + rule = chaz_MakeFile_clean_rule(self->makefile); + chaz_MakeRule_add_recursive_rm_command(rule, "autogen"); chaz_MakeFile_write(self->makefile); } @@ -546,69 +507,47 @@ lucy_MakeFile_write_c_cfc_rules(lucy_MakeFile *self) { static void lucy_MakeFile_write_c_test_rules(lucy_MakeFile *self) { - const char *dir_sep = chaz_OS_dir_sep(); - const char *exe_ext = chaz_CC_exe_ext(); - const char *obj_ext = chaz_CC_obj_ext(); - - chaz_CFlags *cflags; - chaz_CFlags *link_flags; - chaz_MakeRule *rule; - chaz_MakeRule *clean_rule; - - char *test_lucy_exe; - char *test_lucy_obj; - - clean_rule = chaz_MakeFile_clean_rule(self->makefile); + chaz_MakeBinary *test_exe; + chaz_CFlags *link_flags; + chaz_MakeRule *rule; - test_lucy_exe = chaz_Util_join("", "t", dir_sep, "test_lucy", exe_ext, - NULL); - test_lucy_obj = chaz_Util_join("", "t", dir_sep, "test_lucy", obj_ext, - NULL); - - chaz_MakeFile_add_rule(self->makefile, test_lucy_obj, + test_exe = chaz_MakeFile_add_exe(self->makefile, "t", "test_lucy"); + chaz_MakeBinary_add_src_file(test_exe, "t", "test_lucy.c"); + chaz_MakeFile_add_rule(self->makefile, "$(TEST_LUCY_EXE_OBJS)", self->autogen_target); - - cflags = chaz_CC_new_cflags(); - chaz_CFlags_enable_optimization(cflags); - chaz_CFlags_add_include_dir(cflags, self->autogen_inc_dir); - chaz_MakeFile_override_cflags(self->makefile, test_lucy_obj, cflags); - chaz_CFlags_destroy(cflags); - - link_flags = chaz_CC_new_cflags(); - chaz_CFlags_add_library(link_flags, self->shared_lib); + link_flags = chaz_MakeBinary_get_link_flags(test_exe); + chaz_CFlags_add_shared_lib(link_flags, NULL, "lucy", lucy_major_version); + chaz_MakeBinary_add_prereq(test_exe, "$(LUCY_SHARED_LIB)"); if (self->cfish_lib_dir) { chaz_CFlags_add_library_path(link_flags, self->cfish_lib_dir); } - chaz_CFlags_add_external_library(link_flags, self->cfish_lib_name); - rule = chaz_MakeFile_add_exe(self->makefile, test_lucy_exe, test_lucy_obj, - link_flags); - chaz_MakeRule_add_prereq(rule, self->shared_lib_filename); - chaz_CFlags_destroy(link_flags); + chaz_CFlags_add_external_lib(link_flags, self->cfish_lib_name); - rule = chaz_MakeFile_add_rule(self->makefile, "test", test_lucy_exe); + rule = chaz_MakeFile_add_rule(self->makefile, "test", "$(TEST_LUCY_EXE)"); if (self->cfish_lib_dir) { - chaz_MakeRule_add_command_with_libpath(rule, test_lucy_exe, ".", + chaz_MakeRule_add_command_with_libpath(rule, "$(TEST_LUCY_EXE)", ".", self->cfish_lib_dir, NULL); } else { - chaz_MakeRule_add_command_with_libpath(rule, test_lucy_exe, ".", NULL); + chaz_MakeRule_add_command_with_libpath(rule, "$(TEST_LUCY_EXE)", ".", + NULL); } - chaz_MakeRule_add_rm_command(clean_rule, test_lucy_obj); - if (chaz_CLI_defined(self->cli, "enable-coverage")) { - rule = chaz_MakeFile_add_rule(self->makefile, "coverage", test_lucy_exe); + rule = chaz_MakeFile_add_rule(self->makefile, "coverage", + "$(TEST_LUCY_EXE)"); chaz_MakeRule_add_command(rule, "lcov" " --zerocounters" " --directory $(BASE_DIR)"); if (self->cfish_lib_dir) { - chaz_MakeRule_add_command_with_libpath(rule, test_lucy_exe, ".", - self->cfish_lib_dir, NULL); + chaz_MakeRule_add_command_with_libpath(rule, "$(TEST_LUCY_EXE)", + ".", self->cfish_lib_dir, + NULL); } else { - chaz_MakeRule_add_command_with_libpath(rule, test_lucy_exe, ".", - NULL); + chaz_MakeRule_add_command_with_libpath(rule, "$(TEST_LUCY_EXE)", + ".", NULL); } chaz_MakeRule_add_command(rule, "lcov" @@ -623,33 +562,9 @@ lucy_MakeFile_write_c_test_rules(lucy_MakeFile *self) { " --output-directory coverage" " lucy.info"); - chaz_MakeRule_add_rm_command(clean_rule, "lucy.info"); - chaz_MakeRule_add_recursive_rm_command(clean_rule, "coverage"); - } - - free(test_lucy_exe); - free(test_lucy_obj); -} - -static void -S_c_file_callback(const char *dir, char *file, void *context) { - SourceFileContext *sfc = (SourceFileContext*)context; - const char *dir_sep = chaz_OS_dir_sep(); - const char *obj_ext = chaz_CC_obj_ext(); - size_t file_len = strlen(file); - char *obj_file; - - /* Strip extension */ - if (!S_ends_with(file, ".c")) { - chaz_Util_warn("Unexpected C filename: %s", file); - return; - } - file[file_len-2] = '\0'; - - if (!S_ends_with(file, "JsonParser")) { - obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); - chaz_MakeVar_append(sfc->var, obj_file); - free(obj_file); + rule = chaz_MakeFile_clean_rule(self->makefile); + chaz_MakeRule_add_rm_command(rule, "lucy.info"); + chaz_MakeRule_add_recursive_rm_command(rule, "coverage"); } }
