From 5db3db7a6bbae314788c973c0566f804982ea3fa Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 10 Feb 2024 04:05:34 +0000 Subject: link mode: move the import library logic to its own translation unit. --- src/logic/linkcmd/slbt_linkcmd_implib.c | 96 +++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/logic/linkcmd/slbt_linkcmd_implib.c (limited to 'src/logic/linkcmd') 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 +#include +#include +#include +#include +#include + +#include +#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; +} -- cgit v1.2.3