forked from lmbelo/python3-embeddable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
61 lines (48 loc) · 1.42 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -e
set -x
# Initialize variables
THIS_DIR="$PWD"
SRCDIR=src/Python-$PYVER
# Clear the last build
if [ -d src ]; then rm -Rf src; fi
if [ -d build ]; then rm -Rf build; fi
if [ -d embedabble ]; then rm -Rf embedabble; fi
if [ ! -d $SRCDIR ]; then
mkdir -p src
pushd src
curl -vLO https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tar.xz
# Use --no-same-owner so that files extracted are still owned by the
# running user in a rootless container
tar --no-same-owner -xf Python-$PYVER.tar.xz
popd
fi
cp -r Linux $SRCDIR
pushd $SRCDIR
# Build deps
./Linux/build_deps.py
./Linux/configure.py --prefix=/usr --disable-test-modules "$@"
# Make Python from source
make
make install DESTDIR="$THIS_DIR/build"
popd
# Create the embeddable dir and moves Python distribution into it
mkdir -p embedabble
mv build/usr/* embedabble
cd "$THIS_DIR/embedabble"
# Delete undesired packages
PYSIMPLEVER=$(cut -d '.' -f 1,2 <<< "$PYVER")
find "lib/python$PYSIMPLEVER" -type d -name "config-$PYSIMPLEVER*" -prune -exec rm -rf {} \;
find "lib/python$PYSIMPLEVER" -type d -name "test" -prune -exec rm -rf {} \;
# Create the activate script
touch activate.sh
cat <<EOT >> activate.sh
#!/bin/bash
export PYTHONHOME=\$PWD
export PATH=\$PWD/bin:\$PATH
if [ ! -z "\$LD_LIBRARY_PATH" ] ; then
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:"
fi
export LD_LIBRARY_PATH="\$PWD/lib:\$LD_LIBRARY_PATH"
EOT
chmod a+x activate.sh