Position independence: $PREFIX-populate has absolute paths

Michael Abbott michael@araneidae.co.uk
Tue Aug 5 09:46:00 GMT 2008


On Mon, 4 Aug 2008, Yann E. MORIN wrote:
> Care to look at revision r793, please? I just checked in something that
> takes your comments into account...

I guess you mean r893.  

$ svn diff -c 893
Index: populate.in
===================================================================
--- populate.in (revision 892)
+++ populate.in (revision 893)
@@ -4,8 +4,10 @@
 # (C) 2007 Yann E. MORIN
 # Licensed under the GPL v2
 
-CT_READELF="@@CT_READELF@@"
-CT_SYSROOT_DIR="@@CT_SYSROOT_DIR@@"
+# Detect where the toolchain is:
+BIN_DIR="$(cd "$(dirname "$(readlink -fn "$0")")"; pwd)"
+CT_READELF="${BIN_DIR}/@@CT_TARGET@@-readelf"
+CT_SYSROOT_DIR="${BIN_DIR}/../@@CT_TARGET@@/sys-root"
 
 myname=$(basename "$0")
 

That looks good to me ... but I'm a little queasy about using readlink: 
I've got three reasons for this.

1. If we're accessing ${CT_PREFIX}-populate through a link direct to the 
script then there's a fair chance that whoever created the link isn't 
playing by the rules anyway -- in other words, it seems to be redundant.  

2. I have at least one machine (FreeBSD 4 -- yes, it really is that old) 
which has a funny idea about what `readline -fn $file` means.  It takes 
-f<format> as an argument!

3. I don't think readlink is part of the core Posix specification (to be 
honest I didn't even know that commands were part of Posix until the other 
day!)  I'm looking here at 
http://www.opengroup.org/onlinepubs/007908799/xcuix.html but don't know 
how definitive this is. 

So 3&2 don't carry much weight (after all, we'll be crippled if we stick 
to Posix only, and FreeBSD 4 is rather out of date as a build platform), 
but in combination with 1 I'd be inclined to leave the readlink out.

--
For unsubscribe information see http://sourceware.org/lists.html#faq



More information about the crossgcc mailing list