summaryrefslogtreecommitdiff
path: root/src/driver/slbt_amain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/driver/slbt_amain.c')
-rw-r--r--src/driver/slbt_amain.c84
1 files changed, 68 insertions, 16 deletions
diff --git a/src/driver/slbt_amain.c b/src/driver/slbt_amain.c
index eff2b45..e0f4241 100644
--- a/src/driver/slbt_amain.c
+++ b/src/driver/slbt_amain.c
@@ -1,6 +1,6 @@
/*******************************************************************/
-/* slibtool: a skinny libtool implementation, written in C */
-/* Copyright (C) 2016--2021 SysDeer Technologies, LLC */
+/* slibtool: a strong libtool implementation, written in C */
+/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
/*******************************************************************/
@@ -41,7 +41,7 @@ static ssize_t slbt_version(struct slbt_driver_ctx * dctx, int fdout)
const char * const * verclr;
bool gitver;
- verinfo = slbt_source_version();
+ verinfo = slbt_api_source_version();
verclr = isatty(fdout) ? slbt_ver_color : slbt_ver_plain;
gitver = strcmp(verinfo->commit,"unknown");
@@ -57,34 +57,53 @@ static ssize_t slbt_version(struct slbt_driver_ctx * dctx, int fdout)
verclr[5],gitver ? "]" : "");
}
+static ssize_t slbt_print_aux_dir(int fdout)
+{
+ return slbt_dprintf(fdout,"%s\n",SLBT_PACKAGE_DATADIR);
+}
+
+static ssize_t slbt_print_m4_dir(int fdout)
+{
+ return slbt_dprintf(fdout,"%s\n",SLBT_PACKAGE_DATADIR);
+}
+
static void slbt_perform_driver_actions(struct slbt_driver_ctx * dctx)
{
- if (dctx->cctx->drvflags & SLBT_DRIVER_CONFIG)
- slbt_output_config(dctx);
+ if (dctx->cctx->drvflags & SLBT_DRIVER_INFO)
+ slbt_output_info(dctx);
if (dctx->cctx->drvflags & SLBT_DRIVER_FEATURES)
slbt_output_features(dctx);
+ if (dctx->cctx->mode == SLBT_MODE_CONFIG)
+ slbt_output_config(dctx);
+
if (dctx->cctx->mode == SLBT_MODE_COMPILE)
- slbt_exec_compile(dctx,0);
+ slbt_exec_compile(dctx);
if (dctx->cctx->mode == SLBT_MODE_EXECUTE)
- slbt_exec_execute(dctx,0);
+ slbt_exec_execute(dctx);
if (dctx->cctx->mode == SLBT_MODE_INSTALL)
- slbt_exec_install(dctx,0);
+ slbt_exec_install(dctx);
if (dctx->cctx->mode == SLBT_MODE_LINK)
- slbt_exec_link(dctx,0);
+ slbt_exec_link(dctx);
if (dctx->cctx->mode == SLBT_MODE_UNINSTALL)
- slbt_exec_uninstall(dctx,0);
+ slbt_exec_uninstall(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)
{
slbt_output_error_vector(dctx);
- slbt_free_driver_ctx(dctx);
+ slbt_lib_free_driver_ctx(dctx);
return ret;
}
@@ -122,6 +141,17 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
else if (!(strcmp(dash,"static")))
flags = SLBT_DRIVER_FLAGS | SLBT_DRIVER_DISABLE_SHARED;
+ /* internal ar mode */
+ 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;
@@ -159,7 +189,7 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
| SLBT_DRIVER_LEGABITS);
/* driver context */
- if ((ret = slbt_get_driver_ctx(argv,envp,flags|noclr,fdctx,&dctx)))
+ if ((ret = slbt_lib_get_driver_ctx(argv,envp,flags|noclr,fdctx,&dctx)))
return (ret == SLBT_USAGE)
? !argv || !argv[0] || !argv[1] || !argv[2]
: SLBT_ERROR;
@@ -169,12 +199,34 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
return slbt_output_machine(dctx)
? SLBT_ERROR : SLBT_OK;
- /* --version is always the first action */
+ /* --version must be the first (and only) action */
if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION)
- if ((slbt_version(dctx,fdout)) < 0)
- return slbt_exit(dctx,SLBT_ERROR);
-
+ if (dctx->cctx->mode != SLBT_MODE_AR)
+ if (dctx->cctx->mode != SLBT_MODE_STOOLIE)
+ return (slbt_version(dctx,fdout) < 0)
+ ? slbt_exit(dctx,SLBT_ERROR)
+ : slbt_exit(dctx,SLBT_OK);
+
+ /* -print-aux-dir must be the first (and only) action */
+ if (dctx->cctx->drvflags & SLBT_DRIVER_OUTPUT_AUX_DIR)
+ return (slbt_print_aux_dir(fdout) < 0)
+ ? slbt_exit(dctx,SLBT_ERROR)
+ : slbt_exit(dctx,SLBT_OK);
+
+ /* -print-m4-dir must be the first (and only) action */
+ if (dctx->cctx->drvflags & SLBT_DRIVER_OUTPUT_M4_DIR)
+ return (slbt_print_m4_dir(fdout) < 0)
+ ? slbt_exit(dctx,SLBT_ERROR)
+ : slbt_exit(dctx,SLBT_OK);
+
+ /* perform all other actions */
slbt_perform_driver_actions(dctx);
+ /* print --version on behalf of a secondary tool as needed */
+ if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION)
+ return (slbt_version(dctx,fdout) < 0)
+ ? slbt_exit(dctx,SLBT_ERROR)
+ : slbt_exit(dctx,SLBT_OK);
+
return slbt_exit(dctx,dctx->errv[0] ? SLBT_ERROR : SLBT_OK);
}