How to build python 2 (optional)

Note: Tips for building python were taken from this site:

Tips for building python taken from: https://gist.github.com/lukaslundgren/2659457

Why this may be needed

On some Linux systems, e.g. Debian-12, Python 2 is no longer available as a package.

The RTEMS source builder that build the RTEMS cross tools however, still depends on Python 2.

So if your system doesn’t have Python 2 installed and there is no package available, you need to build Python 2 from source with the script “build-python2.sh” that is described here.

How to build

You first have to review or change some configuration variables in file CONFIG.COMMON.

Activate local Python 2 usage by setting RTEMS_CROSS_USE_LOCAL_PYTHON2 to “yes” (see common configuration variables).

Python 2 directory settings

Note

You usually don’t need to change these.

The installation base directory is given on the command line and Python 2 will be installed in directory “python2” below this.

If you want to fine-tune installation, build and source directories, you can do this by changing the following variables in file CONFIG.COMMON:

Note

$INSTALLTOP is defined by bin/setup.sh, $TOP is the directory where rtems-from-scratch is located

Variable

default value

explanation

PYTHON2_INSTALL_DIR

$INSTALLTOP/python2

Directory where Python 2 is installed

PYTHON2_SRC_DIR

$TOP/src/python2

Directory where Python 2 sources are put

PYTHON2_VERSION

2.7.18

Version of Python 2 that is built

PYTHON2_MAKE_OPTS

“-s -j”

Make options for Python 2

Prerequisites

Python 2 needs some libraries and tools to be installed on your system.

For Debian 12 they are listed here: Debian 12 Python 2 prerequisites.

Run the build script

The python 2 interpreter will be installed in directory PYTHON2_INSTALL_DIR.

Run:

bin/build-python2.sh

How to use Python 2

In file CONFIG.COMMON variable RTEMS_CROSS_USE_LOCAL_PYTHON2 must be set to “yes”.

The Python 2 interpreter is then found by build-crosstools.sh automatically.

If you want to this Python interpreter other applications, source file setenv.sh which is placed in directory $PYTHON2_INSTALL_DIR as it is defined in file CONFIG.COMMON.

If for example, you defined INSTALLTOP <setup> as ‘/usr/local/rtems’ and didn’t change PYTHON2_INSTALL_DIR in file CONFIG.COMMON the command would be:

. /usr/local/rtems/python2/setenv.sh

This redefines the PATH variable so Python 2 is found. Note that this also sets LD_LIBRARY_PATH.