Regenerate charmonizer.c
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/cbc7c4c2 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/cbc7c4c2 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/cbc7c4c2 Branch: refs/heads/c-bindings-wip2 Commit: cbc7c4c2ef222d94d08003f1917f3fb344d100d6 Parents: 28827f0 Author: Nick Wellnhofer <[email protected]> Authored: Sat Jan 5 23:15:40 2013 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Sun Feb 24 20:37:59 2013 +0100 ---------------------------------------------------------------------- clownfish/compiler/common/charmonizer.c | 28 ++-- clownfish/runtime/common/charmonizer.c | 22 ++- common/charmonizer.c | 231 +++++++++++++++++++++++++- 3 files changed, 254 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/cbc7c4c2/clownfish/compiler/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/clownfish/compiler/common/charmonizer.c b/clownfish/compiler/common/charmonizer.c index 486e3a1..b431d19 100644 --- a/clownfish/compiler/common/charmonizer.c +++ b/clownfish/compiler/common/charmonizer.c @@ -432,9 +432,9 @@ chaz_MakeFile_add_to_cleanup(chaz_MakeFile *makefile, const char *target); * @param exe The name of the executable. * @param objects The list of object files. */ -void +chaz_MakeRule* chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, - const char *objects); + const char *objects, const char *extra_link_flags); /** Add a rule to link a shared object. The shared object will also be added to * the list of files to clean. @@ -443,7 +443,7 @@ chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, * @param shared_obj The name of the shared object. * @param objects The list of object files. */ -void +chaz_MakeRule* chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, const char *objects); @@ -2763,10 +2763,10 @@ chaz_MakeFile_add_to_cleanup(chaz_MakeFile *makefile, const char *target) { makefile->num_cleanups = num_cleanups; } -void +chaz_MakeRule* chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, - const char *objects) { - const char *pattern = "%s %s %s %s%s"; + const char *objects, const char *extra_link_flags) { + const char *pattern = "%s %s %s %s %s%s"; const char *link = chaz_CC_link_command(); const char *link_flags = chaz_CC_link_flags(); const char *output_flag = chaz_CC_link_output_flag(); @@ -2779,18 +2779,22 @@ chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, size = strlen(pattern) + strlen(link) + strlen(link_flags) + + strlen(extra_link_flags) + strlen(objects) + strlen(output_flag) + strlen(exe) + 50; command = (char*)malloc(size); - sprintf(command, pattern, link, link_flags, objects, output_flag, exe); + sprintf(command, pattern, link, link_flags, extra_link_flags, objects, + output_flag, exe); chaz_MakeRule_add_command(rule, command); chaz_MakeFile_add_to_cleanup(makefile, exe); + + return rule; } -void +chaz_MakeRule* chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, const char *objects) { const char *pattern = "%s %s %s %s %s%s"; @@ -2818,6 +2822,8 @@ chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, chaz_MakeRule_add_command(rule, command); chaz_MakeFile_add_to_cleanup(makefile, shared_obj); + + return rule; } void @@ -4787,7 +4793,7 @@ S_write_makefile() { chaz_MakeFile_add_rule(makefile, "all", "$(CFC_EXE)"); - chaz_MakeFile_add_exe(makefile, "$(LEMON_EXE)", "$(LEMON_OBJS)"); + chaz_MakeFile_add_exe(makefile, "$(LEMON_EXE)", "$(LEMON_OBJS)", ""); rule = chaz_MakeFile_add_rule(makefile, parse_header_c, NULL); chaz_MakeRule_add_prereq(rule, "$(LEMON_EXE)"); @@ -4800,9 +4806,9 @@ S_write_makefile() { chaz_MakeFile_add_rule(makefile, "$(COMMON_OBJS)", parse_header_c); chaz_MakeFile_add_exe(makefile, "$(CFC_EXE)", - "$(COMMON_OBJS) $(CFC_OBJS)"); + "$(COMMON_OBJS) $(CFC_OBJS)", ""); chaz_MakeFile_add_exe(makefile, "$(TEST_CFC_EXE)", - "$(COMMON_OBJS) $(TEST_CFC_OBJS)"); + "$(COMMON_OBJS) $(TEST_CFC_OBJS)", ""); rule = chaz_MakeFile_add_rule(makefile, "test", "$(TEST_CFC_EXE)"); chaz_MakeRule_add_command(rule, "$(TEST_CFC_EXE)"); http://git-wip-us.apache.org/repos/asf/lucy/blob/cbc7c4c2/clownfish/runtime/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/clownfish/runtime/common/charmonizer.c b/clownfish/runtime/common/charmonizer.c index 534a4dd..6401759 100644 --- a/clownfish/runtime/common/charmonizer.c +++ b/clownfish/runtime/common/charmonizer.c @@ -432,9 +432,9 @@ chaz_MakeFile_add_to_cleanup(chaz_MakeFile *makefile, const char *target); * @param exe The name of the executable. * @param objects The list of object files. */ -void +chaz_MakeRule* chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, - const char *objects); + const char *objects, const char *extra_link_flags); /** Add a rule to link a shared object. The shared object will also be added to * the list of files to clean. @@ -443,7 +443,7 @@ chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, * @param shared_obj The name of the shared object. * @param objects The list of object files. */ -void +chaz_MakeRule* chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, const char *objects); @@ -3045,10 +3045,10 @@ chaz_MakeFile_add_to_cleanup(chaz_MakeFile *makefile, const char *target) { makefile->num_cleanups = num_cleanups; } -void +chaz_MakeRule* chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, - const char *objects) { - const char *pattern = "%s %s %s %s%s"; + const char *objects, const char *extra_link_flags) { + const char *pattern = "%s %s %s %s %s%s"; const char *link = chaz_CC_link_command(); const char *link_flags = chaz_CC_link_flags(); const char *output_flag = chaz_CC_link_output_flag(); @@ -3061,18 +3061,22 @@ chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, size = strlen(pattern) + strlen(link) + strlen(link_flags) + + strlen(extra_link_flags) + strlen(objects) + strlen(output_flag) + strlen(exe) + 50; command = (char*)malloc(size); - sprintf(command, pattern, link, link_flags, objects, output_flag, exe); + sprintf(command, pattern, link, link_flags, extra_link_flags, objects, + output_flag, exe); chaz_MakeRule_add_command(rule, command); chaz_MakeFile_add_to_cleanup(makefile, exe); + + return rule; } -void +chaz_MakeRule* chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, const char *objects) { const char *pattern = "%s %s %s %s %s%s"; @@ -3100,6 +3104,8 @@ chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, chaz_MakeRule_add_command(rule, command); chaz_MakeFile_add_to_cleanup(makefile, shared_obj); + + return rule; } void http://git-wip-us.apache.org/repos/asf/lucy/blob/cbc7c4c2/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/common/charmonizer.c b/common/charmonizer.c index 47689c4..b03944f 100644 --- a/common/charmonizer.c +++ b/common/charmonizer.c @@ -432,9 +432,9 @@ chaz_MakeFile_add_to_cleanup(chaz_MakeFile *makefile, const char *target); * @param exe The name of the executable. * @param objects The list of object files. */ -void +chaz_MakeRule* chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, - const char *objects); + const char *objects, const char *extra_link_flags); /** Add a rule to link a shared object. The shared object will also be added to * the list of files to clean. @@ -443,7 +443,7 @@ chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, * @param shared_obj The name of the shared object. * @param objects The list of object files. */ -void +chaz_MakeRule* chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, const char *objects); @@ -3045,10 +3045,10 @@ chaz_MakeFile_add_to_cleanup(chaz_MakeFile *makefile, const char *target) { makefile->num_cleanups = num_cleanups; } -void +chaz_MakeRule* chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, - const char *objects) { - const char *pattern = "%s %s %s %s%s"; + const char *objects, const char *extra_link_flags) { + const char *pattern = "%s %s %s %s %s%s"; const char *link = chaz_CC_link_command(); const char *link_flags = chaz_CC_link_flags(); const char *output_flag = chaz_CC_link_output_flag(); @@ -3061,18 +3061,22 @@ chaz_MakeFile_add_exe(chaz_MakeFile *makefile, const char *exe, size = strlen(pattern) + strlen(link) + strlen(link_flags) + + strlen(extra_link_flags) + strlen(objects) + strlen(output_flag) + strlen(exe) + 50; command = (char*)malloc(size); - sprintf(command, pattern, link, link_flags, objects, output_flag, exe); + sprintf(command, pattern, link, link_flags, extra_link_flags, objects, + output_flag, exe); chaz_MakeRule_add_command(rule, command); chaz_MakeFile_add_to_cleanup(makefile, exe); + + return rule; } -void +chaz_MakeRule* chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, const char *objects) { const char *pattern = "%s %s %s %s %s%s"; @@ -3100,6 +3104,8 @@ chaz_MakeFile_add_shared_obj(chaz_MakeFile *makefile, const char *shared_obj, chaz_MakeRule_add_command(rule, command); chaz_MakeFile_add_to_cleanup(makefile, shared_obj); + + return rule; } void @@ -5771,6 +5777,13 @@ chaz_VariadicMacros_run(void) { /* #include "Charmonizer/Core/ConfWriterPerl.h" */ /* #include "Charmonizer/Core/ConfWriterRuby.h" */ +#define DIR_SEP "/" + +typedef struct SourceFileContext { + chaz_MakeVar *var; + const char *dir; +} SourceFileContext; + static void S_add_compiler_flags(struct chaz_CLIArgs *args) { if (chaz_Probe_gcc_version_num()) { @@ -5817,6 +5830,198 @@ S_add_compiler_flags(struct chaz_CLIArgs *args) { } } +static void +S_source_file_callback(char *file, void *context) { + SourceFileContext *sfc = (SourceFileContext*)context; + const char *json_parser_c = "Lucy" DIR_SEP "Util" DIR_SEP "Json" DIR_SEP + "JsonParser.c"; + size_t file_len = strlen(file); + size_t obj_file_size; + const char *pattern; + char *obj_file; + + if (strcmp(file, json_parser_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'; + + pattern = "%s" DIR_SEP "%s$(OBJ_EXT)"; + obj_file_size = strlen(pattern) + file_len + 10; + obj_file = (char*)malloc(obj_file_size); + sprintf(obj_file, pattern, sfc->dir, file); + chaz_MakeVar_append(sfc->var, obj_file); + free(obj_file); +} + +static void +S_write_makefile() { + SourceFileContext sfc; + + const char *base_dir = ".."; + const char *exe_ext = chaz_OS_exe_ext(); + const char *obj_ext = chaz_OS_obj_ext(); + const char *shobj_ext = chaz_OS_shared_obj_ext(); + + const char *json_parser_y = "$(CORE_DIR)" DIR_SEP "Lucy" DIR_SEP "Util" + DIR_SEP "Json" DIR_SEP "JsonParser.y"; + const char *json_parser_h = "$(CORE_DIR)" DIR_SEP "Lucy" DIR_SEP "Util" + DIR_SEP "Json" DIR_SEP "JsonParser.h"; + const char *json_parser_c = "$(CORE_DIR)" DIR_SEP "Lucy" DIR_SEP "Util" + DIR_SEP "Json" DIR_SEP "JsonParser.c"; + + char *scratch; + + chaz_MakeFile *makefile; + chaz_MakeVar *var; + chaz_MakeRule *rule; + + printf("Creating Makefile...\n"); + + makefile = chaz_MakeFile_new(); + + /* Directories */ + + chaz_MakeFile_add_var(makefile, "SRC_DIR", "src"); + chaz_MakeFile_add_var(makefile, "AUTOGEN_DIR", "autogen"); + chaz_MakeFile_add_var(makefile, "BASE_DIR", base_dir); + chaz_MakeFile_add_var(makefile, "CORE_DIR", + "$(BASE_DIR)" DIR_SEP "core"); + chaz_MakeFile_add_var(makefile, "MODULES_DIR", + "$(BASE_DIR)" DIR_SEP "modules"); + chaz_MakeFile_add_var(makefile, "LEMON_DIR", + "$(BASE_DIR)" DIR_SEP "lemon"); + chaz_MakeFile_add_var(makefile, "CFC_DIR", + "$(BASE_DIR)" DIR_SEP "clownfish" DIR_SEP "compiler" + DIR_SEP "c"); + chaz_MakeFile_add_var(makefile, "SNOWSTEM_DIR", + "$(MODULES_DIR)" DIR_SEP "analysis" DIR_SEP + "snowstem" DIR_SEP "source"); + chaz_MakeFile_add_var(makefile, "SNOWSTOP_DIR", + "$(MODULES_DIR)" DIR_SEP "analysis" DIR_SEP + "snowstop" DIR_SEP "source"); + chaz_MakeFile_add_var(makefile, "UTF8PROC_DIR", + "$(MODULES_DIR)" DIR_SEP "unicode" DIR_SEP + "utf8proc"); + + /* File extensions */ + + chaz_MakeFile_add_var(makefile, "EXE_EXT", exe_ext); + chaz_MakeFile_add_var(makefile, "OBJ_EXT", obj_ext); + chaz_MakeFile_add_var(makefile, "SHOBJ_EXT", shobj_ext); + + /* C compiler */ + + chaz_MakeFile_add_var(makefile, "CC", chaz_CC_get_cc()); + + if (chaz_CC_msvc_version_num()) { + chaz_CC_add_extra_cflags("/nologo"); + } + chaz_CC_set_optimization_level("2"); + chaz_CC_add_include_dir("."); + chaz_CC_add_include_dir("$(SRC_DIR)"); + chaz_CC_add_include_dir("$(CORE_DIR)"); + chaz_CC_add_include_dir("$(AUTOGEN_DIR)" DIR_SEP "include"); + chaz_CC_add_include_dir("$(SNOWSTEM_DIR)" DIR_SEP "include"); + chaz_CC_add_include_dir("$(MODULES_DIR)" DIR_SEP "unicode" DIR_SEP "ucd"); + chaz_CC_add_include_dir("$(UTF8PROC_DIR)"); + + var = chaz_MakeFile_add_var(makefile, "CFLAGS", NULL); + chaz_MakeVar_append(var, chaz_CC_get_cflags()); + chaz_MakeVar_append(var, chaz_CC_get_extra_cflags()); + + /* Object files */ + + chaz_MakeFile_add_var(makefile, "LEMON_OBJS", + "$(LEMON_DIR)" DIR_SEP "lemon$(OBJ_EXT)"); + + var = chaz_MakeFile_add_var(makefile, "LUCY_OBJS", NULL); + sfc.var = var; + + sfc.dir = "$(SRC_DIR)"; + chaz_Make_list_files("src", "c", S_source_file_callback, &sfc); + + scratch = (char*)malloc(strlen(base_dir) + 20); + sprintf(scratch, "%s" DIR_SEP "core", base_dir); + sfc.dir = "$(CORE_DIR)"; + chaz_Make_list_files(scratch, "c", S_source_file_callback, &sfc); + free(scratch); + chaz_MakeVar_append(var, "$(CORE_DIR)" DIR_SEP "Lucy" DIR_SEP "Util" + DIR_SEP "Json" DIR_SEP "JsonParser$(OBJ_EXT)"); + + scratch = (char*)malloc(strlen(base_dir) + 80); + sprintf(scratch, "%s" DIR_SEP "modules" DIR_SEP "analysis" DIR_SEP + "snowstem" DIR_SEP "source", base_dir); + sfc.dir = "$(SNOWSTEM_DIR)"; + chaz_Make_list_files(scratch, "c", S_source_file_callback, &sfc); + free(scratch); + + scratch = (char*)malloc(strlen(base_dir) + 80); + sprintf(scratch, "%s" DIR_SEP "modules" DIR_SEP "analysis" DIR_SEP + "snowstop" DIR_SEP "source", base_dir); + sfc.dir = "$(SNOWSTOP_DIR)"; + chaz_Make_list_files(scratch, "c", S_source_file_callback, &sfc); + free(scratch); + + scratch = (char*)malloc(strlen(base_dir) + 80); + sprintf(scratch, "%s" DIR_SEP "modules" DIR_SEP "unicode" DIR_SEP + "utf8proc", base_dir); + sfc.dir = "$(UTF8PROC_DIR)"; + chaz_Make_list_files(scratch, "c", S_source_file_callback, &sfc); + free(scratch); + + chaz_MakeVar_append(var, "$(AUTOGEN_DIR)" DIR_SEP "source" DIR_SEP + "parcel$(OBJ_EXT)"); + + /* Executables */ + + chaz_MakeFile_add_var(makefile, "LEMON_EXE", + "$(LEMON_DIR)" DIR_SEP "lemon$(EXE_EXT)"); + chaz_MakeFile_add_var(makefile, "CFC_EXE", + "$(CFC_DIR)" DIR_SEP "cfc$(EXE_EXT)"); + + /* Shared library */ + + chaz_MakeFile_add_var(makefile, "LUCY_SHOBJ", "liblucy$(SHOBJ_EXT)"); + + /* Rules */ + + chaz_MakeFile_add_rule(makefile, "all", "$(LUCY_SHOBJ)"); + + chaz_MakeFile_add_exe(makefile, "$(LEMON_EXE)", "$(LEMON_OBJS)", ""); + + rule = chaz_MakeFile_add_rule(makefile, "$(CFC_EXE)", NULL); + chaz_MakeRule_add_command_make(rule, "$(CFC_DIR)", NULL); + + rule = chaz_MakeFile_add_rule(makefile, "$(AUTOGEN_DIR)", "$(CFC_EXE)"); + chaz_MakeRule_add_command(rule, "$(CFC_EXE) --source=$(CORE_DIR) " + "--dest=$(AUTOGEN_DIR) --header=cfc_header"); + + rule = chaz_MakeFile_add_rule(makefile, json_parser_c, NULL); + chaz_MakeRule_add_prereq(rule, "$(LEMON_EXE)"); + chaz_MakeRule_add_prereq(rule, json_parser_y); + scratch = (char*)malloc(strlen(json_parser_y) + 20); + sprintf(scratch, "$(LEMON_EXE) -q %s", json_parser_y); + chaz_MakeRule_add_command(rule, scratch); + free(scratch); + + rule = chaz_MakeFile_add_rule(makefile, "$(LUCY_OBJS)", NULL); + chaz_MakeRule_add_prereq(rule, json_parser_c); + chaz_MakeRule_add_prereq(rule, "$(AUTOGEN_DIR)"); + + chaz_MakeFile_add_shared_obj(makefile, "$(LUCY_SHOBJ)", "$(LUCY_OBJS)"); + + chaz_MakeFile_add_to_cleanup(makefile, "$(LUCY_OBJS)"); + chaz_MakeFile_add_to_cleanup(makefile, "$(AUTOGEN_DIR)"); + chaz_MakeFile_add_to_cleanup(makefile, json_parser_h); + chaz_MakeFile_add_to_cleanup(makefile, json_parser_c); + + chaz_MakeFile_write(makefile); +} + int main(int argc, const char **argv) { /* Initialize. */ { @@ -5885,6 +6090,16 @@ int main(int argc, const char **argv) { "#endif\n\n" ); + { + int i; + for (i = 0; i < argc; i++) { + if (strncmp(argv[i], "--enable-makefile", 17) == 0) { + S_write_makefile(); + break; + } + } + } + /* Clean up. */ chaz_Probe_clean_up();
