Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag

COMPONENT_TARGETS  = $(HARDWARE_INTEL_PC64)

NEED_ABS_PATH      = true
COMPONENT_IS_3PP   = true

CREATE_X86_32_PACKAGE = true


include ../../../build-system/constants.mk


SOURCE_REQUIRES    = sources/packages/d/python3

REQUIRES           = dev/python3/3.12.9
REQUIRES          += env/libuuid/2.40.4-x86_32
REQUIRES          += libs/libxcrypt/4.4.38-x86_32
REQUIRES          += app/xz/5.6.3-x86_32
REQUIRES          += app/bzip2/1.0.8-x86_32
REQUIRES          += app/sqlite/3.49.1.0-x86_32
REQUIRES          += libs/libffi/3.4.7-x86_32
REQUIRES          += libs/readline/8.2-x86_32
REQUIRES          += libs/expat/2.6.4-x86_32
REQUIRES          += libs/gdbm/1.24-x86_32
REQUIRES          += net/libnsl/2.0.1-x86_32
REQUIRES          += net/openssl/3.4.1-x86_32

# ======= __END_OF_REQUIRES__ =======


version            = 3.12.9
tar_xz_archive     = $(SRC_PACKAGE_PATH)/packages/d/python3/Python-$(version).tar.xz
SRC_ARCHIVE        = $(tar_xz_archive)
SRC_DIR            = $(TARGET_BUILD_DIR)/Python-$(version)
src_dir_name       = Python-$(version)
src_done           = $(TARGET_BUILD_DIR)/.source_done

scripts_dir        = $(CURDIR)/scripts

PATCHES = PATCHES

build_target       = $(TARGET_BUILD_DIR)/.build_done
install_target     = $(TARGET_BUILD_DIR)/.install_done

hw_cache_in        = $(CURDIR)/cross/hw.cache
hw_cache           = $(CURDIR)/$(SRC_DIR)/hw.cache

####### Targets

PKG_GROUP = dev
#
# *PKG_NAME & *PKG_VERSION shouldn't be a reference to value.
#
PYTHON32_PKG_NAME                = python3-x32
PYTHON32_PKG_VERSION             = 3.12.9
PYTHON32_PKG_ARCH                = $(PKGARCH)
PYTHON32_PKG_DISTRO_NAME         = $(DISTRO_NAME)
PYTHON32_PKG_DISTRO_VERSION      = $(DISTRO_VERSION)
PYTHON32_PKG_GROUP               = $(PKG_GROUP)
###                               |---handy-ruler-------------------------------|
PYTHON32_PKG_SHORT_DESCRIPTION   = interpreted programming language
PYTHON32_PKG_URL                 = $(BUG_URL)
PYTHON32_PKG_LICENSE             = GPLv2
PYTHON32_PKG_DESCRIPTION_FILE    = $(TARGET_BUILD_DIR)/$(PYTHON32_PKG_NAME)-pkg-description
PYTHON32_PKG_DESCRIPTION_FILE_IN = $(PYTHON32_PKG_NAME)-pkg-description.in
PYTHON32_PKG_INSTALL_SCRIPT      = $(PYTHON32_PKG_NAME)-pkg-install.sh

PYTHON32_PKG     = $(CURDIR)/$(TARGET_BUILD_DIR)/$(PYTHON32_PKG_NAME)-package

pkg_basename     = $(PYTHON32_PKG_NAME)-$(PYTHON32_PKG_VERSION)-$(PYTHON32_PKG_ARCH)-$(PYTHON32_PKG_DISTRO_NAME)-$(PYTHON32_PKG_DISTRO_VERSION)

pkg_archive      = $(TARGET_BUILD_DIR)/$(PKG_GROUP)/$(pkg_basename).$(pkg_arch_suffix)
pkg_certificate  = $(call cert-name,$(pkg_archive))
pkg_signature    = $(call sign-name,$(pkg_archive))
pkg_description  = $(call desc-name,$(pkg_archive))
products         = $(call pkg-files,$(pkg_archive))

BUILD_TARGETS    = $(build_target)
BUILD_TARGETS   += $(install_target)

