How to add the tool in the package "python_undef" to cpython Tools

This package is to analyse “<pyconfig.h>” and generate the “Python_undef.h” to undefine the macros in “pyconfig.h” if the macro doesn’t start with “Py”, “PY”, “_Py” or “_PY”. It will help to implement PEP743.

The imagine is:

  • On Unix system, when running the command make to compile, if the compiling is successful, it will run the python script to generate “pyconfig_undef.h”. Then make install will install both “pyconfig.h” and “pyconfig_undef.h” to “include/3.x.y/”
  • On windows, running “build.bat” will also do it.
  • The finally “legacy.h” may like this:
#ifndef Py_LEGACY_H
#define Py_LEGACY_H
#include <pyconfig_undef.h>
// Other C-API that needed to be omitted.
#endif /*Py_LEGACY_H*/

Reason

The “pyconfig.h” is automatically generated on Unix system, which means that this file is dynamic. To omit the macros in this file, the undefining file should be automatically generated too.

These macros which are not standard are used mainly for python building itself, a few that are needed when include “<Python.h>”, then they finish their tasks and need to be discarded, or they will distrub the other projects’ configure.

On windows, though it is frozen, for compatibility, it also defines some of these macros like on Unix.