tools/populate.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Jul 25 14:08:03 2008 +0000 (2008-07-25)
changeset 722 37968404e9b9
parent 523 010f6f4e4dd6
child 755 c2212f59e1cf
permissions -rw-r--r--
When dumping the DokuWiki table of samples, don't leave the kernel headers version empty if using a custom headers set., and say so.

/trunk/scripts/showSamples.sh | 6 5 1 0 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
     1 #!/bin/bash
     2 
     3 # This script will populate the root directory with libs from the sysroot.
     4 # (C) 2007 Yann E. MORIN
     5 # Licensed under the GPL v2
     6 
     7 CT_READELF="@@CT_READELF@@"
     8 CT_SYSROOT_DIR="@@CT_SYSROOT_DIR@@"
     9 
    10 myname=$(basename "$0")
    11 
    12 doHelp() {
    13     cat <<_EOF_
    14 $myname [-f] [-v] -s source_root -d destination_root
    15 
    16     -s dir
    17         use 'dir' as the un-populated (source) root directory
    18 
    19     -d dir
    20         use 'dir' as the place to put the populated root directory
    21 
    22     -f  force execution: if destination directory already exists,
    23         it will be removed first.
    24 
    25     -v  Be verbose
    26 _EOF_
    27 }
    28 
    29 CT_ROOT_SRC_DIR=
    30 CT_ROOT_DST_DIR=
    31 CT_FORCE=no
    32 CT_ECHO=true
    33 while getopts ":s:d:fvh" CT_OPT; do
    34     case "${CT_OPT}" in
    35         s)  CT_ROOT_SRC_DIR="${OPTARG}";;
    36         d)  CT_ROOT_DST_DIR="${OPTARG}";;
    37         f)  CT_FORCE=y;;
    38         v)  CT_ECHO=echo;;
    39         h)  doHelp
    40             exit 0
    41             ;;
    42         :)  echo "$myname: '-${OPTARG}' takes exactly one argument."
    43             exit 1
    44             ;;
    45         ?)  echo "$myname: unknown option '-${OPTARG}'."
    46             exit 1
    47             ;;
    48     esac
    49 done
    50 
    51 # Sanity checks
    52 if [ -z "${CT_ROOT_SRC_DIR}" -o -z "${CT_ROOT_DST_DIR}" ]; then
    53     doHelp
    54     exit 1
    55 fi
    56 if [ ! -d "${CT_ROOT_SRC_DIR}" ]; then
    57     echo "$myname: '${CT_ROOT_SRC_DIR}': no such file or directory"
    58     exit 1
    59 fi
    60 if [ -d "${CT_ROOT_DST_DIR}" -a "${CT_FORCE}" != "y" ]; then
    61     echo "$myname: '${CT_ROOT_DST_DIR}': already exists"
    62     exit 1
    63 fi
    64 src_inode=$(ls -di "${CT_ROOT_SRC_DIR}")
    65 dst_inode=$(ls -di "${CT_ROOT_DST_DIR}" 2>/dev/null)
    66 if [ "${src_inode}" = "${dst_inode}" ]; then
    67     echo "$myname: source and destination are the same!"
    68     exit 1
    69 fi
    70 
    71 # Get rid of potentially older destination directory
    72 if [ -d "${CT_ROOT_DST_DIR}" ]; then
    73     mv "${CT_ROOT_DST_DIR}" "${CT_ROOT_DST_DIR}.$$"
    74     setsid nohup rm -rf "${CT_ROOT_DST_DIR}.$$" >/dev/null 2>&1 &
    75 fi
    76 
    77 # Create the working copy
    78 mkdir -p "${CT_ROOT_DST_DIR}"
    79 
    80 # Make all path absolute
    81 CT_ROOT_SRC_DIR=$(cd "${CT_ROOT_SRC_DIR}"; pwd)
    82 CT_ROOT_DST_DIR=$(cd "${CT_ROOT_DST_DIR}"; pwd)
    83 
    84 cd "${CT_ROOT_SRC_DIR}"
    85 tar cf - . |(cd "${CT_ROOT_DST_DIR}"; tar xf -)
    86 
    87 # Parse the working copy for executables and libraries
    88 cd "${CT_ROOT_DST_DIR}"
    89 still_needed=1
    90 while [ ${still_needed} -eq 1 ]; do
    91     ${CT_ECHO} "Looping..."
    92     still_needed=0
    93     for f in $(find . -type f -exec file {} \; |egrep ': ELF [[:digit:]]+-bit .SB (executable|shared object),' |cut -d ":" -f 1); do
    94         ${CT_ECHO} "Scanning '${f}'"
    95         for libname in $("${CT_READELF}" -d "${f}" |egrep '(NEEDED)' |sed -r -e 's,.+\[(.+)\] *$,\1,;'); do
    96             ${CT_ECHO} "  searching for '${libname}'"
    97             if [    -e "lib/${libname}"     \
    98                  -o -e "usr/lib/${libname}" ]; then
    99                 ${CT_ECHO} "    already present"
   100                 continue
   101             fi
   102             for dir in . usr; do
   103                 ${CT_ECHO} -n "    trying in '${dir}'"
   104                 libfile="${CT_SYSROOT_DIR}/${dir}/lib/${libname}"
   105                 ${CT_ECHO} ": '${libfile}'"
   106                 if [ -e "${libfile}" ]; then
   107                     mkdir -p "${dir}/lib"
   108                     ${CT_ECHO} "      installing '${dir}/lib/${libname}'"
   109                     cp "${libfile}" "${dir}/lib/${libname}"
   110                     still_needed=1
   111                     break
   112                 fi
   113             done
   114         done
   115     done
   116 done