PRODUCT_TARGETS  = $(products)

ROOTFS_TARGETS   = $(pkg_archive)


include ../../../build-system/core.mk


env_sysroot = DESTDIR=$(PYTHON32_PKG)

LDFLAGS    += -L.

extra_configure_switches  = --libdir=/usr/lib$(MULTILIB_X86_32_SUFFIX)
extra_configure_switches += --with-platlibdir=lib$(MULTILIB_X86_32_SUFFIX)
extra_configure_switches += --docdir=/usr/share/doc/$(src_dir_name)
extra_configure_switches += --mandir=/usr/share/man

extra_configure_switches += --bindir=/usr/bin/32

extra_configure_switches += --enable-ipv6
extra_configure_switches += --with-system-expat
extra_configure_switches += --with-openssl=$(TARGET_DEST_DIR)/usr
extra_configure_switches += --with-readline=readline
extra_configure_switches += --with-dbmliborder=gdbm:ndbm
extra_configure_switches += --enable-loadable-sqlite-extensions
extra_configure_switches += --without-ensurepip
extra_configure_switches += --with-tzpath=/usr/share/zoneinfo
extra_configure_switches += --enable-shared

extra_configure_switches += --with-build-python=$(PYTHON3)

extra_configure_switches += --cache-file=$(hw_cache)

python_environment  = RFS=$(TARGET_DEST_DIR)
python_environment += HOSTARCH=$(TARGET32)
python_environment += BUILDARCH=$(BUILD)

BUILD_ALIAS = $(shell echo $(BUILD) | sed 's,-gnu$$,,')

CFLAGS  += -Wno-array-bounds -Wno-stringop-overflow -Wno-stringop-truncation -Wimplicit-fallthrough=0
CFLAGS  += -Wno-maybe-uninitialized -Wno-type-limits -Wno-pointer-to-int-cast -Wno-cpp

LDFLAGS += -L. -Wl,-rpath,/lib$(MULTILIB_X86_32_SUFFIX):/usr/lib$(MULTILIB_X86_32_SUFFIX)


####### Dependencies

