|
|
616016 |
/****************************************************************/
|
|
|
616016 |
/* mdso: midipix dso scavenger */
|
|
|
d5fc3d |
/* Copyright (C) 2015--2021 SysDeer Technologies, LLC */
|
|
|
616016 |
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
|
|
|
616016 |
/****************************************************************/
|
|
|
616016 |
|
|
|
616016 |
#include <stdio.h>
|
|
|
616016 |
#include <unistd.h>
|
|
|
f1dbc6 |
|
|
|
616016 |
#include <mdso/mdso.h>
|
|
|
616016 |
#include <mdso/mdso_output.h>
|
|
|
616016 |
#include "mdso_driver_impl.h"
|
|
|
f1dbc6 |
#include "mdso_dprintf_impl.h"
|
|
|
616016 |
|
|
|
616016 |
#ifndef MDSO_DRIVER_FLAGS
|
|
|
616016 |
#define MDSO_DRIVER_FLAGS MDSO_DRIVER_VERBOSITY_ERRORS \
|
|
|
616016 |
| MDSO_DRIVER_VERBOSITY_USAGE
|
|
|
616016 |
#endif
|
|
|
616016 |
|
|
|
616016 |
static const char vermsg[] = "%s%s%s (git://midipix.org/mdso): "
|
|
|
616016 |
"version %s%d.%d.%d%s.\n"
|
|
|
616016 |
"[commit reference: %s%s%s]\n";
|
|
|
616016 |
|
|
|
616016 |
static const char * const mdso_ver_color[6] = {
|
|
|
616016 |
"\x1b[1m\x1b[35m","\x1b[0m",
|
|
|
616016 |
"\x1b[1m\x1b[32m","\x1b[0m",
|
|
|
616016 |
"\x1b[1m\x1b[34m","\x1b[0m"
|
|
|
616016 |
};
|
|
|
616016 |
|
|
|
616016 |
static const char * const mdso_ver_plain[6] = {
|
|
|
616016 |
"","",
|
|
|
616016 |
"","",
|
|
|
616016 |
"",""
|
|
|
616016 |
};
|
|
|
616016 |
|
|
|
b5540e |
static ssize_t mdso_version(struct mdso_driver_ctx * dctx, int fdout)
|
|
|
616016 |
{
|
|
|
616016 |
const struct mdso_source_version * verinfo;
|
|
|
616016 |
const char * const * verclr;
|
|
|
616016 |
|
|
|
616016 |
verinfo = mdso_source_version();
|
|
|
f1dbc6 |
verclr = isatty(fdout) ? mdso_ver_color : mdso_ver_plain;
|
|
|
616016 |
|
|
|
f1dbc6 |
return mdso_dprintf(
|
|
|
f1dbc6 |
fdout,vermsg,
|
|
|
616016 |
verclr[0],dctx->program,verclr[1],
|
|
|
616016 |
verclr[2],verinfo->major,verinfo->minor,
|
|
|
616016 |
verinfo->revision,verclr[3],
|
|
|
616016 |
verclr[4],verinfo->commit,verclr[5]);
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
63e310 |
static void mdso_perform_unit_actions(
|
|
|
63e310 |
struct mdso_driver_ctx * dctx,
|
|
|
63e310 |
struct mdso_unit_ctx * uctx)
|
|
|
616016 |
{
|
|
|
c12a92 |
if (uctx->cctx->fmtflags & MDSO_OUTPUT_EXPORT_SYMS)
|
|
|
551500 |
mdso_output_export_symbols(dctx,uctx);
|
|
|
113d3f |
|
|
|
113d3f |
if (uctx->cctx->drvflags & MDSO_DRIVER_COMPUTE_CRC32)
|
|
|
113d3f |
mdso_output_expsyms_crc32(dctx,uctx);
|
|
|
113d3f |
|
|
|
113d3f |
if (uctx->cctx->drvflags & MDSO_DRIVER_COMPUTE_CRC64)
|
|
|
113d3f |
mdso_output_expsyms_crc64(dctx,uctx);
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
d30cda |
static int mdso_exit(struct mdso_driver_ctx * dctx, int ret)
|
|
|
616016 |
{
|
|
|
d30cda |
mdso_output_error_vector(dctx);
|
|
|
616016 |
mdso_free_driver_ctx(dctx);
|
|
|
d30cda |
return ret;
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
85cfaa |
int mdso_main(char ** argv, char ** envp, const struct mdso_fd_ctx * fdctx)
|
|
|
616016 |
{
|
|
|
616016 |
int ret;
|
|
|
f1dbc6 |
int fdout;
|
|
|
f1dbc6 |
uint64_t flags;
|
|
|
616016 |
struct mdso_driver_ctx * dctx;
|
|
|
616016 |
struct mdso_unit_ctx * uctx;
|
|
|
616016 |
const char ** unit;
|
|
|
616016 |
|
|
|
f1dbc6 |
flags = MDSO_DRIVER_FLAGS;
|
|
|
f1dbc6 |
fdout = fdctx ? fdctx->fdout : STDOUT_FILENO;
|
|
|
f1dbc6 |
|
|
|
f1dbc6 |
if ((ret = mdso_get_driver_ctx(argv,envp,flags,fdctx,&dctx)))
|
|
|
99b875 |
return (ret == MDSO_USAGE)
|
|
|
85cfaa |
? !argv || !argv[0] || !argv[1]
|
|
|
99b875 |
: MDSO_ERROR;
|
|
|
616016 |
|
|
|
616016 |
if (dctx->cctx->drvflags & MDSO_DRIVER_VERSION)
|
|
|
b5540e |
if ((mdso_version(dctx,fdout)) < 0)
|
|
|
99b875 |
return mdso_exit(dctx,MDSO_ERROR);
|
|
|
616016 |
|
|
|
c70c0a |
if (dctx->cctx->implib)
|
|
|
c70c0a |
mdso_create_implib_archive(dctx);
|
|
|
c70c0a |
|
|
|
c12a92 |
if (dctx->cctx->drvflags & MDSO_DRIVER_GENERATE_ASM)
|
|
|
c12a92 |
mdso_create_implib_sources(dctx);
|
|
|
c12a92 |
|
|
|
3e55ee |
if (dctx->cctx->drvflags & MDSO_DRIVER_GENERATE_OBJECTS)
|
|
|
3e55ee |
mdso_create_implib_objects(dctx);
|
|
|
3e55ee |
|
|
|
461b1f |
for (unit=dctx->units; *unit && !dctx->errv[0]; unit++) {
|
|
|
616016 |
if (!(mdso_get_unit_ctx(dctx,*unit,&uctx))) {
|
|
|
63e310 |
mdso_perform_unit_actions(dctx,uctx);
|
|
|
616016 |
mdso_free_unit_ctx(uctx);
|
|
|
616016 |
}
|
|
|
616016 |
}
|
|
|
616016 |
|
|
|
99b875 |
return mdso_exit(dctx,dctx->errv[0] ? MDSO_ERROR : MDSO_OK);
|
|
|
616016 |
}
|