Now have caching of xified C sources using a modification time check
authorNick Downing <downing.nick@gmail.com>
Sat, 21 Jan 2017 15:59:27 +0000 (02:59 +1100)
committerNick Downing <downing.nick@gmail.com>
Sat, 21 Jan 2017 15:59:27 +0000 (02:59 +1100)
test/Makefile
xify/cc.c
xify/ld.c

index 6b194e7..e7fb58d 100644 (file)
@@ -7,4 +7,3 @@ hello: hello.o
 
 clean:
        rm -f hello *.o
-       rm -rf .xify
index 18c0b24..2f05f4c 100644 (file)
--- a/xify/cc.c
+++ b/xify/cc.c
@@ -52,6 +52,14 @@ char *npassname;
 
 int    nc, nl, np, nxo, na;
 
+#ifdef XIFY
+char   **ilist;
+int    ni;
+
+/*char in_path[BUFSIZ];*/
+char   out_path[BUFSIZ];
+#endif
+
 #define        cunlink(s)      if (s) unlink(s)
 
 #ifndef __P
@@ -68,6 +76,10 @@ int dexit __P((void));
 void error __P((char *s, char *x));
 int getsuf __P((char as[]));
 char *setsuf __P((char *as, int ch));
+#ifdef XIFY
+int xify_include __P((char *in_name));
+int xify_file __P((char *in_name, struct stat *in_statbuf));
+#endif
 int callsys __P((char *f, char **v));
 int nodup __P((char **l, char *os));
 char *savestr __P((register char *cp));
@@ -79,6 +91,9 @@ int main(argc, argv) int argc; char **argv; {
        char *assource;
 #endif
        int i, j, c;
+#ifdef XIFY
+       struct stat statbuf;
+#endif
 
        /* ld currently adds upto 5 args; 10 is room to spare */
        av = (char **)calloc(argc+10, sizeof (char **));
@@ -257,6 +272,7 @@ int main(argc, argv) int argc; char **argv; {
                        if (plist[i][2] == '/')
                                plist[i] = strspl("-I", strspl(t, plist[i] + 2));
        }
+       ilist = (char **)calloc(0x100, sizeof (char **));
 #else
        if (pflag==0)
                sprintf(tmp0, "/tmp/ctm%05.5d", getpid());
@@ -276,19 +292,17 @@ int main(argc, argv) int argc; char **argv; {
 #ifdef XIFY
                c = getsuf(clist[i]);
                if (c == 'c') {
-                       t = ".xify";
-                       if (mkdir(t, 0777) == -1 && errno != EEXIST) {
-                               error("can't mkdir: %s", t);
-                               exit(1);
+                       if (stat(clist[i], &statbuf)) {
+                               error("not found: %s", clist[i]);
+                               goto nogood;
                        }
-                       t = strspl(".xify/x_", setsuf(clist[i], 'c'));
-                       av[0] = "xify"; av[1] = clist[i]; av[2] = t; av[3] = 0;
-                       if (callsys(xify, av)) {
+                       if (xify_file(clist[i], &statbuf)) {
+                       nogood:
                                cflag++;
                                eflag++;
                                continue;
                        }
-                       clist[i] = t;
+                       clist[i] = savestr(out_path);
                }
                av[0] = "gcc"; av[1] = "-o";
                na = 2;
@@ -498,6 +512,40 @@ char *setsuf(as, ch) char *as; int ch; {
        return (s1);
 }
 
+#ifdef XIFY
+int xify_file(in_name, in_statbuf) char *in_name; struct stat *in_statbuf; {
+       int i;
+       struct stat out_statbuf;
+       /* note: out_path is an output parameter on success */
+
+       for (i = strlen(in_name); i > 0 && in_name[i - 1] != '/'; --i)
+               ;
+       bcopy(in_name, out_path, i);
+       strcpy(out_path + i, ".xify/x_");
+       strcat(out_path + i, in_name + i);
+       if (
+               stat(out_path, &out_statbuf) == 0 && (
+                       out_statbuf.st_mtim.tv_sec > in_statbuf->st_mtim.tv_sec || (
+                               out_statbuf.st_mtim.tv_sec == in_statbuf->st_mtim.tv_sec &&
+                               out_statbuf.st_mtim.tv_nsec >= in_statbuf->st_mtim.tv_nsec
+                       )
+               )
+               
+       )
+               return 0;
+
+       out_path[i + 5] = 0;
+       if (mkdir(out_path, 0777) == -1 && errno != EEXIST) {
+               error("can't mkdir: %s\n", out_path);
+               return 1;
+       }
+       out_path[i + 5] = '/';
+
+       av[0] = "xify"; av[1] = in_name; av[2] = out_path; av[3] = 0;
+       return callsys(xify, av);
+}
+#endif
+
 int callsys(f, v) char *f; char **v; {
        int t, status;
        char **cpp;
index dd5e18e..be30be2 100644 (file)
--- a/xify/ld.c
+++ b/xify/ld.c
@@ -355,8 +355,12 @@ int        ndir;                   /* number of directories */
 
 #ifdef XIFY
 char   *gcc = "/usr/bin/gcc";
+
 char   **av;
 int    na;
+
+char   in_path[BUFSIZ];
+char   out_path[BUFSIZ];
 #else
 /*
  * Base of the string table of the current module (pass1 and pass2).
@@ -389,7 +393,7 @@ int htoi __P((register char *p));
 void delexit __P((void));
 void endload __P((int argc, char **argv));
 #ifdef XIFY
-void xify_lib __P((char *in_name));
+void xify_library __P((char *in_name));
 int callsys __P((char *f, char **v));
 #else
 void load1arg __P((register char *cp));
@@ -789,7 +793,7 @@ void endload(argc, argv) int argc; char **argv; {
                        ap[--i]='-';
 #ifdef XIFY
                        filname = ap + i;
-                       xify_lib(filname + 2);
+                       xify_library(filname + 2);
                        av[na++] = strspl("-lx_", filname + 2);
 #else
 
@@ -808,16 +812,14 @@ next:
 }
 
 #ifdef XIFY
-void xify_lib(in_name) char *in_name; {
+void xify_library(in_name) char *in_name; {
        int i, j;
-       char in_path[BUFSIZ];
-       char out_path[BUFSIZ];
        struct stat statbuf;
 
        for (int i = 0; i < ndir; ++i) {
-               j = strlen(dirs[i]) - 6; /* always ends with "/.xify" */
+               j = strlen(dirs[i]) - 5; /* remove ".xify" */
                bcopy(dirs[i], in_path, j);
-               strcpy(in_path + j, "/lib");
+               strcpy(in_path + j, "lib");
                strcat(in_path + j, in_name);
                strcat(in_path + j, ".a");
                if (stat(in_path, &statbuf) == 0)
@@ -827,7 +829,7 @@ void xify_lib(in_name) char *in_name; {
        exit(1);
 
 found:
-       j += 6; /* j = strlen(dirs[i]); */
+       j += 5; /* j = strlen(dirs[i]); */
        bcopy(dirs[i], out_path, j);
        strcpy(out_path + j, "/libx_");
        strcat(out_path + j, in_name);