$(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
	$(UNPACK_SRC_ARCHIVE)
	$(APPLY_PATCHES)
	@( cd $(SRC_DIR) ; \
	   sed -i '1s|^#.*/usr/local/bin/python|#!/usr/bin/python3|' Lib/cgi.py ; \
	   sed -i 's|\("install",\)|\1 "--ignore-installed",|' Lib/ensurepip/__init__.py ; \
	   sed -i 's|#define HAVE_UUID_H 1|#define HAVE_UUID_UUID_H 1|g' configure ; \
	 )
	@touch $@

$(build_target): $(src_done)
	@cp -a $(hw_cache_in) $(hw_cache)
	@cd $(SRC_DIR) && $(BUILD_ENVIRONMENT) $(python_environment) ./configure \
	  --prefix=/usr               \
	  --build=$(BUILD)            \
	  --host=$(TARGET32)          \
	  $(extra_configure_switches)
	@cd $(SRC_DIR) && $(BUILD_ENVIRONMENT) $(python_environment) $(MAKE)
	@touch $@

$(install_target): $(build_target)
	@mkdir -p $(PYTHON32_PKG)
	@cd $(SRC_DIR) && $(BUILD_ENVIRONMENT) $(python_environment) $(MAKE) -j1 install $(env_sysroot)
	# ======= Install 2to3/3to2 scripts =======
	@mkdir -p $(PYTHON32_PKG)/usr/bin/32
	@cat $(scripts_dir)/python-2to3 > $(PYTHON32_PKG)/usr/bin/32/python-2to3
	@cat $(scripts_dir)/python-3to2 > $(PYTHON32_PKG)/usr/bin/32/python-3to2
	@chmod 0755 $(PYTHON32_PKG)/usr/bin/32/python-2to3
	@chmod 0755 $(PYTHON32_PKG)/usr/bin/32/python-3to2
	# ======= copy pyconfig.h for x86_32 =======
	@rm -rf $(PYTHON32_PKG)/usr/include/python3.12/cpython
	@rm -rf $(PYTHON32_PKG)/usr/include/python3.12/internal
	@( cd $(PYTHON32_PKG)/usr/include ; \
	   mv python3.12/pyconfig.h . ; \
	   rm -f python3.12/* ; \
	   mv pyconfig.h python3.12/pyconfig-32.h ; \
	 )
	@rm -rf $(PYTHON32_PKG)/usr/share
	@mkdir -p $(PYTHON32_PKG)/usr/lib$(MULTILIB_X86_32_SUFFIX)/python3.12/site-packages
	@( cd $(SRC_DIR) ; \
	   rm -rf Tools/buildbot ; \
	   mv Tools/README Tools/README.python-tools ; \
	   cp -a Tools/* \
	         $(PYTHON32_PKG)/usr/lib$(MULTILIB_X86_32_SUFFIX)/python3.12/site-packages \
	 )
	@mkdir -p $(PYTHON32_PKG)/usr/bin/32
	@( cd $(PYTHON32_PKG)/usr/bin/32 ; \
	   ln -sf ../../lib$(MULTILIB_X86_32_SUFFIX)/python3.12/site-packages/i18n/msgfmt.py msgfmt-3.12.py ; \
	   ln -sf ../../lib$(MULTILIB_X86_32_SUFFIX)/python3.12/site-packages/i18n/pygettext.py pygettext-3.12.py ; \
	 )
	# ======= tune python3.12-config CFLAGS for target machine =======
	@( cd $(PYTHON32_PKG)/usr/bin/32 ; \
	   sed -i 's,RESULT=\(\$$(dirname .*\)$$,RESULT=\$$(dirname \1),' python3.12-config ; \
	   sed -i 's,includedir=$$(echo "$${prefix},includedir=$$(echo "/usr,g' python3.12-config ; \
	   sed -i 's,LIBPL=$$(echo "$${prefix},LIBPL=$$(echo "/usr,g' python3.12-config ; \
	   sed -i "s,$(TARGET_DEST_DIR),,g" python3.12-config ; \
	 )
	# ======= Install the same to $(TARGET_DEST_DIR) =======
	$(call install-into-devenv, $(PYTHON32_PKG))
	# ======= tune pkg-config *.pc search path to the target destination for development =======
	@( cd $(TARGET_DEST_DIR)/usr/lib$(MULTILIB_X86_32_SUFFIX)/pkgconfig ; \
	   sed -i "s,/usr,$(TARGET_DEST_DIR)/usr,g" python-3.12.pc ; \
	 )
	# ======= tune target Python _sysconfigdata.py script =======
	@( cd $(PYTHON32_PKG)/usr/lib$(MULTILIB_X86_32_SUFFIX)/python3.12 ; \
	   PY_MACHDEP=`ls _sysconfigdata__*.py | cut -f4 -d'_'` ; \
	   PY_MULTIARCH=`ls _sysconfigdata__*.py | cut -f5,6 -d'_' | sed 's,\.py,,'` ; \
	   sed -i "s,$(CURDIR)/$(TARGET_BUILD_DIR),/usr/src,g" _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   sed -i "s,$(TARGET_DEST_DIR),,g"                    _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   sed -i "s,$(BUILD),$(TARGET),g"                     _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   sed -i "s,$(BUILD_ALIAS),$(TARGET),g"               _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   sed -i "s,$(CROSS_PREFIX),/usr/bin/,g"              _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   sed -i "s,$(BUILDSYSTEM),,g"                        _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   sed -i "s,--sysroot=,,g"                            _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	   host=`cat _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py | grep "'HOST_GNU_TYPE'" | sed "s,.*'HOST_GNU_TYPE': '\([^\']*\)'.*,\1,"` ; \
	   host=`echo "$$host" | sed 's,i686,x86_64,'` ; \
	   sed -i "s|\(BUILD_GNU_TYPE': '\).*$$|\1$$host',|" _sysconfigdata__$${PY_MACHDEP}_$${PY_MULTIARCH}.py ; \
	 )
	@chmod +w $(PYTHON32_PKG)/usr/lib$(MULTILIB_X86_32_SUFFIX)/libpython*.so*
	# ======= tune LIBPL config-3.12*/Makefile for target machine =======
	@( cd $(PYTHON32_PKG)/usr/lib$(MULTILIB_X86_32_SUFFIX)/python3.12 ; \
	   sed -i 's,$(CURDIR)/$(TARGET_BUILD_DIR),/usr/src,g' config-3.12*/Makefile ; \
	   sed -i "s,$(TARGET_DEST_DIR),,g"                    config-3.12*/Makefile ; \
	   sed -i 's,$(TOOLCHAIN_PATH),/usr,g'                 config-3.12*/Makefile ; \
	   sed -i "s,$(BUILD),$(TARGET),g"                     config-3.12*/Makefile ; \
	   sed -i "s,$(BUILD_ALIAS),$(TARGET),g"               config-3.12*/Makefile ; \
	   sed -i "s,$(BUILDSYSTEM),,g"                        config-3.12*/Makefile ; \
	   sed -i 's,$(TARGET)-,,g'                            config-3.12*/Makefile ; \
	   sed -i 's, --sysroot=,,g'                           config-3.12*/Makefile ; \
	   sed -i "s, '--cache-file=[^\']*',,g"                config-3.12*/Makefile ; \
	   host=`cat config-3.12*/Makefile | grep '^HOST_GNU_TYPE' | sed 's,HOST_GNU_TYPE=[ \t]*\(.*\)$$,\1,'` ; \
	   host=`echo "$$host" | sed 's,i686,x86_64,'` ; \
	   sed -i "s,\(^BUILD_GNU_TYPE=[ \t]*\).*,\1$$host,"   config-3.12*/Makefile ; \
	   sed -i "s,$(TARGET_DEST_DIR),,g"                    config-3.12*/Setup ; \
	 )
	# ======= Strip binaries =======
	@( cd $(PYTHON32_PKG) ; \
	   find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs $(STRIP) --strip-unneeded 2> /dev/null ; \
	   find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs $(STRIP) --strip-unneeded 2> /dev/null ; \
	 )
	@touch $@

$(PYTHON32_PKG_DESCRIPTION_FILE): $(PYTHON32_PKG_DESCRIPTION_FILE_IN)
	@cat $< | $(SED) -e "s/@VERSION@/$(version)/g" > $@

$(pkg_certificate) : $(pkg_archive) ;
$(pkg_signature)   : $(pkg_archive) ;
$(pkg_description) : $(pkg_archive) ;

$(pkg_archive): $(install_target) $(PYTHON32_PKG_DESCRIPTION_FILE) $(PYTHON32_PKG_INSTALL_SCRIPT)
	@cp $(PYTHON32_PKG_DESCRIPTION_FILE) $(PYTHON32_PKG)/.DESCRIPTION
	@cp $(PYTHON32_PKG_INSTALL_SCRIPT) $(PYTHON32_PKG)/.INSTALL
	@$(BUILD_PKG_REQUIRES) $(PYTHON32_PKG)/.REQUIRES
	@echo "pkgname=$(PYTHON32_PKG_NAME)"                            >  $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "pkgver=$(PYTHON32_PKG_VERSION)"                          >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "arch=$(PYTHON32_PKG_ARCH)"                               >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "distroname=$(PYTHON32_PKG_DISTRO_NAME)"                  >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "distrover=$(PYTHON32_PKG_DISTRO_VERSION)"                >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "group=$(PYTHON32_PKG_GROUP)"                             >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "short_description=\"$(PYTHON32_PKG_SHORT_DESCRIPTION)\"" >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "url=$(PYTHON32_PKG_URL)"                                 >> $(PYTHON32_PKG)/.PKGINFO ; \
	 echo "license=$(PYTHON32_PKG_LICENSE)"                         >> $(PYTHON32_PKG)/.PKGINFO
	@$(PSEUDO) sh -c "cd $(PYTHON32_PKG) && \
	                  chown -R root:root . && \
	                  $(MAKE_PACKAGE) -J --linkadd=yes $(GNUPG_OPTIONS) -m -d .. ."