summaryrefslogtreecommitdiffhomepage
path: root/src/logic/slbt_exec_link.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/logic/slbt_exec_link.c')
-rw-r--r--src/logic/slbt_exec_link.c58
1 files changed, 58 insertions, 0 deletions
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;