From c486f26f7759687536270a2ab46e4f639005555a Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 10 Feb 2024 04:02:04 +0000 Subject: link mode: move the host tag logic to its own translation unit. --- project/common.mk | 1 + src/internal/slibtool_linkcmd_impl.h | 5 +++ src/logic/linkcmd/slbt_linkcmd_host.c | 69 +++++++++++++++++++++++++++++++++++ src/logic/slbt_exec_link.c | 48 ------------------------ 4 files changed, 75 insertions(+), 48 deletions(-) create mode 100644 src/logic/linkcmd/slbt_linkcmd_host.c diff --git a/project/common.mk b/project/common.mk index e3ca463..c0f0984 100644 --- a/project/common.mk +++ b/project/common.mk @@ -30,6 +30,7 @@ API_SRCS = \ src/logic/slbt_exec_uninstall.c \ src/logic/linkcmd/slbt_linkcmd_argv.c \ src/logic/linkcmd/slbt_linkcmd_deps.c \ + src/logic/linkcmd/slbt_linkcmd_host.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 df5a731..141d732 100644 --- a/src/internal/slibtool_linkcmd_impl.h +++ b/src/internal/slibtool_linkcmd_impl.h @@ -51,4 +51,9 @@ int slbt_exec_link_finalize_argument_vector( const struct slbt_driver_ctx * dctx, struct slbt_exec_ctx * ectx); +int slbt_exec_link_create_host_tag( + const struct slbt_driver_ctx * dctx, + struct slbt_exec_ctx * ectx, + char * deffilename); + #endif diff --git a/src/logic/linkcmd/slbt_linkcmd_host.c b/src/logic/linkcmd/slbt_linkcmd_host.c new file mode 100644 index 0000000..060975e --- /dev/null +++ b/src/logic/linkcmd/slbt_linkcmd_host.c @@ -0,0 +1,69 @@ +/*******************************************************************/ +/* 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" + +int slbt_exec_link_create_host_tag( + const struct slbt_driver_ctx * dctx, + struct slbt_exec_ctx * ectx, + char * deffilename) +{ + char * slash; + char hosttag[PATH_MAX]; + char hostlnk[PATH_MAX]; + + /* libfoo.so.def.{flavor} */ + if (slbt_snprintf(hosttag, + sizeof(hosttag), + "%s.%s", + deffilename, + dctx->cctx->host.flavor) < 0) + return SLBT_BUFFER_ERROR(dctx); + + if (slbt_snprintf(hostlnk, + sizeof(hostlnk), + "%s.host", + deffilename) < 0) + return SLBT_BUFFER_ERROR(dctx); + + /* libfoo.so.def is under .libs/ */ + if (!(slash = strrchr(deffilename,'/'))) + return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW); + + if (slbt_create_symlink( + dctx,ectx, + deffilename, + hosttag, + SLBT_SYMLINK_DEFAULT)) + return SLBT_NESTED_ERROR(dctx); + + /* libfoo.so.def.{flavor} is under .libs/ */ + if (!(slash = strrchr(hosttag,'/'))) + return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW); + + if (slbt_create_symlink( + dctx,ectx, + ++slash, + hostlnk, + SLBT_SYMLINK_DEFAULT)) + return SLBT_NESTED_ERROR(dctx); + + return 0; +} diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c index c21af58..23cc999 100644 --- a/src/logic/slbt_exec_link.c +++ b/src/logic/slbt_exec_link.c @@ -128,54 +128,6 @@ static int slbt_exec_link_remove_file( return SLBT_SYSTEM_ERROR(dctx,0); } -static int slbt_exec_link_create_host_tag( - const struct slbt_driver_ctx * dctx, - struct slbt_exec_ctx * ectx, - char * deffilename) -{ - char * slash; - char hosttag[PATH_MAX]; - char hostlnk[PATH_MAX]; - - /* libfoo.so.def.{flavor} */ - if (slbt_snprintf(hosttag, - sizeof(hosttag), - "%s.%s", - deffilename, - dctx->cctx->host.flavor) < 0) - return SLBT_BUFFER_ERROR(dctx); - - if (slbt_snprintf(hostlnk, - sizeof(hostlnk), - "%s.host", - deffilename) < 0) - return SLBT_BUFFER_ERROR(dctx); - - /* libfoo.so.def is under .libs/ */ - if (!(slash = strrchr(deffilename,'/'))) - return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW); - - if (slbt_create_symlink( - dctx,ectx, - deffilename, - hosttag, - SLBT_SYMLINK_DEFAULT)) - return SLBT_NESTED_ERROR(dctx); - - /* libfoo.so.def.{flavor} is under .libs/ */ - if (!(slash = strrchr(hosttag,'/'))) - return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW); - - if (slbt_create_symlink( - dctx,ectx, - ++slash, - hostlnk, - SLBT_SYMLINK_DEFAULT)) - return SLBT_NESTED_ERROR(dctx); - - return 0; -} - static int slbt_exec_link_create_import_library( const struct slbt_driver_ctx * dctx, struct slbt_exec_ctx * ectx, -- cgit v1.2.3