ref: 25be8b19d826b8faf73275e0294f661f1a4c32fe
parent: 6880f73fd5b9578a804856ee907bf246bba2687d
author: Ori Bernstein <[email protected]>
date: Sat Feb 9 09:59:10 EST 2013
Teach myrbuild about linker scripts. Useful for building a kernel.
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -35,6 +35,8 @@
/* libraries to link against. */
char **libs;
size_t nlibs;
+/* the linker script to use */
+char *ldscript;
regex_t usepat;
@@ -44,6 +46,7 @@
printf("\t-h\tprint this help\n");
printf("\t-b bin\tBuild a binary called 'bin'\n");
printf("\t-l lib\tBuild a library called 'name'\n");
+ printf("\t-s script\tUse the linker script 'script' when linking\n");
printf("\t-I path\tAdd 'path' to use search path\n");
}
@@ -288,12 +291,18 @@
args = NULL;
nargs = 0;
- /* ld -o outfile */
+ /* ld -T ldscript -o outfile */
lappend(&args, &nargs, strdup(ld));
lappend(&args, &nargs, strdup("-o"));
lappend(&args, &nargs, strdup(binname));
- /* ld -o outfile foo.o bar.o baz.o */
+ /* ld -T ldscript */
+ if (ldscript) {
+ snprintf(buf, sizeof buf, "-T%s", ldscript);
+ lappend(&args, &nargs, strdup(buf));
+ }
+
+ /* ld -T ldscript -o outfile foo.o bar.o baz.o */
for (i = 0; i < nfiles; i++) {
if (hassuffix(files[i], ".myr"))
swapsuffix(buf, sizeof buf, files[i], ".myr", ".o");
@@ -304,7 +313,7 @@
lappend(&args, &nargs, strdup(buf));
}
- /* ld -o outfile foo.o bar.o baz.o -L/path1 -L/path2 */
+ /* ld -T ldscript -o outfile foo.o bar.o baz.o -L/path1 -L/path2 */
for (i = 0; i < nincpaths; i++) {
snprintf(buf, sizeof buf, "-L%s", incpaths[i]);
lappend(&args, &nargs, strdup(buf));
@@ -312,7 +321,7 @@
snprintf(buf, sizeof buf, "-L%s%s", Instroot, "/lib/myr");
lappend(&args, &nargs, strdup(buf));
- /* ld -o outfile foo.o bar.o baz.o -L/path1 -L/path2 -llib1 -llib2*/
+ /* ld -T ldscript -o outfile foo.o bar.o baz.o -L/path1 -L/path2 -llib1 -llib2*/
for (i = 0; i < nlibs; i++) {
snprintf(buf, sizeof buf, "-l%s", libs[i]);
lappend(&args, &nargs, strdup(buf));
@@ -331,10 +340,11 @@
int opt;
int i;
- while ((opt = getopt(argc, argv, "hb:l:I:C:A:M:L:R:")) != -1) {
+ while ((opt = getopt(argc, argv, "hb:l:s:I:C:A:M:L:R:")) != -1) {
switch (opt) {
case 'b': binname = optarg; break;
case 'l': libname = optarg; break;
+ case 's': ldscript = optarg; break;
case 'C': mc = optarg; break;
case 'A': as = optarg; break;
case 'M': muse = optarg; break;