summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/slibtool_driver_impl.h5
-rw-r--r--src/internal/slibtool_lconf_impl.c41
-rw-r--r--src/internal/slibtool_lconf_impl.h3
-rw-r--r--src/internal/slibtool_mkvars_impl.c245
-rw-r--r--src/internal/slibtool_mkvars_impl.h13
5 files changed, 298 insertions, 9 deletions
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 b332f9b..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);
@@ -725,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;
@@ -740,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..155036a
--- /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((*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