altomaltes / cross / slibtool

Forked from cross/slibtool 3 years ago
Clone

0f5ca7 link mode: added compatible -rpath support.

Authored and Committed by midipix 8 years ago
    link mode: added compatible -rpath support.
    
        
file modified
+42 -0
src/logic/slbt_exec_link.c CHANGED
@@ -88,6 +88,19 @@ static int slbt_get_deps_meta(
88
88
char depfile[4*PATH_MAX];
89
89
char * deplibs = depfile;
90
90
91
+ /* -rpath */
92
+ if ((size_t)snprintf(depfile,sizeof(depfile),"%s.slibtool.rpath",
93
+ libfilename)
94
+ >= sizeof(depfile))
95
+ return -1;
96
+
97
+ if (!(lstat(depfile,&st))) {
98
+ /* -Wl,%s */
99
+ depsmeta->infolen += st.st_size + 4;
100
+ depsmeta->infolen++;
101
+ }
102
+
103
+ /* .deps */
91
104
if ((size_t)snprintf(depfile,sizeof(depfile),"%s.slibtool.deps",
92
105
libfilename)
93
106
>= sizeof(depfile))
@@ -232,7 +245,10 @@ static int slbt_exec_link_adjust_argument_vector(
232
245
int argc;
233
246
char arg[PATH_MAX];
234
247
char lib[PATH_MAX];
248
+ char rpathdir[PATH_MAX];
249
+ char rpathlnk[PATH_MAX];
235
250
bool fwholearchive = false;
251
+ struct stat st;
236
252
237
253
for (argc=0,carg=ectx->cargv; *carg; carg++)
238
254
argc++;
@@ -285,6 +301,23 @@ static int slbt_exec_link_adjust_argument_vector(
285
301
/* ^^^hoppla^^^ */
286
302
*aarg++ = *carg++;
287
303
} else {
304
+ /* -rpath */
305
+ sprintf(rpathlnk,"%s.slibtool.rpath",*carg);
306
+
307
+ if (!(lstat(rpathlnk,&st))) {
308
+ if (slbt_readlink(
309
+ rpathlnk,\
310
+ rpathdir,
311
+ sizeof(rpathdir)))
312
+ return -1;
313
+
314
+ sprintf(darg,"-Wl,%s",rpathdir);
315
+ *aarg++ = "-Wl,-rpath";
316
+ *aarg++ = darg;
317
+ darg += strlen(darg);
318
+ darg++;
319
+ }
320
+
288
321
dpath = lib;
289
322
freqd = true;
290
323
sprintf(lib,"%s.slibtool.deps",*carg);
@@ -685,6 +718,15 @@ static int slbt_exec_link_create_library(
685
718
*ectx->lout[0] = "-o";
686
719
*ectx->lout[1] = output;
687
720
721
+ /* ldrpath */
722
+ if (dctx->cctx->host.ldrpath) {
723
+ if (slbt_exec_link_remove_file(dctx,ectx,ectx->rpathfilename))
724
+ return -1;
725
+
726
+ if (symlink(dctx->cctx->host.ldrpath,ectx->rpathfilename))
727
+ return -1;
728
+ }
729
+
688
730
/* cwd */
689
731
if (!getcwd(cwd,sizeof(cwd)))
690
732
return -1;