summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-04-30 15:34:39 -0400
committermidipix <writeonce@midipix.org>2016-04-30 15:43:35 -0400
commite956c85f08020ed4048ff1d9fe16750f2d08ad87 (patch)
tree840384b23009c2b5098f2e61e09e4d07079b0b9d
parent045b885d9f005157d8c2911f4b2f0e5256d7d30b (diff)
downloadslibtool-e956c85f08020ed4048ff1d9fe16750f2d08ad87.tar.bz2
slibtool-e956c85f08020ed4048ff1d9fe16750f2d08ad87.tar.xz
execute mode: initial implementation.
-rw-r--r--include/slibtool/slibtool.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/logic/slbt_exec_execute.c82
3 files changed, 84 insertions, 0 deletions
diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h
index f03155a..e02e6dc 100644
--- a/include/slibtool/slibtool.h
+++ b/include/slibtool/slibtool.h
@@ -239,6 +239,7 @@ slbt_api void slbt_reset_placeholders (struct slbt_exec_ctx *);
slbt_api void slbt_disable_placeholders (struct slbt_exec_ctx *);
slbt_api int slbt_exec_compile (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
+slbt_api int slbt_exec_execute (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
slbt_api int slbt_exec_install (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
slbt_api int slbt_exec_link (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
diff --git a/project/common.mk b/project/common.mk
index 4bcbc5f..f55726a 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -7,6 +7,7 @@ COMMON_SRCS = \
src/helper/slbt_dump_machine.c \
src/logic/slbt_exec_compile.c \
src/logic/slbt_exec_ctx.c \
+ src/logic/slbt_exec_execute.c \
src/logic/slbt_exec_install.c \
src/logic/slbt_exec_link.c \
src/logic/slbt_map_input.c \
diff --git a/src/logic/slbt_exec_execute.c b/src/logic/slbt_exec_execute.c
new file mode 100644
index 0000000..04fec87
--- /dev/null
+++ b/src/logic/slbt_exec_execute.c
@@ -0,0 +1,82 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016 Z. Gilboa */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <string.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <slibtool/slibtool.h>
+#include "slibtool_spawn_impl.h"
+
+int slbt_exec_execute(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx)
+{
+ int ret;
+ char ** parg;
+ char * program;
+ char * script;
+ char * base;
+ char * mark;
+ char exeref [PATH_MAX];
+ char wrapper[PATH_MAX];
+ struct slbt_exec_ctx * actx = 0;
+
+ /* context */
+ if (ectx)
+ slbt_disable_placeholders(ectx);
+ else if ((ret = slbt_get_exec_ctx(dctx,&ectx)))
+ return ret;
+ else {
+ actx = ectx;
+ slbt_disable_placeholders(ectx);
+ }
+
+ /* script, program */
+ program = ectx->cargv[0];
+ script = ectx->cargv[1];
+
+ /* wrapper */
+ if ((size_t)snprintf(wrapper,sizeof(wrapper),"%s.exe.wrapper",
+ script)
+ >= sizeof(wrapper)) {
+ slbt_free_exec_ctx(actx);
+ return -1;
+ }
+
+ /* exeref */
+ if ((base = strrchr(script,'/')))
+ base++;
+ else
+ base = script;
+
+ strcpy(exeref,script);
+ mark = exeref + (base - script);
+ sprintf(mark,".libs/%s",base);
+
+ /* swap vector */
+ ectx->cargv[0] = wrapper;
+ ectx->cargv[1] = program;
+ ectx->cargv[2] = exeref;
+
+ /* execute mode */
+ ectx->program = script;
+ ectx->argv = ectx->cargv;
+
+ /* step output */
+ if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
+ if (slbt_output_execute(dctx,ectx)) {
+ slbt_free_exec_ctx(actx);
+ return -1;
+ }
+
+ execvp(wrapper,ectx->argv);
+
+ slbt_free_exec_ctx(actx);
+ return -1;
+}