lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [06/13] git commit: refs/heads/makefile-rework - Functions to create lemon rules in chaz_MakeFile
Date Wed, 15 May 2013 17:24:30 GMT
Functions to create lemon rules in chaz_MakeFile


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/1ad02f6e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/1ad02f6e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/1ad02f6e

Branch: refs/heads/makefile-rework
Commit: 1ad02f6e3e11c21d65297f57f8a136675440362b
Parents: ff53edf
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Tue May 14 21:31:57 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Wed May 15 19:13:54 2013 +0200

----------------------------------------------------------------------
 charmonizer/src/Charmonizer/Core/Make.c    |   44 +++++++++++++++++++++
 charmonizer/src/Charmonizer/Core/Make.h    |   17 ++++++++
 clownfish/compiler/common/charmonizer.main |   42 +++++++-------------
 common/charmonizer.main                    |   47 +++++++---------------
 4 files changed, 90 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/1ad02f6e/charmonizer/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Core/Make.c b/charmonizer/src/Charmonizer/Core/Make.c
index 22d4764..ef7a2ee 100644
--- a/charmonizer/src/Charmonizer/Core/Make.c
+++ b/charmonizer/src/Charmonizer/Core/Make.c
@@ -370,6 +370,50 @@ chaz_MakeFile_add_shared_lib(chaz_MakeFile *makefile, chaz_SharedLib
*lib,
     return rule;
 }
 
