We weren't using the compiler and cflags options in tools/compile.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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;
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);
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.",
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);
#include <stdbool.h>
#include "../doc_extract.h"
#include "../manifest.h"
+#include "../tools.h"
#include "licenses.h"
AUTODATA_TYPE(ccanlint_tests, struct ccanlint);
/* 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;
#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. */
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;
}
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;
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++) {
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;
}
/* 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 */
#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" \
#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);