1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
17 static const char *can_build(struct manifest *m)
20 return "Safe mode enabled";
24 static char *obj_list(const struct manifest *m)
26 char *list = talloc_strdup(m, "");
29 /* Other CCAN deps. */
30 list_for_each(&m->deps, i, list) {
32 list = talloc_asprintf_append(list, "%s ",
38 static char *lib_list(const struct manifest *m)
41 char **libs = get_libs(m, ".", &num, &m->info_file->compiled);
42 char *ret = talloc_strdup(m, "");
44 for (i = 0; i < num; i++)
45 ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
49 static void check_use_build(struct manifest *m,
51 unsigned int *timeleft, struct score *score)
54 char *tmpfile, *cmdout;
55 char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
58 tmpfile = maybe_temp_file(m, ".c", keep, basename);
60 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
62 err(1, "Creating temporary file %s", tmpfile);
64 contents = talloc_asprintf(tmpfile,
65 "#include <ccan/%s/%s.h>\n"
70 m->basename, m->basename);
71 if (write(fd, contents, strlen(contents)) != strlen(contents))
72 err(1, "Failure writing to temporary file %s", tmpfile);
75 if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
76 compiler, cflags, lib_list(m),
77 maybe_temp_file(m, "", keep, tmpfile),
80 score->score = score->total;
82 score->error = cmdout;
86 struct ccanlint module_links = {
87 .key = "module_links",
88 .name = "Module can be linked against trivial program",
89 .check = check_use_build,
91 .needs = "module_builds depends_build"
94 REGISTER_TEST(module_links);