Salome HOME
add pip symbolic link to pip3
[tools/sat_salome.git] / products / compil_scripts / Python.sh
1 #!/bin/bash
2
3 echo "##########################################################################"
4 echo "Python" $VERSION
5 echo "##########################################################################"
6
7 if [ ${#VERSION} -lt 5 ]
8 then
9     echo "ERROR : VERSION argument of Python compilation script has not the expected x.y.z format"
10     exit 1
11 fi
12 PYTHON_VERSION="${VERSION:0:3}"
13 PYTHON_VERSION_MAJ=${PYTHON_VERSION:0:1}
14
15
16 function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
17 if version_ge $VERSION "3.6"; then
18     echo "*** Python version is newer than version 3.6 ..."
19     # --enable-shared   : enable building shared python library
20     # --with-threads    : enable thread support
21     # --without-pymalloc: disable specialized mallocs
22     # --with-ensurepip  : installation using bundled pip
23     # --enable-optimizations:  recommandé et utilisé par Nijni -> mais trop long!
24     CONFIGURE_ARGUMENTS="--enable-shared --with-threads --without-pymalloc --with-ensurepip=install"
25 else
26     echo "*** Python version is older than version 3.6 ..."
27     CONFIGURE_ARGUMENTS="--enable-shared --with-threads --without-pymalloc --enable-unicode=ucs4"
28 fi
29
30 echo
31 echo   "*** configure --prefix=$PRODUCT_INSTALL $CONFIGURE_ARGUMENTS"
32 $SOURCE_DIR/configure --prefix=$PRODUCT_INSTALL $CONFIGURE_ARGUMENTS
33 if [ $? -ne 0 ]
34 then
35     echo "ERROR on configure"
36     exit 1
37 fi
38
39 echo
40 echo "*** make" $MAKE_OPTIONS
41 make $MAKE_OPTIONS
42 if [ $? -ne 0 ]
43 then
44     echo "ERROR on make"
45     exit 2
46 fi
47
48 echo
49 echo "*** make install"
50 make install
51 if [ $? -ne 0 ]
52 then
53     echo "ERROR on make install"
54     exit 3
55 fi
56
57 if [ ${PYTHON_VERSION_MAJ} == 3 ]
58 then
59     # OP trick for Python 3.6.1
60     #cd ${PRODUCT_INSTALL}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}
61     cd ${PRODUCT_INSTALL}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}*
62 else
63     cd ${PRODUCT_INSTALL}/lib/python${PYTHON_VERSION}/config
64 fi
65
66 if [ ! -e libpython${PYTHON_VERSION}.so ]
67 then
68     echo
69     echo "*** create missing link"
70     ln -sf ../../libpython${PYTHON_VERSION}.so .
71     if [ $? -ne 0 ]
72     then
73         echo "ERROR when creating missing link"
74         # no error here
75     fi
76 fi
77 if [ ${PYTHON_VERSION_MAJ} == 3 ]
78 then
79     cd ${PRODUCT_INSTALL}/bin
80     ln -s python3 python
81     ln -s pip3 pip
82 fi
83
84 # fix the path... 
85 if version_ge $VERSION "3.6"; then
86     L="2to3  2to3-3.6 easy_install-3.6 idle3 idle3.6 pip3 pip3.6 pydoc3 pydoc3.6 pyvenv pyvenv-3.6"
87     cd ${PRODUCT_INSTALL}/bin
88     for f in  $L; do
89         awk '$0 = NR==1 ? replace : $0' replace="#!/usr/bin/env python3" $f > $f.t && mv $f.t $f && chmod 755 $f
90     done
91 fi
92
93 echo
94 echo "########## END"
95