On Sun, 16 May 2010, Guillem Jover wrote:
> On Mon, 2010-05-10 at 10:59:25 +0200, Cristian Ionescu-Idbohrn wrote:
> > And when you're at it, I dare to have one more wish :)
> >
> > I'm cross-building libbsd for an embedded system, and I need the
> > symlink to _not_ point to the host installed lib, but to the
> > cross-built one (inside the installed directory tree). I hacked the
> > Makefile to do it:
> >
> > - ln -sf $(libdir)/$(LIB_SHARED)
> > $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
> > + ln -sf ../..$(libdir)/$(LIB_SHARED)
> > $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
> >
> > but I'm convinced there's a better (although more intricate) way to do
> > it.
>
> The problem with this patch is that it assumes the relationship
> between libdir and usrlibdir is fixed and there's always going to be
> two directories below.
Yes. As I wrote, it's a hack.
> The question though, is why do you need this at all?
Yes.
> I assume you are placing the files on a different path from the intended
> on the target?
Yes.
> This is problematic, and you'll probably find that all other packages
> which have the shared library in /lib but the .so symlink in /usr/lib
> (as it should be) fail in your case.
My problem is this snippet in the upstream Makefile:
ifeq ($(libdir),$(usrlibdir))
# If both dirs are the same, do a relative symlink.
ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
else
# Otherwise, do an absolute one.
ln -sf $(libdir)/$(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
endif
Specifically, the absolute link.
What I have in mind is attached.
That will create (in debian/tmp/usr/lib) a relative symlink that looks
like this:
libbsd.so -> ../../lib/libbsd.so.0.2.0
not assuming a relationship between libdir and usrlibdir, using a new
script: lib-link-path.sh.
What do you think?
Cheers,
--
Cristian
diff -ubBwpNr libbsd-0.2.0/Makefile libbsd-0.2.0.cii0/Makefile
--- libbsd-0.2.0/Makefile 2010-01-10 15:29:51.000000000 +0100
+++ libbsd-0.2.0.cii0/Makefile 2010-05-16 14:06:18.000000000 +0200
@@ -184,11 +184,11 @@ install: libs man
install -m644 $(LIB_MANS) $(DESTDIR)$(mandir)/man3
install -m644 $(LIB_PKGCONFIG) $(DESTDIR)$(pkgconfigdir)
ifeq ($(libdir),$(usrlibdir))
- # If both dirs are the same, do a relative symlink.
+ # If both dirs are the same, do a symlink.
ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
else
- # Otherwise, do an absolute one.
- ln -sf $(libdir)/$(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
+ # Otherwise, do a relative one.
+ ln -sf $(shell ./lib-link-path.sh "$(usrlibdir)" "$(libdir)" "$(LIB_SHARED)") $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
endif
ln -sf $(LIB_SHARED) $(DESTDIR)$(libdir)/$(LIB_SONAME)
diff -ubBwpNr libbsd-0.2.0/debian/changelog libbsd-0.2.0.cii0/debian/changelog
--- libbsd-0.2.0/debian/changelog 2010-01-11 15:49:01.000000000 +0100
+++ libbsd-0.2.0.cii0/debian/changelog 2010-05-16 14:35:26.000000000 +0200
@@ -1,3 +1,9 @@
+libbsd (0.2.0-1cii0) unstable; urgency=low
+
+ * Made /usr/lib symlink relative.
+
+ -- Cristian Ionescu-Idbohrn <c...@axis.com> Sun, 16 May 2010 14:33:35 +0200
+
libbsd (0.2.0-1) unstable; urgency=low
* New upstream release.
diff -ubBwpNr libbsd-0.2.0/lib-link-path.sh libbsd-0.2.0.cii0/lib-link-path.sh
--- libbsd-0.2.0/lib-link-path.sh 1970-01-01 01:00:00.000000000 +0100
+++ libbsd-0.2.0.cii0/lib-link-path.sh 2010-05-16 14:51:14.000000000 +0200
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+# $1 - usrlibdir
+# $3 - libdir
+# $4 - libname
+
+set -e
+set -u
+#set -x
+
+TAG="${0##*/}"
+
+whine() {
+ echo "$TAG: $*" >&2
+}
+
+croak() {
+ whine "$*"
+ exit 1
+}
+
+ck_for_absolute_path() {
+ local f=ck_for_absolute_path
+
+ [ $# -eq 1 ] && [ ${#1} -gt 1 ] ||
+ croak "$f: missing, empty or invalid argument"
+
+ case $1 in
+ [!/]*)
+ croak "$f: '$1' not an absolute path"
+ ;;
+ esac
+}
+
+[ $# -eq 3 ] && [ ${#1} -gt 1 ] && [ ${#2} -gt 1 ] && [ ${#3} -gt 1 ] ||
+ croak "missing, empty or invalid argument(s)"
+
+usrlibdir=${1%/}
+libdir=${2%/}
+libname=$3
+
+[ ${#usrlibdir} -gt 0 ] && [ ${#libdir} -gt 0 ] && [ ${#libname} -gt 0 ] ||
+ croak "empty path(s) values"
+
+[ "$libdir" != "$usrlibdir" ] ||
+ croak "libdir and usrlibdir paths identical; you loose"
+
+ck_for_absolute_path "$usrlibdir"
+ck_for_absolute_path "$libdir"
+
+case $libname in
+ */*)
+ croak "invalid '/' in libname '$libname'"
+ ;;
+esac
+
+reldir=
+updiradded=n
+str=${usrlibdir#/}
+rest=${str#?}
+char=${str%$rest}
+while [ ${#char} -gt 0 ]; do
+ str=$rest
+ if [ $char = / ]; then
+ reldir="$reldir$char"
+ updiradded=n
+ else
+ [ $updiradded = y ] || {
+ reldir="$reldir.."
+ updiradded=y
+ }
+ fi
+ rest=${str#?}
+ char=${str%$rest}
+done
+
+echo "$reldir$libdir/$libname"