|
|
6f991b |
/*******************************************************************/
|
|
|
6f991b |
/* slibtool: a skinny libtool implementation, written in C */
|
|
|
49181b |
/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
|
|
|
6f991b |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
6f991b |
/*******************************************************************/
|
|
|
6f991b |
|
|
Kylie McClain |
e20148 |
#include <unistd.h>
|
|
|
6f991b |
#include <stdio.h>
|
|
|
6f991b |
#include <slibtool/slibtool.h>
|
|
|
a82cc2 |
|
|
|
a82cc2 |
#include "slibtool_driver_impl.h"
|
|
|
a82cc2 |
#include "slibtool_dprintf_impl.h"
|
|
|
522163 |
#include "slibtool_errinfo_impl.h"
|
|
|
6f991b |
|
|
|
8ea8fc |
static const char aclr_null[] = "";
|
|
|
8ea8fc |
static const char aclr_reset[] = "\x1b[0m";
|
|
|
8ea8fc |
static const char aclr_bold[] = "\x1b[1m";
|
|
Kylie McClain |
e20148 |
|
|
|
8ea8fc |
static const char aclr_green[] = "\x1b[32m";
|
|
|
8ea8fc |
static const char aclr_blue[] = "\x1b[34m";
|
|
|
8ea8fc |
static const char aclr_magenta[] = "\x1b[35m";
|
|
Kylie McClain |
e20148 |
|
|
Kylie McClain |
e20148 |
static int slbt_output_exec_annotated(
|
|
|
6f991b |
const struct slbt_driver_ctx * dctx,
|
|
|
fab986 |
const struct slbt_exec_ctx * ectx,
|
|
|
fab986 |
const char * step)
|
|
|
6f991b |
{
|
|
|
a82cc2 |
int fdout;
|
|
Kylie McClain |
e20148 |
char ** parg;
|
|
Kylie McClain |
e20148 |
const char * aclr_set;
|
|
Kylie McClain |
e20148 |
const char * aclr_color;
|
|
Kylie McClain |
e20148 |
const char * aclr_unset;
|
|
Kylie McClain |
e20148 |
|
|
|
a0573f |
fdout = (strcmp(step,"execute"))
|
|
|
a0573f |
? slbt_driver_fdout(dctx)
|
|
|
a0573f |
: slbt_driver_fderr(dctx);
|
|
|
a82cc2 |
|
|
|
a82cc2 |
if (slbt_dprintf(
|
|
|
a82cc2 |
fdout,"%s%s%s: %s%s%s%s:%s",
|
|
Kylie McClain |
e20148 |
aclr_bold,aclr_magenta,
|
|
Kylie McClain |
e20148 |
dctx->program,aclr_reset,
|
|
Kylie McClain |
e20148 |
aclr_bold,aclr_green,step,aclr_reset) < 0)
|
|
|
6beda1 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
Kylie McClain |
e20148 |
|
|
Kylie McClain |
e20148 |
for (parg=ectx->argv; *parg; parg++) {
|
|
|
df07fb |
if ((parg == ectx->lout[0]) || (parg == ectx->mout[0])) {
|
|
Kylie McClain |
e20148 |
aclr_set = aclr_bold;
|
|
Kylie McClain |
e20148 |
aclr_color = aclr_blue;
|
|
Kylie McClain |
e20148 |
aclr_unset = aclr_null;
|
|
Kylie McClain |
e20148 |
} else {
|
|
Kylie McClain |
e20148 |
aclr_set = aclr_null;
|
|
Kylie McClain |
e20148 |
aclr_color = aclr_null;
|
|
Kylie McClain |
e20148 |
aclr_unset = aclr_reset;
|
|
Kylie McClain |
e20148 |
}
|
|
Kylie McClain |
e20148 |
|
|
|
a82cc2 |
if (slbt_dprintf(
|
|
|
a82cc2 |
fdout," %s%s%s%s",
|
|
Kylie McClain |
e20148 |
aclr_set,aclr_color,
|
|
Kylie McClain |
e20148 |
*parg,
|
|
Kylie McClain |
e20148 |
aclr_unset) < 0)
|
|
|
6beda1 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
Kylie McClain |
e20148 |
|
|
Kylie McClain |
e20148 |
}
|
|
Kylie McClain |
e20148 |
|
|
|
a82cc2 |
if (slbt_dprintf(fdout,"\n") < 0)
|
|
|
6beda1 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
Kylie McClain |
e20148 |
|
|
|
a82cc2 |
return 0;
|
|
Kylie McClain |
e20148 |
}
|
|
Kylie McClain |
e20148 |
|
|
Kylie McClain |
e20148 |
static int slbt_output_exec_plain(
|
|
Kylie McClain |
e20148 |
const struct slbt_driver_ctx * dctx,
|
|
Kylie McClain |
e20148 |
const struct slbt_exec_ctx * ectx,
|
|
Kylie McClain |
e20148 |
const char * step)
|
|
Kylie McClain |
e20148 |
{
|
|
|
a82cc2 |
int fdout;
|
|
|
6f991b |
char ** parg;
|
|
|
6f991b |
|
|
|
a0573f |
fdout = (strcmp(step,"execute"))
|
|
|
a0573f |
? slbt_driver_fdout(dctx)
|
|
|
a0573f |
: slbt_driver_fderr(dctx);
|
|
|
a82cc2 |
|
|
|
a82cc2 |
if (slbt_dprintf(fdout,"%s: %s:",dctx->program,step) < 0)
|
|
|
6beda1 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
|
6f991b |
|
|
|
6f991b |
for (parg=ectx->argv; *parg; parg++)
|
|
|
a82cc2 |
if (slbt_dprintf(fdout," %s",*parg) < 0)
|
|
|
6beda1 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
|
6f991b |
|
|
|
a82cc2 |
if (slbt_dprintf(fdout,"\n") < 0)
|
|
|
6beda1 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
|
6f991b |
|
|
|
a82cc2 |
return 0;
|
|
|
6f991b |
}
|
|
|
fab986 |
|
|
Kylie McClain |
e20148 |
int slbt_output_exec(
|
|
Kylie McClain |
e20148 |
const struct slbt_exec_ctx * ectx,
|
|
Kylie McClain |
e20148 |
const char * step)
|
|
Kylie McClain |
e20148 |
{
|
|
|
33a569 |
const struct slbt_driver_ctx * dctx;
|
|
|
33a569 |
int fdout;
|
|
|
33a569 |
|
|
|
33a569 |
dctx = (slbt_get_exec_ictx(ectx))->dctx;
|
|
|
a0573f |
|
|
|
a0573f |
fdout = (strcmp(step,"execute"))
|
|
|
a0573f |
? slbt_driver_fdout(dctx)
|
|
|
a0573f |
: slbt_driver_fderr(dctx);
|
|
|
a82cc2 |
|
|
Kylie McClain |
e20148 |
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
|
|
Kylie McClain |
e20148 |
return slbt_output_exec_plain(dctx,ectx,step);
|
|
Kylie McClain |
e20148 |
|
|
Kylie McClain |
e20148 |
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
|
|
Kylie McClain |
e20148 |
return slbt_output_exec_annotated(dctx,ectx,step);
|
|
Kylie McClain |
e20148 |
|
|
|
a82cc2 |
else if (isatty(fdout))
|
|
Kylie McClain |
e20148 |
return slbt_output_exec_annotated(dctx,ectx,step);
|
|
Kylie McClain |
e20148 |
|
|
Kylie McClain |
e20148 |
else
|
|
Kylie McClain |
e20148 |
return slbt_output_exec_plain(dctx,ectx,step);
|
|
Kylie McClain |
e20148 |
}
|
|
Kylie McClain |
e20148 |
|
|
|
33a569 |
int slbt_output_compile(const struct slbt_exec_ctx * ectx)
|
|
|
fab986 |
{
|
|
|
33a569 |
return slbt_output_exec(ectx,"compile");
|
|
|
fab986 |
}
|
|
|
ba3523 |
|
|
|
33a569 |
int slbt_output_execute(const struct slbt_exec_ctx * ectx)
|
|
|
045b88 |
{
|
|
|
33a569 |
return slbt_output_exec(ectx,"execute");
|
|
|
045b88 |
}
|
|
|
045b88 |
|
|
|
33a569 |
int slbt_output_install(const struct slbt_exec_ctx * ectx)
|
|
|
ca15b9 |
{
|
|
|
33a569 |
return slbt_output_exec(ectx,"install");
|
|
|
ca15b9 |
}
|
|
|
ca15b9 |
|
|
|
33a569 |
int slbt_output_link(const struct slbt_exec_ctx * ectx)
|
|
|
ba3523 |
{
|
|
|
33a569 |
return slbt_output_exec(ectx,"link");
|
|
|
ba3523 |
}
|
|
|
0fb20a |
|
|
|
33a569 |
int slbt_output_uninstall(const struct slbt_exec_ctx * ectx)
|
|
|
0fb20a |
{
|
|
|
33a569 |
return slbt_output_exec(ectx,"uninstall");
|
|
|
0fb20a |
}
|