1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/grab_file/grab_file.h>
5 #include <ccan/str/str.h>
18 static const char *can_build(struct manifest *m)
21 return "Safe mode enabled";
25 static int cleanup_testfile(char *testfile)
31 static void *check_includes_build(struct manifest *m)
34 char *tmpfile, *objfile;
37 tmpfile = talloc_strdup(m, tempnam("/tmp", "ccanlint"));
38 talloc_set_destructor(tmpfile, cleanup_testfile);
39 objfile = talloc_strdup(m, tempnam("/tmp", "ccanlint"));
40 talloc_set_destructor(objfile, cleanup_testfile);
42 fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
44 return talloc_asprintf(m, "Creating temporary file: %s",
47 contents = talloc_asprintf(tmpfile, "#include <ccan/%s/%s.h>\n",
48 m->basename, m->basename);
49 if (write(fd, contents, strlen(contents)) != strlen(contents)) {
51 return "Failure writing to temporary file";
55 return run_command(m, "cc " CFLAGS " -o %s -c -x c %s",
59 static const char *describe_includes_build(struct manifest *m,
62 return talloc_asprintf(check_result,
63 "#include of the main header file:\n"
64 "%s", (char *)check_result);
67 struct ccanlint includes_build = {
68 .name = "Can compile against main header",
70 .check = check_includes_build,
71 .describe = describe_includes_build,
75 REGISTER_TEST(includes_build, &depends_exist, NULL);