summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-02-10 04:05:34 +0000
committermidipix <writeonce@midipix.org>2024-02-10 04:33:08 +0000
commit5db3db7a6bbae314788c973c0566f804982ea3fa (patch)
tree34ccd476499e02d2fedbcac0c0c6f91a77ddc10e
parentc486f26f7759687536270a2ab46e4f639005555a (diff)
downloadslibtool-5db3db7a6bbae314788c973c0566f804982ea3fa.tar.bz2
slibtool-5db3db7a6bbae314788c973c0566f804982ea3fa.tar.xz
link mode: move the import library logic to its own translation unit.
-rw-r--r--project/common.mk1
-rw-r--r--src/internal/slibtool_linkcmd_impl.h7
-rw-r--r--src/logic/linkcmd/slbt_linkcmd_implib.c96
-rw-r--r--src/logic/slbt_exec_link.c74
4 files changed, 104 insertions, 74 deletions
diff --git a/project/common.mk b/project/common.mk
index c0f0984..4901c39 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -31,6 +31,7 @@ API_SRCS = \
src/logic/linkcmd/slbt_linkcmd_argv.c \
src/logic/linkcmd/slbt_linkcmd_deps.c \
src/logic/linkcmd/slbt_linkcmd_host.c \
+ src/logic/linkcmd/slbt_linkcmd_implib.c \
src/output/slbt_output_config.c \
src/output/slbt_output_error.c \
src/output/slbt_output_exec.c \
diff --git a/src/internal/slibtool_linkcmd_impl.h b/src/internal/slibtool_linkcmd_impl.h
index 141d732..db6cd8f 100644
--- a/src/internal/slibtool_linkcmd_impl.h
+++ b/src/internal/slibtool_linkcmd_impl.h
@@ -56,4 +56,11 @@ int slbt_exec_link_create_host_tag(
struct slbt_exec_ctx * ectx,
char * deffilename);
+int slbt_exec_link_create_import_library(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ char * impfilename,
+ char * deffilename,
+ char * soname);
+
#endif
diff --git a/src/logic/linkcmd/slbt_linkcmd_implib.c b/src/logic/linkcmd/slbt_linkcmd_implib.c
new file mode 100644
index 0000000..a3cb626
--- /dev/null
+++ b/src/logic/linkcmd/slbt_linkcmd_implib.c
@@ -0,0 +1,96 @@
+/*******************************************************************/
+/* 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <slibtool/slibtool.h>
+#include "slibtool_driver_impl.h"
+#include "slibtool_errinfo_impl.h"
+#include "slibtool_linkcmd_impl.h"
+#include "slibtool_mapfile_impl.h"
+#include "slibtool_metafile_impl.h"
+#include "slibtool_snprintf_impl.h"
+#include "slibtool_symlink_impl.h"
+#include "slibtool_spawn_impl.h"
+
+int slbt_exec_link_create_import_library(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ char * impfilename,
+ char * deffilename,
+ char * soname)
+{
+ int fmdso;
+ char * eargv[8];
+ char program[PATH_MAX];
+
+ /* dlltool or mdso? */
+ if (dctx->cctx->drvflags & SLBT_DRIVER_IMPLIB_DSOMETA)
+ fmdso = 1;
+
+ else if (dctx->cctx->drvflags & SLBT_DRIVER_IMPLIB_DSOMETA)
+ fmdso = 0;
+
+ else if (!(strcmp(dctx->cctx->host.flavor,"midipix")))
+ fmdso = 1;
+
+ else
+ fmdso = 0;
+
+ /* eargv */
+ if (fmdso) {
+ if (slbt_snprintf(program,sizeof(program),
+ "%s",dctx->cctx->host.mdso) < 0)
+ return SLBT_BUFFER_ERROR(dctx);
+
+ eargv[0] = program;
+ eargv[1] = "-i";
+ eargv[2] = impfilename;
+ eargv[3] = "-n";
+ eargv[4] = soname;
+ eargv[5] = deffilename;
+ eargv[6] = 0;
+ } else {
+ if (slbt_snprintf(program,sizeof(program),
+ "%s",dctx->cctx->host.dlltool) < 0)
+ return SLBT_BUFFER_ERROR(dctx);
+
+ eargv[0] = program;
+ eargv[1] = "-l";
+ eargv[2] = impfilename;
+ eargv[3] = "-d";
+ eargv[4] = deffilename;
+ eargv[5] = "-D";
+ eargv[6] = soname;
+ eargv[7] = 0;
+ }
+
+ /* alternate argument vector */
+ ectx->argv = eargv;
+ ectx->program = program;
+
+ /* step output */
+ if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
+ if (slbt_output_link(dctx,ectx))
+ return SLBT_NESTED_ERROR(dctx);
+
+ /* dlltool/mdso spawn */
+ if ((slbt_spawn(ectx,true) < 0) && (ectx->pid < 0)) {
+ return SLBT_SPAWN_ERROR(dctx);
+
+ } else if (ectx->exitcode) {
+ return SLBT_CUSTOM_ERROR(
+ dctx,
+ fmdso ? SLBT_ERR_MDSO_ERROR : SLBT_ERR_DLLTOOL_ERROR);
+ }
+
+ return 0;
+}
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 23cc999..be2e143 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -128,80 +128,6 @@ static int slbt_exec_link_remove_file(
return SLBT_SYSTEM_ERROR(dctx,0);
}
-static int slbt_exec_link_create_import_library(
- const struct slbt_driver_ctx * dctx,
- struct slbt_exec_ctx * ectx,
- char * impfilename,
- char * deffilename,
- char * soname)
-{
- int fmdso;
- char * eargv[8];
- char program[PATH_MAX];
-
- /* dlltool or mdso? */
- if (dctx->cctx->drvflags & SLBT_DRIVER_IMPLIB_DSOMETA)
- fmdso = 1;
-
- else if (dctx->cctx->drvflags & SLBT_DRIVER_IMPLIB_DSOMETA)
- fmdso = 0;
-
- else if (!(strcmp(dctx->cctx->host.flavor,"midipix")))
- fmdso = 1;
-
- else
- fmdso = 0;
-
- /* eargv */
- if (fmdso) {
- if (slbt_snprintf(program,sizeof(program),
- "%s",dctx->cctx->host.mdso) < 0)
- return SLBT_BUFFER_ERROR(dctx);
-
- eargv[0] = program;
- eargv[1] = "-i";
- eargv[2] = impfilename;
- eargv[3] = "-n";
- eargv[4] = soname;
- eargv[5] = deffilename;
- eargv[6] = 0;
- } else {
- if (slbt_snprintf(program,sizeof(program),
- "%s",dctx->cctx->host.dlltool) < 0)
- return SLBT_BUFFER_ERROR(dctx);
-
- eargv[0] = program;
- eargv[1] = "-l";
- eargv[2] = impfilename;
- eargv[3] = "-d";
- eargv[4] = deffilename;
- eargv[5] = "-D";
- eargv[6] = soname;
- eargv[7] = 0;
- }
-
- /* alternate argument vector */
- ectx->argv = eargv;
- ectx->program = program;
-
- /* step output */
- if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
- if (slbt_output_link(dctx,ectx))
- return SLBT_NESTED_ERROR(dctx);
-
- /* dlltool/mdso spawn */
- if ((slbt_spawn(ectx,true) < 0) && (ectx->pid < 0)) {
- return SLBT_SPAWN_ERROR(dctx);
-
- } else if (ectx->exitcode) {
- return SLBT_CUSTOM_ERROR(
- dctx,
- fmdso ? SLBT_ERR_MDSO_ERROR : SLBT_ERR_DLLTOOL_ERROR);
- }
-
- return 0;
-}
-
static int slbt_exec_link_create_noop_symlink(
const struct slbt_driver_ctx * dctx,
struct slbt_exec_ctx * ectx,