summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-04-16 20:53:08 -0400
committermidipix <writeonce@midipix.org>2016-04-17 02:51:57 -0400
commit0913c3d46b180e40867e7de6a062582acd1902e9 (patch)
treeaf3169150d257fabb06d7073a9a7b1c0e038580c
parentdcb4535da0c4e22eafb51a20128c436e3337f8b7 (diff)
downloadslibtool-0913c3d46b180e40867e7de6a062582acd1902e9.tar.bz2
slibtool-0913c3d46b180e40867e7de6a062582acd1902e9.tar.xz
link mode: .deps file generation: initial implementation.
-rw-r--r--include/slibtool/slibtool.h1
-rw-r--r--src/logic/slbt_exec_ctx.c3
-rw-r--r--src/logic/slbt_exec_link.c58
3 files changed, 62 insertions, 0 deletions
diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h
index 265ba49..24dd8be 100644
--- a/include/slibtool/slibtool.h
+++ b/include/slibtool/slibtool.h
@@ -100,6 +100,7 @@ struct slbt_exec_ctx {
char ** lout[2];
char ** sentinel;
FILE * fwrapper;
+ FILE * fdeps;
char * csrc;
char * ldirname;
char * lbasename;
diff --git a/src/logic/slbt_exec_ctx.c b/src/logic/slbt_exec_ctx.c
index 39fa26c..37bb475 100644
--- a/src/logic/slbt_exec_ctx.c
+++ b/src/logic/slbt_exec_ctx.c
@@ -329,6 +329,9 @@ static int slbt_free_exec_ctx_impl(
if (ictx->ctx.fwrapper)
fclose(ictx->ctx.fwrapper);
+ if (ictx->ctx.fdeps)
+ fclose(ictx->ctx.fdeps);
+
free(ictx->args);
free(ictx->shadow);
free (ictx);
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 501486f..3fd35ad 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -245,6 +245,56 @@ static int slbt_exec_link_remove_file(
return -1;
}
+static int slbt_exec_link_create_dep_file(
+ struct slbt_exec_ctx * ectx,
+ char ** altv,
+ const char * libfilename)
+{
+ char ** parg;
+ char * popt;
+ char * plib;
+ char depfile[PATH_MAX];
+
+ if (ectx->fdeps)
+ fclose(ectx->fdeps);
+
+ if ((size_t)snprintf(depfile,sizeof(depfile),"%s.slibtool.deps",
+ libfilename)
+ >= sizeof(depfile))
+ return -1;
+
+ if (!(ectx->fdeps = fopen(depfile,"w")))
+ return -1;
+
+ for (parg=altv; *parg; parg++) {
+ popt = 0;
+ plib = 0;
+
+ if (!strcmp(*parg,"-l")) {
+ popt = *parg++;
+ plib = *parg;
+ } else if (!strcmp(*parg,"--library")) {
+ popt = *parg++;
+ plib = *parg;
+ } else if (!strncmp(*parg,"-l",2)) {
+ popt = *parg;
+ plib = popt + 2;
+ } else if (!strncmp(*parg,"--library=",10)) {
+ popt = *parg;
+ plib = popt + 10;
+ }
+
+ if (plib)
+ if (fprintf(ectx->fdeps,"-l%s\n",plib) < 0)
+ return -1;
+ }
+
+ if (fflush(ectx->fdeps))
+ return -1;
+
+ return 0;
+}
+
static int slbt_exec_link_create_archive(
const struct slbt_driver_ctx * dctx,
struct slbt_exec_ctx * ectx,
@@ -298,6 +348,10 @@ static int slbt_exec_link_create_archive(
if (slbt_exec_link_remove_file(dctx,ectx,output))
return -1;
+ /* .deps */
+ if (slbt_exec_link_create_dep_file(ectx,ectx->cargv,arfilename))
+ return -1;
+
/* ar spawn */
if ((slbt_spawn(ectx,true) < 0) || ectx->exitcode)
return -1;
@@ -413,6 +467,10 @@ static int slbt_exec_link_create_library(
if (slbt_output_link(dctx,ectx))
return -1;
+ /* .deps */
+ if (slbt_exec_link_create_dep_file(ectx,ectx->argv,dsofilename))
+ return -1;
+
/* spawn */
if ((slbt_spawn(ectx,true) < 0) || ectx->exitcode)
return -1;