Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / external / python3 / ExternalProject_python3.mk
blob6c958431cd97f1d3a37fda3e3c8cd5f9faaf0de0
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 $(eval $(call gb_ExternalProject_ExternalProject,python3))
12 $(eval $(call gb_ExternalProject_use_externals,python3,\
13 expat \
14 $(if $(filter LINUX,$(OS)),libffi) \
15 openssl \
16 zlib \
19 $(eval $(call gb_ExternalProject_register_targets,python3,\
20 build \
21 $(if $(filter MACOSX,$(OS)),\
22 fixscripts \
23 fixinstallnames \
24 executables \
25 removeunnecessarystuff \
26 ) \
29 ifeq ($(OS),WNT)
31 # TODO: using Debug configuration and related mangling of pyconfig.h
33 # at least for MSVC 2008 it is necessary to clear MAKEFLAGS because
34 # nmake is invoked
35 $(call gb_ExternalProject_get_state_target,python3,build) :
36 $(call gb_ExternalProject_run,build,\
37 MAKEFLAGS= MSBuild.exe pcbuild.sln /t:Build \
38 /p:Configuration=$(if $(MSVC_USE_DEBUG_RUNTIME),Debug,Release) \
39 /p:Platform=$(if $(filter INTEL,$(CPUNAME)),Win32,x64) \
40 /p:opensslIncludeDir=$(call gb_UnpackedTarball_get_dir,openssl)/include \
41 /p:opensslOutDir=$(call gb_UnpackedTarball_get_dir,openssl)/out32dll \
42 /p:zlibDir=$(call gb_UnpackedTarball_get_dir,zlib) \
43 /maxcpucount \
44 $(if $(filter 150,$(VCVER)),/p:PlatformToolset=v141 /p:VisualStudioVersion=15.0 /ToolsVersion:15.0) \
45 $(if $(filter 160,$(VCVER)),/p:PlatformToolset=v142 /p:VisualStudioVersion=16.0 /ToolsVersion:Current) \
46 $(if $(filter 10,$(WINDOWS_SDK_VERSION)),/p:WindowsTargetPlatformVersion=$(UCRTVERSION)) \
47 ,PCBuild)
49 else
51 # --with-system-expat: this should find the one in the workdir (or system)
53 # OPENSSL_INCLUDES OPENSSL_LDFLAGS OPENSSL_LIBS cannot be set via commandline!
54 # use --with-openssl instead, which requires include/ and lib/ subdirs.
56 # libffi is not all that stable, with 3 different SONAMEs currently, so we
57 # have to bundle it; --without-system-ffi does not work any more on Linux.
58 # Unfortuantely (as of 3.7) pkg-config is used to locate libffi so we do some
59 # hacks to find the libffi.pc in workdir by overriding PKG_CONFIG_LIBDIR.
60 # Also, pkg-config is only used to find the headers, the libdir needs to be
61 # passed extra.
63 # create a symlink "LO_lib" because the .so are in a directory with platform
64 # specific name like build/lib.linux-x86_64-3.3
66 python3_cflags = $(ZLIB_CFLAGS)
67 ifneq (,$(ENABLE_VALGRIND))
68 python3_cflags += $(VALGRIND_CFLAGS)
69 endif
71 $(call gb_ExternalProject_get_state_target,python3,build) :
72 $(call gb_ExternalProject_run,build,\
73 $(if $(filter MACOSX,$(OS)), \
74 $(if $(filter 10.8 10.9 10.10 10.11,$(MACOSX_DEPLOYMENT_TARGET)), \
75 ac_cv_func_getentropy=no \
76 ac_cv_func_clock_gettime=no \
77 ) \
78 ) \
79 ./configure \
80 $(if $(CROSS_COMPILING),--build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM)) \
81 $(if $(ENABLE_VALGRIND),--with-valgrind) \
82 --prefix=/python-inst \
83 --with-system-expat \
84 $(if $(filter AIX,$(OS)), \
85 --disable-ipv6 --with-threads OPT="-g0 -fwrapv -O3 -Wall", \
86 $(if $(gb_Module_CURRENTMODULE_DEBUG_ENABLED), \
87 OPT="$(gb_COMPILERNOOPTFLAGS) $(gb_DEBUGINFO_FLAGS)")) \
88 $(if $(filter MACOSX,$(OS)), \
89 $(if $(filter INTEL,$(CPUNAME)),--enable-universalsdk=$(MACOSX_SDK_PATH) \
90 --with-universal-archs=intel \
91 ) \
92 --enable-framework=/@__________________________________________________OOO --with-framework-name=LibreOfficePython, \
93 --enable-shared \
94 $(if $(filter 1090 101000 101100 101200,$(MAC_OS_X_VERSION_MIN_REQUIRED)),ac_cv_func_utimensat=no) \
95 ) \
96 $(if $(SYSTEM_OPENSSL)$(DISABLE_OPENSSL),,\
97 --with-openssl=$(call gb_UnpackedTarball_get_dir,openssl) \
98 ) \
99 $(if $(filter LINUX,$(OS)), \
100 PKG_CONFIG_LIBDIR="$(call gb_UnpackedTarball_get_dir,libffi)/$(HOST_PLATFORM)$${PKG_CONFIG_LIBDIR:+:$$PKG_CONFIG_LIBDIR}" \
102 CC="$(strip $(CC) \
103 $(if $(SYSTEM_EXPAT),,-I$(call gb_UnpackedTarball_get_dir,expat)/lib) \
104 $(if $(SYSBASE), -I$(SYSBASE)/usr/include) \
105 )" \
106 $(if $(python3_cflags),CFLAGS='$(python3_cflags)') \
107 $(if $(filter -fsanitize=%,$(CC)),LINKCC="$(CXX) -pthread") \
108 LDFLAGS="$(strip $(LDFLAGS) \
109 $(if $(filter LINUX,$(OS)),-L$(call gb_UnpackedTarball_get_dir,libffi)/$(HOST_PLATFORM)/.libs) \
110 $(if $(SYSTEM_EXPAT),,-L$(gb_StaticLibrary_WORKDIR)) \
111 $(if $(SYSTEM_ZLIB),,-L$(gb_StaticLibrary_WORKDIR)) \
112 $(if $(SYSBASE), -L$(SYSBASE)/usr/lib) \
113 $(gb_LTOFLAGS) \
114 )" \
115 && MAKEFLAGS= $(MAKE) \
116 $(if $(filter MACOSX,$(OS)),DESTDIR=$(EXTERNAL_WORKDIR)/python-inst install) \
117 $(if $(SYSTEM_ZLIB),,ZLIB_INCDIR=$(WORKDIR)/UnpackedTarball/zlib) \
118 && ln -s build/lib.* LO_lib \
121 endif
123 ifeq ($(OS),MACOSX)
125 python3_fw_prefix=$(call gb_UnpackedTarball_get_dir,python3)/python-inst/@__________________________________________________OOO/LibreOfficePython.framework
127 # rule to allow relocating the whole framework, removing reference to buildinstallation directory
128 $(call gb_ExternalProject_get_state_target,python3,fixscripts) : $(call gb_ExternalProject_get_state_target,python3,build)
129 $(call gb_Output_announce,python3 - remove reference to installroot from scripts,build,CUS,5)
130 $(COMMAND_ECHO)for file in \
131 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/2to3 \
132 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/2to3-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
133 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/idle$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
134 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/pydoc$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
135 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)-config \
136 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)m-config \
137 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/pyvenv-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) ; do \
138 { rm "$$file" && $(gb_AWK) '\
139 BEGIN {print "#!/bin/bash\n\
140 origpath=$$(pwd)\n\
141 bindir=$$(cd $$(dirname \"$$0\") ; pwd)\n\
142 cd \"$$origpath\"\n\
143 \"$$bindir/../Resources/Python.app/Contents/MacOS/LibreOfficePython\" - $$@ <<EOF"} \
144 FNR==1{next} \
145 {print} \
146 END {print "EOF"}' > "$$file" ; } < "$$file" ; chmod +x "$$file" ; done
147 touch $@
149 $(call gb_ExternalProject_get_state_target,python3,fixinstallnames) : $(call gb_ExternalProject_get_state_target,python3,build)
150 $(INSTALL_NAME_TOOL) -change \
151 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/LibreOfficePython \
152 @executable_path/../../../../LibreOfficePython \
153 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/Resources/Python.app/Contents/MacOS/LibreOfficePython
154 for file in $(shell $(FIND) $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib-dynload -name "*.so") ; do \
155 $(INSTALL_NAME_TOOL) -change \
156 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/LibreOfficePython \
157 @loader_path/../../../LibreOfficePython $$file ; done
158 touch $@
160 # also delete binaries that are symlinked in scp2
161 $(call gb_ExternalProject_get_state_target,python3,executables) : $(call gb_ExternalProject_get_state_target,python3,build)
162 cd $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin ; \
163 for file in python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
164 python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)m ; do \
165 $(INSTALL_NAME_TOOL) -change \
166 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/LibreOfficePython \
167 @executable_path/../LibreOfficePython $$file ; done
168 touch $@
170 $(call gb_ExternalProject_get_state_target,python3,removeunnecessarystuff) : $(call gb_ExternalProject_get_state_target,python3,build)
171 $(call gb_Output_announce,python3 - remove the stuff we don't need to ship,build,CUS,5)
172 rm -rf $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/test
174 endif
176 # vim: set noet sw=4 ts=4: