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)
19 if (list_empty(&m->c_files))
20 return "No C files in module";
22 return "Safe mode enabled";
26 static bool compile_obj(struct ccan_file *c_file, char *objfile, char **report)
30 contents = run_command(objfile, "cc " CFLAGS " -o %s -c %s",
31 objfile, c_file->name);
34 *report = talloc_append_string(*report, contents);
42 static int cleanup_obj(char *objfile)
48 static void *check_objs_build(struct manifest *m)
53 /* One point for each obj file. */
54 build_objs.total_score = 0;
55 list_for_each(&m->c_files, i, list)
56 build_objs.total_score++;
58 list_for_each(&m->c_files, i, list) {
59 char *objfile = talloc_strdup(m, i->name);
60 objfile[strlen(objfile)-1] = 'o';
62 if (compile_obj(i, objfile, &report))
63 talloc_set_destructor(objfile, cleanup_obj);
68 static const char *describe_objs_build(struct manifest *m, void *check_result)
70 return talloc_asprintf(check_result,
71 "%s", (char *)check_result);
74 struct ccanlint build_objs = {
75 .name = "Module object files can be built",
77 .check = check_objs_build,
78 .describe = describe_objs_build,
82 REGISTER_TEST(build_objs, &depends_exist, NULL);