changeset 179:606123758641

Added --sysroot support to lwlink and the ld wrapper script
author lost@l-w.ca
date Thu, 15 Sep 2011 17:08:16 -0600
parents 35f7ce3ef857
children 11b710d231bd
files extra/ld lwlink/lwlink.c lwlink/lwlink.h lwlink/main.c lwlink/readfiles.c
diffstat 5 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/extra/ld	Fri Sep 09 22:08:07 2011 -0600
+++ b/extra/ld	Thu Sep 15 17:08:16 2011 -0600
@@ -28,7 +28,13 @@
 output_file=a.out
 libpaths=
 libs=
+stdlibpaths="-L=/usr/local/lib -L=/usr/lib -L=/lib"
 verbose=
+
+if [ "$verbose" = 1 ]; then
+	echo "$0 $@"
+fi
+
 case $0 in
 	*m6809-coco-*)
 		options="--format=decb"
@@ -101,6 +107,14 @@
 		--format-lwex)
 			options="$options --format=lwex"
 			;;
+		
+		--sysroot=*)
+			options="$options $arg"
+			;;
+			
+		-nostdlib)
+			stdlibpaths=
+			;;
 
 		-*)
 			echo "ld (m6809): unknown option $arg"
@@ -115,7 +129,7 @@
 options="$options -o $output_file"
 
 if [ "$verbose" = "1" ]; then
-	echo "$path_to_lwlink $options $input_files $startup_files $libpaths $libs"
+	echo "$path_to_lwlink $options $input_files $startup_files $libpaths $stdlibpaths $libs"
 fi
 
 $path_to_lwlink $options $input_files $startup_files $libpaths $libs
--- a/lwlink/lwlink.c	Fri Sep 09 22:08:07 2011 -0600
+++ b/lwlink/lwlink.c	Thu Sep 15 17:08:16 2011 -0600
@@ -49,6 +49,8 @@
 int nscriptls = 0;
 char **scriptls = NULL;
 
+char *sysroot = "/";
+
 void add_input_file(char *fn)
 {
 	inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1));
--- a/lwlink/lwlink.h	Fri Sep 09 22:08:07 2011 -0600
+++ b/lwlink/lwlink.h	Thu Sep 15 17:08:16 2011 -0600
@@ -120,6 +120,8 @@
 
 extern char *map_file;
 
+extern char *sysroot;
+
 #define __lwlink_E__ extern
 #else
 #define __lwlink_E__
--- a/lwlink/main.c	Fri Sep 09 22:08:07 2011 -0600
+++ b/lwlink/main.c	Thu Sep 15 17:08:16 2011 -0600
@@ -100,6 +100,10 @@
 		add_section_base(arg);
 		break;
 	
+	case 0x101:
+		sysroot = arg;
+		break;
+	
 	case 'm':
 		map_file = arg;
 		break;
@@ -134,6 +138,8 @@
 				"Add DIR to the library search path" },
 	{ "section-base", 0x100,	"SECT=BASE",	0,
 				"Load section SECT at BASE" },
+	{ "sysroot", 0x101,	"DIR",	0,
+				"Specify the path to replace an initial = with in library paths" },
 	{ "map",		'm',	"FILE",		0,
 				"Output informaiton about the link" },
 	{ 0 }
--- a/lwlink/readfiles.c	Fri Sep 09 22:08:07 2011 -0600
+++ b/lwlink/readfiles.c	Thu Sep 15 17:08:16 2011 -0600
@@ -77,9 +77,19 @@
 			
 			for (j = 0; j < nlibdirs; j++)
 			{
-				s = strlen(libdirs[j]) + 7 + strlen(inputfiles[i] -> filename);
-				tf = lw_alloc(s + 1);
-				sprintf(tf, "%s/lib%s.a", libdirs[j], inputfiles[i] -> filename);
+				if (libdirs[j][0] == '=')
+				{
+					// handle sysroot
+					s = strlen(libdirs[j]) + 7 + strlen(sysroot) + strlen(inputfiles[i] -> filename);
+					tf = lw_alloc(s + 1);
+					sprintf(tf, "%s/%s/lib%s.a", sysroot, libdirs[j] + 1, inputfiles[i] -> filename);
+				}
+				else
+				{
+					s = strlen(libdirs[j]) + 7 + strlen(inputfiles[i] -> filename);
+					tf = lw_alloc(s + 1);
+					sprintf(tf, "%s/lib%s.a", libdirs[j], inputfiles[i] -> filename);
+				}
 				f = fopen(tf, "rb");
 				if (!f)
 				{