Implement chaz_MakeFile_override_cflags

Specifies a custom set of compiler flags for an object file.


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

Branch: refs/heads/master
Commit: 79216ae87053c241c49fb3e3bbee4180611b357b
Parents: aa559ff
Author: Nick Wellnhofer <wellnho...@aevum.de>
Authored: Tue Jun 2 19:45:22 2015 +0200
Committer: Nick Wellnhofer <wellnho...@aevum.de>
Committed: Wed Jun 3 13:40:50 2015 +0200

----------------------------------------------------------------------
 src/Charmonizer/Core/Make.c | 41 ++++++++++++++++++++++++++++++++++++++++
 src/Charmonizer/Core/Make.h | 10 ++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/79216ae8/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index ffb6ce6..1063bf3 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -504,6 +504,47 @@ chaz_MakeFile_add_lemon_grammar(chaz_MakeFile *makefile,
 }
 
 void
+chaz_MakeFile_override_cflags(chaz_MakeFile *makefile, const char *obj,
+                              chaz_CFlags *cflags) {
+    const char *obj_ext       = chaz_CC_obj_ext();
+    const char *cflags_string = chaz_CFlags_get_string(cflags);
+    size_t obj_ext_len = strlen(obj_ext);
+    size_t obj_len     = strlen(obj);
+    size_t base_len;
+    char *src;
+    char *command;
+    chaz_MakeRule *rule;
+
+    if (obj_len <= obj_ext_len) {
+       chaz_Util_die("Invalid object file: %s", obj);
+    }
+
+    base_len = obj_len - obj_ext_len;
+
+    if (strcmp(obj + base_len, obj_ext) != 0) {
+       chaz_Util_die("Invalid object file: %s", obj);
+    }
+
+    src = malloc(base_len + sizeof(".c"));
+    memcpy(src, obj, base_len);
+    memcpy(src + base_len, ".c", sizeof(".c"));
+
+    rule = chaz_MakeFile_add_rule(makefile, obj, src);
+    if (chaz_CC_msvc_version_num()) {
+        command = chaz_Util_join(" ", "$(CC) /nologo", cflags_string, "/c",
+                                 src, "/Fo$@", NULL);
+    }
+    else {
+        command = chaz_Util_join(" ", "$(CC)", cflags_string, "-c", src,
+                                 "-o $@", NULL);
+    }
+    chaz_MakeRule_add_command(rule, command);
+
+    free(command);
+    free(src);
+}
+
+void
 chaz_MakeFile_write(chaz_MakeFile *makefile) {
     FILE   *out;
     size_t  i;

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/79216ae8/src/Charmonizer/Core/Make.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.h b/src/Charmonizer/Core/Make.h
index e00a83e..50fc301 100644
--- a/src/Charmonizer/Core/Make.h
+++ b/src/Charmonizer/Core/Make.h
@@ -181,6 +181,16 @@ chaz_MakeRule*
 chaz_MakeFile_add_lemon_grammar(chaz_MakeFile *makefile,
                                 const char *base_name);
 
+/** Override compiler flags for a single object file.
+ *
+ * @param makefile The makefile.
+ * @param obj The object file.
+ * @param cflags Compiler flags.
+ */
+void
+chaz_MakeFile_override_cflags(chaz_MakeFile *makefile, const char *obj,
+                              chaz_CFlags *cflags);
+
 /** Write the makefile to a file named 'Makefile' in the current directory.
  *
  * @param makefile The makefile.

Reply via email to