Skip to content

Instantly share code, notes, and snippets.

@rowillia
Created July 26, 2017 23:03
Show Gist options
  • Save rowillia/f53eb58c96c907c0315a3c3a59e40986 to your computer and use it in GitHub Desktop.
Save rowillia/f53eb58c96c907c0315a3c3a59e40986 to your computer and use it in GitHub Desktop.
#!/bin/bash
VERSION_SHAS="
3.6.2;e1a36bfffdd1d3a780b1825daf16e56c
3.6.1;2d0fc9f3a5940707590e07f03ecb08b9
3.6.0;3f7062ccf8be76491884d0e47ac8b251
3.5.3;6192f0e45f02575590760e68c621a488
3.5.2;3fe8434643a78630c61c6464fe2e7e72
3.5.1;be78e48cdfc1a7ad90efff146dce6cfe
3.5.0;a56c0c0b45d75a0ec9c6dee933c41c36
"
set -e
PYTHON_VERSION=$1
if [ -z "$PYTHON_VERSION" ]; then
echo "PYTHON_VERSION is required"
echo "example: ./build_python.sh 3.6.2"
exit 1
fi
shift
apt-get install -yq --force-yes software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get install -yq --force-yes gcc-7 \
g++-7 \
checkinstall \
build-essential \
cmake \
gfortran \
libffi-dev \
libssl-dev \
pkg-config \
zlib1g-dev \
libbz2-dev \
libncurses5-dev \
libreadline6-dev \
libsqlite3-dev \
libgdbm-dev \
liblzma-dev \
openssl \
tk8.5-dev
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 50
ORIGINAL_DIRECTORY="$PWD"
cd $(mktemp -d)
PYTHON_MINOR_VERSION=$(echo "${PYTHON_VERSION}" | cut -d. -f1-2)
wget "https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz"
downloaded_md5=$(md5sum Python-${PYTHON_VERSION}.tgz | awk '{print $1}')
if ! echo $VERSION_SHAS | grep "${PYTHON_VERSION}"; then
echo "Missing md5 for ${PYTHON_VERSION}, refusing to build."
exit 1
fi
if ! echo $VERSION_SHAS | grep "${PYTHON_VERSION};${downloaded_md5}"; then
echo "Downloaded source doesn't match expected checksum, refusing to build."
exit 1
fi
tar xf Python-${PYTHON_VERSION}.tgz
cd "Python-${PYTHON_VERSION}"
cat << EOF > description-pak
Python "${PYTHON_VERSION}"
EOF
mkdir -p "${ORIGINAL_DIRECTORY}/build"
./configure \
--prefix=/usr \
--disable-rpath \
--enable-ipv6 \
--enable-loadable-sqlite-extensions \
--enable-shared \
--enable-optimize \
--enable-optimizations \
--enable-lto \
--with-computed-gotos \
--with-threads \
|| return 1
checkinstall -y \
--pkgname="python${PYTHON_MINOR_VERSION}" \
--pkgversion="${PYTHON_VERSION}" \
--pkgrelease=1 \
--pkglicense=PSF \
--pkgsource=https://www.python.org/ \
-D make altinstall | tee "${ORIGINAL_DIRECTORY}/build/make_output.txt"
cp ./*.deb "${ORIGINAL_DIRECTORY}/build"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment