-
-
Save sobreira/9abb6abe13f46801bd236f9e65bdc529 to your computer and use it in GitHub Desktop.
A simple script that builds static versions of Python and LibPython using musl-libc
This file contains hidden or 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
#!/bin/bash | |
# set -eux | |
# This a simple script that builds static versions of Python and LibPython using musl-libc | |
# Find the associated article at: http://general-purpose.io/2015/12/06/compiling-python-and-libpython-statically-using-musl-libc/ | |
WORKING_DIR="/code/static-python" | |
MUSL_PREFIX="/code/static-python/musl" | |
PY_PREFIX="/code/static-python/python" | |
# COMPILER="gcc" | |
# COMPILER_VERSION="4.8" | |
COMPILER="clang" | |
COMPILER_VERSION="3.7" | |
# make the compiler's actual command name | |
export CC="${COMPILER}-${COMPILER_VERSION}" | |
# prepare the working directory | |
mkdir --parents "${WORKING_DIR}" | |
# download/extract/build static musl libc | |
cd "${WORKING_DIR}" | |
wget "http://www.musl-libc.org/releases/musl-1.1.12.tar.gz" | |
tar -xzf musl-1.1.12.tar.gz | |
cd musl-1.1.12 | |
./configure --prefix="${MUSL_PREFIX}" --disable-shared | |
make | |
make install | |
# enable the "musl compiler" | |
export CC="${MUSL_PREFIX}/bin/musl-${COMPILER}" | |
# download/extract/build static python/libpython | |
cd "${WORKING_DIR}" | |
wget "https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz" | |
tar -xJf Python-3.5.0.tar.xz | |
cd Python-3.5.0 | |
./configure --prefix="${PY_PREFIX}" --disable-shared \ | |
LDFLAGS="-static" CFLAGS="-static" CPPFLAGS="-static" | |
make | |
make install | |
# done ! (ignore any error that might happen during "make install") | |
# we now have: | |
# ${MUSL_PREFIX}/bin/musl-gcc : "static gcc" that uses musl | |
# ${PY_PREFIX}/bin/python3.5 : static python interpreter | |
# ${PY_PREFIX}/lib/libpython3.5m.a : static libpython | |
# ${PY_PREFIX}/include/python3.5m : include directory for libpython |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment