From: Rusty Russell Date: Fri, 7 Dec 2012 05:56:07 +0000 (+1030) Subject: ccanlint: fix --compiler and --cflags options to apply to _info files as well. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=0248fa2c84bdf4b5117d2672a68d89505aacae8f ccanlint: fix --compiler and --cflags options to apply to _info files as well. We weren't using the compiler and cflags options in tools/compile. Signed-off-by: Rusty Russell --- diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index 2fdb8863..1a847deb 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -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 ", opt_set_target, NULL, &all, "only run one test (and its prerequisites)"); opt_register_arg("--compiler ", opt_set_const_charp, - NULL, &compiler, "set the compiler"); + NULL, &override_compiler, "set the compiler"); opt_register_arg("--cflags ", 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); diff --git a/tools/ccanlint/ccanlint.h b/tools/ccanlint/ccanlint.h index 6c4a1ba7..8b6e81f7 100644 --- a/tools/ccanlint/ccanlint.h +++ b/tools/ccanlint/ccanlint.h @@ -8,6 +8,7 @@ #include #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; diff --git a/tools/compile.c b/tools/compile.c index 65283bc7..b88c1d86 100644 --- a/tools/compile.c +++ b/tools/compile.c @@ -1,6 +1,15 @@ #include "tools.h" #include +#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. */ diff --git a/tools/depends.c b/tools/depends.c index 4f56d14e..399b0aad 100644 --- a/tools/depends.c +++ b/tools/depends.c @@ -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; } diff --git a/tools/read_config_header.c b/tools/read_config_header.c index 732ab4ab..2701c902 100644 --- a/tools/read_config_header.c +++ b/tools/read_config_header.c @@ -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; } diff --git a/tools/read_config_header.h b/tools/read_config_header.h index 62eb152e..8554f762 100644 --- a/tools/read_config_header.h +++ b/tools/read_config_header.h @@ -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 */ diff --git a/tools/tools.h b/tools/tools.h index 40f1bcb0..60707499 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -8,12 +8,9 @@ #include #include -#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);