Skip to content

Instantly share code, notes, and snippets.

@allenh1
Created September 2, 2022 19:09
Show Gist options
  • Select an option

  • Save allenh1/a6a0039a3caf6fce681223f23cef6d64 to your computer and use it in GitHub Desktop.

Select an option

Save allenh1/a6a0039a3caf6fce681223f23cef6d64 to your computer and use it in GitHub Desktop.
Bundle so files for an exe
#!/bin/bash
if [[ -z $1 ]]; then
echo "error: please provide an executable"
exit 1
fi
out_dir="$(basename ${1}).bundled"
mkdir -p "${out_dir}"
# ldd gives the SO files the exe links with
so_list=( $(ldd $1 | awk '{print $3}') )
next_so_list=so_list
while (( ${#so_list[@]} > 0 )); do
next_so_list=()
for f in ${so_list[@]}; do
[ -f "${out_dir}/$(basename ${f})" ] || {
cp -L $f "${out_dir}" && echo "Copying $(basename $f)";
next_so_list+=( $(ldd $1 | awk '{print $3}') );
}
done
so_list=( ${next_so_list[@]} )
done
cp -L "${1}" "${out_dir}/$(basename ${1}).exe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment