• Building CPython from source, stripping executable

    From Keith Thompson@3:633/280.2 to All on Wed Feb 12 10:25:27 2025
    I'm building CPython 3.14.0a5 from source on Ubuntu 22.04.5.

    Is there some way to specify that the python3.14 executable should
    be stripped? (Stripping reduces the size of the executable from
    33M to 5.8M.)

    Of course I can run "strip" manually after installing, but I'm
    looking for a way to do it as part of the build.

    For a lot of software packages, invoking "make install-strip"
    rather than "make install" does this, but CPython's generated
    Makefile doesn't include this target.

    Diving into the Makefile, I see this:

    # Option to install to strip binaries
    STRIPFLAG=-s

    but STRIPFLAG is used only if PYTHONFRAMEWORKDIR is set, which
    seems to be Mac-specific.

    The Makefile also has:

    INSTALL= /usr/bin/install -c

    (The "-c" option is ignored by the GNU Coreutils install command.)
    I tried setting INSTALL to "install -s", and the installation
    failed because it tried to strip Python scripts as well as the
    python3.14 executable:

    install -s -m 644 ./Tools/gdb/libpython.py python-gdb.py
    strip: python-gdb.py: file format not recognized
    install: strip process terminated abnormally
    make: *** [Makefile:1117: python-gdb.py] Error 1

    Is there a straightforward way to strip executables during installation?

    If not, I'll run "strip" manually for now and submit an issue on <https://github.com/python/cpython/issues> suggesting adding an
    "install-strip" target to the Makefile.

    I don't think this is a new issue in 3.14.0a5; that's just where
    I happened to run into it.

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */

    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: None to speak of (3:633/280.2@fidonet)