Make depends build the _info files (easier for Dinesh's work)
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 5 Aug 2008 08:28:02 +0000 (18:28 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 5 Aug 2008 08:28:02 +0000 (18:28 +1000)
Makefile
tools/ccan_depends.c
tools/depends.c

index 0e31fa641dcb62dd9a0279fb9012133e78841206..6329f05b46b9515d05bfe84d72f9f56ff76d817f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,11 +14,8 @@ libccan.a: $(ALL_LIBS)
 check: $(ALL_DIRS:%=test-%)
 
 distclean: clean
-       rm -f */_info
        rm -f $(ALL_DEPENDS)
 
-$(ALL_DEPENDS): $(ALL_DIRS:=/_info)
-
 $(ALL_DEPENDS): %/.depends: tools/ccan_depends
        tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
 
index 982d13b32b9f90e3d555efffc44fa16c8ee0d486..a5f6cc287ef0fd7458b26d170bd937b48d57c0b2 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include "string/string.h"
+#include "talloc/talloc.h"
 
 int main(int argc, char *argv[])
 {
@@ -13,7 +14,7 @@ int main(int argc, char *argv[])
                errx(1, "Usage: ccan_depends <dir>\n"
                        "Spits out all the ccan dependencies (recursively)");
 
-       deps = get_deps(NULL, argv[1]);
+       deps = get_deps(talloc_autofree_context(), argv[1]);
        for (i = 0; deps[i]; i++)
                if (strstarts(deps[i], "ccan/"))
                        printf("%s\n", deps[i]);
index 1422c8585f51d8b220fc04ca9144dc91d9eaacae..e8cb53b8394c807aa9ddb6a7ba7a55777a06c38b 100644 (file)
@@ -3,6 +3,7 @@
 #include "tools.h"
 #include <err.h>
 #include <stdbool.h>
+#include <unistd.h>
 
 static char ** __attribute__((format(printf, 3, 4)))
 lines_from_cmd(const void *ctx, unsigned int *num, char *format, ...)
@@ -27,11 +28,34 @@ lines_from_cmd(const void *ctx, unsigned int *num, char *format, ...)
        return strsplit(ctx, buffer, "\n", num);
 }
 
+static int unlink_info(char *infofile)
+{
+       unlink(infofile);
+       return 0;
+}
+
+/* Be careful about trying to compile over running programs (parallel make) */
+static char *compile_info(const void *ctx, const char *dir)
+{
+       char *infofile = talloc_asprintf(ctx, "%s/_info.%u", dir, getpid());
+       char *cmd = talloc_asprintf(ctx, "cc " CFLAGS " -o %s %s/_info.c",
+                                   infofile, dir);
+       talloc_set_destructor(infofile, unlink_info);
+       if (system(cmd) != 0)
+               return NULL;
+
+       return infofile;
+}
+
 static char **get_one_deps(const void *ctx, const char *dir, unsigned int *num)
 {
-       char **deps, *cmd;
+       char **deps, *cmd, *infofile;
+
+       infofile = compile_info(ctx, dir);
+       if (!infofile)
+               errx(1, "Could not compile _info for '%s'", dir);
 
-       cmd = talloc_asprintf(ctx, "%s/_info depends", dir);
+       cmd = talloc_asprintf(ctx, "%s depends", infofile);
        deps = lines_from_cmd(cmd, num, "%s", cmd);
        if (!deps)
                err(1, "Could not run '%s'", cmd);