Blame src/output/slbt_output_info.c

617bbc
/*******************************************************************/
617bbc
/*  slibtool: a skinny libtool implementation, written in C        */
49181b
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
617bbc
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
617bbc
/*******************************************************************/
617bbc
617bbc
#include <stdio.h>
617bbc
#include <string.h>
617bbc
#include <stdbool.h>
617bbc
617bbc
#include <slibtool/slibtool.h>
a82cc2
#include "slibtool_driver_impl.h"
a82cc2
#include "slibtool_dprintf_impl.h"
522163
#include "slibtool_errinfo_impl.h"
617bbc
617bbc
#ifndef SLBT_TAB_WIDTH
617bbc
#define SLBT_TAB_WIDTH 8
617bbc
#endif
617bbc
617bbc
#ifndef SLBT_KEY_WIDTH
617bbc
#define SLBT_KEY_WIDTH 16
617bbc
#endif
617bbc
c57816
static bool slbt_output_info_line(
a82cc2
	int		fd,
617bbc
	const char *	key,
617bbc
	const char *	value,
617bbc
	const char *	annotation,
617bbc
	int		midwidth)
617bbc
{
a82cc2
	return (slbt_dprintf(fd,"%-*s%-*s%s\n",
617bbc
			SLBT_KEY_WIDTH, key,
617bbc
			midwidth, value ? value : "",
617bbc
			annotation ? annotation : "") < 0)
617bbc
		? true : false;
617bbc
}
617bbc
c57816
int slbt_output_info(const struct slbt_driver_ctx * dctx)
617bbc
{
617bbc
	const struct slbt_common_ctx *	cctx;
617bbc
	const char *			compiler;
617bbc
	const char *			target;
617bbc
	int				len;
617bbc
	int				midwidth;
a82cc2
	int				fdout;
617bbc
617bbc
	cctx     = dctx->cctx;
617bbc
	compiler = cctx->cargv[0] ? cctx->cargv[0] : "";
617bbc
	target   = cctx->target   ? cctx->target   : "";
617bbc
	midwidth = strlen(compiler);
a82cc2
	fdout    = slbt_driver_fdout(dctx);
617bbc
617bbc
	if ((len = strlen(target)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.host)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.flavor)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.ar)) > midwidth)
617bbc
		midwidth = len;
617bbc
6bc170
	if ((len = strlen(cctx->host.as)) > midwidth)
6bc170
		midwidth = len;
6bc170
b5e104
	if ((len = strlen(cctx->host.nm)) > midwidth)
b5e104
		midwidth = len;
b5e104
617bbc
	if ((len = strlen(cctx->host.ranlib)) > midwidth)
617bbc
		midwidth = len;
617bbc
9a02e2
	if ((len = strlen(cctx->host.windres)) > midwidth)
9a02e2
		midwidth = len;
9a02e2
617bbc
	if ((len = strlen(cctx->host.dlltool)) > midwidth)
617bbc
		midwidth = len;
617bbc
fbda3a
	if ((len = strlen(cctx->host.mdso)) > midwidth)
fbda3a
		midwidth = len;
fbda3a
617bbc
	midwidth += SLBT_TAB_WIDTH;
617bbc
	midwidth &= (~(SLBT_TAB_WIDTH-1));
617bbc
c57816
	if (slbt_output_info_line(fdout,"key","value","annotation",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"---","-----","----------",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"compiler",cctx->cargv[0],"",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"target",cctx->target,"",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"host",cctx->host.host,cctx->cfgmeta.host,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
6bc170
	if (slbt_output_info_line(fdout,"as",cctx->host.as,cctx->cfgmeta.as,midwidth))
6bc170
		return SLBT_SYSTEM_ERROR(dctx,0);
6bc170
b5e104
	if (slbt_output_info_line(fdout,"nm",cctx->host.nm,cctx->cfgmeta.nm,midwidth))
b5e104
		return SLBT_SYSTEM_ERROR(dctx,0);
b5e104
c57816
	if (slbt_output_info_line(fdout,"ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"windres",cctx->host.windres,cctx->cfgmeta.windres,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
9a02e2
c57816
	if (slbt_output_info_line(fdout,"dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
c57816
	if (slbt_output_info_line(fdout,"mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
fbda3a
a82cc2
	return 0;
617bbc
}