+int main(int argc, char *argv[])
+{
+ bool summary = false, pass = true, deps_fail_ignore = false;
+ unsigned int i;
+ const char *prefix = "";
+ char *cwd = path_cwd(NULL), *dir;
+ struct ccanlint top; /* cannot_run may try to set ->can_run */
+ const char *override_compiler = NULL, *override_cflags = NULL;
+
+ /* Empty graph node to which we attach everything else. */
+ dgraph_init_node(&top.node);
+
+ opt_register_early_noarg("--verbose|-v", opt_inc_intval, &verbose,
+ "verbose mode (up to -vvvv)");
+ opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
+ "do not compile anything");
+ opt_register_noarg("-l|--list-tests", list_tests, NULL,
+ "list tests ccanlint performs (and exit)");
+ opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
+ "print dependency graph of tests in Graphviz .dot format");
+ opt_register_noarg("-k|--keep", keep_tests, NULL,
+ "do not delete ccanlint working files");
+ opt_register_noarg("--summary|-s", opt_set_bool, &summary,
+ "simply give one line summary");
+ opt_register_arg("-x|--exclude <testname>", exclude_test, NULL, NULL,
+ "exclude <testname> (can be used multiple times)");
+ opt_register_arg("--timeout <milleseconds>", opt_set_uintval,
+ NULL, &timeout,
+ "ignore (terminate) tests that are slower than this");
+ opt_register_arg("-t|--target <testname>", opt_set_target, NULL,
+ &top.node,
+ "only run one test (and its prerequisites)");
+ opt_register_arg("--compiler <compiler>", opt_set_const_charp,
+ NULL, &override_compiler, "set the compiler");
+ opt_register_arg("--cflags <flags>", opt_set_const_charp,
+ NULL, &override_cflags, "set the compiler flags");
+ opt_register_noarg("--deps-fail-ignore", opt_set_bool,
+ &deps_fail_ignore,
+ "don't fail if external dependencies are missing");
+ opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
+ "\nA program for checking and guiding development"
+ " of CCAN modules.",
+ "This usage message");
+
+ /* Do verbose before anything else... */
+ opt_early_parse(argc, argv, opt_log_stderr_exit);
+
+ /* We move into temporary directory, so gcov dumps its files there. */
+ if (chdir(temp_dir()) != 0)
+ err(1, "Error changing to %s temporary dir", temp_dir());
+
+ init_tests();
+
+ if (verbose >= 3) {
+ compile_verbose = true;
+ print_test_depends();
+ }
+ if (verbose >= 4)
+ tools_verbose = true;
+
+ opt_parse(&argc, argv, opt_log_stderr_exit);
+
+ if (!targeting)
+ strmap_iterate(&tests, add_to_all, &top.node);
+
+ if (argc == 1)
+ dir = cwd;
+ else
+ dir = path_simplify(NULL, take(path_join(NULL, cwd, argv[1])));
+
+ 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, 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(&top.node, cwd, "",
+ summary, deps_fail_ignore);
+ else {
+ for (i = 1; i < argc; i++) {
+ dir = path_canon(NULL,
+ take(path_join(NULL, cwd, argv[i])));
+ if (!dir)
+ err(1, "Cannot get canonical name of '%s'",
+ argv[i]);
+
+ prefix = path_join(NULL, ccan_dir, "ccan");
+ prefix = path_rel(NULL, take(prefix), dir);
+ prefix = tal_strcat(NULL, take(prefix), ": ");
+
+ pass &= test_module(&top.node, dir, prefix, summary,
+ deps_fail_ignore);
+ reset_tests(&top.node);
+ }
+ }
+ return pass ? 0 : 1;