ccanlint: Add cflags support to _info
[ccan] / tools / ccanlint / tests / module_links.c
index 79aa7d1a872a6421c6fb8706142fe2df0c2b9e76..403fff1a56120d31926359ca64af51afd3480732 100644 (file)
@@ -1,7 +1,7 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
 #include <ccan/str/str.h>
+#include <ccan/take/take.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -27,29 +27,40 @@ static char *obj_list(const struct manifest *m)
        struct manifest *i;
 
        if (m->compiled[COMPILE_NORMAL])
        struct manifest *i;
 
        if (m->compiled[COMPILE_NORMAL])
-               list = talloc_strdup(m, m->compiled[COMPILE_NORMAL]);
+               list = tal_strdup(m, m->compiled[COMPILE_NORMAL]);
        else
        else
-               list = talloc_strdup(m, "");
+               list = tal_strdup(m, "");
 
        /* Other CCAN deps. */
        list_for_each(&m->deps, i, list) {
 
        /* Other CCAN deps. */
        list_for_each(&m->deps, i, list) {
-               if (i->compiled[COMPILE_NORMAL])
-                       list = talloc_asprintf_append(list, " %s",
-                                                     i->compiled
-                                                     [COMPILE_NORMAL]);
+               if (!i->compiled[COMPILE_NORMAL])
+                       continue;
+               list = tal_strcat(m, take(list), " ");
+               list = tal_strcat(m, take(list), i->compiled[COMPILE_NORMAL]);
        }
        return list;
 }
 
        }
        return list;
 }
 
+static char *cflags_list(const struct manifest *m)
+{
+       unsigned int i;
+       char *ret = tal_strdup(m, cflags);
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&ret, " %s", flags[i]);
+       return ret;
+}
+
 static char *lib_list(const struct manifest *m)
 {
        unsigned int i;
        char **libs;
 static char *lib_list(const struct manifest *m)
 {
        unsigned int i;
        char **libs;
-       char *ret = talloc_strdup(m, "");
+       char *ret = tal_strdup(m, "");
 
 
-       libs = get_libs(m, m->dir, true, get_or_compile_info);
+       libs = get_libs(m, m->dir, "depends", get_or_compile_info);
        for (i = 0; libs[i]; i++)
        for (i = 0; libs[i]; i++)
-               ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
+               tal_append_fmt(&ret, "-l%s ", libs[i]);
        return ret;
 }
 
        return ret;
 }
 
@@ -58,28 +69,30 @@ static void check_use_build(struct manifest *m,
 {
        char *contents;
        char *tmpfile, *cmdout;
 {
        char *contents;
        char *tmpfile, *cmdout;
-       char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
        int fd;
        int fd;
+       char *flags;
 
 
-       tmpfile = temp_file(m, ".c", basename);
+       tmpfile = temp_file(m, ".c", "example.c");
 
        fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
        if (fd < 0)
                err(1, "Creating temporary file %s", tmpfile);
 
 
        fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
        if (fd < 0)
                err(1, "Creating temporary file %s", tmpfile);
 
-       contents = talloc_asprintf(tmpfile,
-                                  "#include <ccan/%s/%s.h>\n"
-                                  "int main(void)\n"
-                                  "{\n"
-                                  "    return 0;\n"
-                                  "}\n",
-                                  m->basename, m->basename);
+       contents = tal_fmt(tmpfile,
+                          "#include <ccan/%s/%s.h>\n"
+                          "int main(void)\n"
+                          "{\n"
+                          "    return 0;\n"
+                          "}\n",
+                          m->modname, m->basename);
        if (write(fd, contents, strlen(contents)) != strlen(contents))
                err(1, "Failure writing to temporary file %s", tmpfile);
        close(fd);
 
        if (write(fd, contents, strlen(contents)) != strlen(contents))
                err(1, "Failure writing to temporary file %s", tmpfile);
        close(fd);
 
+       flags = cflags_list(m);
+
        if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
        if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
-                            compiler, cflags, lib_list(m),
+                            compiler, flags, lib_list(m),
                             temp_file(m, "", tmpfile),
                             &cmdout)) {
                score->pass = true;
                             temp_file(m, "", tmpfile),
                             &cmdout)) {
                score->pass = true;