14 static char *ldscriptname
, *tempoutput
, *ld_name
, *strip_name
;
15 static FILE *ldscriptfile
;
17 static void exitfunc(void)
19 if (ldscriptfile
!= NULL
)
22 if (ldscriptname
!= NULL
)
25 if (tempoutput
!= NULL
)
29 int main(int argc
, char *argv
[])
32 char *output
, **ldargs
;
33 /* incremental = 1 -> don't do final linking.
34 incremental = 2 -> don't do final linking AND STILL produce symbol sets. */
35 int incremental
= 0, ignore_undefined_symbols
= 0;
37 char *do_verbose
= NULL
;
39 setnode
*setlist
= NULL
;
41 program_name
= argv
[0];
43 strip_name
= STRIP_NAME
;
45 /* Do some stuff with the arguments */
47 for (cnt
= 1; argv
[cnt
]; cnt
++)
49 /* We've encountered an option */
50 if (argv
[cnt
][0]=='-')
52 /* Get the output file name */
53 if (argv
[cnt
][1]=='o')
54 output
= argv
[cnt
][2]?&argv
[cnt
][2]:argv
[++cnt
];
56 /* Incremental linking is requested */
57 if ((argv
[cnt
][1]=='r' || argv
[cnt
][1]=='i') && argv
[cnt
][2]=='\0')
60 /* Incremental, but produce the symbol sets */
61 if (strncmp(&argv
[cnt
][1], "Ur", 3) == 0)
65 argv
[cnt
][1] = 'r'; /* Just some non-harming option... */
69 /* Ignoring of missing symbols is requested */
70 if (strncmp(&argv
[cnt
][1], "ius", 4) == 0)
72 ignore_undefined_symbols
= 1;
73 argv
[cnt
][1] = 'r'; /* Just some non-harming option... */
77 /* Complete stripping is requested, but we do it our own way */
78 if (argv
[cnt
][1]=='s' && argv
[cnt
][2]=='\0')
81 argv
[cnt
][1] = 'r'; /* Just some non-harming option... */
84 /* The user just requested help info, don't do anything else */
85 if (strncmp(&argv
[cnt
][1], "-help", 6) == 0)
87 /* I know, it's not incremental linking we're after, but the end result
94 if (strncmp(&argv
[cnt
][1], "-verbose", 9) == 0)
96 do_verbose
= argv
[cnt
];
102 ldargs
= xmalloc(sizeof(char *) * (argc
+2 + 2*(incremental
!= 1)));
107 for (cnt
= 1; cnt
< argc
; cnt
++)
108 ldargs
[cnt
+1] = argv
[cnt
];
110 if (incremental
!= 1)
115 !(tempoutput
= make_temp_file(NULL
)) ||
116 !(ldscriptname
= make_temp_file(NULL
)) ||
117 !(ldscriptfile
= fopen(ldscriptname
, "w"))
120 fatal(ldscriptname
? ldscriptname
: "make_temp_file()", strerror(errno
));
123 ldargs
[cnt
+ 1] = "-o";
124 ldargs
[cnt
+ 2] = tempoutput
;
128 ldargs
[cnt
+1] = NULL
;
130 docommandvp(ld_name
, ldargs
);
132 if (incremental
== 1)
135 collect_sets(tempoutput
, &setlist
);
138 fprintf(ldscriptfile
, "EXTERN(__this_program_requires_symbol_sets_handling)\n");
140 fwrite(LDSCRIPT_PART1
, sizeof(LDSCRIPT_PART1
) - 1, 1, ldscriptfile
);
141 emit_sets(setlist
, ldscriptfile
);
142 fwrite(LDSCRIPT_PART2
, sizeof(LDSCRIPT_PART2
) - 1, 1, ldscriptfile
);
143 if (incremental
== 0)
144 fputs("PROVIDE(SysBase = 0x515BA5E);\n", ldscriptfile
);
145 fwrite(LDSCRIPT_PART3
, sizeof(LDSCRIPT_PART3
) - 1, 1, ldscriptfile
);
147 fclose(ldscriptfile
);
150 docommandlp(ld_name
, ld_name
, "-r", "-o", output
, tempoutput
, "-T", ldscriptname
, do_verbose
, NULL
);
152 if (incremental
!= 0)
155 if (!ignore_undefined_symbols
&& check_and_print_undefined_symbols(output
))
165 docommandlp(strip_name
, strip_name
, "--strip-unneeded", output
, NULL
);