summaryrefslogtreecommitdiffhomepage
path: root/src/internal/slibtool_libmeta_impl.c
blob: e8159838109e07a1bf1cf02fcc9f91a043a49508 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*******************************************************************/
/*  slibtool: a skinny libtool implementation, written in C        */
/*  Copyright (C) 2016  Z. Gilboa                                  */
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
/*******************************************************************/

#include <stdio.h>
#include <stdbool.h>
#include <slibtool/slibtool.h>
#include "slibtool_errinfo_impl.h"
#include "slibtool_metafile_impl.h"

static int  slbt_create_default_library_wrapper(
	const struct slbt_driver_ctx *	dctx,
	struct slbt_exec_ctx *		ectx,
	char *				arname,
	char *				soname,
	char *				soxyz,
	char *				solnk)
{
	int					ret;
	FILE *					fout;
	const char *				header;
	const char *				base;
	bool					fnover;
	bool					fvernum;
	int					current;
	int					revision;
	int					age;
	const struct slbt_source_version *	verinfo;

	(void)ectx;

	/* create */
	if (!(fout = fopen(dctx->cctx->output,"w")))
		return SLBT_SYSTEM_ERROR(dctx);

	/* version info */
	current  = 0;
	age      = 0;
	revision = 0;

	if (dctx->cctx->verinfo.verinfo)
		sscanf(dctx->cctx->verinfo.verinfo,"%d:%d:%d",
			&current,&revision,&age);

	fnover  = !!(dctx->cctx->drvflags & SLBT_DRIVER_AVOID_VERSION);
	fvernum = !!(dctx->cctx->verinfo.vernumber);
	verinfo = slbt_source_version();

	/* wrapper header */
	header = "libtool compatible library wrapper\n";
	base   = "";

	/* wrapper content */
	ret = fprintf(fout,
		"# %s%s"
		"# Generated by %s (slibtool %d.%d.%d)\n"
		"# [commit reference: %s]\n\n"

		"dlname='%s'\n"
		"library_names='%s %s %s'\n"
		"old_library='%s'\n\n"

		"inherited_linker_flags='%s'\n"
		"dependency_libs='%s'\n"
		"weak_library_names='%s'\n\n"

		"current=%d\n"
		"age=%d\n"
		"revision=%d\n\n"

		"installed=%s\n"
		"shouldnotlink=%s\n\n"

		"dlopen='%s'\n"
		"dlpreopen='%s'\n\n"

		"libdir='%s'\n",

		/* wrapper header */
		base,header,

		/* nickname, verinfo */
		dctx->program,
		verinfo->major,verinfo->minor,verinfo->revision,
		verinfo->commit,

		/* dlname */
		fnover ? solnk : soxyz,

		/* library_names */
		fnover ? solnk : soxyz,
		fnover ? solnk : soname,
		solnk,

		/* old_library */
		arname,

		/* inherited_linker_flags, dependency_libs, weak_library_names */
		"","","",

		/* current, age, revision */
		fvernum ? dctx->cctx->verinfo.major : current,
		fvernum ? dctx->cctx->verinfo.minor : age,
		fvernum ? dctx->cctx->verinfo.major : revision,

		/* installed, shouldnotlink */
		"no","no",

		/* dlopen, dlpreopen */
		"","",

		/* libdir */
		dctx->cctx->rpath ? dctx->cctx->rpath : "");

	return (ret <= 0) || fclose(fout)
		? SLBT_SYSTEM_ERROR(dctx)
		: 0;
}

static int  slbt_create_compatible_library_wrapper(
	const struct slbt_driver_ctx *	dctx,
	struct slbt_exec_ctx *		ectx,
	char *				arname,
	char *				soname,
	char *				soxyz,
	char *				solnk)
{
	/* awaiting submission */
	return slbt_create_default_library_wrapper(
		dctx,ectx,arname,soxyz,soname,solnk);
}

int  slbt_create_library_wrapper(
	const struct slbt_driver_ctx *	dctx,
	struct slbt_exec_ctx *		ectx,
	char *				arname,
	char *				soname,
	char *				soxyz,
	char *				solnk)
{
	if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS)
		return slbt_create_compatible_library_wrapper(
			dctx,ectx,arname,soxyz,soname,solnk);
	else
		return slbt_create_default_library_wrapper(
			dctx,ectx,arname,soxyz,soname,solnk);
}