summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-03-19 21:45:57 -0400
committermidipix <writeonce@midipix.org>2016-03-19 21:45:57 -0400
commitf8e27e77f70a0fd66b69adabb73e75282d98935e (patch)
tree7eee11108025455fcd67bf4f115072eb67367580 /src
parent869626694d99107761eecd81082b7166e829ef4c (diff)
downloadslibtool-f8e27e77f70a0fd66b69adabb73e75282d98935e.tar.bz2
slibtool-f8e27e77f70a0fd66b69adabb73e75282d98935e.tar.xz
driver: added libname heuristics.
Diffstat (limited to 'src')
-rw-r--r--src/driver/slbt_driver_ctx.c103
-rw-r--r--src/internal/slibtool_driver_impl.h1
2 files changed, 104 insertions, 0 deletions
diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c
index b293df6..be43926 100644
--- a/src/driver/slbt_driver_ctx.c
+++ b/src/driver/slbt_driver_ctx.c
@@ -447,6 +447,99 @@ static int slbt_init_version_info(
return 0;
}
+static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx)
+{
+ const char * program;
+ const char * libname;
+ const char * prefix;
+ char * dot;
+
+ program = argv_program_name(ctx->cctx.targv[0]);
+ libname = 0;
+
+ /* output */
+ if (!(ctx->cctx.output)) {
+ if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
+ fprintf(stderr,
+ "%s: error: output file must be "
+ "specified in link mode.\n",
+ program);
+ return -1;
+ }
+
+ /* executable? */
+ if (!(dot = strrchr(ctx->cctx.output,'.')))
+ return 0;
+
+ /* todo: archive? library? wrapper? inlined function, avoid repetition */
+
+ /* archive? */
+ if (!strcmp(dot,ctx->cctx.settings.arsuffix)) {
+ prefix = ctx->cctx.settings.arprefix;
+
+ if (!strncmp(prefix,ctx->cctx.output,strlen(prefix)))
+ libname = ctx->cctx.output;
+ else {
+ if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
+ fprintf(stderr,
+ "%s: error: output file prefix does "
+ "not match its (archive) suffix; "
+ "the expected prefix was '%s'\n",
+ program,prefix);
+ return -1;
+ }
+ }
+
+ /* library? */
+ else if (!strcmp(dot,ctx->cctx.settings.dsosuffix)) {
+ prefix = ctx->cctx.settings.dsoprefix;
+
+ if (!strncmp(prefix,ctx->cctx.output,strlen(prefix)))
+ libname = ctx->cctx.output;
+ else {
+ if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
+ fprintf(stderr,
+ "%s: error: output file prefix does "
+ "not match its (shared library) suffix; "
+ "the expected prefix was '%s'\n",
+ program,prefix);
+ return -1;
+ }
+ }
+
+ /* wrapper? */
+ else if (!strcmp(dot,".la")) {
+ prefix = ctx->cctx.settings.dsoprefix;
+
+ if (!strncmp(prefix,ctx->cctx.output,strlen(prefix)))
+ libname = ctx->cctx.output;
+ else {
+ if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
+ fprintf(stderr,
+ "%s: error: output file prefix does "
+ "not match its (libtool wrapper) suffix; "
+ "the expected prefix was '%s'\n",
+ program,prefix);
+ return -1;
+ }
+ }
+
+ /* executable? */
+ if (!libname)
+ return 0;
+
+ /* libname alloc */
+ if (!(ctx->libname = strdup(libname + strlen(prefix))))
+ return -1;
+
+ dot = strrchr(ctx->libname,'.');
+ *dot = '\0';
+
+ ctx->cctx.libname = ctx->libname;
+
+ return 0;
+}
+
int slbt_get_driver_ctx(
char ** argv,
char ** envp,
@@ -650,6 +743,13 @@ int slbt_get_driver_ctx(
return -1;
}
+ /* link params */
+ if (cctx.mode == SLBT_MODE_LINK)
+ if (slbt_init_link_params(ctx)) {
+ slbt_free_driver_ctx(&ctx->ctx);
+ return -1;
+ }
+
*pctx = &ctx->ctx;
return SLBT_OK;
}
@@ -679,6 +779,9 @@ static void slbt_free_driver_ctx_impl(struct slbt_driver_ctx_alloc * ictx)
if (ictx->ctx.targv)
free(ictx->ctx.targv);
+ if (ictx->ctx.libname)
+ free(ictx->ctx.libname);
+
if (ictx->ctx.host.host)
free(ictx->ctx.host.host);
diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h
index 91bdc92..2753bf0 100644
--- a/src/internal/slibtool_driver_impl.h
+++ b/src/internal/slibtool_driver_impl.h
@@ -55,6 +55,7 @@ struct slbt_driver_ctx_impl {
struct slbt_common_ctx cctx;
struct slbt_driver_ctx ctx;
struct slbt_host_strs host;
+ char * libname;
char ** targv;
char ** cargv;
};