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->dep_dirs, i, list) {
32 list = talloc_asprintf_append(list, "%s ", i->compiled);
37 static char *lib_list(const struct manifest *m)
40 char **libs = get_libs(m, ".", &num, &m->info_file->compiled);
41 char *ret = talloc_strdup(m, "");
43 for (i = 0; i < num; i++)
44 ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
48 static void *check_use_build(struct manifest *m,
50 unsigned int *timeleft)
54 char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
57 tmpfile = maybe_temp_file(m, ".c", keep, basename);
59 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
61 return talloc_asprintf(m, "Creating temporary file: %s",
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)) {
73 return "Failure writing to temporary file";
77 return compile_and_link(m, tmpfile, ccan_dir, obj_list(m), "",
79 maybe_temp_file(m, "", keep, tmpfile));
82 static const char *describe_use_build(struct manifest *m, void *check_result)
84 return talloc_asprintf(check_result,
85 "Linking against module:\n"
86 "%s", (char *)check_result);
89 struct ccanlint check_build = {
91 .name = "Module can be linked against trivial program",
93 .check = check_use_build,
94 .describe = describe_use_build,
98 REGISTER_TEST(check_build, &build, NULL);