Optimize static2dll script

This commit is contained in:
RichardG867
2021-11-13 00:30:42 -03:00
parent e6fddf9823
commit 5021457017

View File

@@ -37,11 +37,12 @@ find_lib() {
add_lib() { add_lib() {
# Always make sure this lib is listed after the last lib that depends on it. # Always make sure this lib is listed after the last lib that depends on it.
if grep -q -- '^'"$*"'$' "$libs_file" old_libs=$(cat "$libs_file")
then rm -f "$libs_file"
cp "$libs_file" "$libs_file.tmp" for lib in $old_libs
grep -v -- '^'"$*"'$' "$libs_file.tmp" > "$libs_file" do
fi [ "$lib" != "$*" ] && echo "$lib" >> "$libs_file"
done
echo "$*" >> "$libs_file" echo "$*" >> "$libs_file"
# Add libstdc++ in the end if required. # Add libstdc++ in the end if required.
@@ -63,6 +64,16 @@ add_lib() {
fi fi
} }
run_pkgconfig() {
local cache_file="static2dll.$1.cache"
if [ -e "$cache_file" ]
then
cat "$cache_file"
else
pkg-config --static --libs "$1" 2> /dev/null | tee "$cache_file"
fi
}
parse_pkgconfig() { parse_pkgconfig() {
# Parse arguments. # Parse arguments.
local layers=$1 local layers=$1
@@ -80,6 +91,7 @@ parse_pkgconfig() {
for arg in $* for arg in $*
do do
local arg_base="$(echo $arg | cut -c1-2)" local arg_base="$(echo $arg | cut -c1-2)"
echo $arg
if [ "x$arg_base" = "x-l" ] if [ "x$arg_base" = "x-l" ]
then then
# Don't process the same lib again. # Don't process the same lib again.
@@ -90,7 +102,7 @@ parse_pkgconfig() {
add_lib "$(find_lib $lib_name)" add_lib "$(find_lib $lib_name)"
# Get this lib's dependencies through pkg-config. # Get this lib's dependencies through pkg-config.
local pkgconfig="$(pkg-config --static --libs "$lib_name" 2>/dev/null)" local pkgconfig="$(run_pkgconfig "$lib_name")"
[ $? -eq 0 ] && parse_pkgconfig "$layers"'>' "$lib_name" $pkgconfig || echo $lib_name >> "$seen_file" [ $? -eq 0 ] && parse_pkgconfig "$layers"'>' "$lib_name" $pkgconfig || echo $lib_name >> "$seen_file"
elif [ "x$(echo $arg_base | cut -c1)" = "x-" ] elif [ "x$(echo $arg_base | cut -c1)" = "x-" ]
then then
@@ -107,7 +119,7 @@ parse_pkgconfig() {
case $1 in case $1 in
-p) # -p pkg_config_name static_lib_path out_dll -p) # -p pkg_config_name static_lib_path out_dll
shift shift
base_pkgconfig=$(pkg-config --static --libs "$1") base_pkgconfig=$(run_pkgconfig "$1")
base_path="$2" base_path="$2"
base_name="$1" base_name="$1"
;; ;;
@@ -141,6 +153,7 @@ parse_pkgconfig '>' $base_name $base_pkgconfig
# Produce final DLL. # Produce final DLL.
dllwrap --def "$def_file" -o "$3" -Wl,--allow-multiple-definition "$base_path" $(cat "$libs_file") dllwrap --def "$def_file" -o "$3" -Wl,--allow-multiple-definition "$base_path" $(cat "$libs_file")
status=$? status=$?
[ $status -eq 0 ] && rm -f "$def_file" "$seen_file" "$libs_file" "static2dll.*.cache"
# Update final DLL timestamp. # Update final DLL timestamp.
touch -r "$base_path" "$3" touch -r "$base_path" "$3"