mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: bernhard@bwalle.de
To: ptxdist@pengutronix.de
Cc: Bernhard Walle <bernhard@bwalle.de>
Subject: [ptxdist] [PATCH] ptxdist: Check for GNU readlink
Date: Tue, 13 Mar 2012 12:30:23 +0100	[thread overview]
Message-ID: <1331638223-8889-1-git-send-email-bernhard@bwalle.de> (raw)
In-Reply-To: <20120313101643.GL29221@pengutronix.de>

From: Bernhard Walle <bernhard@bwalle.de>

ptxdist heavily uses "readlink -f" which only works with GNU readlink.
So add the usual check here.

However, because "readlink -f" is also used before the symlinks in the
ptxdist directory is added to the PATH, that "readlink -f" call is
replaced by a bash-only implementation. This one is inspired from
http://mailman.archlinux.org/pipermail/pacman-dev/2009-February/008130.html.

Tested on Mac OS 10.7.

Signed-off-by: Bernhard Walle <bernhard@bwalle.de>
---
===== Sorry, forget the first version. I forgot to commit.

 Makefile.in  |    1 +
 bin/ptxdist  |   22 +++++++++++++++++++++-
 configure.ac |    1 +
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index e62a2d9..17a6ce6 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -54,6 +54,7 @@ environment:
 	@ln -sf @GNU_stat@ "$(abs_srcdir)/bin/stat"
 	@ln -sf @GNU_mknod@ "$(abs_srcdir)/bin/mknod"
 	@ln -sf @GNU_tar@ "$(abs_srcdir)/bin/tar"
+	@ln -sf @GNU_readlink@ "$(abs_srcdir)/bin/readlink"
 	@ln -sf @PYTHON@ "$(abs_srcdir)/bin/python"
 	@ln -sf @SED@ "$(abs_srcdir)/bin/sed"
 	@ln -sf @XARGS@ "$(abs_srcdir)/bin/xargs"
diff --git a/bin/ptxdist b/bin/ptxdist
index eb3366a..3cb8eed 100755
--- a/bin/ptxdist
+++ b/bin/ptxdist
@@ -1843,6 +1843,26 @@ EOF
 ################ setup stuff only ################################
 ##################################################################
 
+#
+# bash implementation of realpath / readlink -f
+#   arg1 - filename
+realpath()
+{
+	local fname oldfname
+
+	fname=${1%/} # strips trailing '/'
+	while [ -L "${fname}" ]; do
+		oldfname="${fname}"
+		fname="$(readlink ${fname})"
+		if [ "$fname" = . ] ; then
+			fname="$(dirname $oldfname)"
+		elif [ "${fname}" = "${fname#/}" ]; then
+			fname="$(dirname "${oldfname}")/${fname}"
+		fi
+	done
+
+	(cd "$(dirname "${fname}")"; echo $(pwd -P)/$(basename "${fname}"))
+}
 
 #
 # figure out PTXDIST_TOPDIR
@@ -1859,7 +1879,7 @@ EOF
 setup_topdir() {
 	local ptxdist topdir
 
-	ptxdist="$(readlink -f "${0}")" &&
+	ptxdist="$(realpath "${0}")" &&
 	topdir="$(cd "$(dirname "${ptxdist}")"/.. && pwd)" || return
 
 	#
diff --git a/configure.ac b/configure.ac
index 37a01ae..780bf28 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,6 +155,7 @@ GNU_TOOL(mkdir, coreutils)
 GNU_TOOL(install, coreutils)
 GNU_TOOL(stat, coreutils)
 GNU_TOOL(mknod, coreutils)
+GNU_TOOL(readlink, coreutils)
 GNU_TOOL(tar, tar)
 
 dnl Check for egrep
-- 
1.7.9.4


-- 
ptxdist mailing list
ptxdist@pengutronix.de

  parent reply	other threads:[~2012-03-13 11:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-12 19:56 [ptxdist] [PATCH 1/2] Makefile.in: Create symlink for xargs Bernhard Walle
2012-03-12 19:56 ` [ptxdist] [PATCH 2/2] ptxdist: Check for GNU readlink Bernhard Walle
2012-03-13 10:16   ` Michael Olbrich
2012-03-13 11:23     ` [ptxdist] [PATCH] " bernhard
2012-03-13 11:30     ` bernhard [this message]
2012-03-13 13:17       ` Michael Olbrich
2012-03-13  9:42 ` [ptxdist] [PATCH 1/2] Makefile.in: Create symlink for xargs Michael Olbrich
  -- strict thread matches above, loose matches on Subject: below --
2012-02-14 20:55 [ptxdist] [PATCH] ptxdist: Check for GNU readlink Bernhard Walle
2012-02-14 22:05 ` Michael Olbrich
2012-03-12 19:56   ` Bernhard Walle
2012-03-13 10:14     ` Michael Olbrich
2012-03-13 11:32       ` Bernhard Walle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331638223-8889-1-git-send-email-bernhard@bwalle.de \
    --to=bernhard@bwalle.de \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox