diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/slbt_amain.c | 22 | ||||
-rw-r--r-- | src/driver/slbt_driver_ctx.c | 100 | ||||
-rw-r--r-- | src/driver/slbt_split_argv.c | 14 | ||||
-rw-r--r-- | src/host/slbt_host_params.c | 65 | ||||
-rw-r--r-- | src/internal/slibtool_driver_impl.h | 5 | ||||
-rw-r--r-- | src/internal/slibtool_lconf_impl.c | 45 | ||||
-rw-r--r-- | src/internal/slibtool_lconf_impl.h | 3 | ||||
-rw-r--r-- | src/internal/slibtool_mkvars_impl.c | 245 | ||||
-rw-r--r-- | src/internal/slibtool_mkvars_impl.h | 13 | ||||
-rw-r--r-- | src/output/slbt_output_config.c | 90 | ||||
-rw-r--r-- | src/skin/slbt_skin_default.c | 17 | ||||
-rw-r--r-- | src/skin/slbt_skin_stoolie.c | 6 | ||||
-rw-r--r-- | src/stoolie/slbt_stoolie_ctx.c | 2 |
13 files changed, 605 insertions, 22 deletions
diff --git a/src/driver/slbt_amain.c b/src/driver/slbt_amain.c index 73d1462..e0f4241 100644 --- a/src/driver/slbt_amain.c +++ b/src/driver/slbt_amain.c @@ -57,6 +57,16 @@ 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_INFO) @@ -197,6 +207,18 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx) ? 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); diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index 85c75d2..76c7c4a 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -22,6 +22,7 @@ #include "slibtool_objlist_impl.h" #include "slibtool_errinfo_impl.h" #include "slibtool_lconf_impl.h" +#include "slibtool_mkvars_impl.h" #include "slibtool_txtline_impl.h" #include "slibtool_stoolie_impl.h" #include "slibtool_ar_impl.h" @@ -32,6 +33,7 @@ extern char ** environ; /* annotation strings */ static const char cfgexplicit[] = "command-line argument"; static const char cfglconf[] = "derived from <libtool>"; +static const char cfgmkvars[] = "derived from <makefile>"; /* package info */ static const struct slbt_source_version slbt_src_version = { @@ -398,6 +400,7 @@ int slbt_lib_get_driver_ctx( struct slbt_obj_list * objlistv; struct slbt_driver_ctx_impl * ctx; struct slbt_common_ctx cctx; + struct slbt_error_info** errinfp; const struct argv_option * optv[SLBT_OPTV_ELEMENTS]; struct argv_meta * meta; struct argv_entry * entry; @@ -407,6 +410,7 @@ int slbt_lib_get_driver_ctx( struct argv_entry * cmdnoshared; const char * program; const char * lconf; + const char * mkvars; uint64_t lflags; size_t ndlopen; struct argv_entry ** dlopenv; @@ -455,6 +459,7 @@ int slbt_lib_get_driver_ctx( return slbt_free_argv_buffer(&sargv,objlistv); lconf = 0; + mkvars = 0; program = argv_program_name(argv[0]); memset(&cctx,0,sizeof(cctx)); @@ -519,6 +524,10 @@ int slbt_lib_get_driver_ctx( lconf = entry->arg; break; + case TAG_MKVARS: + mkvars = entry->arg; + break; + case TAG_MODE: if (!strcmp("clean",entry->arg)) cctx.mode = SLBT_MODE_CLEAN; @@ -600,6 +609,14 @@ int slbt_lib_get_driver_ctx( cctx.drvflags |= SLBT_DRIVER_OUTPUT_MACHINE; break; + case TAG_PRINT_AUX_DIR: + cctx.drvflags |= SLBT_DRIVER_OUTPUT_AUX_DIR; + break; + + case TAG_PRINT_M4_DIR: + cctx.drvflags |= SLBT_DRIVER_OUTPUT_M4_DIR; + break; + case TAG_DEBUG: cctx.drvflags |= SLBT_DRIVER_DEBUG; break; @@ -862,6 +879,14 @@ int slbt_lib_get_driver_ctx( "--disable-static", "--disable-shared"); + if (lconf && mkvars) + return slbt_driver_fail_incompatible_args( + fdctx->fderr, + cctx.drvflags, + meta,program, + "--heuristics=<cfgfile>", + "--mkvars=<makefile>"); + /* -static? */ if (cmdstatic) { cctx.drvflags |= SLBT_DRIVER_STATIC; @@ -930,11 +955,81 @@ int slbt_lib_get_driver_ctx( ctx->cctx.cargv = sargv.cargv; ctx->meta = meta; + /* mkvars */ + if (mkvars) { + if (slbt_get_mkvars_flags(&ctx->ctx,mkvars,&lflags) < 0) + return slbt_lib_get_driver_ctx_fail(&ctx->ctx,0); + + if (ctx->cctx.host.host && !cfgmeta_host) + cfgmeta_host = cfgmkvars; + + if (ctx->cctx.host.ar && !cfgmeta_ar) + cfgmeta_ar = cfgmkvars; + + if (ctx->cctx.host.as && !cfgmeta_as) + cfgmeta_as = cfgmkvars; + + if (ctx->cctx.host.nm && !cfgmeta_nm) + cfgmeta_nm = cfgmkvars; + + if (ctx->cctx.host.ranlib && !cfgmeta_ranlib) + cfgmeta_ranlib = cfgmkvars; + + if (ctx->cctx.host.dlltool && !cfgmeta_dlltool) + cfgmeta_dlltool = cfgmkvars; + + if (cmdnoshared) + lflags &= ~(uint64_t)SLBT_DRIVER_DISABLE_STATIC; + + if (cmdnostatic) + if (lflags & SLBT_DRIVER_DISABLE_SHARED) + cctx.drvflags &= ~(uint64_t)SLBT_DRIVER_DISABLE_STATIC; + + cctx.drvflags |= lflags; + + /* -disable-static? */ + if (cctx.drvflags & SLBT_DRIVER_DISABLE_STATIC) + cctx.drvflags &= ~(uint64_t)SLBT_DRIVER_STATIC; + + /* -disable-shared? */ + if (cctx.drvflags & SLBT_DRIVER_DISABLE_SHARED) + cctx.drvflags &= ~(uint64_t)SLBT_DRIVER_SHARED; + + ctx->cctx.drvflags = cctx.drvflags; + } + /* heuristics */ + if (mkvars) + cctx.drvflags &= ~(uint64_t)SLBT_DRIVER_HEURISTICS; + if (cctx.drvflags & SLBT_DRIVER_HEURISTICS) { - if (slbt_get_lconf_flags(&ctx->ctx,lconf,&lflags) < 0) + if (slbt_get_lconf_flags(&ctx->ctx,lconf,&lflags,false) < 0) return slbt_lib_get_driver_ctx_fail(&ctx->ctx,0); + } else { + switch (cctx.mode) { + case SLBT_MODE_UNKNOWN: + case SLBT_MODE_STOOLIE: + break; + + case SLBT_MODE_CONFIG: + lconf = mkvars ? 0 : "slibtool.cfg"; + break; + + default: + lconf = "slibtool.cfg"; + break; + } + + if (lconf && (errinfp = ctx->errinfp)) + if (slbt_get_lconf_flags(&ctx->ctx,lconf,&lflags,true) < 0) + for (ctx->errinfp=errinfp; *errinfp; errinfp++) + *errinfp = 0; + + if (ctx->lconfctx) + cctx.drvflags |= SLBT_DRIVER_HEURISTICS; + } + if (cctx.drvflags & SLBT_DRIVER_HEURISTICS) { if (ctx->cctx.host.host && !cfgmeta_host) cfgmeta_host = cfglconf; @@ -1113,6 +1208,9 @@ static void slbt_lib_free_driver_ctx_impl(struct slbt_driver_ctx_alloc * ictx) if (ictx->ctx.lconfctx) slbt_lib_free_txtfile_ctx(ictx->ctx.lconfctx); + if (ictx->ctx.mkvarsctx) + slbt_lib_free_txtfile_ctx(ictx->ctx.mkvarsctx); + for (objlistp=ictx->ctx.objlistv; objlistp->name; objlistp++) { free(objlistp->objv); free(objlistp->addr); diff --git a/src/driver/slbt_split_argv.c b/src/driver/slbt_split_argv.c index 7ad20a3..8fd131a 100644 --- a/src/driver/slbt_split_argv.c +++ b/src/driver/slbt_split_argv.c @@ -59,6 +59,7 @@ slbt_hidden int slbt_split_argv( struct argv_entry * features; struct argv_entry * ccwrap; struct argv_entry * dumpmachine; + struct argv_entry * printdir; struct argv_entry * aropt; struct argv_entry * stoolieopt; const struct argv_option ** popt; @@ -124,7 +125,8 @@ slbt_hidden int slbt_split_argv( } /* missing all of --mode, --help, --version, --info, --config, --dumpmachine, --features, and --finish? */ - mode = help = version = info = config = finish = features = ccwrap = dumpmachine = aropt = stoolieopt = 0; + /* as well as -print-aux-dir and -print-m4-dir? */ + mode = help = version = info = config = finish = features = ccwrap = dumpmachine = printdir = aropt = stoolieopt = 0; for (entry=meta->entries; entry->fopt; entry++) if (entry->tag == TAG_MODE) @@ -145,6 +147,10 @@ slbt_hidden int slbt_split_argv( ccwrap = entry; else if (entry->tag == TAG_DUMPMACHINE) dumpmachine = entry; + else if (entry->tag == TAG_PRINT_AUX_DIR) + printdir = entry; + else if (entry->tag == TAG_PRINT_M4_DIR) + printdir = entry; /* alternate execusion mode? */ if (!altmode && mode && !strcmp(mode->arg,"ar")) @@ -169,7 +175,7 @@ slbt_hidden int slbt_split_argv( return -1; } - if (!mode && !help && !version && !info && !config && !finish && !features && !dumpmachine && !altmode) { + if (!mode && !help && !version && !info && !config && !finish && !features && !dumpmachine && !printdir && !altmode) { slbt_dprintf(fderr, "%s: error: --mode must be specified.\n", program); @@ -177,7 +183,7 @@ slbt_hidden int slbt_split_argv( } /* missing compiler? */ - if (!ctx.unitidx && !help && !info && !config && !version && !finish && !features && !dumpmachine) { + if (!ctx.unitidx && !help && !info && !config && !version && !finish && !features && !dumpmachine && !printdir) { if (!altmode && !aropt && !stoolieopt) { if (flags & SLBT_DRIVER_VERBOSITY_ERRORS) slbt_dprintf(fderr, @@ -339,7 +345,7 @@ slbt_hidden int slbt_split_argv( if (ctx.unitidx) { (void)0; - } else if (help || version || features || info || config || dumpmachine || altmode) { + } else if (help || version || features || info || config || dumpmachine || printdir || altmode) { for (i=0; i<argc; i++) sargv->targv[i] = argv[i]; diff --git a/src/host/slbt_host_params.c b/src/host/slbt_host_params.c index cd9ad87..6191ea5 100644 --- a/src/host/slbt_host_params.c +++ b/src/host/slbt_host_params.c @@ -4,6 +4,7 @@ /* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ /*******************************************************************/ +#include <ctype.h> #include <stdint.h> #include <string.h> #include <unistd.h> @@ -24,6 +25,8 @@ /* annotation strings */ static const char cfgexplicit[] = "command-line argument"; static const char cfghost[] = "derived from <host>"; +static const char cfgar[] = "derived from <ar>"; +static const char cfgranlib[] = "derived from <ranlib>"; static const char cfgtarget[] = "derived from <target>"; static const char cfgcompiler[] = "derived from <compiler>"; static const char cfgnmachine[] = "native (cached in ccenv/host.mk)"; @@ -97,6 +100,7 @@ slbt_hidden int slbt_init_host_params( int arprobe; int arfd; int ecode; + int cint; size_t toollen; char * dash; char * base; @@ -106,6 +110,7 @@ slbt_hidden int slbt_init_host_params( bool fhost = false; bool fcompiler = false; bool fnative = false; + bool fnativear = false; bool fdumpmachine = false; char buf [256]; char hostbuf [256]; @@ -251,6 +256,7 @@ slbt_hidden int slbt_init_host_params( /* toollen */ toollen = fnative ? 0 : strlen(host->host); toollen += strlen("-utility-name"); + toollen += host->ranlib ? strlen(host->ranlib) : 0; /* ar */ if (host->ar) @@ -314,6 +320,7 @@ slbt_hidden int slbt_init_host_params( if (ecode && !strcmp(host->host,SLBT_MACHINE)) { strcpy(drvhost->ar,"ar"); cfgmeta->ar = cfgnative; + fnative = true; } /* fdcwd */ @@ -329,6 +336,13 @@ slbt_hidden int slbt_init_host_params( host->ar = drvhost->ar; } + if (!fnative && !strncmp(host->ar,"ar",2)) { + if (!host->ar[2] || isspace((cint = host->ar[2]))) { + fnative = true; + fnativear = true; + } + } + /* as */ if (host->as) cfgmeta->as = cfgmeta_as ? cfgmeta_as : cfgexplicit; @@ -338,12 +352,25 @@ slbt_hidden int slbt_init_host_params( if (fnative) { strcpy(drvhost->as,"as"); - cfgmeta->as = cfgnative; + cfgmeta->as = fnativear ? cfgar : cfgnative; } else { sprintf(drvhost->as,"%s-as",host->host); cfgmeta->as = cfghost; } + if (host->ranlib && (mark = strrchr(host->ranlib,'/'))) { + if (strcmp(++mark,"ranlib")) + if ((mark = strrchr(mark,'-'))) + if (strcmp(++mark,"ranlib")) + mark = 0; + + if (mark) { + strcpy(drvhost->as,host->ranlib); + strcpy(&drvhost->as[mark-host->ranlib],"as"); + cfgmeta->as = cfgranlib; + } + } + host->as = drvhost->as; } @@ -356,7 +383,7 @@ slbt_hidden int slbt_init_host_params( if (fnative) { strcpy(drvhost->nm,"nm"); - cfgmeta->nm = cfgnative; + cfgmeta->nm = fnativear ? cfgar : cfgnative; } else { sprintf(drvhost->nm,"%s-nm",host->host); cfgmeta->nm = cfghost; @@ -374,7 +401,7 @@ slbt_hidden int slbt_init_host_params( if (fnative) { strcpy(drvhost->ranlib,"ranlib"); - cfgmeta->ranlib = cfgnative; + cfgmeta->ranlib = fnativear ? cfgar : cfgnative; } else { sprintf(drvhost->ranlib,"%s-ranlib",host->host); cfgmeta->ranlib = cfghost; @@ -400,12 +427,25 @@ slbt_hidden int slbt_init_host_params( if (fnative) { strcpy(drvhost->windres,"windres"); - cfgmeta->windres = cfgnative; + cfgmeta->windres = fnativear ? cfgar : cfgnative; } else { sprintf(drvhost->windres,"%s-windres",host->host); cfgmeta->windres = cfghost; } + if ((mark = strrchr(host->ranlib,'/'))) { + if (strcmp(++mark,"ranlib")) + if ((mark = strrchr(mark,'-'))) + if (strcmp(++mark,"ranlib")) + mark = 0; + + if (mark) { + strcpy(drvhost->windres,host->ranlib); + strcpy(&drvhost->windres[mark-host->ranlib],"windres"); + cfgmeta->windres = cfgranlib; + } + } + host->windres = drvhost->windres; } @@ -426,12 +466,25 @@ slbt_hidden int slbt_init_host_params( if (fnative) { strcpy(drvhost->dlltool,"dlltool"); - cfgmeta->dlltool = cfgnative; + cfgmeta->dlltool = fnativear ? cfgar : cfgnative; } else { sprintf(drvhost->dlltool,"%s-dlltool",host->host); cfgmeta->dlltool = cfghost; } + if ((mark = strrchr(host->ranlib,'/'))) { + if (strcmp(++mark,"ranlib")) + if ((mark = strrchr(mark,'-'))) + if (strcmp(++mark,"ranlib")) + mark = 0; + + if (mark) { + strcpy(drvhost->dlltool,host->ranlib); + strcpy(&drvhost->dlltool[mark-host->ranlib],"dlltool"); + cfgmeta->dlltool = cfgranlib; + } + } + host->dlltool = drvhost->dlltool; } @@ -452,7 +505,7 @@ slbt_hidden int slbt_init_host_params( if (fnative) { strcpy(drvhost->mdso,"mdso"); - cfgmeta->mdso = cfgnative; + cfgmeta->mdso = fnativear ? cfgar : cfgnative; } else { sprintf(drvhost->mdso,"%s-mdso",host->host); cfgmeta->mdso = cfghost; diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h index 65e5f96..429cdc4 100644 --- a/src/internal/slibtool_driver_impl.h +++ b/src/internal/slibtool_driver_impl.h @@ -28,7 +28,10 @@ enum app_tags { TAG_VERSION, TAG_INFO, TAG_CONFIG, + TAG_MKVARS, TAG_DUMPMACHINE, + TAG_PRINT_AUX_DIR, + TAG_PRINT_M4_DIR, TAG_DEBUG, TAG_DRY_RUN, TAG_FEATURES, @@ -114,6 +117,7 @@ enum app_tags { TAG_STLE_VERBOSE, TAG_STLE_WARNINGS, TAG_STLE_NO_WARNINGS, + TAG_STLE_LTDL, }; struct slbt_split_vector { @@ -160,6 +164,7 @@ struct slbt_driver_ctx_impl { struct slbt_fd_ctx fdctx; struct slbt_map_info lconf; struct slbt_txtfile_ctx * lconfctx; + struct slbt_txtfile_ctx * mkvarsctx; struct slbt_obj_list * objlistv; struct argv_entry ** dlopenv; diff --git a/src/internal/slibtool_lconf_impl.c b/src/internal/slibtool_lconf_impl.c index 33dfb23..ffe92b0 100644 --- a/src/internal/slibtool_lconf_impl.c +++ b/src/internal/slibtool_lconf_impl.c @@ -515,6 +515,7 @@ static int slbt_lconf_trace_result_annotated( static int slbt_lconf_open( struct slbt_driver_ctx * dctx, const char * lconf, + bool fsilent, char (*lconfpath)[PATH_MAX]) { int fderr; @@ -525,6 +526,7 @@ static int slbt_lconf_open( struct stat stcwd; struct stat stparent; ino_t stinode; + const char * mconf; int (*trace_lconf)(struct slbt_driver_ctx *, const char *); @@ -539,12 +541,19 @@ static int slbt_lconf_open( int,int,const char *,int, char (*)[PATH_MAX]); - lconf = lconf ? lconf : "libtool"; fderr = slbt_driver_fderr(dctx); fdcwd = slbt_driver_fdcwd(dctx); fdlconfdir = fdcwd; + fsilent |= (dctx->cctx->drvflags & SLBT_DRIVER_SILENT); - if (dctx->cctx->drvflags & SLBT_DRIVER_SILENT) { + if (lconf) { + mconf = 0; + } else { + mconf = "slibtool.cfg"; + lconf = "libtool"; + } + + if (fsilent) { trace_lconf = 0; trace_fstat = slbt_lconf_trace_fstat_silent; trace_openat = slbt_lconf_trace_openat_silent; @@ -580,8 +589,10 @@ static int slbt_lconf_open( trace_openat = slbt_lconf_trace_openat_silent; } - if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) { - trace_lconf(dctx,lconf); + if (!fsilent) { + if (!mconf) + trace_lconf(dctx,lconf); + slbt_output_fdcwd(dctx); } @@ -594,7 +605,14 @@ static int slbt_lconf_open( return SLBT_SYSTEM_ERROR(dctx,0); stinode = stcwd.st_ino; - fdlconf = trace_openat(dctx,fdlconfdir,lconf,O_RDONLY,0); + fdlconf = -1; + + if (mconf) + if ((fdlconf = trace_openat(dctx,fdlconfdir,mconf,O_RDONLY,0)) >= 0) + lconf = mconf; + + if (fdlconf < 0) + fdlconf = trace_openat(dctx,fdlconfdir,lconf,O_RDONLY,0); while (fdlconf < 0) { fdparent = trace_openat(dctx,fdlconfdir,"../",O_DIRECTORY,0); @@ -623,8 +641,14 @@ static int slbt_lconf_open( } fdlconfdir = fdparent; - fdlconf = trace_openat(dctx,fdlconfdir,lconf,O_RDONLY,0); stinode = stparent.st_ino; + + if (mconf) + if ((fdlconf = trace_openat(dctx,fdlconfdir,mconf,O_RDONLY,0)) >= 0) + lconf = mconf; + + if (fdlconf < 0) + fdlconf = trace_openat(dctx,fdlconfdir,lconf,O_RDONLY,0); } trace_result(dctx,fdlconf,fdlconfdir,lconf,0,lconfpath); @@ -662,8 +686,10 @@ static int slbt_get_lconf_var( } /* not found? */ - if (!match) + if (!match) { + (*val)[0] = '\0'; return 0; + } /* support a single pair of double quotes */ match = &match[len]; @@ -723,7 +749,8 @@ static int slbt_get_lconf_var( slbt_hidden int slbt_get_lconf_flags( struct slbt_driver_ctx * dctx, const char * lconf, - uint64_t * flags) + uint64_t * flags, + bool fsilent) { struct slbt_driver_ctx_impl * ctx; struct slbt_txtfile_ctx * confctx; @@ -738,7 +765,7 @@ slbt_hidden int slbt_get_lconf_flags( ctx = slbt_get_driver_ictx(dctx); /* open relative libtool script */ - if ((fdlconf = slbt_lconf_open(dctx,lconf,&val)) < 0) + if ((fdlconf = slbt_lconf_open(dctx,lconf,fsilent,&val)) < 0) return SLBT_NESTED_ERROR(dctx); /* cache the configuration in library friendly form) */ diff --git a/src/internal/slibtool_lconf_impl.h b/src/internal/slibtool_lconf_impl.h index d2bd44c..05c7537 100644 --- a/src/internal/slibtool_lconf_impl.h +++ b/src/internal/slibtool_lconf_impl.h @@ -8,6 +8,7 @@ struct slbt_driver_ctx; int slbt_get_lconf_flags( struct slbt_driver_ctx * dctx, const char * lconf, - uint64_t * flags); + uint64_t * flags, + bool fsilent); #endif diff --git a/src/internal/slibtool_mkvars_impl.c b/src/internal/slibtool_mkvars_impl.c new file mode 100644 index 0000000..5245034 --- /dev/null +++ b/src/internal/slibtool_mkvars_impl.c @@ -0,0 +1,245 @@ +/*******************************************************************/ +/* slibtool: a strong libtool implementation, written in C */ +/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include <ctype.h> +#include <stdio.h> +#include <stdint.h> +#include <stdbool.h> + +#include "slibtool_mkvars_impl.h" +#include "slibtool_driver_impl.h" +#include "slibtool_errinfo_impl.h" +#include "slibtool_symlink_impl.h" +#include "slibtool_readlink_impl.h" +#include "slibtool_realpath_impl.h" +#include "slibtool_visibility_impl.h" + +static int slbt_get_mkvars_var( + const struct slbt_driver_ctx * dctx, + const struct slbt_txtfile_ctx * tctx, + const char * var, + const char space, + char (*val)[PATH_MAX]) +{ + const char ** pline; + const char * mark; + const char * match; + char * ch; + ssize_t len; + int cint; + + /* init */ + match = 0; + len = strlen(var); + + /* search for ^var= */ + for (pline=tctx->txtlinev; !match && *pline; pline++) { + if (!strncmp(*pline,var,len)) { + if (isspace((cint = (*pline)[len])) || ((*pline)[len] == '=')) { + mark = &(*pline)[len]; + + for (; isspace(cint = *mark); ) + mark++; + + if (mark[0] != '=') + return SLBT_CUSTOM_ERROR( + dctx, + SLBT_ERR_MKVARS_PARSE); + + mark++; + + for (; isspace(cint = *mark); ) + mark++; + + match = mark; + } + } + } + + /* not found? */ + if (!match) { + (*val)[0] = '\0'; + return 0; + } + + /* special case the SLIBTOOL make variable */ + if (!strcmp(var,"SLIBTOOL")) { + mark = match; + ch = *val; + + for (; *mark; ) { + if (isspace(cint = *mark)) { + *ch = '\0'; + return 0; + } + + *ch++ = *mark++; + } + } + + /* validate */ + for (mark=match; *mark; mark++) { + if ((*mark >= 'a') && (*mark <= 'z')) + (void)0; + + else if ((*mark >= 'A') && (*mark <= 'Z')) + (void)0; + + else if ((*mark >= '0') && (*mark <= '9')) + (void)0; + + else if ((*mark == '+') || (*mark == '-')) + (void)0; + + else if ((*mark == '/') || (*mark == '@')) + (void)0; + + else if ((*mark == '.') || (*mark == '_')) + (void)0; + + else if ((*mark == ':') || (*mark == space)) + (void)0; + + else + return SLBT_CUSTOM_ERROR( + dctx, + SLBT_ERR_MKVARS_PARSE); + } + + /* all done */ + strcpy(*val,match); + + return 0; +} + +slbt_hidden int slbt_get_mkvars_flags( + struct slbt_driver_ctx * dctx, + const char * mkvars, + uint64_t * flags) +{ + struct slbt_driver_ctx_impl * ctx; + struct slbt_txtfile_ctx * confctx; + char * dash; + uint64_t optshared; + uint64_t optstatic; + char val[PATH_MAX]; + + /* driver context (ar, ranlib, cc) */ + ctx = slbt_get_driver_ictx(dctx); + + /* cache the makefile in library friendly form) */ + if (slbt_lib_get_txtfile_ctx(dctx,mkvars,&ctx->mkvarsctx) < 0) + return SLBT_NESTED_ERROR(dctx); + + confctx = ctx->mkvarsctx; + + /* scan */ + optshared = 0; + optstatic = 0; + + /* slibtool */ + if (slbt_get_mkvars_var(dctx,confctx,"SLIBTOOL",0,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if ((dash = strrchr(val,'-'))) { + if (!strcmp(dash,"-shared")) { + optshared = SLBT_DRIVER_SHARED; + optstatic = SLBT_DRIVER_DISABLE_STATIC; + + } else if (!strcmp(dash,"-static")) { + optshared = SLBT_DRIVER_DISABLE_SHARED; + optstatic = SLBT_DRIVER_STATIC; + } else { + return SLBT_CUSTOM_ERROR( + dctx, + SLBT_ERR_MKVARS_PARSE); + } + } else if (!strcmp(val,"false")) { + optshared = SLBT_DRIVER_DISABLE_SHARED; + optstatic = SLBT_DRIVER_DISABLE_STATIC; + } else { + optshared = SLBT_DRIVER_SHARED; + optstatic = SLBT_DRIVER_STATIC; + } + + *flags = optshared | optstatic; + + /* host */ + if (!ctx->cctx.host.host) { + if (slbt_get_mkvars_var(dctx,confctx,"host",0,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if (val[0] && !(ctx->host.host = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + + ctx->cctx.host.host = ctx->host.host; + } + + + /* ar tool */ + if (!ctx->cctx.host.ar) { + if (slbt_get_mkvars_var(dctx,confctx,"AR",0x20,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if (val[0] && !(ctx->host.ar = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + + ctx->cctx.host.ar = ctx->host.ar; + } + + + /* nm tool */ + if (!ctx->cctx.host.nm) { + if (slbt_get_mkvars_var(dctx,confctx,"NM",0x20,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if (val[0] && !(ctx->host.nm = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + + ctx->cctx.host.nm = ctx->host.nm; + } + + + /* ranlib tool */ + if (!ctx->cctx.host.ranlib) { + if (slbt_get_mkvars_var(dctx,confctx,"RANLIB",0x20,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if (val[0] && !(ctx->host.ranlib = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + + ctx->cctx.host.ranlib = ctx->host.ranlib; + } + + + /* as tool (optional) */ + if (!ctx->cctx.host.as) { + if (slbt_get_mkvars_var(dctx,confctx,"AS",0x20,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if (val[0] && !(ctx->host.as = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + + + ctx->cctx.host.as = ctx->host.as; + } + + + /* dlltool tool (optional) */ + if (!ctx->cctx.host.dlltool) { + if (slbt_get_mkvars_var(dctx,confctx,"DLLTOOL",0x20,&val) < 0) + return SLBT_NESTED_ERROR(dctx); + + if (val[0] && !(ctx->host.dlltool = strdup(val))) + return SLBT_SYSTEM_ERROR(dctx,0); + + ctx->cctx.host.dlltool = ctx->host.dlltool; + } + + + /* all done */ + return 0; +} diff --git a/src/internal/slibtool_mkvars_impl.h b/src/internal/slibtool_mkvars_impl.h new file mode 100644 index 0000000..00ebd99 --- /dev/null +++ b/src/internal/slibtool_mkvars_impl.h @@ -0,0 +1,13 @@ +#ifndef SLIBTOOL_MKVARS_IMPL_H +#define SLIBTOOL_MKVARS_IMPL_H + +#include <stdint.h> + +struct slbt_driver_ctx; + +int slbt_get_mkvars_flags( + struct slbt_driver_ctx * dctx, + const char * mkvars, + uint64_t * flags); + +#endif diff --git a/src/output/slbt_output_config.c b/src/output/slbt_output_config.c index 5d52e44..0442884 100644 --- a/src/output/slbt_output_config.c +++ b/src/output/slbt_output_config.c @@ -13,8 +13,12 @@ #include "slibtool_dprintf_impl.h" #include "slibtool_errinfo_impl.h" +static const char enable[] = "yes"; +static const char disable[] = "no"; + static const char lconf_begin[] = "# ### BEGIN LIBTOOL CONFIG\n"; static const char lconf_end [] = "# ### END LIBTOOL CONFIG\n"; +static const char lconf_guard[] = "# ### ##################\n"; static int slbt_output_config_lconf( const struct slbt_driver_ctx * dctx, @@ -84,6 +88,89 @@ static int slbt_output_config_lconf( return 0; } +static int slbt_output_config_mkvars(const struct slbt_driver_ctx * dctx) +{ + int fdout; + const char * shared_option; + const char * static_option; + const struct slbt_source_version * verinfo; + const struct slbt_common_ctx * cctx; + + /* init */ + fdout = slbt_driver_fdout(dctx); + + shared_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_SHARED) + ? disable : enable; + + static_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC) + ? disable : enable; + + cctx = dctx->cctx; + + /* header */ + verinfo = slbt_api_source_version(); + + if (slbt_dprintf( + fdout, + "%s\n\n" + "%s\n" + "# %s\n" + "# Generated by %s (slibtool %d.%d.%d)\n" + "# [commit reference: %s]\n\n", + "#!/dev/null", + lconf_begin, + "Backward compatible build configuration", + dctx->program, + verinfo->major,verinfo->minor,verinfo->revision, + verinfo->commit) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + /* shared & static build options */ + if (slbt_dprintf(fdout,"# shared libraries?\n" "build_libtool_libs=%s\n\n",shared_option) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# static libraries?\n" "build_old_libs=%s\n\n",static_option) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# host identification\n" "host=%s\n\n",cctx->host.host) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# archiver\n" "AR=\"%s\"\n\n",cctx->host.ar) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# name mangler\n" "NM=\"%s\"\n\n",cctx->host.nm) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# archive librarian\n" "RANLIB=\"%s\"\n\n",cctx->host.ranlib) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# assembler\n" "AS=\"%s\"\n\n",cctx->host.as) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# PE targets: modern import library compiler\n" "MDSO=%s%s%s\n\n", + cctx->host.mdso[0] ? "\"" : "", + cctx->host.mdso[0] ? cctx->host.mdso : "", + cctx->host.mdso[0] ? "\"" : "") < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# PE targets: coff import library compiler\n" "DLLTOOL=%s%s%s\n\n", + cctx->host.dlltool[0] ? "\"" : "", + cctx->host.dlltool[0] ? cctx->host.dlltool : "", + cctx->host.dlltool[0] ? "\"" : "") < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"# PE targets: resource compiler\n" "WINDRES=%s%s%s\n\n", + cctx->host.windres[0] ? "\"" : "", + cctx->host.windres[0] ? cctx->host.windres : "", + cctx->host.windres[0] ? "\"" : "") < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + if (slbt_dprintf(fdout,"%s%s%s\n",lconf_end,lconf_guard,lconf_guard) < 0) + return SLBT_SYSTEM_ERROR(dctx,0); + + return 0; +} + int slbt_output_config(const struct slbt_driver_ctx * dctx) { struct slbt_driver_ctx_impl * ictx; @@ -96,5 +183,8 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx) return slbt_output_config_lconf( dctx,lconf); + if (ictx->mkvarsctx || true) + return slbt_output_config_mkvars(dctx); + return 0; } diff --git a/src/skin/slbt_skin_default.c b/src/skin/slbt_skin_default.c index 7c54f76..07f099d 100644 --- a/src/skin/slbt_skin_default.c +++ b/src/skin/slbt_skin_default.c @@ -18,6 +18,10 @@ const slbt_hidden struct argv_option slbt_default_options[] = { "the %s of which is either provided via this " "command-line argument, or detected by the program."}, + {"mkvars", 0,TAG_MKVARS,ARGV_OPTARG_REQUIRED,0,0,"<makefile>", + "obtain information about the current build project " + "from the specified %s."}, + {"mode", 0,TAG_MODE,ARGV_OPTARG_REQUIRED,0, "clean|compile|execute|finish" "|install|link|uninstall|ar" @@ -29,6 +33,19 @@ const slbt_hidden struct argv_option slbt_default_options[] = { "however its addition is expected before the " "next major release."}, + {"print-aux-dir", 0,TAG_PRINT_AUX_DIR,ARGV_OPTARG_NONE, + ARGV_OPTION_HYBRID_ONLY,0,0, + "print the directory of the package-installed, " + "backward-compatible ltmain.sh and slibtool.sh; " + "for additional information, see the slibtoolize(1) " + "manual page."}, + + {"print-m4-dir", 0,TAG_PRINT_M4_DIR,ARGV_OPTARG_NONE, + ARGV_OPTION_HYBRID_ONLY,0,0, + "print the directory of the package-installed slibtool.m4; " + "for additional information, see the slibtoolize(1) " + "manual page."}, + {"finish", 0,TAG_FINISH,ARGV_OPTARG_NONE,0,0,0, "same as --mode=finish"}, diff --git a/src/skin/slbt_skin_stoolie.c b/src/skin/slbt_skin_stoolie.c index 598a410..e058fed 100644 --- a/src/skin/slbt_skin_stoolie.c +++ b/src/skin/slbt_skin_stoolie.c @@ -48,5 +48,11 @@ const slbt_hidden struct argv_option slbt_stoolie_options[] = { {"no-warnings", 0,TAG_STLE_NO_WARNINGS,ARGV_OPTARG_NONE,0,0,0, "suppress all warning messages (or not)."}, + {"ltdl", 0,TAG_STLE_LTDL,ARGV_OPTARG_OPTIONAL,0,0,"<dir>", + "install [s]ltdl sources to %s; this option " + "provided is provided for the purpose of backward " + "compatibility, and is currently a no-op, thereby " + "deferring -lltdl to the system install library."}, + {0,0,0,0,0,0,0,0} }; diff --git a/src/stoolie/slbt_stoolie_ctx.c b/src/stoolie/slbt_stoolie_ctx.c index b74edd3..3457fbe 100644 --- a/src/stoolie/slbt_stoolie_ctx.c +++ b/src/stoolie/slbt_stoolie_ctx.c @@ -208,7 +208,7 @@ int slbt_st_get_stoolie_ctx( if (!ctx->m4buf && ctx->makam) { for (pline=ctx->makam->txtlinev; !ctx->m4argv && *pline; pline++) { if (!strncmp(*pline,"ACLOCAL_AMFLAGS",15)) { - if (isspace((*pline)[15]) || ((*pline)[15] == '=')) { + if (isspace((cint = (*pline)[15])) || ((*pline)[15] == '=')) { mark = &(*pline)[15]; for (; isspace(cint = *mark); ) |