ccanlint: fix --compiler and --cflags options to apply to _info files as well.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 7 Dec 2012 05:56:07 +0000 (16:26 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 7 Dec 2012 05:56:07 +0000 (16:26 +1030)
We weren't using the compiler and cflags options in tools/compile.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/ccanlint/ccanlint.c
tools/ccanlint/ccanlint.h
tools/compile.c
tools/depends.c
tools/read_config_header.c
tools/read_config_header.h
tools/tools.h

index 2fdb8863cea9dc79c291518bb89c668a653e80c5..1a847deb4c7e326203ba33ca2b5189a58c34bece 100644 (file)
@@ -46,10 +46,6 @@ bool keep_results = false;
 static bool targeting = false;
 static unsigned int timeout;
 
-/* These are overridden at runtime if we can find config.h */
-const char *compiler = NULL;
-const char *cflags = NULL;
-
 const char *config_header;
 
 const char *ccan_dir;
@@ -607,6 +603,7 @@ int main(int argc, char *argv[])
        const char *prefix = "";
        char *cwd = path_cwd(NULL), *dir;
        struct dgraph_node all;
+       const char *override_compiler = NULL, *override_cflags = NULL;
        
        /* Empty graph node to which we attach everything else. */
        dgraph_init_node(&all);
@@ -631,9 +628,9 @@ int main(int argc, char *argv[])
        opt_register_arg("-t|--target <testname>", opt_set_target, NULL, &all,
                         "only run one test (and its prerequisites)");
        opt_register_arg("--compiler <compiler>", opt_set_const_charp,
-                        NULL, &compiler, "set the compiler");
+                        NULL, &override_compiler, "set the compiler");
        opt_register_arg("--cflags <flags>", opt_set_const_charp,
-                        NULL, &cflags, "set the compiler flags");
+                        NULL, &override_cflags, "set the compiler flags");
        opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
                           "\nA program for checking and guiding development"
                           " of CCAN modules.",
@@ -668,8 +665,13 @@ int main(int argc, char *argv[])
        ccan_dir = find_ccan_dir(dir);
        if (!ccan_dir)
                errx(1, "Cannot find ccan/ base directory in %s", dir);
-       config_header = read_config_header(ccan_dir, &compiler, &cflags,
-                                          verbose > 1);
+       config_header = read_config_header(ccan_dir, verbose > 1);
+
+       /* We do this after read_config_header has set compiler & cflags */
+       if (override_cflags)
+               cflags = override_cflags;
+       if (override_compiler)
+               compiler = override_compiler;
 
        if (argc == 1)
                pass = test_module(&all, cwd, "", summary);
index 6c4a1ba7744d8a28fd994d9df79440d3a460fb0b..8b6e81f75247f3cbcf0547e7b65de0ed509238a2 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdbool.h>
 #include "../doc_extract.h"
 #include "../manifest.h"
+#include "../tools.h"
 #include "licenses.h"
 
 AUTODATA_TYPE(ccanlint_tests, struct ccanlint);
@@ -189,9 +190,6 @@ extern bool safe_mode;
 /* Did the user want to keep all the results? */
 extern bool keep_results;
 
-/* Compiler and CFLAGS, from config.h if available. */
-extern const char *compiler, *cflags;
-
 /* Contents of config.h (or NULL if not found) */
 extern const char *config_header;
 
index 65283bc7a166bd8d797fa0c444de25fa37014a53..b88c1d865186b636e35ee359186517196d80b7ac 100644 (file)
@@ -1,6 +1,15 @@
 #include "tools.h"
 #include <stdlib.h>
 
+#ifndef CCAN_COMPILER
+#define CCAN_COMPILER DEFAULT_CCAN_COMPILER
+#endif
+#ifndef CCAN_CFLAGS
+#define CCAN_CFLAGS DEFAULT_CCAN_CFLAGS
+#endif
+const char *compiler = CCAN_COMPILER;
+const char *cflags = CCAN_CFLAGS;
+
 bool compile_verbose = false;
 
 /* Compile multiple object files into a single.  Returns NULL if fails. */
index 4f56d14e1eeb97edf71f5b07b2e7050ec3c940a1..399b0aadf5affee6b8b814d2facc118a40150bf0 100644 (file)
@@ -62,8 +62,7 @@ char *compile_info(const void *ctx, const char *dir)
 
        compiled = temp_file(ctx, "", "info");
        if (compile_and_link(ctx, info_c_file, find_ccan_dir(dir), "",
-                            CCAN_COMPILER, CCAN_CFLAGS " -I.", "",
-                            compiled, &output))
+                            compiler, cflags, "", compiled, &output))
                return compiled;
        return NULL;
 }
