firasuke / cross / slibtool

Forked from cross/slibtool 6 months ago
Clone

8b7d50 link mode: slbt_get_deps_meta(): initial implementation.

Authored and Committed by midipix 8 years ago
    link mode: slbt_get_deps_meta(): initial implementation.
    
        
file modified
+56 -4
src/logic/slbt_exec_link.c CHANGED
@@ -4,6 +4,7 @@
4
4
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
5
5
/*******************************************************************/
6
6
7
+ #include <stdlib.h>
7
8
#include <stdio.h>
8
9
#include <string.h>
9
10
#include <stdbool.h>
@@ -15,6 +16,13 @@
15
16
#include "slibtool_spawn_impl.h"
16
17
#include "slibtool_symlink_impl.h"
17
18
19
+ struct slbt_deps_meta {
20
+ char ** altv;
21
+ char * args;
22
+ int depscnt;
23
+ int infolen;
24
+ };
25
+
18
26
/*******************************************************************/
19
27
/* */
20
28
/* -o <ltlib> switches input result */
@@ -56,6 +64,45 @@
56
64
/* */
57
65
/*******************************************************************/
58
66
67
+ static int slbt_get_deps_meta(
68
+ char * libfilename,
69
+ struct slbt_deps_meta * depsmeta)
70
+ {
71
+ int ret;
72
+ FILE * fdeps;
73
+ struct stat st;
74
+ char depfile[4*PATH_MAX];
75
+ char * deplibs = depfile;
76
+
77
+ if ((size_t)snprintf(depfile,sizeof(depfile),"%s.slibtool.deps",
78
+ libfilename)
79
+ >= sizeof(depfile))
80
+ return -1;
81
+
82
+ if ((stat(depfile,&st)))
83
+ return -1;
84
+
85
+ if (!(fdeps = fopen(depfile,"r")))
86
+ return -1;
87
+
88
+ if ((size_t)st.st_size >= sizeof(depfile))
89
+ if (!(deplibs = malloc(st.st_size+1))) {
90
+ fclose(fdeps);
91
+ return -1;
92
+ }
93
+
94
+ depsmeta->infolen += st.st_size;
95
+ depsmeta->infolen++;
96
+
97
+ while (fscanf(fdeps,"%s\n",deplibs) == 1)
98
+ depsmeta->depscnt++;
99
+
100
+ ret = ferror(fdeps) ? -1 : 0;
101
+ fclose(fdeps);
102
+
103
+ return ret;
104
+ }
105
+
59
106
static bool slbt_adjust_input_argument(
60
107
char * arg,
61
108
const char * osuffix,
@@ -97,7 +144,8 @@ static int slbt_adjust_linker_argument(
97
144
char * arg,
98
145
bool fpic,
99
146
const char * dsosuffix,
100
- const char * arsuffix)
147
+ const char * arsuffix,
148
+ struct slbt_deps_meta * depsmeta)
101
149
{
102
150
int fdlib;
103
151
char * slash;
@@ -136,7 +184,7 @@ static int slbt_adjust_linker_argument(
136
184
else
137
185
sprintf(dot,"%s",arsuffix);
138
186
139
- return 0;
187
+ return slbt_get_deps_meta(arg,depsmeta);
140
188
}
141
189
142
190
/* input archive */
@@ -393,6 +441,7 @@ static int slbt_exec_link_create_library(
393
441
char cwd [PATH_MAX];
394
442
char output [PATH_MAX];
395
443
char soname [PATH_MAX];
444
+ struct slbt_deps_meta depsmeta = {0};
396
445
397
446
/* initial state */
398
447
slbt_reset_arguments(ectx);
@@ -409,7 +458,8 @@ static int slbt_exec_link_create_library(
409
458
if (slbt_adjust_linker_argument(
410
459
*parg,true,
411
460
dctx->cctx->settings.dsosuffix,
412
- dctx->cctx->settings.arsuffix) < 0)
461
+ dctx->cctx->settings.arsuffix,
462
+ &depsmeta) < 0)
413
463
return -1;
414
464
415
465
/* --no-undefined */
@@ -490,6 +540,7 @@ static int slbt_exec_link_create_executable(
490
540
char wrapper[PATH_MAX];
491
541
char wraplnk[PATH_MAX];
492
542
bool fabspath;
543
+ struct slbt_deps_meta depsmeta = {0};
493
544
494
545
/* initial state */
495
546
slbt_reset_arguments(ectx);
@@ -506,7 +557,8 @@ static int slbt_exec_link_create_executable(
506
557
if (slbt_adjust_linker_argument(
507
558
*parg,true,
508
559
dctx->cctx->settings.dsosuffix,
509
- dctx->cctx->settings.arsuffix) < 0)
560
+ dctx->cctx->settings.arsuffix,
561
+ &depsmeta) < 0)
510
562
return -1;
511
563
512
564
/* --no-undefined */