Last active
December 31, 2023 13:29
-
-
Save userdocs/7d6b30b2602ea1d9284508878e7c7e2d to your computer and use it in GitHub Desktop.
A simple example of how to build libtorrent and the python binding using the boost source files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# | |
# shellcheck disable=SC1091,SC2034 # sourced files | |
# | |
set -a | |
# | |
export DEBIAN_FRONTEND="noninteractive" TZ="Europe/London" | |
# | |
cr="\e[31m" # [c]olor[r]ed | |
cg="\e[32m" # [c]olor[g]reen | |
cend="\e[0m" # [c]olor[end] | |
# | |
build_dir="$HOME/docker" | |
# | |
install_prefix="$HOME/docker" | |
# | |
mkdir -p "${build_dir}" | |
# | |
boost_version="1.75.0" | |
# | |
lt_prefix="${install_prefix}/local" | |
# | |
BOOST_ROOT="${build_dir}/boost_${boost_version//./_}" | |
BOOST_INCLUDEDIR="${BOOST_ROOT}/boost" | |
BOOST_BUILD_PATH="${BOOST_ROOT}" | |
# | |
deps() { | |
apt-get update | |
# | |
echo | |
qb_required_pkgs=("ca-certificates" "curl" "build-essential" "pkg-config" "git" "zlib1g-dev" "libicu-dev" "libssl-dev" "python3" "python3-dev") | |
for pkg in "${qb_required_pkgs[@]}"; do | |
pkgman() { dpkg -s "${pkg}"; } | |
if pkgman > /dev/null 2>&1; then | |
echo -e "Dependency - ${cg}OK${cend} - ${pkg}" | |
else | |
echo -e "Dependency - ${cr}NO${cend} - ${pkg}" | |
qb_checked_required_pkgs+=("$pkg") | |
fi | |
done | |
echo | |
if [[ ${#qb_checked_required_pkgs[@]} -eq 0 ]]; then | |
echo "All deps installed" | |
else | |
if ! apt-get -y install --no-install-recommends "${qb_checked_required_pkgs[@]}"; then | |
exit | |
fi | |
fi | |
echo | |
# | |
if [[ "$1" == 'deps' ]]; then exit; fi | |
} | |
boost() { | |
cd "${build_dir}" || exit | |
curl -sL "https://boostorg.jfrog.io/artifactory/main/release/${boost_version}/source/boost_${boost_version//./_}.tar.gz" > "${boost_version//./_}.tar.gz" | |
tar xf "${boost_version//./_}.tar.gz" | |
cd "boost_${boost_version//./_}" || exit | |
./bootstrap.sh | |
} | |
libtorrent() { | |
python_major="$(python3 -c "import sys; print(sys.version_info[0])")" | |
python_minor="$(python3 -c "import sys; print(sys.version_info[1])")" | |
python_short_version="${python_major}.${python_minor}" | |
# | |
echo -e "using gcc : : : <cflags>-march=native -std=c++17 <cxxflags>-march=native -std=c++17 ;\nusing python : ${python_short_version} : /usr/bin/python${python_short_version} : /usr/include/python${python_short_version} : /usr/lib/python${python_short_version} ;" > "$HOME/user-config.jam" | |
cd "${build_dir}" || exit | |
[[ -d libtorrent ]] && rm -rf libtorrent | |
git clone --single-branch --branch RC_1_2 --shallow-submodules --recurse-submodules --depth 1 https://github.com/arvidn/libtorrent | |
# | |
# libtorrent | |
cd "${build_dir}/libtorrent" || exit | |
"${BOOST_ROOT}/b2" -j"$(nproc)" optimization=speed crypto=openssl cxxstd=17 variant=release threading=multi link=static boost-link=static install --prefix="${lt_prefix}" | |
# | |
# libtorrent python binding | |
cd "${build_dir}/libtorrent/bindings/python" || exit | |
"${BOOST_ROOT}/b2" -j"$(nproc)" fpic=on optimization=speed crypto=openssl cxxstd=17 variant=release threading=multi libtorrent-link=static boost-link=static install_module python-install-scope=user # stage_dependencies | |
} | |
deps "${@}" | |
boost | |
libtorrent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment