From 741c4dddf7138471f6929e6550b6557fce0f8bf2 Mon Sep 17 00:00:00 2001 From: midipix Date: Feb 09 2024 20:19:41 +0000 Subject: driver: move slbt_init_link_params() to its own translation unit. --- diff --git a/project/common.mk b/project/common.mk index 0f638eb..275b69c 100644 --- a/project/common.mk +++ b/project/common.mk @@ -12,6 +12,7 @@ API_SRCS = \ src/driver/slbt_amain.c \ src/driver/slbt_driver_ctx.c \ src/driver/slbt_host_params.c \ + src/driver/slbt_link_params.c \ src/driver/slbt_split_argv.c \ src/driver/slbt_version_info.c \ src/fallback/slbt_archive_import_mri.c \ diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index 8dd463d..57d8cef 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -227,119 +227,6 @@ static int slbt_get_driver_ctx_fail( } -static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) -{ - const char * program; - const char * libname; - const char * prefix; - const char * base; - char * dot; - bool fmodule; - int fderr; - - fderr = ctx->fdctx.fderr; - program = argv_program_name(ctx->cctx.targv[0]); - libname = 0; - prefix = 0; - fmodule = false; - - /* output */ - if (!(ctx->cctx.output)) { - if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - slbt_dprintf(fderr, - "%s: error: output file must be " - "specified in link mode.\n", - program); - return -1; - } - - /* executable? */ - if (!(dot = strrchr(ctx->cctx.output,'.'))) - if (!(ctx->cctx.drvflags & SLBT_DRIVER_MODULE)) - return 0; - - /* todo: archive? library? wrapper? inlined function, avoid repetition */ - if ((base = strrchr(ctx->cctx.output,'/'))) - base++; - else - base = ctx->cctx.output; - - /* archive? */ - if (dot && !strcmp(dot,ctx->cctx.settings.arsuffix)) { - prefix = ctx->cctx.settings.arprefix; - - if (!strncmp(prefix,base,strlen(prefix))) - libname = base; - else { - if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - slbt_dprintf(fderr, - "%s: error: output file prefix does " - "not match its (archive) suffix; " - "the expected prefix was '%s'\n", - program,prefix); - return -1; - } - } - - /* library? */ - else if (dot && !strcmp(dot,ctx->cctx.settings.dsosuffix)) { - prefix = ctx->cctx.settings.dsoprefix; - - if (!strncmp(prefix,base,strlen(prefix))) { - libname = base; - - } else if (ctx->cctx.drvflags & SLBT_DRIVER_MODULE) { - libname = base; - fmodule = true; - - } else { - if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - slbt_dprintf(fderr, - "%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 (dot && !strcmp(dot,".la")) { - prefix = ctx->cctx.settings.dsoprefix; - - if (!strncmp(prefix,base,strlen(prefix))) { - libname = base; - fmodule = !!(ctx->cctx.drvflags & SLBT_DRIVER_MODULE); - } else if (ctx->cctx.drvflags & SLBT_DRIVER_MODULE) { - libname = base; - fmodule = true; - } else { - if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - slbt_dprintf(fderr, - "%s: error: output file prefix does " - "not match its (libtool wrapper) suffix; " - "the expected prefix was '%s'\n", - program,prefix); - return -1; - } - } else - return 0; - - /* libname alloc */ - if (!fmodule) - libname += strlen(prefix); - - if (!(ctx->libname = strdup(libname))) - return -1; - - if ((dot = strrchr(ctx->libname,'.'))) - *dot = 0; - - ctx->cctx.libname = ctx->libname; - - return 0; -} - static int slbt_driver_fail_incompatible_args( int fderr, uint64_t drvflags, diff --git a/src/driver/slbt_link_params.c b/src/driver/slbt_link_params.c new file mode 100644 index 0000000..b5ab706 --- /dev/null +++ b/src/driver/slbt_link_params.c @@ -0,0 +1,130 @@ +/*******************************************************************/ +/* slibtool: a skinny libtool implementation, written in C */ +/* Copyright (C) 2016--2021 SysDeer Technologies, LLC */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include "slibtool_version.h" +#include "slibtool_driver_impl.h" +#include "slibtool_errinfo_impl.h" + + +int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) +{ + const char * program; + const char * libname; + const char * prefix; + const char * base; + char * dot; + bool fmodule; + int fderr; + + fderr = ctx->fdctx.fderr; + program = slbt_program_name(ctx->cctx.targv[0]); + libname = 0; + prefix = 0; + fmodule = false; + + /* output */ + if (!(ctx->cctx.output)) { + if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) + slbt_dprintf(fderr, + "%s: error: output file must be " + "specified in link mode.\n", + program); + return -1; + } + + /* executable? */ + if (!(dot = strrchr(ctx->cctx.output,'.'))) + if (!(ctx->cctx.drvflags & SLBT_DRIVER_MODULE)) + return 0; + + /* todo: archive? library? wrapper? inlined function, avoid repetition */ + if ((base = strrchr(ctx->cctx.output,'/'))) + base++; + else + base = ctx->cctx.output; + + /* archive? */ + if (dot && !strcmp(dot,ctx->cctx.settings.arsuffix)) { + prefix = ctx->cctx.settings.arprefix; + + if (!strncmp(prefix,base,strlen(prefix))) + libname = base; + else { + if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) + slbt_dprintf(fderr, + "%s: error: output file prefix does " + "not match its (archive) suffix; " + "the expected prefix was '%s'\n", + program,prefix); + return -1; + } + } + + /* library? */ + else if (dot && !strcmp(dot,ctx->cctx.settings.dsosuffix)) { + prefix = ctx->cctx.settings.dsoprefix; + + if (!strncmp(prefix,base,strlen(prefix))) { + libname = base; + + } else if (ctx->cctx.drvflags & SLBT_DRIVER_MODULE) { + libname = base; + fmodule = true; + + } else { + if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) + slbt_dprintf(fderr, + "%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 (dot && !strcmp(dot,".la")) { + prefix = ctx->cctx.settings.dsoprefix; + + if (!strncmp(prefix,base,strlen(prefix))) { + libname = base; + fmodule = !!(ctx->cctx.drvflags & SLBT_DRIVER_MODULE); + } else if (ctx->cctx.drvflags & SLBT_DRIVER_MODULE) { + libname = base; + fmodule = true; + } else { + if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) + slbt_dprintf(fderr, + "%s: error: output file prefix does " + "not match its (libtool wrapper) suffix; " + "the expected prefix was '%s'\n", + program,prefix); + return -1; + } + } else + return 0; + + /* libname alloc */ + if (!fmodule) + libname += strlen(prefix); + + if (!(ctx->libname = strdup(libname))) + return -1; + + if ((dot = strrchr(ctx->libname,'.'))) + *dot = 0; + + ctx->cctx.libname = ctx->libname; + + return 0; +} diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h index 282659e..52ccf9d 100644 --- a/src/internal/slibtool_driver_impl.h +++ b/src/internal/slibtool_driver_impl.h @@ -213,6 +213,9 @@ int slbt_init_host_params( void slbt_free_host_params(struct slbt_host_strs * host); +int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx); + + void slbt_init_flavor_settings( struct slbt_common_ctx * cctx, const struct slbt_host_params * ahost,