1 #ifndef SLIBTOOL_H
2 #define SLIBTOOL_H
3 
4 #include <stdint.h>
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 
9 #include "slibtool_api.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /* pre-alpha */
16 #ifndef SLBT_APP
17 #ifndef SLBT_PRE_ALPHA
18 #error  libslibtool: pre-alpha: ABI is not final!
19 #error  to use the library, please pass -DSLBT_PRE_ALPHA to the compiler.
20 #endif
21 #endif
22 
23 /* status codes */
24 #define SLBT_OK				0x00
25 #define SLBT_USAGE			0x01
26 #define SLBT_ERROR			0x02
27 
28 /* driver flags */
29 #define SLBT_DRIVER_XFLAG(x)		((uint64_t)(x) << 32)
30 
31 #define SLBT_DRIVER_VERBOSITY_NONE	0x0000
32 #define SLBT_DRIVER_VERBOSITY_ERRORS	0x0001
33 #define SLBT_DRIVER_VERBOSITY_STATUS	0x0002
34 #define SLBT_DRIVER_VERBOSITY_USAGE	0x0004
35 #define SLBT_DRIVER_CLONE_VECTOR	0x0008
36 
37 #define SLBT_DRIVER_VERSION		0x0010
38 #define SLBT_DRIVER_DRY_RUN		0x0020
39 #define SLBT_DRIVER_CONFIG		0x0040
40 #define SLBT_DRIVER_DEBUG		0x0080
41 #define SLBT_DRIVER_FEATURES		0x0100
42 #define SLBT_DRIVER_DEPS		0x0200
43 #define SLBT_DRIVER_SILENT		0x0400
44 #define SLBT_DRIVER_VERBOSE		0x0800
45 #define SLBT_DRIVER_PRO_PIC		0x1000
46 #define SLBT_DRIVER_ANTI_PIC		0x2000
47 #define SLBT_DRIVER_SHARED		0x4000
48 #define SLBT_DRIVER_STATIC		0x8000
49 
50 #define SLBT_DRIVER_HEURISTICS		0x010000
51 #define SLBT_DRIVER_STRICT		0x020000
52 #define SLBT_DRIVER_NO_UNDEFINED	0x040000
53 #define SLBT_DRIVER_MODULE		0x080000
54 #define SLBT_DRIVER_AVOID_VERSION	0x100000
55 #define SLBT_DRIVER_IMAGE_ELF		0x200000
56 #define SLBT_DRIVER_IMAGE_PE		0x400000
57 #define SLBT_DRIVER_IMAGE_MACHO		0x800000
58 
59 #define SLBT_DRIVER_ALL_STATIC		0x01000000
60 #define SLBT_DRIVER_DISABLE_STATIC	0x02000000
61 #define SLBT_DRIVER_DISABLE_SHARED	0x04000000
62 #define SLBT_DRIVER_LEGABITS		0x08000000
63 
64 #define SLBT_DRIVER_ANNOTATE_ALWAYS	0x10000000
65 #define SLBT_DRIVER_ANNOTATE_NEVER	0x20000000
66 #define SLBT_DRIVER_ANNOTATE_FULL	0x40000000
67 
68 #define SLBT_DRIVER_IMPLIB_IDATA	SLBT_DRIVER_XFLAG(0x0001)
69 #define SLBT_DRIVER_IMPLIB_DSOMETA	SLBT_DRIVER_XFLAG(0x0002)
70 #define SLBT_DRIVER_EXPORT_DYNAMIC	SLBT_DRIVER_XFLAG(0x0010)
71 #define SLBT_DRIVER_STATIC_LIBTOOL_LIBS	SLBT_DRIVER_XFLAG(0x0100)
72 
73 /* error flags */
74 #define SLBT_ERROR_TOP_LEVEL		0x0001
75 #define SLBT_ERROR_NESTED		0x0002
76 #define SLBT_ERROR_CHILD		0x0004
77 #define SLBT_ERROR_CUSTOM		0x0008
78 
79 enum slbt_custom_error {
80 	SLBT_ERR_FLOW_ERROR,
81 	SLBT_ERR_FLEE_ERROR,
82 	SLBT_ERR_ARCHIVE_IMPORT,
83 	SLBT_ERR_HOST_INIT,
84 	SLBT_ERR_INSTALL_FAIL,
85 	SLBT_ERR_INSTALL_FLOW,
86 	SLBT_ERR_INSTALL_REV,
87 	SLBT_ERR_LDRPATH_INIT,
88 	SLBT_ERR_LINK_FLOW,
89 	SLBT_ERR_LINK_FREQ,
90 	SLBT_ERR_BAD_DATA,
91 	SLBT_ERR_UNINSTALL_FAIL,
92 	SLBT_ERR_LCONF_OPEN,
93 	SLBT_ERR_LCONF_MAP,
94 	SLBT_ERR_LCONF_PARSE,
95 };
96 
97 /* execution modes */
98 enum slbt_mode {
99 	SLBT_MODE_UNKNOWN,
100 	SLBT_MODE_INFO,
101 	SLBT_MODE_CLEAN,
102 	SLBT_MODE_COMPILE,
103 	SLBT_MODE_EXECUTE,
104 	SLBT_MODE_FINISH,
105 	SLBT_MODE_INSTALL,
106 	SLBT_MODE_LINK,
107 	SLBT_MODE_UNINSTALL,
108 };
109 
110 enum slbt_tag {
111 	SLBT_TAG_UNKNOWN,
112 	SLBT_TAG_CC,
113 	SLBT_TAG_CXX,
114 	SLBT_TAG_FC,
115 	SLBT_TAG_F77,
116 	SLBT_TAG_NASM,
117 	SLBT_TAG_RC,
118 };
119 
120 enum slbt_warning_level {
121 	SLBT_WARNING_LEVEL_UNKNOWN,
122 	SLBT_WARNING_LEVEL_ALL,
123 	SLBT_WARNING_LEVEL_ERROR,
124 	SLBT_WARNING_LEVEL_NONE,
125 };
126 
127 struct slbt_source_version {
128 	int		major;
129 	int		minor;
130 	int		revision;
131 	const char *	commit;
132 };
133 
134 struct slbt_fd_ctx {
135 	int		fdin;
136 	int		fdout;
137 	int		fderr;
138 	int		fdlog;
139 	int		fdcwd;
140 	int		fddst;
141 };
142 
143 struct slbt_exec_ctx {
144 	char *		program;
145 	char *		compiler;
146 	char **		cargv;
147 	char **		xargv;
148 	char **		argv;
149 	char **		envp;
150 	char ** 	altv;
151 	char ** 	dpic;
152 	char ** 	fpic;
153 	char ** 	cass;
154 	char ** 	noundef;
155 	char ** 	soname;
156 	char ** 	lsoname;
157 	char ** 	symdefs;
158 	char ** 	symfile;
159 	char ** 	lout[2];
160 	char ** 	mout[2];
161 	char ** 	rpath[2];
162 	char ** 	sentinel;
163 	char *		csrc;
164 	int		ldirdepth;
165 	char *		ldirname;
166 	char *		lbasename;
167 	char *		lobjname;
168 	char *		aobjname;
169 	char *		ltobjname;
170 	char *		arfilename;
171 	char *		lafilename;
172 	char *		laifilename;
173 	char *		dsobasename;
174 	char *		dsofilename;
175 	char *		relfilename;
176 	char *		dsorellnkname;
177 	char *		deffilename;
178 	char *		rpathfilename;
179 	char *		dimpfilename;
180 	char *		pimpfilename;
181 	char *		vimpfilename;
182 	char *		exefilename;
183 	char *		sonameprefix;
184 	pid_t		pid;
185 	int		exitcode;
186 };
187 
188 struct slbt_version_info {
189 	int		major;
190 	int		minor;
191 	int		revision;
192 	const char *	verinfo;
193 	const char *	vernumber;
194 };
195 
196 struct slbt_error_info {
197 	const struct slbt_driver_ctx *	edctx;
198 	int				esyscode;
199 	int				elibcode;
200 	const char *			efunction;
201 	int				eline;
202 	unsigned			eflags;
203 	void *				eany;
204 };
205 
206 struct slbt_host_params {
207 	const char *			host;
208 	const char *			flavor;
209 	const char *			ar;
210 	const char *			ranlib;
211 	const char *			windres;
212 	const char *			dlltool;
213 	const char *			mdso;
214 	const char *			ldrpath;
215 };
216 
217 struct slbt_flavor_settings {
218 	const char *			imagefmt;
219 	const char *			arprefix;
220 	const char *			arsuffix;
221 	const char *			dsoprefix;
222 	const char *			dsosuffix;
223 	const char *			osdsuffix;
224 	const char *			osdfussix;
225 	const char *			exeprefix;
226 	const char *			exesuffix;
227 	const char *			impprefix;
228 	const char *			impsuffix;
229 	const char *			ldpathenv;
230 	char *				picswitch;
231 };
232 
233 struct slbt_common_ctx {
234 	uint64_t			drvflags;
235 	uint64_t			actflags;
236 	uint64_t			fmtflags;
237 	struct slbt_host_params		host;
238 	struct slbt_host_params		cfgmeta;
239 	struct slbt_flavor_settings	settings;
240 	struct slbt_host_params		ahost;
241 	struct slbt_host_params		acfgmeta;
242 	struct slbt_flavor_settings	asettings;
243 	struct slbt_version_info	verinfo;
244 	enum slbt_mode			mode;
245 	enum slbt_tag			tag;
246 	enum slbt_warning_level		warnings;
247 	char **				cargv;
248 	char **				targv;
249 	char *				libname;
250 	const char *			ccwrap;
251 	const char *			target;
252 	const char *			output;
253 	const char *			shrext;
254 	const char *			rpath;
255 	const char *			sysroot;
256 	const char *			release;
257 	const char *			symfile;
258 	const char *			regex;
259 	const char *			user;
260 };
261 
262 struct slbt_driver_ctx {
263 	const char *			program;
264 	const char *			module;
265 	const struct slbt_common_ctx *	cctx;
266 	struct slbt_error_info **	errv;
267 	void *				any;
268 };
269 
270 /* driver api */
271 slbt_api int  slbt_get_driver_ctx       (char ** argv, char ** envp, uint32_t flags,
272                                          const struct slbt_fd_ctx *,
273                                          struct slbt_driver_ctx **);
274 
275 slbt_api void slbt_free_driver_ctx      (struct slbt_driver_ctx *);
276 
277 slbt_api int  slbt_get_driver_fdctx     (const struct slbt_driver_ctx *, struct slbt_fd_ctx *);
278 slbt_api int  slbt_set_driver_fdctx     (struct slbt_driver_ctx *, const struct slbt_fd_ctx *);
279 
280 /* execution context api */
281 slbt_api int  slbt_get_exec_ctx         (const struct slbt_driver_ctx *, struct slbt_exec_ctx **);
282 slbt_api void slbt_free_exec_ctx        (struct slbt_exec_ctx *);
283 slbt_api void slbt_reset_argvector      (struct slbt_exec_ctx *);
284 slbt_api void slbt_reset_arguments      (struct slbt_exec_ctx *);
285 slbt_api void slbt_reset_placeholders   (struct slbt_exec_ctx *);
286 slbt_api void slbt_disable_placeholders (struct slbt_exec_ctx *);
287 
288 /* core api */
289 slbt_api int  slbt_exec_compile         (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
290 slbt_api int  slbt_exec_execute         (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
291 slbt_api int  slbt_exec_install         (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
292 slbt_api int  slbt_exec_link            (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
293 slbt_api int  slbt_exec_uninstall       (const struct slbt_driver_ctx *, struct slbt_exec_ctx *);
294 
295 slbt_api int  slbt_set_alternate_host   (const struct slbt_driver_ctx *, const char * host, const char * flavor);
296 slbt_api void slbt_reset_alternate_host (const struct slbt_driver_ctx *);
297 
298 slbt_api int  slbt_get_flavor_settings  (const char *, const struct slbt_flavor_settings **);
299 
300 /* helper api */
301 slbt_api int  slbt_archive_import       (const struct slbt_driver_ctx *, struct slbt_exec_ctx *,
302                                          char * dstarchive, char * srcarchive);
303 slbt_api int  slbt_copy_file            (const struct slbt_driver_ctx *, struct slbt_exec_ctx *,
304                                          char * src, char * dst);
305 slbt_api int  slbt_dump_machine         (const char * compiler, char * machine, size_t bufsize);
306 slbt_api int  slbt_realpath             (int, const char *, int, char *, size_t);
307 
308 /* utility api */
309 slbt_api int  slbt_main                 (char **, char **,
310                                          const struct slbt_fd_ctx *);
311 
312 slbt_api int  slbt_output_config        (const struct slbt_driver_ctx *);
313 slbt_api int  slbt_output_features      (const struct slbt_driver_ctx *);
314 slbt_api int  slbt_output_fdcwd         (const struct slbt_driver_ctx *);
315 slbt_api int  slbt_output_exec          (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *, const char *);
316 slbt_api int  slbt_output_compile       (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *);
317 slbt_api int  slbt_output_execute       (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *);
318 slbt_api int  slbt_output_install       (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *);
319 slbt_api int  slbt_output_link          (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *);
320 slbt_api int  slbt_output_uninstall     (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *);
321 slbt_api int  slbt_output_error_record  (const struct slbt_driver_ctx *, const struct slbt_error_info *);
322 slbt_api int  slbt_output_error_vector  (const struct slbt_driver_ctx *);
323 
324 /* package info */
325 slbt_api const struct slbt_source_version * slbt_source_version(void);
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 
331 #endif
332