This is an automated email from the ASF dual-hosted git repository.

cederom pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 4c6a6c7b162dde00e163a9e8766779e2a3c1e503
Author: Tiago Medicci <tiago.medi...@espressif.com>
AuthorDate: Tue Jan 21 17:32:37 2025 -0300

    interpreters/python: create Python's config files dynamically
    
    The `Setup.local` and the `config.site` files are used by Python's
    build system to, respectively, enable or disable Python's modules
    and set/unset available functions in the target system. These files
    are now set according to NuttX's configs, enabling or disabling
    Python's features according to the configs set on NuttX.
---
 interpreters/python/.gitignore                     |  2 ++
 interpreters/python/Makefile                       | 34 +++++++++++++++++++++-
 .../python/{Setup.local => Setup.local.in}         |  0
 .../python/{config.site => config.site.in}         |  4 +--
 4 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/interpreters/python/.gitignore b/interpreters/python/.gitignore
index ad58719cd..33efb9cbe 100644
--- a/interpreters/python/.gitignore
+++ b/interpreters/python/.gitignore
@@ -4,3 +4,5 @@
 /Python/
 /romfs_cpython_modules.h
 /romfs_cpython_modules.img
+/config.site
+/Setup.local
diff --git a/interpreters/python/Makefile b/interpreters/python/Makefile
index c478ec1e4..810904f50 100644
--- a/interpreters/python/Makefile
+++ b/interpreters/python/Makefile
@@ -32,6 +32,7 @@ UNPACK ?= unzip -q -o
 
 MACHDEP=nuttx
 CONFIG_SITE=${CURDIR}/config.site
+SETUP_LOCAL=${CURDIR}/Setup.local
 CPYTHON_PATH=$(CURDIR)/$(CPYTHON_UNPACKNAME)
 
 BUILDIR=$(CURDIR)/build
@@ -92,6 +93,35 @@ $(HOSTPYTHON):
                 )
        $(MAKE) -C $(HOSTBUILD) install
 
+# The `config.site` file contains settings that override the configuration
+# settings provided by the `configure` script. Depending on the features
+# enabled on NuttX, this file may need to be adjusted.
+
+$(CONFIG_SITE):
+       $(Q) ( cp $(CONFIG_SITE).in $(CONFIG_SITE))
+ifeq ($(CONFIG_ARCH_HAVE_FORK),y)
+       @echo "export ac_cv_func_fork=\"yes\"" >> $@
+else
+       @echo "export ac_cv_func_fork=\"no\"" >> $@
+endif
+ifeq ($(CONFIG_SYSTEM_SYSTEM),y)
+       @echo "export ac_cv_func_system=\"yes\"" >> $@
+else
+       @echo "export ac_cv_func_system=\"no\"" >> $@
+endif
+
+# The `Setup.local` file enables or disables Python modules.
+# Depending on the features enabled on NuttX, this file may need to be
+# adjusted. Please note that the base `Setup.local.in` file  only contains
+# a section to disable Python modules. Inserting lines to it will disable
+# such modules.
+
+$(SETUP_LOCAL):
+       $(Q) ( cp $(SETUP_LOCAL).in $(SETUP_LOCAL))
+ifneq ($(CONFIG_ARCH_HAVE_FORK),y)
+       @echo "_posixsubprocess" >> $@
+endif
+
 # For the Python's `configure` script, please consider the following
 # when building for NuttX:
 #
@@ -103,7 +133,7 @@ $(HOSTPYTHON):
 # Python/Modules/getpath.c (issue will be filed soon to track this
 # problem).
 
-$(TARGETBUILD)/Makefile: $(HOSTPYTHON)
+$(TARGETBUILD)/Makefile: $(HOSTPYTHON) $(CONFIG_SITE) $(SETUP_LOCAL)
        $(Q) mkdir -p $(TARGETBUILD)/Modules
        $(Q) mkdir -p $(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR)
        $(Q) ( cp Setup.local $(TARGETBUILD)/Modules/Setup.local )
@@ -177,5 +207,7 @@ distclean::
        $(call DELFILE, $(CPYTHON_ZIP))
        $(call DELFILE, romfs_cpython_modules.img)
        $(call DELFILE, romfs_cpython_modules.h)
+       $(call DELFILE, config.site)
+       $(call DELFILE, Setup.local)
 
 include $(APPDIR)/Application.mk
diff --git a/interpreters/python/Setup.local 
b/interpreters/python/Setup.local.in
similarity index 100%
rename from interpreters/python/Setup.local
rename to interpreters/python/Setup.local.in
diff --git a/interpreters/python/config.site 
b/interpreters/python/config.site.in
similarity index 95%
rename from interpreters/python/config.site
rename to interpreters/python/config.site.in
index 28313d75e..eb37e5a88 100644
--- a/interpreters/python/config.site
+++ b/interpreters/python/config.site.in
@@ -1,3 +1,4 @@
+export MODULE_BUILDTYPE="static"
 export ac_cv_file__dev_ptmx="no"
 export ac_cv_file__dev_ptc="no"
 export ac_cv_buggy_getaddrinfo="no"
@@ -15,10 +16,9 @@ export ac_cv_func_clock_gettime="yes"
 export ac_cv_header_sys_syscall_h="no"
 export ac_cv_func_timegm="yes"
 export ac_cv_func_clock="yes"
-export ac_cv_func_fork="yes"
 export ac_cv_func_waitpid="yes"
 export ac_cv_func_pipe="yes"
 export ac_cv_enable_strict_prototypes_warning="no"
 export ac_cv_func_getnameinfo="yes"
 export ac_cv_func_poll="yes"
-export MODULE_BUILDTYPE="static"
+export ac_cv_func_gethostname="yes"
\ No newline at end of file

Reply via email to