1 #!/bin/sh 2 3 # List the modules required by a particular L4Re program configuration. 4 # 5 # Copyright (C) 2018, 2019, 2022, 2023 Paul Boddie <paul@boddie.org.uk> 6 # 7 # This program is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License as 9 # published by the Free Software Foundation; either version 2 of 10 # the License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 # Boston, MA 02110-1301, USA 21 22 MODULES="$1" 23 24 if [ ! "$MODULES" ] || [ ! -e "$MODULES" ] ; then 25 cat 1>&2 <<EOF 26 Usage: $0 <module list filename> [ --ignore-missing ] [ <arch> ] [ <build directory> ] 27 28 List modules required by the given system/payload configuration. These modules 29 should be added to the configuration file so that the dynamic linker can find 30 them in the running system. 31 32 The optional build directory indicates where executable programs may be found, 33 having been built. An initial build must have been performed before running this 34 program. 35 EOF 36 exit 1 37 fi 38 39 # Skip the module list file. 40 41 shift 1 42 43 # Get flag. 44 45 if [ "$1" ] && [ "$1" = '--ignore-missing' ] ; then 46 IGNORE_MISSING="$1" 47 shift 1 48 else 49 IGNORE_MISSING= 50 fi 51 52 # Get other options. 53 54 ARCHDIR= 55 BUILDDIR= 56 57 # Look for an architecture or build directory. 58 59 if [ "$1" ] && [ ! -e "$1" ] ; then 60 ARCH="$1" 61 shift 1 62 else 63 ARCH= 64 fi 65 66 # Look for any additional build directory. 67 68 if [ "$1" ] && [ -e "$1" ] ; then 69 BUILDDIR="$1" 70 fi 71 72 # Use a default build directory if none specified or found. 73 74 if [ ! "$BUILDDIR" ] ; then 75 BUILDDIR=mybuild 76 fi 77 78 if [ ! -e "$BUILDDIR" ] ; then 79 cat 1>&2 <<EOF 80 Not found (build directory): $BUILDDIR 81 EOF 82 exit 1 83 fi 84 85 # Test for architecture-specific program directories. 86 87 for FILENAME in "$BUILDDIR/bin/"* ; do 88 if [ "$FILENAME" = "$BUILDDIR/bin/*" ] ; then 89 cat 1>&2 <<EOF 90 No architecture-specific directories in the build directory hierarchy: 91 92 $BUILDDIR/bin 93 EOF 94 exit 1 95 fi 96 97 BASENAME=$(basename "$FILENAME") 98 99 if [ "$BASENAME" = 'host' ] ; then 100 : 101 elif [ ! "$ARCH" ] || [ "$ARCH" = "$BASENAME" ] ; then 102 ARCHDIR="$BASENAME" 103 break 104 fi 105 done 106 107 # Exit if no architecture resources available. 108 109 if [ ! "$ARCHDIR" ] ; then 110 cat 1>&2 <<EOF 111 Architecture not in use or no appropriate program directory found. 112 Possible architectures are as follows: 113 114 EOF 115 for FILENAME in "$BUILDDIR/bin/"* ; do 116 ARCH=$(basename "$FILENAME") 117 if [ "$ARCH" != 'host' ] ; then 118 echo "$ARCH" 119 fi 120 done 121 exit 1 122 fi 123 124 # Obtain module details. 125 126 BIN="$BUILDDIR/bin/$ARCHDIR/l4f" 127 TMPLIBS=_libs.txt 128 129 echo -n > "$TMPLIBS" 130 131 for MODULE in $(grep '^module ' "$MODULES" | sed 's/module //') ; do 132 PROG=$(basename "$MODULE" .cfg) 133 if [ "$PROG" != "$MODULE" ] ; then 134 continue 135 fi 136 PROG=$(basename "$MODULE" .io) 137 if [ "$PROG" != "$MODULE" ] ; then 138 continue 139 fi 140 PROG=$(basename "$MODULE" .so) 141 if [ "$PROG" != "$MODULE" ] ; then 142 continue 143 fi 144 PROG=$(basename "$MODULE" .txt) 145 if [ "$PROG" != "$MODULE" ] ; then 146 continue 147 fi 148 if [ ! -e "$BIN/$PROG" ] && [ ! "$IGNORE_MISSING" ] ; then 149 echo "Not found: $PROG" 1>&2 150 rm "$TMPLIBS" 151 exit 1 152 fi 153 154 # NOTE: Architecture needs fixing. 155 156 mipsel-linux-gnu-readelf -d "$BIN/$PROG" | grep NEEDED | sed 's/.*\[//;s/\]$//' >> "$TMPLIBS" 157 done 158 159 # Explicitly add undetected module. 160 161 echo "libl4sys-direct.so" >> "$TMPLIBS" 162 163 sort -u "$TMPLIBS" | sed 's/^/module /' 164 rm "$TMPLIBS" 165 166 # vim: tabstop=4 expandtab shiftwidth=4