|
|
70f645 |
/*******************************************************************/
|
|
|
70f645 |
/* slibtool: a skinny libtool implementation, written in C */
|
|
|
6803d8 |
/* Copyright (C) 2016--2018 Z. Gilboa */
|
|
|
70f645 |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
70f645 |
/*******************************************************************/
|
|
|
70f645 |
|
|
|
2c013f |
#include <fcntl.h>
|
|
|
70f645 |
#include <stdio.h>
|
|
|
70f645 |
#include <slibtool/slibtool.h>
|
|
|
2c013f |
#include "slibtool_dprintf_impl.h"
|
|
|
3d54f3 |
#include "slibtool_errinfo_impl.h"
|
|
|
70f645 |
#include "slibtool_metafile_impl.h"
|
|
|
70f645 |
|
|
|
70f645 |
static int slbt_create_default_object_wrapper(
|
|
|
70f645 |
const struct slbt_driver_ctx * dctx,
|
|
|
70f645 |
struct slbt_exec_ctx * ectx)
|
|
|
70f645 |
{
|
|
|
70f645 |
int ret;
|
|
|
2c013f |
int fdout;
|
|
|
70f645 |
const struct slbt_source_version * verinfo;
|
|
|
70f645 |
|
|
|
2c013f |
if ((fdout = openat(
|
|
|
2c013f |
AT_FDCWD,
|
|
|
2c013f |
ectx->ltobjname,
|
|
|
2c013f |
O_RDWR|O_CREAT|O_TRUNC,
|
|
|
2c013f |
0644)) < 0)
|
|
|
3d54f3 |
return SLBT_SYSTEM_ERROR(dctx);
|
|
|
70f645 |
|
|
|
70f645 |
verinfo = slbt_source_version();
|
|
|
70f645 |
|
|
|
2c013f |
ret = slbt_dprintf(fdout,
|
|
|
70f645 |
"# libtool compatible object wrapper\n"
|
|
|
70f645 |
"# Generated by %s (slibtool %d.%d.%d)\n"
|
|
|
70f645 |
"# [commit reference: %s]\n\n"
|
|
|
70f645 |
|
|
|
70f645 |
"pic_object='%s'\n"
|
|
|
70f645 |
"non_pic_object='%s'\n",
|
|
|
70f645 |
|
|
|
70f645 |
dctx->program,
|
|
|
70f645 |
verinfo->major,verinfo->minor,verinfo->revision,
|
|
|
70f645 |
verinfo->commit,
|
|
|
70f645 |
|
|
|
70f645 |
(dctx->cctx->drvflags & SLBT_DRIVER_SHARED)
|
|
|
70f645 |
? ectx->lobjname
|
|
|
70f645 |
: "none",
|
|
|
70f645 |
(dctx->cctx->drvflags & SLBT_DRIVER_STATIC)
|
|
|
70f645 |
? ectx->aobjname
|
|
|
70f645 |
: "none");
|
|
|
70f645 |
|
|
|
2c013f |
close(fdout);
|
|
|
2c013f |
|
|
|
2c013f |
return (ret < 0) ? SLBT_SYSTEM_ERROR(dctx) : 0;
|
|
|
70f645 |
}
|
|
|
70f645 |
|
|
|
70f645 |
static int slbt_create_compatible_object_wrapper(
|
|
|
70f645 |
const struct slbt_driver_ctx * dctx,
|
|
|
70f645 |
struct slbt_exec_ctx * ectx)
|
|
|
70f645 |
{
|
|
Sebastian Wiedenroth |
ec296a |
int ret;
|
|
Sebastian Wiedenroth |
ec296a |
FILE * fout;
|
|
Sebastian Wiedenroth |
ec296a |
const struct slbt_source_version * verinfo;
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
if (!(fout = fopen(ectx->ltobjname,"w")))
|
|
Sebastian Wiedenroth |
ec296a |
return SLBT_SYSTEM_ERROR(dctx);
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
verinfo = slbt_source_version();
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
ret = fprintf(fout,
|
|
Sebastian Wiedenroth |
ec296a |
"# %s - a libtool object file\n"
|
|
Sebastian Wiedenroth |
ec296a |
"# Generated by %s (slibtool %d.%d.%d)\n"
|
|
Sebastian Wiedenroth |
ec296a |
"# [commit reference: %s]\n"
|
|
Sebastian Wiedenroth |
ec296a |
"#\n"
|
|
Sebastian Wiedenroth |
ec296a |
"# Please DO NOT delete this file!\n"
|
|
Sebastian Wiedenroth |
ec296a |
"# It is necessary for linking the library.\n\n"
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
"# Name of the PIC object.\n"
|
|
Sebastian Wiedenroth |
ec296a |
"pic_object='%s'\n\n"
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
"# Name of the non-PIC object\n"
|
|
Sebastian Wiedenroth |
ec296a |
"non_pic_object='%s'\n",
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
ectx->ltobjname,
|
|
Sebastian Wiedenroth |
ec296a |
dctx->program,
|
|
Sebastian Wiedenroth |
ec296a |
verinfo->major,verinfo->minor,verinfo->revision,
|
|
Sebastian Wiedenroth |
ec296a |
verinfo->commit,
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
(dctx->cctx->drvflags & SLBT_DRIVER_SHARED)
|
|
Sebastian Wiedenroth |
ec296a |
? ectx->lobjname
|
|
Sebastian Wiedenroth |
ec296a |
: "none",
|
|
Sebastian Wiedenroth |
ec296a |
(dctx->cctx->drvflags & SLBT_DRIVER_STATIC)
|
|
Sebastian Wiedenroth |
ec296a |
? ectx->aobjname
|
|
Sebastian Wiedenroth |
ec296a |
: "none");
|
|
Sebastian Wiedenroth |
ec296a |
|
|
Sebastian Wiedenroth |
ec296a |
return (ret <= 0) || fclose(fout)
|
|
Sebastian Wiedenroth |
ec296a |
? SLBT_SYSTEM_ERROR(dctx)
|
|
Sebastian Wiedenroth |
ec296a |
: 0;
|
|
|
70f645 |
}
|
|
|
70f645 |
|
|
|
70f645 |
int slbt_create_object_wrapper(
|
|
|
70f645 |
const struct slbt_driver_ctx * dctx,
|
|
|
70f645 |
struct slbt_exec_ctx * ectx)
|
|
|
70f645 |
{
|
|
|
70f645 |
if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS)
|
|
|
70f645 |
return slbt_create_compatible_object_wrapper(dctx,ectx);
|
|
|
70f645 |
else
|
|
|
70f645 |
return slbt_create_default_object_wrapper(dctx,ectx);
|
|
|
70f645 |
}
|