summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-04-06 00:50:13 -0400
committermidipix <writeonce@midipix.org>2016-04-06 00:50:13 -0400
commit5ee0d121982c45913ba81fef90cca399e2fb99ce (patch)
tree7eaf1c4c382a00a75ca338d1460f5470b988e43a
parent2ef5be118ccb4838a019549d52544fe800928f67 (diff)
downloadslibtool-5ee0d121982c45913ba81fef90cca399e2fb99ce.tar.bz2
slibtool-5ee0d121982c45913ba81fef90cca399e2fb99ce.tar.xz
link mode: executable wrapper: 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.c60
3 files changed, 64 insertions, 0 deletions
diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h
index 8bbce8c..60b3b73 100644
--- a/include/slibtool/slibtool.h
+++ b/include/slibtool/slibtool.h
@@ -95,6 +95,7 @@ struct slbt_exec_ctx {
char ** noundef;
char ** lout[2];
char ** sentinel;
+ FILE * fwrapper;
char * csrc;
char * ldirname;
char * lbasename;
diff --git a/src/logic/slbt_exec_ctx.c b/src/logic/slbt_exec_ctx.c
index c9cefdc..8b20f95 100644
--- a/src/logic/slbt_exec_ctx.c
+++ b/src/logic/slbt_exec_ctx.c
@@ -320,6 +320,9 @@ static int slbt_free_exec_ctx_impl(
struct slbt_exec_ctx_impl * ictx,
int status)
{
+ if (ictx->ctx.fwrapper)
+ fclose(ictx->ctx.fwrapper);
+
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 4950bcd..ce9d5b4 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -193,6 +193,16 @@ static int slbt_exec_link_adjust_argument_vector(
mark = strrchr(*carg,'/');
*mark = '\0';
+ if (ectx->fwrapper) {
+ *slash = '\0';
+
+ if (fprintf(ectx->fwrapper,
+ "DL_PATH=\"$DL_PATH$COLON%s\"\n"
+ "COLON=':'\n\n",
+ arg) < 0)
+ return -1;
+ }
+
*aarg++ = *carg++;
*aarg++ = ++mark;
@@ -377,7 +387,9 @@ static int slbt_exec_link_create_executable(
const char * exefilename)
{
char ** parg;
+ char cwd [PATH_MAX];
char output [PATH_MAX];
+ char wrapper[PATH_MAX];
/* initial state */
slbt_reset_arguments(ectx);
@@ -400,6 +412,30 @@ static int slbt_exec_link_create_executable(
if (dctx->cctx->drvflags & SLBT_DRIVER_NO_UNDEFINED)
*ectx->noundef = "-Wl,--no-undefined";
+ /* executable wrapper: header */
+ if ((size_t)snprintf(wrapper,sizeof(wrapper),"%s.wrapper.tmp",
+ dctx->cctx->output)
+ >= sizeof(wrapper))
+ return -1;
+
+ if (!(ectx->fwrapper = fopen(wrapper,"w")))
+ return -1;
+
+ if (fprintf(ectx->fwrapper,
+ "#!/bin/sh\n"
+ "# slibtool (pre-alpha): generated executable wrapper\n\n"
+ "if [ -z \"$%s\" ]; then\n"
+ "\tDL_PATH=\n"
+ "\tCOLON=\n"
+ "\tLCOLON=\n"
+ "else\n"
+ "\tDL_PATH=\n"
+ "\tCOLON=\n"
+ "\tLCOLON=':'\n"
+ "fi\n\n",
+ dctx->cctx->settings.ldpathenv) < 0)
+ return -1;
+
/* output */
if ((size_t)snprintf(output,sizeof(output),"%s",
exefilename)
@@ -418,6 +454,20 @@ static int slbt_exec_link_create_executable(
ectx->argv = ectx->altv;
ectx->program = ectx->altv[0];
+
+ /* executable wrapper: footer */
+ if (!getcwd(cwd,sizeof(cwd)))
+ return -1;
+
+ if (fprintf(ectx->fwrapper,
+ "DL_PATH=\"$DL_PATH$LCOLON$%s\"\n\n"
+ "export %s=$DL_PATH\n\n"
+ "exec %s/%s \"$@\"\n",
+ dctx->cctx->settings.ldpathenv,
+ dctx->cctx->settings.ldpathenv,
+ cwd,exefilename) < 0)
+ return -1;
+
/* step output */
if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
if (slbt_output_link(dctx,ectx))
@@ -427,6 +477,16 @@ static int slbt_exec_link_create_executable(
if ((slbt_spawn(ectx,true) < 0) || ectx->exitcode)
return -1;
+ /* executable wrapper: finalize */
+ fclose(ectx->fwrapper);
+ ectx->fwrapper = 0;
+
+ if (rename(wrapper,dctx->cctx->output))
+ return -1;
+
+ if (chmod(dctx->cctx->output,0755))
+ return -1;
+
return 0;
}