orbea / cross / slibtool

Forked from cross/slibtool 3 years ago
Clone

Blame src/internal/slibtool_libmeta_impl.c

a9cfe4
/*******************************************************************/
a9cfe4
/*  slibtool: a skinny libtool implementation, written in C        */
a9cfe4
/*  Copyright (C) 2016  Z. Gilboa                                  */
a9cfe4
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
a9cfe4
/*******************************************************************/
a9cfe4
a9cfe4
#include <stdio.h>
a9cfe4
#include <stdbool.h>
a9cfe4
#include <slibtool/slibtool.h>
a9cfe4
#include "slibtool_metafile_impl.h"
a9cfe4
a9cfe4
static int  slbt_create_default_library_wrapper(
a9cfe4
	const struct slbt_driver_ctx *	dctx,
a9cfe4
	struct slbt_exec_ctx *		ectx,
a9cfe4
	char *				arname,
a9cfe4
	char *				soname,
a9cfe4
	char *				soxyz,
a9cfe4
	char *				solnk)
a9cfe4
{
a9cfe4
	int					ret;
a9cfe4
	FILE *					fout;
a9cfe4
	const char *				header;
a9cfe4
	const char *				base;
a9cfe4
	bool					fnover;
a9cfe4
	bool					fvernum;
a9cfe4
	int					current;
a9cfe4
	int					revision;
a9cfe4
	int					age;
a9cfe4
	const struct slbt_source_version *	verinfo;
a9cfe4
a9cfe4
	(void)ectx;
a9cfe4
a9cfe4
	/* create */
a9cfe4
	if (!(fout = fopen(dctx->cctx->output,"w")))
a9cfe4
		return -1;
a9cfe4
a9cfe4
	/* version info */
a9cfe4
	current  = 0;
a9cfe4
	age      = 0;
a9cfe4
	revision = 0;
a9cfe4
a9cfe4
	if (dctx->cctx->verinfo.verinfo)
a9cfe4
		sscanf(dctx->cctx->verinfo.verinfo,"%d:%d:%d",
a9cfe4
			&current,&revision,&age;;
a9cfe4
a9cfe4
	fnover  = !!(dctx->cctx->drvflags & SLBT_DRIVER_AVOID_VERSION);
a9cfe4
	fvernum = !!(dctx->cctx->verinfo.vernumber);
a9cfe4
	verinfo = slbt_source_version();
a9cfe4
a9cfe4
	/* wrapper header */
a9cfe4
	header = "libtool compatible library wrapper\n";
a9cfe4
	base   = "";
a9cfe4
a9cfe4
	/* wrapper content */
a9cfe4
	ret = fprintf(fout,
a9cfe4
		"# %s%s"
a9cfe4
		"# Generated by %s (slibtool %d.%d.%d)\n"
a9cfe4
		"# [commit reference: %s]\n\n"
a9cfe4
a9cfe4
		"dlname='%s'\n"
a9cfe4
		"library_names='%s %s %s'\n"
a9cfe4
		"old_library='%s'\n\n"
a9cfe4
a9cfe4
		"inherited_linker_flags='%s'\n"
a9cfe4
		"dependency_libs='%s'\n"
a9cfe4
		"weak_library_names='%s'\n\n"
a9cfe4
a9cfe4
		"current=%d\n"
a9cfe4
		"age=%d\n"
a9cfe4
		"revision=%d\n\n"
a9cfe4
a9cfe4
		"installed=%s\n"
a9cfe4
		"shouldnotlink=%s\n\n"
a9cfe4
a9cfe4
		"dlopen='%s'\n"
a9cfe4
		"dlpreopen='%s'\n\n"
a9cfe4
a9cfe4
		"libdir='%s'\n",
a9cfe4
a9cfe4
		/* wrapper header */
a9cfe4
		base,header,
a9cfe4
a9cfe4
		/* nickname, verinfo */
a9cfe4
		dctx->program,
a9cfe4
		verinfo->major,verinfo->minor,verinfo->revision,
a9cfe4
		verinfo->commit,
a9cfe4
a9cfe4
		/* dlname */
a9cfe4
		fnover ? solnk : soxyz,
a9cfe4
a9cfe4
		/* library_names */
a9cfe4
		fnover ? solnk : soxyz,
a9cfe4
		fnover ? solnk : soname,
a9cfe4
		solnk,
a9cfe4
a9cfe4
		/* old_library */
a9cfe4
		arname,
a9cfe4
a9cfe4
		/* inherited_linker_flags, dependency_libs, weak_library_names */
a9cfe4
		"","","",
a9cfe4
a9cfe4
		/* current, age, revision */
a9cfe4
		fvernum ? dctx->cctx->verinfo.major : current,
a9cfe4
		fvernum ? dctx->cctx->verinfo.minor : age,
a9cfe4
		fvernum ? dctx->cctx->verinfo.major : revision,
a9cfe4
a9cfe4
		/* installed, shouldnotlink */
a9cfe4
		"no","no",
a9cfe4
a9cfe4
		/* dlopen, dlpreopen */
a9cfe4
		"","",
a9cfe4
a9cfe4
		/* libdir */
a9cfe4
		dctx->cctx->rpath ? dctx->cctx->rpath : "");
a9cfe4
a9cfe4
	return (ret <= 0) || fclose(fout)
a9cfe4
		? -1 : 0;
a9cfe4
}
a9cfe4
a9cfe4
static int  slbt_create_compatible_library_wrapper(
a9cfe4
	const struct slbt_driver_ctx *	dctx,
a9cfe4
	struct slbt_exec_ctx *		ectx,
a9cfe4
	char *				arname,
a9cfe4
	char *				soname,
a9cfe4
	char *				soxyz,
a9cfe4
	char *				solnk)
a9cfe4
{
a9cfe4
	/* awaiting submission */
a9cfe4
	return slbt_create_default_library_wrapper(
a9cfe4
		dctx,ectx,arname,soxyz,soname,solnk);
a9cfe4
}
a9cfe4
a9cfe4
int  slbt_create_library_wrapper(
a9cfe4
	const struct slbt_driver_ctx *	dctx,
a9cfe4
	struct slbt_exec_ctx *		ectx,
a9cfe4
	char *				arname,
a9cfe4
	char *				soname,
a9cfe4
	char *				soxyz,
a9cfe4
	char *				solnk)
a9cfe4
{
a9cfe4
	if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS)
a9cfe4
		return slbt_create_compatible_library_wrapper(
a9cfe4
			dctx,ectx,arname,soxyz,soname,solnk);
a9cfe4
	else
a9cfe4
		return slbt_create_default_library_wrapper(
a9cfe4
			dctx,ectx,arname,soxyz,soname,solnk);
a9cfe4
}