aboutsummaryrefslogtreecommitdiffstats
path: root/bash_include
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2014-12-14 23:53:20 +0800
committerTing-Wei Lan <lantw44@gmail.com>2014-12-14 23:56:27 +0800
commite0848cbc78c72169ad87a4d0d14597e27863ac8a (patch)
tree7477632eda442adea3368be054a5241f591de5c0 /bash_include
parent7f990880dd3f96443cf64e7a5c07cb44d2e95a16 (diff)
downloadconfigfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.tar
configfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.tar.gz
configfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.tar.bz2
configfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.tar.lz
configfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.tar.xz
configfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.tar.zst
configfile-e0848cbc78c72169ad87a4d0d14597e27863ac8a.zip
bash_include: 加入自動複製 Windows 可執行檔所需 DLL 的小工具bash_include-20141214
Diffstat (limited to 'bash_include')
-rw-r--r--bash_include135
1 files changed, 135 insertions, 0 deletions
diff --git a/bash_include b/bash_include
index 4c33066..936f7da 100644
--- a/bash_include
+++ b/bash_include
@@ -996,6 +996,134 @@ function trash_du ()
}
+# Group: Windows Executable Helpers ##########################################
+
+function windows_exe_get_deps () {
+ : ${OBJDUMP:="objdump"}
+ LANG=C LC_ALL=C LANGUAGE= ${OBJDUMP} -p "$1" | \
+ safe_grep 'DLL Name' | \
+ sed 's|[ ]*DLL Name: \(.*\)$|\1|'
+}
+
+function windows_dll_is_builtin () {
+ local builtin_dlls=(
+ advapi32.dll
+ comctl32.dll
+ comdlg32.dll
+ crypt32.dll
+ dnsapi.dll
+ gdi32.dll
+ gdiplus.dll
+ imm32.dll
+ iphlpapi.dll
+ kernel32.dll
+ msimg32.dll
+ msvcpp.dll
+ msvcrt.dll
+ mpr.dll
+ netapi32.dll
+ ntdll.dll
+ ole32.dll
+ oleaut32.dll
+ opengl32.dll
+ rpcrt4.dll
+ setupapi.dll
+ shell32.dll
+ shlwapi.dll
+ user32.dll
+ usp10.dll
+ version.dll
+ winmm.dll
+ winspool.drv
+ ws2_32.dll
+ )
+ local i
+ for ((i=0; i<"${#builtin_dlls[@]}"; i++)) {
+ if [ "${1,,}" = "${builtin_dlls[$i],,}" ]; then
+ return 0
+ fi
+ }
+ return 1
+}
+
+function windows_exe_find_dlls () {
+ local thisfile="$1"
+ local verbose="$2"
+ local level="$3"
+ local found
+ local i
+
+ for dll in `windows_exe_get_deps "$1"`; do
+ if windows_dll_is_builtin "$dll"; then
+ continue
+ fi
+
+ found="false"
+
+ if [ "${windows_exe_needed_dlls[$dll]}" ]; then
+ if [ "$verbose" = "true" ]; then
+ repeat "$level" echo -n ' '
+ echo "$dll => ${windows_exe_needed_dlls[$dll]}"
+ fi
+ continue
+ fi
+
+ for ((i=0; i<"${#windows_exe_dll_dirs[@]}"; i++)) {
+ if [ -f "${windows_exe_dll_dirs[$i]}/$dll" ]; then
+ if [ "$verbose" = "true" ]; then
+ repeat "$level" echo -n ' '
+ echo "$dll => ${windows_exe_dll_dirs[$i]}/$dll"
+ fi
+ windows_exe_needed_dlls[$dll]="${windows_exe_dll_dirs[$i]}/$dll"
+ windows_exe_find_dlls "${windows_exe_dll_dirs[$i]}/$dll" \
+ "$verbose" "$(( $level + 1 ))"
+ found="true"
+ break
+ fi
+ }
+
+ if [ "$verbose" = "true" ] && [ "$found" = "false" ]; then
+ repeat "$level" echo -n ' '
+ echo "$dll => not found"
+ fi
+ done
+}
+
+function windows_exe_copy () {
+ local dry_run="false"
+ local verbose="false"
+
+ if [ "$1" = "-n" ]; then
+ dry_run="true"
+ verbose="true"
+ shift
+ fi
+
+ local exefile="$1"
+ local destdir="$2"
+ shift 2
+
+ declare -a windows_exe_dll_dirs=("$@")
+ declare -A windows_exe_needed_dlls
+
+ if [ "$verbose" = "true" ]; then
+ echo "$exefile"
+ fi
+ windows_exe_find_dlls "$exefile" "$verbose" "1"
+
+ for i in "${!windows_exe_needed_dlls[@]}"; do
+ if [ "$dry_run" = "false" ]; then
+ echo "Copying ${windows_exe_needed_dlls[$i]} ..."
+ mkdir -p "$destdir"
+ safe_cp "${windows_exe_needed_dlls[$i]}" "$destdir"
+ fi
+ done
+
+ unset windows_exe_dll_dirs
+ unset windows_exe_needed_dlls
+}
+
+
# Tools: Background Notify Daemon ############################################
function check_dmesg ()
@@ -1610,6 +1738,7 @@ function cxx_define ()
function repeat ()
{
local repeat_times="$1"
+ local i
shift
for ((i=0; i<repeat_times; i++))
do
@@ -1772,6 +1901,12 @@ function help_function ()
trash_count (trash_ct)
trash_du [-- sudo_prefix ...]
+ <<< Group: Windows Executable Helpers >>>
+ windows_exe_get_deps
+ windows_exe_copy
+ x windows_dll_is_builtin
+ x windows_exe_find_dlls
+
<<< Tools: Background Notify Daemon >>>
check_dmesg seconds
check_system_status seconds