index 732ab4abb2970d7fd54bb08a720abdc3b98b7ed6..2701c9023ec92f1e68e3b16bb768f68bb396831c 100644 (file)
@@ -87,9 +87,7 @@ static char *demangle_string(char *string)
        return string;
 }
 
-char *read_config_header(const char *ccan_dir,
-                        const char **compiler, const char **cflags,
-                        bool verbose)
+char *read_config_header(const char *ccan_dir, bool verbose)
 {
        char *fname = path_join(NULL, ccan_dir, "config.h");
        char **lines;
@@ -100,7 +98,7 @@ char *read_config_header(const char *ccan_dir,
        tal_free(fname);
 
        if (!config_header)
-               goto out;
+               return NULL;
 
        lines = tal_strsplit(config_header, config_header, "\n", STR_EMPTY_OK);
        for (i = 0; i < tal_count(lines) - 1; i++) {
@@ -112,30 +110,23 @@ char *read_config_header(const char *ccan_dir,
                if (!get_token(line, "define"))
                        continue;
                sym = get_symbol_token(lines, line);
-               if (streq(sym, "CCAN_COMPILER") && !compiler) {
-                       *compiler = demangle_string(lines[i]);
-                       if (!*compiler)
+               if (streq(sym, "CCAN_COMPILER")) {
+                       compiler = demangle_string(lines[i]);
+                       if (!compiler)
                                errx(1, "%s:%u:could not parse CCAN_COMPILER",
                                     fname, i+1);
                        if (verbose)
                                printf("%s: compiler set to '%s'\n",
-                                      fname, *compiler);
-               } else if (streq(sym, "CCAN_CFLAGS") && !cflags) {
-                       *cflags = demangle_string(lines[i]);
-                       if (!*cflags)
+                                      fname, compiler);
+               } else if (streq(sym, "CCAN_CFLAGS")) {
+                       cflags = demangle_string(lines[i]);
+                       if (!cflags)
                                errx(1, "%s:%u:could not parse CCAN_CFLAGS",
                                     fname, i+1);
                        if (verbose)
                                printf("%s: compiler flags set to '%s'\n",
-                                      fname, *cflags);
+                                      fname, cflags);
                }
        }
-
-out:
-       if (!*compiler)
-               *compiler = CCAN_COMPILER;
-       if (!*cflags)
-               *cflags = CCAN_CFLAGS;
-
        return config_header;
 }
index 62eb152e4957fa967260f8576e8048740102af10..8554f7622e8a4c04b6027d8d0d021a782563beb0 100644 (file)
@@ -8,9 +8,7 @@ bool get_token(const char **line, const char *token);
 /* Get an identifier token. */
 char *get_symbol_token(void *ctx, const char **line);
 
-/* Read config header from config_dir/config.h: set compiler/cflags. */
-char *read_config_header(const char *config_dir,
-                        const char **compiler, const char **cflags,
-                        bool verbose);
+/* Read config header from config_dir/config.h: sets compiler/cflags. */
+char *read_config_header(const char *config_dir, bool verbose);
 
 #endif /* CCAN_TOOLS_READ_CONFIG_HEADER_H */
index 40f1bcb0a1299159408ec67dc11d730e67b87b7e..60707499efcf559b2848d1778763eeba809ffa67 100644 (file)
@@ -8,12 +8,9 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
-#ifndef CCAN_COMPILER
-#define CCAN_COMPILER "cc"
-#endif
-#ifndef CCAN_CFLAGS
-#define CCAN_CFLAGS "-g -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"
-#endif
+/* These are the defaults. */
+#define DEFAULT_CCAN_COMPILER "cc"
+#define DEFAULT_CCAN_CFLAGS "-g"
 
 #define IDENT_CHARS    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
                        "abcdefghijklmnopqrstuvwxyz" \
@@ -23,6 +20,9 @@
 
 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
 
+/* Actual compiler and cflags (defaults to CCAN_COMPILER and CCAN_CFLAGS). */
+extern const char *compiler, *cflags;
+
 /* This compiles up the _info file into a temporary. */
 char *compile_info(const void *ctx, const char *dir);