You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/06/03 13:42:48 UTC

[1/2] lucy-charmonizer git commit: Implement chaz_MakeRule_add_command_with_libpath

Repository: lucy-charmonizer
Updated Branches:
  refs/heads/master 1fbb61f42 -> 79216ae87


Implement chaz_MakeRule_add_command_with_libpath

Adds a command to a rule that executes with a special runtime library
path.


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

Branch: refs/heads/master
Commit: aa559ff0c36619f833de51b15c7a3033c90c846c
Parents: 1fbb61f
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Jun 2 18:33:00 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Jun 3 13:40:15 2015 +0200

----------------------------------------------------------------------
 src/Charmonizer/Core/Make.c | 36 ++++++++++++++++++++++++++++++++++++
 src/Charmonizer/Core/Make.h | 10 ++++++++++
 src/Charmonizer/Core/Util.c | 23 +++++++++++++++++++++--
 src/Charmonizer/Core/Util.h |  5 +++++
 4 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/aa559ff0/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index d1ba159..ffb6ce6 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -647,6 +647,42 @@ chaz_MakeRule_add_command(chaz_MakeRule *rule, const char *command) {
 }
 
 void
+chaz_MakeRule_add_command_with_libpath(chaz_MakeRule *rule,
+                                       const char *command, ...) {
+    va_list args;
+    char *path        = NULL;
+    char *lib_command = NULL;
+
+    if (strcmp(chaz_OS_shared_lib_ext(), ".so") == 0) {
+        va_start(args, command);
+        path = chaz_Util_vjoin(":", args);
+        va_end(args);
+
+        lib_command = chaz_Util_join("", "LD_LIBRARY_PATH=", path,
+                                     ":$$LD_LIBRARY_PATH ", command, NULL);
+
+        free(path);
+    }
+    else if (strcmp(chaz_OS_shared_lib_ext(), ".dll") == 0) {
+        va_start(args, command);
+        path = chaz_Util_vjoin(";", args);
+        va_end(args);
+
+        lib_command = chaz_Util_join("", "path ", path, ";%path% && ", command,
+                                     NULL);
+    }
+    else {
+        /* Assume that library paths are compiled into the executable on
+         * Darwin.
+         */
+        lib_command = chaz_Util_strdup(command);
+    }
+
+    chaz_MakeRule_add_command(rule, lib_command);
+    free(lib_command);
+}
+
+void
 chaz_MakeRule_add_rm_command(chaz_MakeRule *rule, const char *files) {
     char *command;
 

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/aa559ff0/src/Charmonizer/Core/Make.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.h b/src/Charmonizer/Core/Make.h
index 2d43f32..e00a83e 100644
--- a/src/Charmonizer/Core/Make.h
+++ b/src/Charmonizer/Core/Make.h
@@ -221,6 +221,16 @@ chaz_MakeRule_add_prereq(chaz_MakeRule *rule, const char *prereq);
 void
 chaz_MakeRule_add_command(chaz_MakeRule *rule, const char *command);
 
+/** Add a command to be executed with a special runtime library path.
+ *
+ * @param rule The rule.
+ * @param command The additional command.
+ * @param ... NULL-terminated list of library directories.
+ */
+void
+chaz_MakeRule_add_command_with_libpath(chaz_MakeRule *rule,
+                                       const char *command, ...);
+
 /** Add a command to remove one or more files.
  *
  * @param rule The rule.

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/aa559ff0/src/Charmonizer/Core/Util.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Util.c b/src/Charmonizer/Core/Util.c
index 2c494ef..0d0cc47 100644
--- a/src/Charmonizer/Core/Util.c
+++ b/src/Charmonizer/Core/Util.c
@@ -21,6 +21,13 @@
 #include "Charmonizer/Core/Util.h"
 #include "Charmonizer/Core/OperatingSystem.h"
 
+/* va_copy is not part of C89. Assume that simple assignment works if it
+ * isn't defined.
+ */
+#ifndef va_copy
+  #define va_copy(dst, src) ((dst) = (src))
+#endif
+
 /* Global verbosity setting. */
 int chaz_Util_verbosity = 1;
 
@@ -120,6 +127,18 @@ chaz_Util_strdup(const char *string) {
 char*
 chaz_Util_join(const char *sep, ...) {
     va_list args;
+    char *result;
+
+    va_start(args, sep);
+    result = chaz_Util_vjoin(sep, args);
+    va_end(args);
+
+    return result;
+}
+
+char*
+chaz_Util_vjoin(const char *sep, va_list orig_args) {
+    va_list args;
     const char *string;
     char *result, *p;
     size_t sep_len = strlen(sep);
@@ -127,7 +146,7 @@ chaz_Util_join(const char *sep, ...) {
     int i;
 
     /* Determine result size. */
-    va_start(args, sep);
+    va_copy(args, orig_args);
     size = 1;
     string = va_arg(args, const char*);
     for (i = 0; string; ++i) {
@@ -140,7 +159,7 @@ chaz_Util_join(const char *sep, ...) {
     result = (char*)malloc(size);
 
     /* Create result string. */
-    va_start(args, sep);
+    va_copy(args, orig_args);
     p = result;
     string = va_arg(args, const char*);
     for (i = 0; string; ++i) {

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/aa559ff0/src/Charmonizer/Core/Util.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Util.h b/src/Charmonizer/Core/Util.h
index cde04d0..67f6dad 100644
--- a/src/Charmonizer/Core/Util.h
+++ b/src/Charmonizer/Core/Util.h
@@ -51,6 +51,11 @@ chaz_Util_strdup(const char *string);
 char*
 chaz_Util_join(const char *sep, ...);
 
+/* Join a NULL-terminated list of strings using a separator.
+ */
+char*
+chaz_Util_vjoin(const char *sep, va_list args);
+
 /* Get the length of a file (may overshoot on text files under DOS).
  */
 long


[2/2] lucy-charmonizer git commit: Implement chaz_MakeFile_override_cflags

Posted by nw...@apache.org.
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 <we...@aevum.de>
Authored: Tue Jun 2 19:45:22 2015 +0200
Committer: Nick Wellnhofer <we...@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.