From d29f9c69021c51af493b43fe5d15dab02881760e Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 8 Feb 2024 20:57:49 +0000 Subject: driver: rlibtool mode: derive AR and RANLIB from the located libtool script. --- src/internal/slibtool_lconf_impl.c | 45 ++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'src/internal') diff --git a/src/internal/slibtool_lconf_impl.c b/src/internal/slibtool_lconf_impl.c index 7ad817c..8271f59 100644 --- a/src/internal/slibtool_lconf_impl.c +++ b/src/internal/slibtool_lconf_impl.c @@ -655,13 +655,22 @@ static int slbt_get_lconf_var( if (mark == cap) return 0; - /* for our purposes, only support non-quoted values */ + /* support a single pair of double quotes */ match = &match[len]; mark = match; - for (; !isspace(*mark) && (mark < cap); ) + if (match[0] == '"') { + match++; mark++; + for (; (*mark != '"') && (mark < cap); ) + mark++; + } else { + for (; !isspace(*mark) && (mark < cap); ) + mark++; + } + + /* validate */ if ((len = mark - match) >= PATH_MAX) return -1; @@ -700,6 +709,7 @@ int slbt_get_lconf_flags( const char * lconf, uint64_t * flags) { + struct slbt_driver_ctx_impl * ctx; int fdlconf; struct stat st; void * addr; @@ -709,6 +719,9 @@ int slbt_get_lconf_flags( uint64_t optstatic; char val[PATH_MAX]; + /* driver context (ar, ranlib, cc) */ + ctx = slbt_get_driver_ictx(dctx); + /* open relative libtool script */ if ((fdlconf = slbt_lconf_open(dctx,lconf)) < 0) return SLBT_NESTED_ERROR(dctx); @@ -760,13 +773,37 @@ int slbt_get_lconf_flags( optstatic = SLBT_DRIVER_DISABLE_STATIC; } - munmap(addr,st.st_size); - if (!optshared || !optstatic) return SLBT_CUSTOM_ERROR( dctx,SLBT_ERR_LCONF_PARSE); *flags = optshared | optstatic; + + /* ar tool */ + if (!ctx->cctx.host.ar) { + if (slbt_get_lconf_var(addr,cap,"AR=",&val) < 0) + return SLBT_CUSTOM_ERROR( + dctx,SLBT_ERR_LCONF_PARSE); + + if (val[0] && !(ctx->cctx.host.ar = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + } + + + /* ranlib tool */ + if (!ctx->cctx.host.ranlib) { + if (slbt_get_lconf_var(addr,cap,"RANLIB=",&val) < 0) + return SLBT_CUSTOM_ERROR( + dctx,SLBT_ERR_LCONF_PARSE); + + if (val[0] && !(ctx->cctx.host.ranlib = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + } + + + /* all done */ + munmap(addr,st.st_size); + return 0; } -- cgit v1.2.3