summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLars <mail@dl5rcw.de>2016-05-17 21:06:13 (GMT)
committerTony Theodore <tonyt@logyst.com>2016-07-15 12:50:09 (GMT)
commit0eda283b50433842fd56c2eb4f4e11aef4f51a22 (patch)
tree51c61ad55a6bfc5f7104b52ad48e3dd07ff8ff9e /tools
parent73ae658c4ad6e919ed0aef231948e545c54b2bd0 (diff)
downloadmxe-0eda283b50433842fd56c2eb4f4e11aef4f51a22.zip
mxe-0eda283b50433842fd56c2eb4f4e11aef4f51a22.tar.gz
mxe-0eda283b50433842fd56c2eb4f4e11aef4f51a22.tar.bz2
tools/copydlldeps: introducing excludepattern and whitelist of DLLs
Diffstat (limited to 'tools')
-rw-r--r--tools/copydlldeps.md12
-rwxr-xr-xtools/copydlldeps.sh122
2 files changed, 102 insertions, 32 deletions
diff --git a/tools/copydlldeps.md b/tools/copydlldeps.md
index 249d993..3b63a03 100644
--- a/tools/copydlldeps.md
+++ b/tools/copydlldeps.md
@@ -54,6 +54,18 @@ I checked if there is a mxe objdump. If not, I took the native one on my server.
I actually do not know the difference but decided to include it in the script
in case it is important to someone.
+whitelist
+---------
+I added a whitelist of *dll files that are widely used and very common on windows systems. Most of them are not to be found on MXE, but on native machines. As they are listed as dependencies, they might create warnings. To avoid anxiety, I introduced str_whiteListDlls. Those will create info instead of warning messages. Do not worry about them any longer. It works anyway as those are to be expected on your windows installation.
+
+exclude directory pattern
+-------------------------
+excludedir was added as an aditional option. You may call it multiple times like
+ --excludepattern /path/folder1/ --excludepattern /path/folder2/ -X /path/folder3/
+Try to make it as explicit as possible. If you choose a generic pattern, you may exclude more paths than you intend to. Actually any pattern will work.
+ -X pattern1 -X pattern2
+This was introduced upon the request to have the script avoid /(PREFIX)/(TARGET)/apps/. You may now pass this as an 'excludepattern' option.
+
enforcedir
----------
My application is using Qt5 and objdump did not return the needed qwindows.dll -
diff --git a/tools/copydlldeps.sh b/tools/copydlldeps.sh
index e64b70e..1699b6c 100755
--- a/tools/copydlldeps.sh
+++ b/tools/copydlldeps.sh
@@ -10,14 +10,14 @@ Welcome to $( basename $0)!
Authors: Lars Holger Engelhard - DL5RCW (2016)
Tiancheng "Timothy" Gu (2014)
-Version: 1.1
+Version: 1.3
# This file is part of the MXE Project, sponsored by the named authors
# it supports the shared build approach by providing an easy way to
# check for library dependencies in a recursive manner
-# Copyright (c) 2014 Tiancheng "Timothy" Gu
-# (c) 2016 Lars Holger Engelhard - DL5RCW
+# Copyright (c) 2016 Lars Holger Engelhard - DL5RCW
+# (c) 2014 Tiancheng "Timothy" Gu
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -47,7 +47,7 @@ EOF
OBJDUMP=objdump
# create a temp directory
-tmp=`mktemp -d`
+tmp=$( mktemp -d )
# print an help menu
help() {
@@ -76,6 +76,7 @@ Operating options:
-s, --srcdir [ multiCall ] The directory with DLLs that can be copied.
-S, --srcdirs [ multiCall ] List of directories with DLLs that can be copied. Put "" around them, e.g. "/dir1 /root/dir2 /root/dir3"
-R, --recursivesrcdir [ multiCall ] Target directory for recursive search of folders containing *dll files
+ -X, --excludepattern [ multiCall ] Exclude any path that contains such pattern, e.g. /(PREFIX)/(TARGET)/apps/
Optional binary settings:
-o, --objdump Specify the path or name of your objdump application
@@ -111,16 +112,16 @@ die() {
# and findAllSrcDirectories will hunt for dlls in each one recursively
# it will return a sorted list and duplicates are removed
findAllSrcDirectories(){
-ar_recursiveDirList=${!1}
-string=""
-for curPath in "${ar_recursiveDirList[@]}"; do
- for element in $(find $curPath -iname "*.dll"); do
- #ar_list+="$(dirname $element) "
- string+="$(dirname $element) "
+ ar_recursiveDirList=${!1}
+ string=""
+ for curPath in "${ar_recursiveDirList[@]}"; do
+ for element in $(find $curPath $excludePattern -iname "*.dll"); do
+ #ar_list+="$(dirname $element) "
+ string+="$(dirname $element) "
+ done
done
-done
-string=$(echo "$string" | tr -s ' ' | tr ' ' '\n' | nl | sort -u -k2 | sort -n | cut -f2-)
-echo $string #returns the string
+ string=$(echo "$string" | tr -s ' ' | tr ' ' '\n' | nl | sort -u -k2 | sort -n | cut -f2-)
+ echo $string #returns the string
}
while [ $# -gt 0 ]; do
@@ -152,6 +153,10 @@ while [ $# -gt 0 ]; do
recursivesrcdir+=" $1"
shift
;;
+ -X|--excludepattern)
+ excludepattern+=" $1"
+ shift
+ ;;
-o|--objdump)
OBJDUMP="$1"
shift
@@ -183,6 +188,8 @@ while [ $# -gt 0 ]; do
;;
esac
done
+
+# setting default values if no arguments were given
if ! [ "$loglevel" ]; then
loglevel=0
fi
@@ -208,6 +215,16 @@ if [ "$loglevel" -gt 1 ]; then
echo "opmode=$opmode"
fi
+excluePattern="" # building an exclude command consisting of patterns. We still contain the first hit of find
+if [ ! -z "$excludepattern" ]; then
+ for curString in $( echo "$excludepattern" | tr -s ' ' | tr ' ' '\n' ); do
+ excludePattern+=" ! -path *$( echo "$curString" | tr -d ' ' )* "
+ done
+fi
+if [ "$loglevel" -gt 1]; then
+ echo "\$excluePattern: $excludePattern"
+fi
+
str_inputFileList=""
if [ "$indir" ]; then
for curPath in $( echo "${indir}" | tr -s ' ' | tr ' ' '\n' ); do
@@ -259,13 +276,16 @@ if [ "$loglevel" -gt 1 ]; then
echo "starting in 5 seconds" && sleep 5
fi
+# introducing a whitelist of well known DLLs
+str_whiteListDlls="advapi32.dll kernel32.dll msvcrt.dll user32.dll ws2_32.dll gdi32.dll shell32.dll d3d9.dll ole32.dll winmm.dll mpr.dll opengl32.dll"
+
# function to append dependencies (recursively)
append_deps() {
if [ "$loglevel" -gt 1 ]; then
echo "\$1=$1 + \$2=$2 "
sleep 2
fi
- local bn="`basename $1`"
+ local bn="$( basename $1 )"
if [ -e "$tmp/$bn" ]; then
return 0
fi
@@ -275,11 +295,21 @@ append_deps() {
path=""
for curPath in $( echo "${str_srcDirList}" | tr -s ' ' | tr ' ' '\n' ); do
counter=0
- result=$(find $curPath -iname "$bn" | tail -n 1)
- if [ ! -z $result ];then
- path=$result
+ result=""
+ result=$(find $curPath $excludePattern -iname "$bn" -type f | tail -n 1)
+ if [ "$loglevel" -gt 1 ]; then
+ echo "complete find command in append_deps(): # find $curPath $excludePattern -iname $bn -type f | tail -n 1 # "
+ fi
+ if [ ! -z "$result" ];then
+ path="$result"
counter=$(expr $counter + 1)
fi
+if [ $counter == 0 ]; then
+ #echo "ERROR: could not find \$path for dll $bn, \$counter=$counter: searched $curPath"
+ str_test="1"
+else
+ echo "OKAY: found path for dll $bn = $path, \$counter=$counter: searched $curPath"
+fi
if [ "$loglevel" -gt 1 ]; then
if [ $counter == 0 ]; then
echo "could not find \$path for dll $bn, \$counter=$counter: searched $curPath"
@@ -304,7 +334,7 @@ append_deps() {
fi
$OBJDUMP -p "$path" | grep 'DLL Name:' | cut -f3 -d' ' > "$tmp/$bn"
echo "executing: $OBJDUMP -p "$path" | grep 'DLL Name:' | cut -f3 -d' ' > "$tmp/$bn""
- for dll in `cat "$tmp/$bn" | tr '\n' ' '`; do
+ for dll in $( cat "$tmp/$bn" | tr '\n' ' ' ); do
append_deps "$dll"
done
alldeps=$(printf "$alldeps\n%s" "$(cat $tmp/$bn)" | sort | uniq)
@@ -343,7 +373,6 @@ if [ ! -z "$enforcedir" ]; then
fi
# then we start with our indir or infile list
-#for file in $filelist; do
for file in $str_inputFileList; do
echo "starting for file $file"
#sleep 4
@@ -361,28 +390,33 @@ if [ "$loglevel" -eq 1 ]; then
tmpStr=${str_srcDirList}
echo "\$alldeps has ${#alldeps[@]} elements"
echo "and \$str_srcDirList has ${#str_srcDirList} elements"
- #echo "waiting another 2 seconds"
- #sleep 2
fi
-for dll in `echo $alldeps | tr '\n' ' '`; do
+str_summary="Here is the summary:"
+str_summary="${str_summary} # ==== 8< ==== START ==== 8< ==== "
+if [ $opmode == "copy" ]; then
+ echo "copying files from \${curFolder} to \$destdir:"
+elif [ $opmode == "print" ]; then
+ echo "printing files:"
+fi
+for dll in $( echo $alldeps | tr '\n' ' ' ); do
counter=0
- lower_dll=`echo $dll | tr '[:upper:]' '[:lower:]'`
- if [ $lower_dll == $dll ]; then
- lower_dll=""
+ lowerDll=$( echo $dll | tr '[:upper:]' '[:lower:]' )
+ if [ $lowerDll == $dll ]; then
+ lowerDll=""
fi
for curFolder in $( echo "${str_srcDirList}" | tr -s ' ' | tr ' ' '\n'); do
if [ "$loglevel" -gt 1 ]; then
echo "search for dll $dll in curFolder $curFolder"
sleep 1
fi
- for the_dll in $dll $lower_dll; do
- if [ -e "${curFolder}/${the_dll}" ]; then
- counter=$(expr $counter + 1)
+ for curDll in $dll $lowerDll; do
+ if [ -e "${curFolder}/${curDll}" ]; then
+ counter=$( expr $counter + 1 )
if [ $opmode == "copy" ]; then
- cp -dpRxv "${curFolder}/${the_dll}" "$destdir"
+ cp -dpRxv "${curFolder}/${curDll}" "$destdir"
elif [ $opmode == "print" ]; then
- echo "found $dll in: ${curFolder}/${the_dll}"
+ echo "found $dll in: ${curFolder}/${curDll}"
else
echo "unknown opmode=$opmode"
fi
@@ -390,10 +424,34 @@ for dll in `echo $alldeps | tr '\n' ' '`; do
done
done
if [ $counter == 0 ]; then
- echo "Warning: \"$dll\" not found. \$counter=$counter." >&2
+ lowerDll=$( echo $dll | tr '[:upper:]' '[:lower:]' )
+ str_whiteListDlls=$( echo ${str_whiteListDlls} | tr '[:upper:]' '[:lower:]' ) # make whiteListDlls lower case to ensure we find the match (case insensitive)
+ if [ -z "${str_whiteListDlls/*${lowerDll}*}" ]; then
+ if [ "$loglevel" -gt 1 ]; then
+ echo "Info: \"$dll\" not found - but it is white-listed. That means: it is well known by Windows - do not worry too much. "
+ fi
+ str_summary="${str_summary} # Info: \"$dll\" not found - but it is white-listed. That means: it is well known by Windows - do not worry too much. "
+ else
+ if [ "$loglevel" -gt 1 ]; then
+ echo "Warn: \"$dll\" NOT found. \$counter=$counter."
+ fi
+ str_summary="${str_summary} # Warn: \"$dll\" NOT found. \$counter=$counter."
+ fi
else
- echo "Found dll $dll in the list. \$counter=$counter" >&2
+ if [ "$loglevel" -gt 1 ]; then
+ echo "Good: \"$dll\" found in the list. \$counter=$counter"
+ fi
+ str_summary="${str_summary} # Good: \"$dll\" Found in the list. \$counter=$counter"
fi
done
+str_summary="${str_summary} # ==== 8< ==== END ==== 8< ==== "
+echo "Job is done."
+# print the summary now
+for curLine in "$( echo "${str_summary}" | tr -s '#' | tr '#' '\n' )"; do # convert # to a linebreak - string ecomes an array that can be processed in for loop
+ echo "$curLine"
+done
+# clean up the temp directory stored in $tmp
rm -rf "$tmp"
+
+exit 0