|
|
5db3db |
/*******************************************************************/
|
|
|
5db3db |
/* slibtool: a skinny libtool implementation, written in C */
|
|
|
49181b |
/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
|
|
|
5db3db |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
5db3db |
/*******************************************************************/
|
|
|
5db3db |
|
|
|
5db3db |
#include <stdlib.h>
|
|
|
5db3db |
#include <stdio.h>
|
|
|
5db3db |
#include <string.h>
|
|
|
5db3db |
#include <fcntl.h>
|
|
|
5db3db |
#include <errno.h>
|
|
|
5db3db |
#include <sys/stat.h>
|
|
|
5db3db |
|
|
|
5db3db |
#include <slibtool/slibtool.h>
|
|
|
5db3db |
#include "slibtool_driver_impl.h"
|
|
|
5db3db |
#include "slibtool_errinfo_impl.h"
|
|
|
5db3db |
#include "slibtool_linkcmd_impl.h"
|
|
|
5db3db |
#include "slibtool_mapfile_impl.h"
|
|
|
5db3db |
#include "slibtool_metafile_impl.h"
|
|
|
5db3db |
#include "slibtool_snprintf_impl.h"
|
|
|
5db3db |
#include "slibtool_symlink_impl.h"
|
|
|
5db3db |
#include "slibtool_spawn_impl.h"
|
|
|
5db3db |
|
|
|
5db3db |
int slbt_exec_link_create_import_library(
|
|
|
5db3db |
const struct slbt_driver_ctx * dctx,
|
|
|
5db3db |
struct slbt_exec_ctx * ectx,
|
|
|
5db3db |
char * impfilename,
|
|
|
5db3db |
char * deffilename,
|
|
|
5db3db |
char * soname)
|
|
|
5db3db |
{
|
|
|
5db3db |
int fmdso;
|
|
|
20bc88 |
char * eargv[14];
|
|
|
5db3db |
char program[PATH_MAX];
|
|
|
a6c393 |
char as[PATH_MAX];
|
|
|
5db3db |
|
|
|
5db3db |
/* dlltool or mdso? */
|
|
|
5db3db |
if (dctx->cctx->drvflags & SLBT_DRIVER_IMPLIB_DSOMETA)
|
|
|
5db3db |
fmdso = 1;
|
|
|
5db3db |
|
|
|
6d7ad6 |
else if (dctx->cctx->drvflags & SLBT_DRIVER_IMPLIB_IDATA)
|
|
|
5db3db |
fmdso = 0;
|
|
|
5db3db |
|
|
|
5db3db |
else if (!(strcmp(dctx->cctx->host.flavor,"midipix")))
|
|
|
5db3db |
fmdso = 1;
|
|
|
5db3db |
|
|
|
5db3db |
else
|
|
|
5db3db |
fmdso = 0;
|
|
|
5db3db |
|
|
|
5db3db |
/* eargv */
|
|
|
5db3db |
if (fmdso) {
|
|
|
5db3db |
if (slbt_snprintf(program,sizeof(program),
|
|
|
5db3db |
"%s",dctx->cctx->host.mdso) < 0)
|
|
|
5db3db |
return SLBT_BUFFER_ERROR(dctx);
|
|
|
5db3db |
|
|
|
5db3db |
eargv[0] = program;
|
|
|
5db3db |
eargv[1] = "-i";
|
|
|
5db3db |
eargv[2] = impfilename;
|
|
|
5db3db |
eargv[3] = "-n";
|
|
|
5db3db |
eargv[4] = soname;
|
|
|
5db3db |
eargv[5] = deffilename;
|
|
|
5db3db |
eargv[6] = 0;
|
|
|
5db3db |
} else {
|
|
|
5db3db |
if (slbt_snprintf(program,sizeof(program),
|
|
|
5db3db |
"%s",dctx->cctx->host.dlltool) < 0)
|
|
|
5db3db |
return SLBT_BUFFER_ERROR(dctx);
|
|
|
5db3db |
|
|
|
5db3db |
eargv[0] = program;
|
|
|
5db3db |
eargv[1] = "-l";
|
|
|
5db3db |
eargv[2] = impfilename;
|
|
|
5db3db |
eargv[3] = "-d";
|
|
|
5db3db |
eargv[4] = deffilename;
|
|
|
5db3db |
eargv[5] = "-D";
|
|
|
5db3db |
eargv[6] = soname;
|
|
|
5db3db |
eargv[7] = 0;
|
|
|
a6c393 |
|
|
|
a6c393 |
if (dctx->cctx->host.as) {
|
|
|
a6c393 |
if (slbt_snprintf(as,sizeof(as),
|
|
|
a6c393 |
"%s",dctx->cctx->host.as) < 0)
|
|
|
a6c393 |
return SLBT_BUFFER_ERROR(dctx);
|
|
|
a6c393 |
|
|
|
a6c393 |
eargv[7] = "-S";
|
|
|
a6c393 |
eargv[8] = as;
|
|
|
a6c393 |
|
|
|
a6c393 |
const char * host = dctx->cctx->host.host;
|
|
|
a6c393 |
|
|
|
a6c393 |
if (host && (host[0] == 'i')
|
|
|
a6c393 |
&& (host[1] >= '3')
|
|
|
a6c393 |
&& (host[1] <= '6')
|
|
|
a6c393 |
&& (host[2] == '8')
|
|
|
a6c393 |
&& (host[3] == '6')
|
|
|
a6c393 |
&& (host[4] == '-')) {
|
|
|
a6c393 |
eargv[9] = "-f";
|
|
|
a6c393 |
eargv[10] = "--32";
|
|
|
20bc88 |
eargv[11] = "-m";
|
|
|
20bc88 |
eargv[12] = "i386";
|
|
|
20bc88 |
eargv[13] = 0;
|
|
|
a6c393 |
} else {
|
|
|
a6c393 |
eargv[9] = "-f";
|
|
|
a6c393 |
eargv[10] = "--64";
|
|
|
20bc88 |
eargv[11] = "-m";
|
|
|
20bc88 |
eargv[12] = "i386:x86-64";
|
|
|
20bc88 |
eargv[13] = 0;
|
|
|
a6c393 |
}
|
|
|
a6c393 |
}
|
|
|
5db3db |
}
|
|
|
5db3db |
|
|
|
5db3db |
/* alternate argument vector */
|
|
|
5db3db |
ectx->argv = eargv;
|
|
|
5db3db |
ectx->program = program;
|
|
|
5db3db |
|
|
|
5db3db |
/* step output */
|
|
|
5db3db |
if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
|
|
|
5db3db |
if (slbt_output_link(dctx,ectx))
|
|
|
5db3db |
return SLBT_NESTED_ERROR(dctx);
|
|
|
5db3db |
|
|
|
5db3db |
/* dlltool/mdso spawn */
|
|
|
5db3db |
if ((slbt_spawn(ectx,true) < 0) && (ectx->pid < 0)) {
|
|
|
5db3db |
return SLBT_SPAWN_ERROR(dctx);
|
|
|
5db3db |
|
|
|
5db3db |
} else if (ectx->exitcode) {
|
|
|
5db3db |
return SLBT_CUSTOM_ERROR(
|
|
|
5db3db |
dctx,
|
|
|
5db3db |
fmdso ? SLBT_ERR_MDSO_ERROR : SLBT_ERR_DLLTOOL_ERROR);
|
|
|
5db3db |
}
|
|
|
5db3db |
|
|
|
5db3db |
return 0;
|
|
|
5db3db |
}
|