summaryrefslogtreecommitdiffhomepage
path: root/src/output/slbt_output_config.c
blob: d1d9712fd729f0fa20b72cc68263f993c45be391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************/
/*  slibtool: a skinny libtool implementation, written in C        */
/*  Copyright (C) 2016--2017  Z. Gilboa                            */
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#include <slibtool/slibtool.h>
#include "slibtool_errinfo_impl.h"

#ifndef SLBT_TAB_WIDTH
#define SLBT_TAB_WIDTH 8
#endif

#ifndef SLBT_KEY_WIDTH
#define SLBT_KEY_WIDTH 16
#endif

static bool slbt_output_config_line(
	const char *	key,
	const char *	value,
	const char *	annotation,
	int		midwidth)
{
	return (fprintf(stdout,"%-*s%-*s%s\n",
			SLBT_KEY_WIDTH, key,
			midwidth, value ? value : "",
			annotation ? annotation : "") < 0)
		? true : false;
}

int slbt_output_config(const struct slbt_driver_ctx * dctx)
{
	const struct slbt_common_ctx *	cctx;
	const char *			compiler;
	const char *			target;
	int				len;
	int				midwidth;

	cctx     = dctx->cctx;
	compiler = cctx->cargv[0] ? cctx->cargv[0] : "";
	target   = cctx->target   ? cctx->target   : "";
	midwidth = strlen(compiler);

	if ((len = strlen(target)) > midwidth)
		midwidth = len;

	if ((len = strlen(cctx->host.host)) > midwidth)
		midwidth = len;

	if ((len = strlen(cctx->host.flavor)) > midwidth)
		midwidth = len;

	if ((len = strlen(cctx->host.ar)) > midwidth)
		midwidth = len;

	if ((len = strlen(cctx->host.ranlib)) > midwidth)
		midwidth = len;

	if ((len = strlen(cctx->host.dlltool)) > midwidth)
		midwidth = len;

	midwidth += SLBT_TAB_WIDTH;
	midwidth &= (~(SLBT_TAB_WIDTH-1));

	if (slbt_output_config_line("key","value","annotation",midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("---","-----","----------",midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("compiler",cctx->cargv[0],"",midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("target",cctx->target,"",midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("host",cctx->host.host,cctx->cfgmeta.host,midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	if (slbt_output_config_line("dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
		return SLBT_SYSTEM_ERROR(dctx);

	return fflush(stdout)
		? SLBT_SYSTEM_ERROR(dctx)
		: 0;
}