This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfigure
executable file
·129 lines (110 loc) · 5.15 KB
/
configure
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# create the makevars for unix like systems (tested on debian and ubuntu)
#
# NOTES:
# The system variable USESPECIALPYTHONVERSION can be used to link to a special
# python version.
# export USESPECIALPYTHONVERSION="python3.4"
# it can be very usefull especially for testing but one has to ensure that
# the file PYVERSION-config is present at the provided location else it will
# fail.
# But when using python3 also python3-dev has to be installed
# (apt-get install python3-dev)
#
# gcc:
# there seems to be a new option which doesn't allows me to compile
# -fstack-protector-strong so I just remove it
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# exit immediately if any step fails
set -e
# ----- install the Python package -----
EMBED_PYTHON_VERSION=3.6
EMBED_PYTHON_VERSION_EXTENDED=${EMBED_PYTHON_VERSION}.8
PYTHON_ARCHIVE_NAME=Python-${EMBED_PYTHON_VERSION_EXTENDED}
PYTHON_RUNTIME_BUNDLE=https://www.python.org/ftp/python/${EMBED_PYTHON_VERSION_EXTENDED}/${PYTHON_ARCHIVE_NAME}.tgz
cd inst
# don't halt the script if wget is not found, just switch to curl
set +e
wget -O ${PYTHON_ARCHIVE_NAME}.tgz ${PYTHON_RUNTIME_BUNDLE}
if [ "$?" -ne "0" ]; then
curl -o ${PYTHON_ARCHIVE_NAME}.tgz ${PYTHON_RUNTIME_BUNDLE}
fi
if [ "$?" -ne "0" ]; then
echo "Failed to download ${PYTHON_RUNTIME_BUNDLE}"
exit 1
fi
# back to the exit-immediately-mode
set -e
tar -xzf ${PYTHON_ARCHIVE_NAME}.tgz
rm ${PYTHON_ARCHIVE_NAME}.tgz
EMBED_PYTHON_DIR=${PWD}
cd ${PYTHON_ARCHIVE_NAME}
if [ $(uname) == "Darwin" ]; then
echo "Mac specific configuration"
# When installing openssl on Mac there is a message:
# For compilers to find this software you may need to set:
# LDFLAGS: -L/usr/local/opt/openssl/lib
# CPPFLAGS: -I/usr/local/opt/openssl/include
# export LDFLAGS=-L/usr/local/opt/openssl/lib
# sdk path needed for zlib on catalina
export CPPFLAGS="-I/usr/local/opt/openssl/include -I$(xcrun --show-sdk-path)/usr/include"
# However the above isn't enough since the libraries have to be bundled into
# the package
mkdir -p ${EMBED_PYTHON_DIR}/lib
LIBCRYPTO_DYLIB_PATH=$(ls -a /usr/local/opt/openssl/lib/libcrypto.1*.dylib)
LIBCRYPTO_DYLIB_FILENAME=$(basename $LIBCRYPTO_DYLIB_PATH)
LIBSSL_DYLIB_PATH=$(ls -a /usr/local/opt/openssl/lib/libssl.1*.dylib)
LIBSSL_DYLIB_FILENAME=$(basename $LIBSSL_DYLIB_PATH)
cp /usr/local/opt/openssl/lib/libcrypto.a ${EMBED_PYTHON_DIR}/lib/
cp $LIBCRYPTO_DYLIB_PATH ${EMBED_PYTHON_DIR}/lib/
cp /usr/local/opt/openssl/lib/libssl.a ${EMBED_PYTHON_DIR}/lib/
cp $LIBSSL_DYLIB_PATH ${EMBED_PYTHON_DIR}/lib/
chmod u+w ${EMBED_PYTHON_DIR}/lib/*
export LIBCRYPTO_LOAD_DYLIB_PATH=$(otool -L ${EMBED_PYTHON_DIR}/lib/$LIBSSL_DYLIB_FILENAME | grep libcrypto | cut -d" " -f1)
# https://blogs.oracle.com/dipol/dynamic-libraries,-rpath,-and-mac-os
install_name_tool -change \
$LIBCRYPTO_LOAD_DYLIB_PATH \
"@loader_path/$LIBCRYPTO_DYLIB_FILENAME" \
${EMBED_PYTHON_DIR}/lib/$LIBSSL_DYLIB_FILENAME
# https://wiki.python.org/moin/BuildStatically
# https://stackoverflow.com/questions/1150373/compile-the-python-interpreter-statically
# errors occur when either of the following is enabled
# echo $'*static*\n_ssl _ssl.c -DUSE_SSL ${CPPFLAGS} ${LDFLAGS} -lssl -lcrypto' >> Modules/Setup.local
# echo $'_ssl _ssl.c -DUSE_SSL ${CPPFLAGS} ${LDFLAGS} -lssl -lcrypto' >> Modules/Setup.local
fi
# in the following line the '--prefix' parameter is the installation location
# NOTE: removed --enable-shared option and added CFLAGS=-fPIC CXXFLAGS=-fPIC to try to get a static library
./configure CFLAGS=-fPIC CXXFLAGS=-fPIC --prefix=${EMBED_PYTHON_DIR}
make
make altinstall
cd ..
rm -R ${PYTHON_ARCHIVE_NAME}
cd ..
# ensure that the embedded python interpreter has newer version of pip so that
# downstream package installations will have a better chance of installing precompiled wheels
${EMBED_PYTHON_DIR}/bin/python${EMBED_PYTHON_VERSION} -m pip install pip==21.0.1
# these exact paths vary by python version so use wildcard expansions to find the actual path
MYPYTHONCONFIG=$(ls ${EMBED_PYTHON_DIR}/bin/python${EMBED_PYTHON_VERSION}*-config)
MYPYTHONLIBDIR=$(ls -d ${EMBED_PYTHON_DIR}/lib/python${EMBED_PYTHON_VERSION}/*config-${EMBED_PYTHON_VERSION}*)
# Extract the linker and include flags for python
: ${PYTHONCONFIG=`which ${MYPYTHONCONFIG}`}
if test -z "${PYTHONCONFIG}"; then
echo "could not locate ${MYPYTHONCONFIG}"
exit 1
fi
echo "python version is ${EMBED_PYTHON_VERSION_EXTENDED}"
PYXY="PYTHONLIBXY=libpython${EMBED_PYTHON_VERSION}m.so"
PYLIBS="PKG_LIBS=-L$MYPYTHONLIBDIR "`$PYTHONCONFIG --libs`
PYCFLAGS="PKG_CFLAGS="`$PYTHONCONFIG --cflags`" -D $PYXY -D PYTHON_IN_R_NO_EXPLICIT_LINKING"
#clean up the old compilation or else it wont recompile
rm -f src/*.o src/*.so src/*.rds src/Makevars
echo ""
echo "Makevars:"
echo $PYLIBS
echo $PYCFLAGS | sed 's/Wstrict-prototypes/pedantic/' | sed 's/ -fstack-protector-strong//'
echo ""
# replacing Wstrict-prototypes removes some unnecessary warnings
echo $PYLIBS > src/Makevars
echo $PYCFLAGS | sed 's/Wstrict-prototypes/pedantic/' | sed 's/ -fstack-protector-strong//' >> src/Makevars