summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/driver/slbt_amain.c17
-rw-r--r--src/driver/slbt_driver_ctx.c10
-rw-r--r--src/driver/slbt_split_argv.c41
-rw-r--r--src/internal/slibtool_driver_impl.h3
-rw-r--r--src/internal/slibtool_stoolie_impl.h15
-rw-r--r--src/logic/slbt_exec_stoolie.c178
-rw-r--r--src/skin/slbt_skin_default.c3
-rw-r--r--src/skin/slbt_skin_stoolie.c13
8 files changed, 266 insertions, 14 deletions
diff --git a/src/driver/slbt_amain.c b/src/driver/slbt_amain.c
index 3b21500..73d1462 100644
--- a/src/driver/slbt_amain.c
+++ b/src/driver/slbt_amain.c
@@ -85,6 +85,9 @@ static void slbt_perform_driver_actions(struct slbt_driver_ctx * dctx)
if (dctx->cctx->mode == SLBT_MODE_AR)
slbt_exec_ar(dctx);
+
+ if (dctx->cctx->mode == SLBT_MODE_STOOLIE)
+ slbt_exec_stoolie(dctx);
}
static int slbt_exit(struct slbt_driver_ctx * dctx, int ret)
@@ -132,6 +135,13 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
else if (!(strcmp(dash,"ar")))
flags |= SLBT_DRIVER_MODE_AR;
+ /* slibtoolize (stoolie) mode */
+ if (!(strcmp(program,"stoolie")))
+ flags |= SLBT_DRIVER_MODE_STOOLIE;
+
+ else if (!(strcmp(program,"slibtoolize")))
+ flags |= SLBT_DRIVER_MODE_STOOLIE;
+
/* debug */
if (!(strcmp(program,"dlibtool")))
flags |= SLBT_DRIVER_DEBUG;
@@ -182,9 +192,10 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
/* --version must be the first (and only) action */
if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION)
if (dctx->cctx->mode != SLBT_MODE_AR)
- return (slbt_version(dctx,fdout) < 0)
- ? slbt_exit(dctx,SLBT_ERROR)
- : slbt_exit(dctx,SLBT_OK);
+ if (dctx->cctx->mode != SLBT_MODE_STOOLIE)
+ return (slbt_version(dctx,fdout) < 0)
+ ? slbt_exit(dctx,SLBT_ERROR)
+ : slbt_exit(dctx,SLBT_OK);
/* perform all other actions */
slbt_perform_driver_actions(dctx);
diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c
index a5b3861..3bb0e58 100644
--- a/src/driver/slbt_driver_ctx.c
+++ b/src/driver/slbt_driver_ctx.c
@@ -454,6 +454,9 @@ int slbt_lib_get_driver_ctx(
if (flags & SLBT_DRIVER_MODE_AR)
cctx.mode = SLBT_MODE_AR;
+ else if (flags & SLBT_DRIVER_MODE_STOOLIE)
+ cctx.mode = SLBT_MODE_STOOLIE;
+
/* default flags (set at compile time and derived from symlink) */
cctx.drvflags = flags;
@@ -484,6 +487,7 @@ int slbt_lib_get_driver_ctx(
case SLBT_MODE_INSTALL:
case SLBT_MODE_UNINSTALL:
case SLBT_MODE_AR:
+ case SLBT_MODE_STOOLIE:
break;
default:
@@ -531,6 +535,12 @@ int slbt_lib_get_driver_ctx(
else if (!strcmp("ar",entry->arg))
cctx.mode = SLBT_MODE_AR;
+
+ else if (!strcmp("stoolie",entry->arg))
+ cctx.mode = SLBT_MODE_STOOLIE;
+
+ else if (!strcmp("slibtoolize",entry->arg))
+ cctx.mode = SLBT_MODE_STOOLIE;
break;
case TAG_FINISH:
diff --git a/src/driver/slbt_split_argv.c b/src/driver/slbt_split_argv.c
index 43af9f8..7ad20a3 100644
--- a/src/driver/slbt_split_argv.c
+++ b/src/driver/slbt_split_argv.c
@@ -16,6 +16,7 @@
#include "slibtool_objlist_impl.h"
#include "slibtool_errinfo_impl.h"
#include "slibtool_visibility_impl.h"
+#include "slibtool_stoolie_impl.h"
#include "slibtool_ar_impl.h"
#include "argv/argv.h"
@@ -59,6 +60,7 @@ slbt_hidden int slbt_split_argv(
struct argv_entry * ccwrap;
struct argv_entry * dumpmachine;
struct argv_entry * aropt;
+ struct argv_entry * stoolieopt;
const struct argv_option ** popt;
const struct argv_option ** optout;
const struct argv_option * optv[SLBT_OPTV_ELEMENTS];
@@ -71,6 +73,8 @@ slbt_hidden int slbt_split_argv(
/* missing arguments? */
if ((altmode = (flags & SLBT_DRIVER_MODE_AR))) {
slbt_optv_init(slbt_ar_options,optv);
+ } else if ((altmode = (flags & SLBT_DRIVER_MODE_STOOLIE))) {
+ slbt_optv_init(slbt_stoolie_options,optv);
} else {
slbt_optv_init(slbt_default_options,optv);
}
@@ -120,7 +124,7 @@ slbt_hidden int slbt_split_argv(
}
/* missing all of --mode, --help, --version, --info, --config, --dumpmachine, --features, and --finish? */
- mode = help = version = info = config = finish = features = ccwrap = dumpmachine = aropt = 0;
+ mode = help = version = info = config = finish = features = ccwrap = dumpmachine = aropt = stoolieopt = 0;
for (entry=meta->entries; entry->fopt; entry++)
if (entry->tag == TAG_MODE)
@@ -146,11 +150,17 @@ slbt_hidden int slbt_split_argv(
if (!altmode && mode && !strcmp(mode->arg,"ar"))
aropt = mode;
+ if (!altmode && mode && !strcmp(mode->arg,"stoolie"))
+ stoolieopt = mode;
+
+ if (!altmode && mode && !strcmp(mode->arg,"slibtoolize"))
+ stoolieopt = mode;
+
/* release temporary argv meta context */
slbt_argv_free(meta);
/* error not due to an altmode argument? */
- if (!aropt && ctx.erridx && (ctx.erridx == ctx.unitidx)) {
+ if (!aropt && !stoolieopt && ctx.erridx && (ctx.erridx == ctx.unitidx)) {
if (flags & SLBT_DRIVER_VERBOSITY_ERRORS)
slbt_argv_get(
argv,optv,
@@ -167,12 +177,14 @@ slbt_hidden int slbt_split_argv(
}
/* missing compiler? */
- if (!ctx.unitidx && !help && !info && !config && !version && !finish && !features && !dumpmachine && !altmode && !aropt) {
- if (flags & SLBT_DRIVER_VERBOSITY_ERRORS)
- slbt_dprintf(fderr,
- "%s: error: <compiler> is missing.\n",
- program);
- return -1;
+ if (!ctx.unitidx && !help && !info && !config && !version && !finish && !features && !dumpmachine) {
+ if (!altmode && !aropt && !stoolieopt) {
+ if (flags & SLBT_DRIVER_VERBOSITY_ERRORS)
+ slbt_dprintf(fderr,
+ "%s: error: <compiler> is missing.\n",
+ program);
+ return -1;
+ }
}
/* clone and normalize the argv vector */
@@ -196,7 +208,7 @@ slbt_hidden int slbt_split_argv(
csysroot = 0;
for (i=0,flast=false,dargv=sargv->dargv,dst=sargv->dargs; i<argc; i++) {
- if ((fcopy = (flast || altmode || aropt))) {
+ if ((fcopy = (flast || altmode || aropt || stoolieopt))) {
(void)0;
} else if (!strcmp(argv[i],"--")) {
@@ -340,6 +352,10 @@ slbt_hidden int slbt_split_argv(
if (aropt && !ctx.unitidx)
ctx.unitidx = argc;
+ /* --mode=slibtoolize and no slibtoolize-specific arguments? */
+ if (stoolieopt && !ctx.unitidx)
+ ctx.unitidx = argc;
+
/* split vectors: slibtool's own options */
for (i=0; i<ctx.unitidx; i++)
sargv->targv[i] = argv[i];
@@ -349,7 +365,7 @@ slbt_hidden int slbt_split_argv(
cargv = sargv->cargv;
/* known wrappers */
- if (ctx.unitidx && !ccwrap && !aropt) {
+ if (ctx.unitidx && !ccwrap && !aropt && !stoolieopt) {
if ((base = strrchr(argv[i],'/')))
base++;
else if ((base = strrchr(argv[i],'\\')))
@@ -375,6 +391,8 @@ slbt_hidden int slbt_split_argv(
i = 0;
} else if (aropt) {
*cargv++ = argv[0];
+ } else if (stoolieopt) {
+ *cargv++ = argv[0];
} else {
*cargv++ = argv[i++];
}
@@ -388,6 +406,9 @@ slbt_hidden int slbt_split_argv(
if (aropt && (i >= ctx.unitidx)) {
*cargv++ = argv[i];
+ } else if (stoolieopt && (i >= ctx.unitidx)) {
+ *cargv++ = argv[i];
+
} else if (argv[i][0] != '-') {
if (argv[i+1] && (argv[i+1][0] == '+')
&& (argv[i+1][1] == '=')
diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h
index 047a69b..458f74f 100644
--- a/src/internal/slibtool_driver_impl.h
+++ b/src/internal/slibtool_driver_impl.h
@@ -102,6 +102,9 @@ enum app_tags {
TAG_AR_MERGE,
TAG_AR_OUTPUT,
TAG_AR_VERBOSE,
+ /* slibtoolize (stoolie) mode */
+ TAG_STLE_VERSION,
+ TAG_STLE_HELP,
};
struct slbt_split_vector {
diff --git a/src/internal/slibtool_stoolie_impl.h b/src/internal/slibtool_stoolie_impl.h
new file mode 100644
index 0000000..43d70a5
--- /dev/null
+++ b/src/internal/slibtool_stoolie_impl.h
@@ -0,0 +1,15 @@
+/*******************************************************************/
+/* slibtool: a strong libtool implementation, written in C */
+/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#ifndef SLIBTOOL_STOOLIE_IMPL_H
+#define SLIBTOOL_STOOLIE_IMPL_H
+
+#include "argv/argv.h"
+#include <slibtool/slibtool.h>
+
+extern const struct argv_option slbt_stoolie_options[];
+
+#endif
diff --git a/src/logic/slbt_exec_stoolie.c b/src/logic/slbt_exec_stoolie.c
new file mode 100644
index 0000000..6b2f883
--- /dev/null
+++ b/src/logic/slbt_exec_stoolie.c
@@ -0,0 +1,178 @@
+/*******************************************************************/
+/* slibtool: a strong libtool implementation, written in C */
+/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <slibtool/slibtool.h>
+#include <slibtool/slibtool_output.h>
+#include "slibtool_driver_impl.h"
+#include "slibtool_stoolie_impl.h"
+#include "slibtool_errinfo_impl.h"
+#include "argv/argv.h"
+
+static int slbt_stoolie_usage(
+ int fdout,
+ const char * program,
+ const char * arg,
+ const struct argv_option ** optv,
+ struct argv_meta * meta,
+ struct slbt_exec_ctx * ectx,
+ int noclr)
+{
+ char header[512];
+ bool stooliemode;
+
+ stooliemode = !strcmp(program,"slibtoolize");
+
+ snprintf(header,sizeof(header),
+ "Usage: %s%s [options] ...\n"
+ "Options:\n",
+ program,
+ stooliemode ? "" : " --mode=slibtoolize");
+
+ switch (noclr) {
+ case 0:
+ slbt_argv_usage(fdout,header,optv,arg);
+ break;
+
+ default:
+ slbt_argv_usage_plain(fdout,header,optv,arg);
+ break;
+ }
+
+ if (ectx)
+ slbt_ectx_free_exec_ctx(ectx);
+
+ slbt_argv_free(meta);
+
+ return SLBT_USAGE;
+}
+
+static int slbt_exec_stoolie_fail(
+ struct slbt_exec_ctx * ectx,
+ struct argv_meta * meta,
+ int ret)
+{
+ slbt_argv_free(meta);
+ slbt_ectx_free_exec_ctx(ectx);
+ return ret;
+}
+
+static int slbt_exec_stoolie_perform_actions(
+ const struct slbt_driver_ctx * dctx)
+{
+ (void)dctx;
+ return 0;
+}
+
+int slbt_exec_stoolie(const struct slbt_driver_ctx * dctx)
+{
+ int ret;
+ int fdout;
+ int fderr;
+ char ** argv;
+ char ** iargv;
+ struct slbt_exec_ctx * ectx;
+ struct slbt_driver_ctx_impl * ictx;
+ const struct slbt_common_ctx * cctx;
+ struct argv_meta * meta;
+ struct argv_entry * entry;
+ size_t nunits;
+ const struct argv_option * optv[SLBT_OPTV_ELEMENTS];
+
+ /* context */
+ if (slbt_ectx_get_exec_ctx(dctx,&ectx) < 0)
+ return SLBT_NESTED_ERROR(dctx);
+
+ /* initial state, slibtoolize (stoolie) mode skin */
+ slbt_ectx_reset_arguments(ectx);
+ slbt_disable_placeholders(ectx);
+
+ ictx = slbt_get_driver_ictx(dctx);
+ cctx = dctx->cctx;
+ iargv = ectx->cargv;
+
+ fdout = slbt_driver_fdout(dctx);
+ fderr = slbt_driver_fderr(dctx);
+
+ (void)fderr;
+
+ /* missing arguments? */
+ slbt_optv_init(slbt_stoolie_options,optv);
+
+ if (!iargv[1] && (dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_USAGE))
+ return slbt_stoolie_usage(
+ fdout,
+ dctx->program,
+ 0,optv,0,ectx,
+ dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER);
+
+ /* <stoolie> argv meta */
+ if (!(meta = slbt_argv_get(
+ iargv,optv,
+ dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_ERRORS
+ ? ARGV_VERBOSITY_ERRORS
+ : ARGV_VERBOSITY_NONE,
+ fdout)))
+ return slbt_exec_stoolie_fail(
+ ectx,meta,
+ SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_AR_FAIL));
+
+ /* dest, alternate argument vector options */
+ argv = ectx->altv;
+ *argv++ = iargv[0];
+ nunits = 0;
+
+ for (entry=meta->entries; entry->fopt || entry->arg; entry++) {
+ if (entry->fopt) {
+ switch (entry->tag) {
+ case TAG_STLE_HELP:
+ slbt_stoolie_usage(
+ fdout,
+ dctx->program,
+ 0,optv,0,ectx,
+ dctx->cctx->drvflags
+ & SLBT_DRIVER_ANNOTATE_NEVER);
+
+ ictx->cctx.drvflags |= SLBT_DRIVER_VERSION;
+ ictx->cctx.drvflags ^= SLBT_DRIVER_VERSION;
+
+ slbt_argv_free(meta);
+
+ return SLBT_OK;
+
+ case TAG_STLE_VERSION:
+ ictx->cctx.drvflags |= SLBT_DRIVER_VERSION;
+ break;
+ }
+
+ if (entry->fval) {
+ *argv++ = (char *)entry->arg;
+ }
+ } else {
+ nunits++;
+ };
+ }
+
+ /* defer --version printing to slbt_main() as needed */
+ if (cctx->drvflags & SLBT_DRIVER_VERSION) {
+ slbt_argv_free(meta);
+ slbt_ectx_free_exec_ctx(ectx);
+ return SLBT_OK;
+ }
+
+ /* slibtoolize operations */
+ ret = slbt_exec_stoolie_perform_actions(dctx);
+
+ /* all done */
+ slbt_argv_free(meta);
+ slbt_ectx_free_exec_ctx(ectx);
+
+ return ret;
+}
+
+int slbt_exec_slibtoolize(const struct slbt_driver_ctx * dctx)
+{
+ return slbt_exec_stoolie(dctx);
+}
diff --git a/src/skin/slbt_skin_default.c b/src/skin/slbt_skin_default.c
index 630afc1..7c54f76 100644
--- a/src/skin/slbt_skin_default.c
+++ b/src/skin/slbt_skin_default.c
@@ -20,7 +20,8 @@ const slbt_hidden struct argv_option slbt_default_options[] = {
{"mode", 0,TAG_MODE,ARGV_OPTARG_REQUIRED,0,
"clean|compile|execute|finish"
- "|install|link|uninstall|ar",0,
+ "|install|link|uninstall|ar"
+ "|stoolie|slibtoolize",0,
"set the execution mode, where <mode> "
"is one of {%s}. of the above modes, "
"'finish' is not needed and is therefore "
diff --git a/src/skin/slbt_skin_stoolie.c b/src/skin/slbt_skin_stoolie.c
new file mode 100644
index 0000000..c4a10b8
--- /dev/null
+++ b/src/skin/slbt_skin_stoolie.c
@@ -0,0 +1,13 @@
+#include "slibtool_driver_impl.h"
+#include "slibtool_visibility_impl.h"
+#include "argv/argv.h"
+
+const slbt_hidden struct argv_option slbt_stoolie_options[] = {
+ {"version", 0,TAG_STLE_VERSION,ARGV_OPTARG_NONE,0,0,0,
+ "show version information"},
+
+ {"help", 'h',TAG_STLE_HELP,ARGV_OPTARG_NONE,0,0,0,
+ "display slibtoolize (stoolie) mode help"},
+
+ {0,0,0,0,0,0,0,0}
+};