firasuke / cross / slibtool

Forked from cross/slibtool 3 months ago
Clone

Blame src/output/slbt_output_config.c

617bbc
/*******************************************************************/
617bbc
/*  slibtool: a skinny libtool implementation, written in C        */
6803d8
/*  Copyright (C) 2016--2018  Z. Gilboa                            */
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
617bbc
static bool slbt_output_config_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
617bbc
int slbt_output_config(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
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
a82cc2
	if (slbt_output_config_line(fdout,"key","value","annotation",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"---","-----","----------",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"compiler",cctx->cargv[0],"",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"target",cctx->target,"",midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"host",cctx->host.host,cctx->cfgmeta.host,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
9a02e2
	if (slbt_output_config_line(fdout,"windres",cctx->host.windres,cctx->cfgmeta.windres,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
9a02e2
a82cc2
	if (slbt_output_config_line(fdout,"dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
617bbc
a82cc2
	if (slbt_output_config_line(fdout,"mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth))
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
fbda3a
a82cc2
	return 0;
617bbc
}