+chaz_MakeRule*
+chaz_MakeFile_add_lemon_exe(chaz_MakeFile *makefile, const char *dir) {
+    chaz_CFlags   *cflags = chaz_CC_new_cflags();
+    chaz_MakeRule *rule;
+    const char *dir_sep = chaz_OS_dir_sep();
+    const char *exe_ext = chaz_OS_exe_ext();
+    char *lemon_exe = chaz_Util_join("", dir, dir_sep, "lemon", exe_ext, NULL);
+    char *lemon_c   = chaz_Util_join(dir_sep, dir, "lemon.c", NULL);
+
+    chaz_CFlags_enable_optimization(cflags);
+    chaz_MakeFile_add_var(makefile, "LEMON_EXE", lemon_exe);
+    rule = chaz_MakeFile_add_compiled_exe(makefile, "$(LEMON_EXE)", lemon_c,
+                                          cflags);
+
+    chaz_CFlags_destroy(cflags);
+    free(lemon_c);
+    free(lemon_exe);
+    return rule;
+}
+
+chaz_MakeRule*
+chaz_MakeFile_add_lemon_grammar(chaz_MakeFile *makefile,
+                                const char *base_name) {
+    char *c_file  = chaz_Util_join(".", base_name, "c", NULL);
+    char *h_file  = chaz_Util_join(".", base_name, "h", NULL);
+    char *y_file  = chaz_Util_join(".", base_name, "y", NULL);
+    char *command = chaz_Util_join(" ", "$(LEMON_EXE) -q", y_file, NULL);
+
+    chaz_MakeRule *rule = chaz_MakeFile_add_rule(makefile, c_file, y_file);
+    chaz_MakeRule *clean_rule = chaz_MakeFile_clean_rule(makefile);
+
+    chaz_MakeRule_add_prereq(rule, "$(LEMON_EXE)");
+    chaz_MakeRule_add_command(rule, command);
+
+    chaz_MakeRule_add_rm_command(clean_rule, h_file);
+    chaz_MakeRule_add_rm_command(clean_rule, c_file);
+
+    free(c_file);
+    free(h_file);
+    free(y_file);
+    free(command);
+    return rule;
+}
+
 void
 chaz_MakeFile_write(chaz_MakeFile *makefile) {
     FILE   *out;

http://git-wip-us.apache.org/repos/asf/lucy/blob/1ad02f6e/charmonizer/src/Charmonizer/Core/Make.h
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Core/Make.h b/charmonizer/src/Charmonizer/Core/Make.h
index 8f2cbc1..0ba87b0 100644
--- a/charmonizer/src/Charmonizer/Core/Make.h
+++ b/charmonizer/src/Charmonizer/Core/Make.h
@@ -150,6 +150,23 @@ chaz_MakeRule*
 chaz_MakeFile_add_shared_lib(chaz_MakeFile *makefile, chaz_SharedLib *lib,
                              const char *sources, chaz_CFlags *link_flags);
 
+/** Add a rule to build the lemon parser generator.
+ *
+ * @param makefile The makefile.
+ * @param dir The lemon directory.
+ */
+chaz_MakeRule*
+chaz_MakeFile_add_lemon_exe(chaz_MakeFile *makefile, const char *dir);
+
+/** Add a rule for a lemon grammar.
+ *
+ * @param makefile The makefile.
+ * @param base_name The filename of the grammar without extension.
+ */
+chaz_MakeRule*
+chaz_MakeFile_add_lemon_grammar(chaz_MakeFile *makefile,
+                                const char *base_name);
+
 /** Write the makefile to a file named 'Makefile' in the current directory.
  *
  * @param makefile The makefile.

http://git-wip-us.apache.org/repos/asf/lucy/blob/1ad02f6e/clownfish/compiler/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/clownfish/compiler/common/charmonizer.main b/clownfish/compiler/common/charmonizer.main
index fd713f3..b79f461 100644
--- a/clownfish/compiler/common/charmonizer.main
+++ b/clownfish/compiler/common/charmonizer.main
@@ -109,9 +109,7 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     const char *exe_ext  = chaz_OS_exe_ext();
     const char *obj_ext  = chaz_CC_obj_ext();
 
-    const char *parse_header_y = "$(SRC_DIR)" DIR_SEP "CFCParseHeader.y";
-    const char *parse_header_h = "$(SRC_DIR)" DIR_SEP "CFCParseHeader.h";
-    const char *parse_header_c = "$(SRC_DIR)" DIR_SEP "CFCParseHeader.c";
+    const char *parse_header = "$(SRC_DIR)" DIR_SEP "CFCParseHeader";
 
     char *src_dir;
     char *scratch;
@@ -124,7 +122,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags();
     chaz_CFlags *makefile_cflags;
     chaz_CFlags *link_flags;
-    chaz_CFlags *lemon_cflags;
 
     printf("Creating Makefile...\n");
 
@@ -139,9 +136,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     chaz_MakeFile_add_var(makefile, "SRC_DIR", src_dir);
     chaz_MakeFile_add_var(makefile, "INCLUDE_DIR",
                           "$(BASE_DIR)" DIR_SEP "include");
-    chaz_MakeFile_add_var(makefile, "LEMON_DIR",
-                          "$(BASE_DIR)" DIR_SEP ".." DIR_SEP ".." DIR_SEP
-                          "lemon");
 
     /* File extensions */
 
@@ -176,16 +170,15 @@ S_write_makefile(struct chaz_CLIArgs *args) {
 
     chaz_Make_list_files(src_dir, "c", S_source_file_callback, &sfc);
 
-    chaz_MakeVar_append(sfc.common_objs,
-                        "$(SRC_DIR)" DIR_SEP "CFCParseHeader$(OBJ_EXT)");
+    scratch = chaz_Util_join("", parse_header, "$(OBJ_EXT)", NULL);
+    chaz_MakeVar_append(sfc.common_objs, scratch);
+    free(scratch);
     chaz_MakeVar_append(sfc.test_cfc_objs, "t" DIR_SEP "test_cfc$(OBJ_EXT)");
 
     chaz_MakeFile_add_var(makefile, "CFC_OBJS", "cfc$(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$(EXE_EXT)");
     chaz_MakeFile_add_var(makefile, "TEST_CFC_EXE",
                           "t" DIR_SEP "test_cfc$(EXE_EXT)");
@@ -194,22 +187,17 @@ S_write_makefile(struct chaz_CLIArgs *args) {
 
     chaz_MakeFile_add_rule(makefile, "all", "$(CFC_EXE)");
 
-    lemon_cflags = chaz_CC_new_cflags();
-    chaz_CFlags_enable_optimization(lemon_cflags);
-    chaz_MakeFile_add_compiled_exe(makefile, "$(LEMON_EXE)",
-                                   "$(LEMON_DIR)" DIR_SEP "lemon.c",
-                                   lemon_cflags);
-    chaz_CFlags_destroy(lemon_cflags);
-
-    rule = chaz_MakeFile_add_rule(makefile, parse_header_c, NULL);
-    chaz_MakeRule_add_prereq(rule, "$(LEMON_EXE)");
-    chaz_MakeRule_add_prereq(rule, parse_header_y);
-    scratch = (char*)malloc(strlen(parse_header_y) + 20);
-    sprintf(scratch, "$(LEMON_EXE) -q %s", parse_header_y);
-    chaz_MakeRule_add_command(rule, scratch);
-    free(scratch);
+    chaz_MakeFile_add_lemon_exe(makefile, "$(BASE_DIR)" DIR_SEP ".." DIR_SEP
+                                ".." DIR_SEP "lemon");
+    chaz_MakeFile_add_lemon_grammar(makefile, parse_header);
 
-    chaz_MakeFile_add_rule(makefile, "$(COMMON_OBJS)", parse_header_c);
+    /*
+     * 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);
 
     link_flags = chaz_CC_new_cflags();
     if (chaz_CC_msvc_version_num()) {
@@ -254,8 +242,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     chaz_MakeRule_add_rm_command(clean_rule, "$(COMMON_OBJS)");
     chaz_MakeRule_add_rm_command(clean_rule, "$(CFC_OBJS)");
     chaz_MakeRule_add_rm_command(clean_rule, "$(TEST_CFC_OBJS)");
-    chaz_MakeRule_add_rm_command(clean_rule, parse_header_h);
-    chaz_MakeRule_add_rm_command(clean_rule, parse_header_c);
 
     if (args->code_coverage) {
         chaz_MakeRule_add_rm_command(clean_rule, "cfc.info");

http://git-wip-us.apache.org/repos/asf/lucy/blob/1ad02f6e/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/common/charmonizer.main b/common/charmonizer.main
index e595057..00a5d1f 100644
--- a/common/charmonizer.main
+++ b/common/charmonizer.main
@@ -135,12 +135,8 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     const char *exe_ext  = chaz_OS_exe_ext();
     const char *obj_ext  = chaz_CC_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";
+    const char *json_parser = "$(CORE_DIR)" DIR_SEP "Lucy" DIR_SEP "Util"
+                              DIR_SEP "Json" DIR_SEP "JsonParser";
 
     chaz_MakeFile *makefile;
     chaz_MakeVar  *var;
@@ -150,7 +146,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
 
     chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags();
     chaz_CFlags *makefile_cflags;
-    chaz_CFlags *lemon_cflags;
     chaz_CFlags *link_flags;
     chaz_CFlags *test_cflags;
 
@@ -173,8 +168,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
                           "$(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");
@@ -239,8 +232,9 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     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 = chaz_Util_join("", json_parser, "$(OBJ_EXT)", NULL);
+    chaz_MakeVar_append(var, scratch);
+    free(scratch);
 
     scratch = (char*)malloc(strlen(base_dir) + 80);
     sprintf(scratch, "%s" DIR_SEP "modules" DIR_SEP "analysis" DIR_SEP
@@ -268,8 +262,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
 
     /* 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)");
     chaz_MakeFile_add_var(makefile, "TEST_LUCY_EXE",
@@ -281,12 +273,8 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     lib_filename = chaz_SharedLib_filename(lib);
     chaz_MakeFile_add_rule(makefile, "all", lib_filename);
 
-    lemon_cflags = chaz_CC_new_cflags();
-    chaz_CFlags_enable_optimization(lemon_cflags);
-    chaz_MakeFile_add_compiled_exe(makefile, "$(LEMON_EXE)",
-                                   "$(LEMON_DIR)" DIR_SEP "lemon.c",
-                                   lemon_cflags);
-    chaz_CFlags_destroy(lemon_cflags);
+    chaz_MakeFile_add_lemon_exe(makefile, "$(BASE_DIR)" DIR_SEP "lemon");
+    chaz_MakeFile_add_lemon_grammar(makefile, json_parser);
 
     /*
      * CFC also builds LEMON_EXE, so it might be built twice at the same time
@@ -299,21 +287,18 @@ S_write_makefile(struct chaz_CLIArgs *args) {
     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);
-
     /* Needed for parallel builds. */
     rule = chaz_MakeFile_add_rule(makefile, "$(AUTOGEN_DIR)" DIR_SEP "source"
                                   DIR_SEP "parcel.c", "$(AUTOGEN_DIR)");
 
-    rule = chaz_MakeFile_add_rule(makefile, "$(LUCY_OBJS)", NULL);
-    chaz_MakeRule_add_prereq(rule, json_parser_c);
-    chaz_MakeRule_add_prereq(rule, "$(AUTOGEN_DIR)");
+    rule = chaz_MakeFile_add_rule(makefile, "$(LUCY_OBJS)", "$(AUTOGEN_DIR)");
+    /*
+     * The dependency is actually on JsonParser.h, but make doesn't cope
+     * well with multiple output files.
+     */
+    scratch = chaz_Util_join(".", json_parser, "c", NULL);
+    chaz_MakeRule_add_prereq(rule, scratch);
+    free(scratch);
 
     link_flags = chaz_CC_new_cflags();
     if (chaz_CC_msvc_version_num()) {
@@ -387,8 +372,6 @@ S_write_makefile(struct chaz_CLIArgs *args) {
         chaz_MakeRule_add_rm_command(clean_rule, "$(LUCY_OBJS)");
     }
 
-    chaz_MakeRule_add_rm_command(clean_rule, json_parser_h);
-    chaz_MakeRule_add_rm_command(clean_rule, json_parser_c);
     chaz_MakeRule_add_recursive_rm_command(clean_rule, "$(AUTOGEN_DIR)");
 
     if (args->code_coverage) {


Mime
View raw message