[PATCH 5/8] Add buildinstall.functions (DSO dependency finding)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 scripts/buildinstall.functions |  120 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/scripts/buildinstall.functions b/scripts/buildinstall.functions
new file mode 100755
index 0000000..fcc4e46
--- /dev/null
+++ b/scripts/buildinstall.functions
@@ -0,0 +1,120 @@
+#!/bin/bash
+
+# pulled right out of mkinitrd....
+DSO_DEPS=""
+LDSO=""
+get_dso_deps() {
+    root="$1" ; shift
+    bin="$1" ; shift
+    DSO_DEPS=""
+
+    declare -a FILES
+    declare -a NAMES
+
+    # this is a hack, but the only better way requires binutils or elfutils
+    # be installed.  i.e., we need readelf to find the interpretter.
+    if [ -z "$LDSO" ]; then
+        for ldso in $root/lib*/ld*.so* ; do
+            [ -L $ldso ] && continue
+            [ -x $ldso ] || continue
+            $ldso --verify $bin >/dev/null 2>&1 || continue
+            LDSO=$(echo $ldso |sed -e "s,$root,,")
+        done
+    fi
+
+    # I still hate shell.
+    declare -i n=0
+    while read NAME I0 FILE ADDR I1 ; do
+        [ "$FILE" == "not" ] && FILE="$FILE $ADDR"
+        NAMES[$n]="$NAME"
+        FILES[$n]="$FILE"
+        let n++
+    done << EOF
+        $(chroot $root env LD_TRACE_PRELINKING=1 LD_WARN= \
+                           LD_TRACE_LOADED_OBJECTS=1 $LDSO $bin)
+EOF
+
+    [ ${#FILES[*]} -eq 0 ] && return 1
+
+    # we don't want the name of the binary in the list
+    if [ "${FILES[0]}" == "$bin" ]; then
+        FILES[0]=""
+        NAMES[0]=""
+        [ ${#FILES[*]} -eq 1 ] && return 1
+    fi
+
+    declare -i n=0
+    while [ $n -lt ${#FILES[*]} ]; do
+        FILE="${FILES[$n]}"
+        if [ "$FILE" == "not found" ]; then
+            cat 1>&2 <<EOF
+There are missing files on your system.  The dynamic object $bin
+requires ${NAMES[$n]} n order to properly function.  mkinitrd cannot continue.
+EOF
+            exit 1
+        fi
+       case "$FILE" in
+         /lib*)
+           TLIBDIR=`echo "$FILE" | sed 's,\(/lib[^/]*\)/.*$,\1,'`
+           BASE=`basename "$FILE"`
+           # Prefer nosegneg libs over direct segment accesses on i686.
+           if [ -f "$TLIBDIR/i686/nosegneg/$BASE" ]; then
+             FILE="$TLIBDIR/i686/nosegneg/$BASE"
+           # Otherwise, prefer base libraries rather than their optimized
+           # variants.
+           elif [ -f "$TLIBDIR/$BASE" ]; then
+             FILE="$TLIBDIR/$BASE"
+           fi
+           ;;
+       esac
+        dynamic="yes"
+        let n++
+    done
+
+    DSO_DEPS="${FILES[@]}"
+
+    for l in $(chroot $root find /lib* -maxdepth 1 -type l -name ld*.so*); do
+       [ "$(chroot $root readlink -f $l)" == "$LDSO" ] && DSO_DEPS="$DSO_DEPS $l"
+    done
+
+    [ -n "$DEBUG" ] && echo "DSO_DEPS for $bin are $DSO_DEPS"
+}
+
+instFile() {
+    FILE=$1
+    DESTROOT=$2
+
+    [ -n "$DEBUG" ] && echo "Installing $FILE"
+    if [ -e $DESTROOT/$FILE -o -L $DESTROOT/$FILE ]; then
+      return
+    elif [ ! -d $DESTROOT/`dirname $FILE` ]; then
+      mkdir -p $DESTROOT/`dirname $FILE`
+    fi
+    if [ -L $FILE ]; then
+	cp -al $FILE $DESTROOT/`dirname $FILE`
+	instFile ./`dirname $FILE`/`readlink $FILE` $DESTROOT
+	return
+    else
+	cp -aL $FILE $DESTROOT/`dirname $FILE`
+    fi
+
+    file $FILE | grep -q ": ELF" &&  {
+        get_dso_deps $(pwd) "$FILE"
+        local DEPS="$DSO_DEPS"
+        for x in $DEPS ; do
+            instFile ./$x $DESTROOT
+        done
+    }
+}
+
+instDir() {
+    DIR=$1
+    DESTROOT=$2
+
+    [ -n "$DEBUG" ] && echo "Installing $DIR"
+    if [ -d $DESTROOT/$DIR -o -h $DESTROOT/$DIR ]; then
+      return
+    fi
+    cp -a --parents $DIR $DESTROOT/
+}
+
-- 
1.5.3.7

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux