From f8e27e77f70a0fd66b69adabb73e75282d98935e Mon Sep 17 00:00:00 2001 From: midipix Date: Mar 20 2016 01:45:57 +0000 Subject: driver: added libname heuristics. --- diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h index 2113a0a..e81f00a 100644 --- a/include/slibtool/slibtool.h +++ b/include/slibtool/slibtool.h @@ -142,6 +142,7 @@ struct slbt_common_ctx { enum slbt_warning_level warnings; const char * target; const char * output; + char * libname; const char * rpath; char ** targv; char ** cargv; 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; };