Repository: lucy-clownfish Updated Branches: refs/heads/master fd9b4c044 -> 32391ee98
Switch to new Charmonizer Make API Rework the Charmonizer fragments to use the new API to build binaries. Build a static library from the core source files of the CFC C build which is used for both the main and test executable. Remove some unnecessary stuff from the Makefiles for other host languages. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/b79b40d3 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b79b40d3 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b79b40d3 Branch: refs/heads/master Commit: b79b40d36419720b743499c6e809719b86fc6401 Parents: fd9b4c0 Author: Nick Wellnhofer <[email protected]> Authored: Wed Jul 6 12:12:22 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Wed Jul 6 12:12:22 2016 +0200 ---------------------------------------------------------------------- compiler/c/.gitignore | 2 + compiler/common/charmonizer.main | 231 ++++++++++++------------------ compiler/src/CFCPerl.c | 16 ++- runtime/common/charmonizer.main | 259 ++++++++++++---------------------- runtime/perl/xs/XSBind.c | 1 + 5 files changed, 196 insertions(+), 313 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b79b40d3/compiler/c/.gitignore ---------------------------------------------------------------------- diff --git a/compiler/c/.gitignore b/compiler/c/.gitignore index bd44f7f..2e64478 100644 --- a/compiler/c/.gitignore +++ b/compiler/c/.gitignore @@ -1,8 +1,10 @@ /Makefile /cfc /cfc.exe +/cfc.lib /charmonizer /charmonizer.exe /charmony.h +/libcfc.a /t/test_cfc /t/test_cfc.exe http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b79b40d3/compiler/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/compiler/common/charmonizer.main b/compiler/common/charmonizer.main index 24fb414..eaf9a29 100644 --- a/compiler/common/charmonizer.main +++ b/compiler/common/charmonizer.main @@ -24,9 +24,8 @@ #include "Charmonizer/Probe/Integers.h" typedef struct SourceFileContext { - chaz_MakeVar *common_objs; - chaz_MakeVar *test_cfc_objs; - chaz_MakeVar *common_test_objs; + chaz_MakeBinary *core_binary; + chaz_MakeBinary *test_binary; } SourceFileContext; static const char cfc_version[] = "0.5.0"; @@ -131,42 +130,30 @@ S_add_compiler_flags(struct chaz_CLI *cli) { } static void -S_add_staticlib_makefile_target(chaz_MakeFile *makefile) { - chaz_Lib *static_lib = chaz_Lib_new_static("cfc"); - char *static_lib_filename = chaz_Lib_filename(static_lib); - chaz_MakeFile_add_rule(makefile, "static", static_lib_filename); - chaz_MakeFile_add_static_lib(makefile, static_lib, "$(COMMON_OBJS)"); - free(static_lib_filename); - chaz_Lib_destroy(static_lib); -} - -static void S_write_makefile(struct chaz_CLI *cli) { SourceFileContext sfc; const char *base_dir = ".."; const char *dir_sep = chaz_OS_dir_sep(); - const char *exe_ext = chaz_CC_exe_ext(); - const char *obj_ext = chaz_CC_obj_ext(); - - char *lemon_dir = chaz_Util_join(dir_sep, base_dir, "..", "lemon", - NULL); - char *src_dir = chaz_Util_join(dir_sep, base_dir, "src", NULL); - char *include_dir = chaz_Util_join(dir_sep, base_dir, "include", NULL); - char *cmark_dir = chaz_Util_join(dir_sep, base_dir, "modules", - "CommonMark", "src", NULL); - char *parse_header = chaz_Util_join(dir_sep, src_dir, "CFCParseHeader", - NULL); - char *cfc_exe = chaz_Util_join("", "cfc", exe_ext, NULL); - char *test_cfc_exe = chaz_Util_join("", "t", dir_sep, "test_cfc", exe_ext, - NULL); - - char *scratch; - - chaz_MakeFile *makefile; - chaz_MakeVar *var; - chaz_MakeRule *rule; - chaz_MakeRule *clean_rule; + const char *host = chaz_CLI_strval(cli, "host"); + + char *lemon_dir = chaz_Util_join(dir_sep, base_dir, "..", "lemon", + NULL); + char *src_dir = chaz_Util_join(dir_sep, base_dir, "src", NULL); + char *include_dir = chaz_Util_join(dir_sep, base_dir, "include", NULL); + char *cmark_dir = chaz_Util_join(dir_sep, base_dir, "modules", + "CommonMark", "src", NULL); + char *parse_header = chaz_Util_join(dir_sep, src_dir, "CFCParseHeader", + NULL); + char *parse_header_c = chaz_Util_join(dir_sep, src_dir, "CFCParseHeader.c", + NULL); + + chaz_MakeFile *makefile = NULL; + chaz_MakeBinary *lib = NULL; + chaz_MakeBinary *exe = NULL; + chaz_MakeBinary *test_exe = NULL; + chaz_MakeVar *var = NULL; + chaz_MakeRule *rule = NULL; chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags(); chaz_CFlags *makefile_cflags; @@ -203,107 +190,89 @@ S_write_makefile(struct chaz_CLI *cli) { chaz_CFlags_destroy(makefile_cflags); - /* Object files */ - - sfc.common_objs = chaz_MakeFile_add_var(makefile, "COMMON_OBJS", NULL); - sfc.test_cfc_objs = chaz_MakeFile_add_var(makefile, "TEST_CFC_OBJS", NULL); - sfc.common_test_objs = chaz_MakeFile_add_var(makefile, "COMMON_TEST_OBJS", NULL); - - chaz_Make_list_files(src_dir, "c", S_source_file_callback, &sfc); - chaz_Make_list_files(cmark_dir, "c", S_source_file_callback, &sfc); - - scratch = chaz_Util_join("", parse_header, obj_ext, NULL); - chaz_MakeVar_append(sfc.common_objs, scratch); - free(scratch); + /* Binaries. */ - scratch = chaz_Util_join("", "t", dir_sep, "test_cfc", obj_ext, NULL); - chaz_MakeVar_append(sfc.test_cfc_objs, scratch); - free(scratch); + if (strcmp(host, "c") == 0) { + chaz_CFlags *link_flags; - scratch = chaz_Util_join("", "cfc", obj_ext, NULL); - chaz_MakeFile_add_var(makefile, "CFC_OBJS", scratch); - free(scratch); + chaz_MakeFile_add_rule(makefile, "all", "$(CFC_EXE)"); - /* Rules */ + exe = chaz_MakeFile_add_exe(makefile, NULL, "cfc"); + chaz_MakeBinary_add_src_file(exe, NULL, "cfc.c"); + chaz_MakeBinary_add_prereq(exe, "$(CFC_STATIC_LIB)"); + link_flags = chaz_MakeBinary_get_link_flags(exe); + chaz_CFlags_append(link_flags, "$(CFC_STATIC_LIB)"); - chaz_MakeFile_add_rule(makefile, "all", cfc_exe); - S_add_staticlib_makefile_target(makefile); + test_exe = chaz_MakeFile_add_exe(makefile, "t", "test_cfc"); + chaz_MakeBinary_add_src_file(test_exe, "t", "test_cfc.c"); + chaz_MakeBinary_add_prereq(test_exe, "$(CFC_STATIC_LIB)"); + link_flags = chaz_MakeBinary_get_link_flags(test_exe); + chaz_CFlags_append(link_flags, "$(CFC_STATIC_LIB)"); + } - chaz_MakeFile_add_lemon_exe(makefile, lemon_dir); - chaz_MakeFile_add_lemon_grammar(makefile, parse_header); + lib = chaz_MakeFile_add_static_lib(makefile, NULL, "cfc"); + chaz_MakeFile_add_rule(makefile, "static", "$(CFC_STATIC_LIB)"); /* * The dependency is actually on CFCParseHeader.h, but make doesn't cope * well with multiple output files. */ - scratch = chaz_Util_join(".", parse_header, "c", NULL); - chaz_MakeFile_add_rule(makefile, "$(COMMON_OBJS)", scratch); - free(scratch); + chaz_MakeFile_add_rule(makefile, "$(CFC_STATIC_LIB_OBJS)", parse_header_c); - link_flags = chaz_CC_new_cflags(); - if (chaz_CC_msvc_version_num()) { - chaz_CFlags_append(link_flags, "/nologo"); - } - if (chaz_CLI_defined(cli, "enable-coverage")) { - chaz_CFlags_enable_code_coverage(link_flags); - } - if (strcmp(chaz_CLI_strval(cli, "host"), "c") == 0) { - chaz_MakeFile_add_exe(makefile, cfc_exe, "$(COMMON_OBJS) $(CFC_OBJS)", - link_flags); - chaz_MakeFile_add_exe(makefile, test_cfc_exe, - "$(COMMON_OBJS) $(COMMON_TEST_OBJS) $(TEST_CFC_OBJS)", - link_flags); - } - chaz_CFlags_destroy(link_flags); - - rule = chaz_MakeFile_add_rule(makefile, "test", "all"); - chaz_MakeRule_add_prereq(rule, test_cfc_exe); - chaz_MakeRule_add_command(rule, test_cfc_exe); - - if (chaz_OS_shell_type() == CHAZ_OS_POSIX) { - rule = chaz_MakeFile_add_rule(makefile, "valgrind", "all"); - chaz_MakeRule_add_prereq(rule, test_cfc_exe); - scratch = chaz_Util_join(" ", "CLOWNFISH_VALGRIND=1", "valgrind", - "--leak-check=full", test_cfc_exe, NULL); - chaz_MakeRule_add_command(rule, scratch); - free(scratch); - } + sfc.core_binary = lib; + sfc.test_binary = test_exe; + chaz_Make_list_files(src_dir, "c", S_source_file_callback, &sfc); + chaz_Make_list_files(cmark_dir, "c", S_source_file_callback, &sfc); - if (chaz_CLI_defined(cli, "enable-coverage")) { - rule = chaz_MakeFile_add_rule(makefile, "coverage", test_cfc_exe); - chaz_MakeRule_add_command(rule, - "lcov" - " --zerocounters" - " --directory $(BASE_DIR)"); - chaz_MakeRule_add_command(rule, test_cfc_exe); - chaz_MakeRule_add_command(rule, - "lcov" - " --capture" - " --directory $(BASE_DIR)" - " --base-directory ." - " --rc lcov_branch_coverage=1" - " --output-file cfc.info"); - chaz_MakeRule_add_command(rule, - "genhtml" - " --branch-coverage" - " --output-directory coverage" - " cfc.info"); - } + chaz_MakeBinary_add_src_file(lib, src_dir, "CFCParseHeader.c"); - clean_rule = chaz_MakeFile_clean_rule(makefile); + /* Rules */ - chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_OBJS)"); - chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_TEST_OBJS)"); - chaz_MakeRule_add_rm_command(clean_rule, "$(CFC_OBJS)"); - chaz_MakeRule_add_rm_command(clean_rule, "$(TEST_CFC_OBJS)"); + chaz_MakeFile_add_lemon_exe(makefile, lemon_dir); + chaz_MakeFile_add_lemon_grammar(makefile, parse_header); - if (chaz_CLI_defined(cli, "enable-coverage")) { - chaz_MakeRule_add_rm_command(clean_rule, "cfc.info"); - chaz_MakeRule_add_recursive_rm_command(clean_rule, "coverage"); - } + if (strcmp(host, "c") == 0) { + rule = chaz_MakeFile_add_rule(makefile, "test", "all"); + chaz_MakeRule_add_prereq(rule, "$(TEST_CFC_EXE)"); + chaz_MakeRule_add_command(rule, "$(TEST_CFC_EXE)"); + + if (chaz_OS_shell_type() == CHAZ_OS_POSIX) { + rule = chaz_MakeFile_add_rule(makefile, "valgrind", "all"); + chaz_MakeRule_add_prereq(rule, "$(TEST_CFC_EXE)"); + chaz_MakeRule_add_command(rule, + "CLOWNFISH_VALGRIND=1 valgrind" + " --leak-check=full" + " $(TEST_CFC_EXE)"); + } - if (chaz_Probe_msvc_version_num()) { - chaz_MakeRule_add_rm_command(clean_rule, "lemon.obj"); + if (chaz_CLI_defined(cli, "enable-coverage")) { + link_flags = chaz_MakeBinary_get_link_flags(test_exe); + chaz_CFlags_enable_code_coverage(link_flags); + + rule = chaz_MakeFile_add_rule(makefile, "coverage", + "$(TEST_CFC_EXE)"); + chaz_MakeRule_add_command(rule, + "lcov" + " --zerocounters" + " --directory $(BASE_DIR)"); + chaz_MakeRule_add_command(rule, "$(TEST_CFC_EXE)"); + chaz_MakeRule_add_command(rule, + "lcov" + " --capture" + " --directory $(BASE_DIR)" + " --base-directory ." + " --rc lcov_branch_coverage=1" + " --output-file cfc.info"); + chaz_MakeRule_add_command(rule, + "genhtml" + " --branch-coverage" + " --output-directory coverage" + " cfc.info"); + + rule = chaz_MakeFile_clean_rule(makefile); + chaz_MakeRule_add_rm_command(rule, "cfc.info"); + chaz_MakeRule_add_recursive_rm_command(rule, "coverage"); + } } chaz_MakeFile_write(makefile); @@ -312,37 +281,25 @@ S_write_makefile(struct chaz_CLI *cli) { free(lemon_dir); free(src_dir); free(include_dir); + free(cmark_dir); free(parse_header); - free(cfc_exe); - free(test_cfc_exe); + free(parse_header_c); } static void S_source_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; if (strcmp(file, "CFCParseHeader.c") == 0) { return; } - /* Strip extension */ - if (file_len <= 2 || memcmp(file + file_len - 2, ".c", 2) != 0) { - chaz_Util_warn("Unexpected source file name: %s", file); - return; - } - file[file_len-2] = '\0'; - - obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); if (strlen(file) >= 7 && memcmp(file, "CFCTest", 7) == 0) { - chaz_MakeVar_append(sfc->common_test_objs, obj_file); + if (sfc->test_binary) { + chaz_MakeBinary_add_src_file(sfc->test_binary, dir, file); + } } else { - chaz_MakeVar_append(sfc->common_objs, obj_file); + chaz_MakeBinary_add_src_file(sfc->core_binary, dir, file); } - - free(obj_file); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b79b40d3/compiler/src/CFCPerl.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c index c58d30c..f038a8c 100644 --- a/compiler/src/CFCPerl.c +++ b/compiler/src/CFCPerl.c @@ -299,10 +299,11 @@ S_write_host_h(CFCPerl *self, CFCParcel *parcel) { static void S_write_host_c(CFCPerl *self, CFCParcel *parcel) { CFCClass **ordered = CFCHierarchy_ordered_classes(self->hierarchy); - const char *prefix = CFCParcel_get_prefix(parcel); - char *includes = CFCUtil_strdup(""); - char *cb_defs = CFCUtil_strdup(""); - char *alias_adds = CFCUtil_strdup(""); + const char *prefix = CFCParcel_get_prefix(parcel); + const char *privacy_sym = CFCParcel_get_privacy_sym(parcel); + char *includes = CFCUtil_strdup(""); + char *cb_defs = CFCUtil_strdup(""); + char *alias_adds = CFCUtil_strdup(""); for (size_t i = 0; ordered[i] != NULL; i++) { CFCClass *klass = ordered[i]; @@ -357,6 +358,8 @@ S_write_host_c(CFCPerl *self, CFCParcel *parcel) { const char pattern[] = "%s" "\n" + "#define %s\n" // privacy_sym + "\n" "#include \"%sperl.h\"\n" "#include \"XSBind.h\"\n" "#include \"Clownfish/Class.h\"\n" @@ -455,8 +458,9 @@ S_write_host_c(CFCPerl *self, CFCParcel *parcel) { "\n" "%s"; char *content - = CFCUtil_sprintf(pattern, self->c_header, prefix, includes, cb_defs, - prefix, prefix, alias_adds, self->c_footer); + = CFCUtil_sprintf(pattern, self->c_header, privacy_sym, prefix, + includes, cb_defs, prefix, prefix, alias_adds, + self->c_footer); const char *src_dest = CFCHierarchy_get_source_dest(self->hierarchy); char *host_c_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%sperl.c", src_dest, http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b79b40d3/runtime/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main index 4a425f3..b8a2c7c 100644 --- a/runtime/common/charmonizer.main +++ b/runtime/common/charmonizer.main @@ -40,10 +40,10 @@ #include "Charmonizer/Core/ConfWriterRuby.h" typedef struct cfish_MakeFile { - chaz_MakeFile *makefile; - chaz_MakeVar *obj_var; - chaz_MakeVar *cfh_var; - chaz_CLI *cli; + chaz_MakeFile *makefile; + chaz_MakeBinary *binary; + chaz_MakeVar *cfh_var; + chaz_CLI *cli; /* Directories and files. */ const char *base_dir; @@ -52,13 +52,6 @@ typedef struct cfish_MakeFile { char *autogen_src_dir; char *autogen_inc_dir; char *autogen_target; - char *core_objects; - - /* Libraries. */ - chaz_Lib *shared_lib; - chaz_Lib *static_lib; - char *shared_lib_filename; - char *static_lib_filename; } cfish_MakeFile; static const char cfish_version[] = "0.5.0"; @@ -86,12 +79,6 @@ static void cfish_MakeFile_write_c_test_rules(cfish_MakeFile *self); static void -S_c_file_callback(const char *dir, char *file, void *context); - -static void -S_add_core_object(cfish_MakeFile *self, const char *obj_file); - -static void S_cfh_file_callback(const char *dir, char *file, void *context); static int @@ -182,12 +169,6 @@ int main(int argc, const char **argv) { if (chaz_CLI_defined(cli, "enable-makefile")) { cfish_MakeFile *mf = cfish_MakeFile_new(cli); cfish_MakeFile_write(mf, link_flags); - /* Export filenames. */ - chaz_ConfWriter_add_def("SHARED_LIB_FILENAME", - mf->shared_lib_filename); - chaz_ConfWriter_add_def("STATIC_LIB_FILENAME", - mf->static_lib_filename); - chaz_ConfWriter_add_def("CORE_OBJECTS", mf->core_objects); cfish_MakeFile_destroy(mf); } @@ -237,9 +218,6 @@ S_add_compiler_flags(struct chaz_CLI *cli) { } } - chaz_CFlags_add_define(extra_cflags, "CFP_CFISH", NULL); - chaz_CFlags_add_define(extra_cflags, "CFP_TESTCFISH", NULL); - chaz_CFlags_hide_symbols(extra_cflags); if (chaz_CLI_defined(cli, "disable-threads")) { @@ -253,10 +231,10 @@ S_link_flags(chaz_CLI *cli) { const char *math_library = chaz_Floats_math_library(); if (math_library) { - chaz_CFlags_add_external_library(link_flags, math_library); + chaz_CFlags_add_external_lib(link_flags, math_library); } if (S_need_libpthread(cli)) { - chaz_CFlags_add_external_library(link_flags, "pthread"); + chaz_CFlags_add_external_lib(link_flags, "pthread"); } if (chaz_CLI_defined(cli, "enable-coverage")) { chaz_CFlags_enable_code_coverage(link_flags); @@ -272,8 +250,7 @@ cfish_MakeFile_new(chaz_CLI *cli) { cfish_MakeFile *self = malloc(sizeof(cfish_MakeFile)); self->makefile = chaz_MakeFile_new(); - self->obj_var = chaz_MakeFile_add_var(self->makefile, "CLOWNFISH_OBJS", - NULL); + self->binary = NULL; self->cfh_var = NULL; self->cli = cli; @@ -300,13 +277,6 @@ cfish_MakeFile_new(chaz_CLI *cli) { self->host_src_dir = NULL; } - self->shared_lib = chaz_Lib_new_shared("cfish", cfish_version, - cfish_major_version); - self->static_lib = chaz_Lib_new_static("clownfish"); - self->shared_lib_filename = chaz_Lib_filename(self->shared_lib); - self->static_lib_filename = chaz_Lib_filename(self->static_lib); - self->core_objects = chaz_Util_strdup(""); - return self; } @@ -319,37 +289,29 @@ cfish_MakeFile_destroy(cfish_MakeFile *self) { free(self->autogen_src_dir); free(self->autogen_target); - chaz_Lib_destroy(self->shared_lib); - chaz_Lib_destroy(self->static_lib); - free(self->shared_lib_filename); - free(self->static_lib_filename); - free(self->core_objects); - free(self); } static void cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags *extra_link_flags) { static const char *const autogen_src_files[] = { - "cfish_parcel", - "testcfish_parcel", + "cfish_parcel.c", + "testcfish_parcel.c", NULL }; - const char *dir_sep = chaz_OS_dir_sep(); - const char *obj_ext = chaz_CC_obj_ext(); + const char *dir_sep = chaz_OS_dir_sep(); + const char *host = chaz_CLI_strval(self->cli, "host"); chaz_MakeVar *var; chaz_MakeRule *rule; - chaz_MakeRule *clean_rule; - chaz_MakeRule *distclean_rule; chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags(); chaz_CFlags *makefile_cflags; + chaz_CFlags *compile_flags; chaz_CFlags *link_flags; - char *scratch; - int i; + int i; printf("Creating Makefile...\n"); @@ -366,7 +328,6 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags *extra_link_flags) { 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); } @@ -385,65 +346,76 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags *extra_link_flags) { chaz_CFlags_destroy(makefile_cflags); - /* Object files */ + /* Binary. */ + + if (strcmp(host, "c") == 0 || strcmp(host, "perl") == 0) { + chaz_MakeFile_add_rule(self->makefile, "all", "$(CFISH_SHARED_LIB)"); + + self->binary + = chaz_MakeFile_add_shared_lib(self->makefile, NULL, "cfish", + cfish_version, cfish_major_version); + chaz_MakeFile_add_rule(self->makefile, "$(CFISH_SHARED_LIB_OBJS)", + self->autogen_target); + } + else { + chaz_MakeFile_add_rule(self->makefile, "static", + "$(CLOWNFISH_STATIC_LIB)"); + + self->binary + = chaz_MakeFile_add_static_lib(self->makefile, NULL, "clownfish"); + chaz_MakeFile_add_rule(self->makefile, "$(CLOWNFISH_STATIC_LIB_OBJS)", + self->autogen_target); + } if (self->host_src_dir) { - chaz_Make_list_files(self->host_src_dir, "c", S_c_file_callback, self); + chaz_MakeBinary_add_src_dir(self->binary, self->host_src_dir); } - chaz_Make_list_files(self->core_dir, "c", S_c_file_callback, self); + chaz_MakeBinary_add_src_dir(self->binary, self->core_dir); + + compile_flags = chaz_MakeBinary_get_compile_flags(self->binary); + chaz_CFlags_add_define(compile_flags, "CFP_CFISH", NULL); + chaz_CFlags_add_define(compile_flags, "CFP_TESTCFISH", NULL); + + link_flags = chaz_MakeBinary_get_link_flags(self->binary); + chaz_CFlags_enable_debugging(link_flags); + chaz_CFlags_append(link_flags, chaz_CFlags_get_string(extra_link_flags)); for (i = 0; autogen_src_files[i] != NULL; ++i) { - char *path = chaz_Util_join("", self->autogen_src_dir, dir_sep, - autogen_src_files[i], obj_ext, NULL); - S_add_core_object(self, path); - free(path); + chaz_MakeBinary_add_src_file(self->binary, self->autogen_src_dir, + autogen_src_files[i]); } - /* Rules */ - - chaz_MakeFile_add_rule(self->makefile, "all", self->shared_lib_filename); - chaz_MakeFile_add_rule(self->makefile, "static", self->static_lib_filename); - chaz_MakeFile_add_rule(self->makefile, "core_objects", - "$(CLOWNFISH_OBJS)"); + /* Additional rules. */ - if (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) { + if (strcmp(host, "c") == 0) { cfish_MakeFile_write_c_cfc_rules(self); + cfish_MakeFile_write_c_test_rules(self); + } + + if (strcmp(host, "perl") == 0) { + char *core_objects = chaz_MakeBinary_obj_string(self->binary); + chaz_MakeFile_add_rule(self->makefile, "core_objects", + "$(CFISH_SHARED_LIB_OBJS)"); + chaz_ConfWriter_add_def("CORE_OBJECTS", core_objects); + free(core_objects); } /* Needed for parallel builds. */ for (i = 0; autogen_src_files[i] != NULL; ++i) { - char *path = chaz_Util_join("", self->autogen_src_dir, dir_sep, - autogen_src_files[i], ".c", NULL); + char *path = chaz_Util_join(dir_sep, self->autogen_src_dir, + autogen_src_files[i], NULL); chaz_MakeFile_add_rule(self->makefile, path, self->autogen_target); free(path); } - chaz_MakeFile_add_rule(self->makefile, "$(CLOWNFISH_OBJS)", - self->autogen_target); - - link_flags = chaz_CC_new_cflags(); - chaz_CFlags_enable_debugging(link_flags); - chaz_CFlags_append(link_flags, chaz_CFlags_get_string(extra_link_flags)); - chaz_MakeFile_add_shared_lib(self->makefile, self->shared_lib, - "$(CLOWNFISH_OBJS)", link_flags); - chaz_CFlags_destroy(link_flags); - chaz_MakeFile_add_static_lib(self->makefile, self->static_lib, - "$(CLOWNFISH_OBJS)"); - - if (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) { - cfish_MakeFile_write_c_test_rules(self); - } - - clean_rule = chaz_MakeFile_clean_rule(self->makefile); - chaz_MakeRule_add_rm_command(clean_rule, "$(CLOWNFISH_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); } static void cfish_MakeFile_write_c_cfc_rules(cfish_MakeFile *self) { - chaz_MakeVar *var; chaz_MakeRule *rule; const char *dir_sep = chaz_OS_dir_sep(); @@ -483,64 +455,53 @@ cfish_MakeFile_write_c_cfc_rules(cfish_MakeFile *self) { static void cfish_MakeFile_write_c_test_rules(cfish_MakeFile *self) { - const char *dir_sep = chaz_OS_dir_sep(); - const char *exe_ext = chaz_CC_exe_ext(); + chaz_MakeBinary *exe; + chaz_CFlags *link_cflags; + chaz_MakeRule *rule; - chaz_CFlags *test_cflags; - chaz_MakeRule *rule; - char *test_cfish_exe; - char *test_cfish_c; - char *test_command; - char *valgrind_command = NULL; - - test_cfish_exe = chaz_Util_join("", "t", dir_sep, "test_cfish", exe_ext, - NULL); - test_cfish_c = chaz_Util_join(dir_sep, "t", "test_cfish.c", NULL); - test_cflags = chaz_CC_new_cflags(); - chaz_CFlags_enable_optimization(test_cflags); - chaz_CFlags_add_include_dir(test_cflags, self->autogen_inc_dir); - chaz_CFlags_add_library(test_cflags, self->shared_lib); - rule = chaz_MakeFile_add_compiled_exe(self->makefile, test_cfish_exe, - test_cfish_c, test_cflags); - chaz_MakeRule_add_prereq(rule, self->shared_lib_filename); - chaz_CFlags_destroy(test_cflags); - - /* TODO: This should be added by Charmonizer. */ - if (chaz_Probe_msvc_version_num()) { - rule = chaz_MakeFile_clean_rule(self->makefile); - chaz_MakeRule_add_rm_command(rule, "test_cfish.obj"); - } + const char *test_command; + + exe = chaz_MakeFile_add_exe(self->makefile, "t", "test_cfish"); + chaz_MakeBinary_add_src_file(exe, "t", "test_cfish.c"); + chaz_MakeFile_add_rule(self->makefile, "$(TEST_CFISH_EXE_OBJS)", + self->autogen_target); + link_cflags = chaz_MakeBinary_get_link_flags(exe); + chaz_CFlags_add_shared_lib(link_cflags, NULL, "cfish", + cfish_major_version); + chaz_MakeBinary_add_prereq(exe, "$(CFISH_SHARED_LIB)"); - rule = chaz_MakeFile_add_rule(self->makefile, "test", test_cfish_exe); + rule = chaz_MakeFile_add_rule(self->makefile, "test", "$(TEST_CFISH_EXE)"); if (chaz_CC_binary_format() == CHAZ_CC_BINFMT_ELF) { - test_command = chaz_Util_join(" ", "LD_LIBRARY_PATH=.", test_cfish_exe, - NULL); + test_command = "LD_LIBRARY_PATH=. $(TEST_CFISH_EXE)"; } else { - test_command = chaz_Util_strdup(test_cfish_exe); + test_command = "$(TEST_CFISH_EXE)"; } chaz_MakeRule_add_command(rule, test_command); if (chaz_OS_shell_type() == CHAZ_OS_POSIX) { + const char *valgrind_command; + rule = chaz_MakeFile_add_rule(self->makefile, "valgrind", - test_cfish_exe); + "$(TEST_CFISH_EXE)"); if (chaz_CC_binary_format() == CHAZ_CC_BINFMT_ELF) { - valgrind_command - = chaz_Util_join(" ", "LD_LIBRARY_PATH=.", - "CLOWNFISH_VALGRIND=1", "valgrind", - "--leak-check=full", test_cfish_exe, NULL); + valgrind_command = "LD_LIBRARY_PATH=. CLOWNFISH_VALGRIND=1" + " valgrind" + " --leak-check=full" + " $(TEST_CFISH_EXE)"; } else { - valgrind_command - = chaz_Util_join(" ", "CLOWNFISH_VALGRIND=1", "valgrind", - "--leak-check=full", test_cfish_exe, NULL); + valgrind_command = "CLOWNFISH_VALGRIND=1" + " valgrind" + " --leak-check=full" + " $(TEST_CFISH_EXE)"; } chaz_MakeRule_add_command(rule, valgrind_command); } if (chaz_CLI_defined(self->cli, "enable-coverage")) { rule = chaz_MakeFile_add_rule(self->makefile, "coverage", - test_cfish_exe); + "$(TEST_CFISH_EXE)"); chaz_MakeRule_add_command(rule, "lcov" " --zerocounters" @@ -573,48 +534,6 @@ cfish_MakeFile_write_c_test_rules(cfish_MakeFile *self) { chaz_MakeRule_add_rm_command(rule, "clownfish.info"); chaz_MakeRule_add_recursive_rm_command(rule, "coverage"); } - - free(test_cfish_exe); - free(test_cfish_c); - free(test_command); - free(valgrind_command); -} - -static void -S_c_file_callback(const char *dir, char *file, void *context) { - cfish_MakeFile *self = (cfish_MakeFile*)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'; - - obj_file = chaz_Util_join("", dir, dir_sep, file, obj_ext, NULL); - S_add_core_object(self, obj_file); - free(obj_file); -} - -static void -S_add_core_object(cfish_MakeFile *self, const char *obj_file) { - char *new_core_objects; - - chaz_MakeVar_append(self->obj_var, obj_file); - - if (self->core_objects[0] == '\0') { - new_core_objects = chaz_Util_strdup(obj_file); - } - else { - new_core_objects = chaz_Util_join(" ", self->core_objects, obj_file, - NULL); - } - free(self->core_objects); - self->core_objects = new_core_objects; } static void @@ -668,7 +587,7 @@ S_need_libpthread(chaz_CLI *cli) { } temp_cflags = chaz_CC_get_temp_cflags(); - chaz_CFlags_add_external_library(temp_cflags, "pthread"); + chaz_CFlags_add_external_lib(temp_cflags, "pthread"); if (!chaz_CC_test_link(source)) { chaz_Util_die("Can't link with libpthread. Try --disable-threads."); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b79b40d3/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 4839f98..ab9ee82 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -16,6 +16,7 @@ #include <string.h> +#define CFP_CFISH #define C_CFISH_OBJ #define C_CFISH_CLASS #define C_CFISH_FLOAT
