Drop unneeded indirection and unused argument
[LibreOffice.git] / external / python3 / ExternalProject_python3.mk
blob5bafc38e5260c6f0e483db4e60c3856375d7dbfe
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
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 bzip2 \
14 expat \
15 $(if $(filter WNT LINUX,$(OS)),libffi) \
16 openssl \
17 zlib \
20 $(eval $(call gb_ExternalProject_register_targets,python3,\
21 build \
22 $(if $(filter MACOSX,$(OS)),\
23 fixscripts \
24 fixinstallnames \
25 executables \
26 removeunnecessarystuff \
27 ) \
30 ifeq ($(OS),WNT)
32 # TODO: using Debug configuration and related mangling of pyconfig.h
34 # at least for MSVC 2008 it is necessary to clear MAKEFLAGS because
35 # nmake is invoked
36 $(call gb_ExternalProject_get_state_target,python3,build) :
37 $(call gb_Trace_StartRange,python3,EXTERNAL)
38 $(call gb_ExternalProject_run,build,\
39 MAKEFLAGS= MSBuild.exe pcbuild.sln /t:Build $(gb_MSBUILD_CONFIG_AND_PLATFORM) \
40 /p:bz2Dir=$(gb_UnpackedTarball_workdir)/bzip2 \
41 /p:opensslIncludeDir=$(gb_UnpackedTarball_workdir)/openssl/include \
42 /p:opensslOutDir=$(gb_UnpackedTarball_workdir)/openssl \
43 /p:zlibDir=$(gb_UnpackedTarball_workdir)/zlib \
44 /p:libffiOutDir=$(gb_UnpackedTarball_workdir)/libffi/$(HOST_PLATFORM)/.libs \
45 /p:libffiIncludeDir=$(gb_UnpackedTarball_workdir)/libffi/$(HOST_PLATFORM)/include \
46 /maxcpucount \
47 /p:PlatformToolset=$(VCTOOLSET) /p:VisualStudioVersion=$(VCVER) /ToolsVersion:Current \
48 $(if $(filter 10,$(WINDOWS_SDK_VERSION)),/p:WindowsTargetPlatformVersion=$(UCRTVERSION)) \
49 $(foreach i,$(python3_EXTENSION_MODULES), \
50 && { test -e ../$i || { printf 'Error: missing %s\n' $i; false; } }) \
51 ,PCBuild)
52 $(call gb_Trace_EndRange,python3,EXTERNAL)
54 else
56 # --with-system-expat: this should find the one in the workdir (or system)
58 # OPENSSL_INCLUDES OPENSSL_LDFLAGS OPENSSL_LIBS cannot be set via commandline!
59 # use --with-openssl instead, which requires include/ and lib/ subdirs.
61 # libffi is not all that stable, with 3 different SONAMEs currently, so we
62 # have to bundle it; --without-system-ffi does not work any more on Linux.
63 # Unfortunately (as of 3.7) pkg-config is used to locate libffi so we do some
64 # hacks to find the libffi.pc in workdir by overriding PKG_CONFIG_LIBDIR.
65 # Also, pkg-config is only used to find the headers, the libdir needs to be
66 # passed extra.
68 # create a symlink "LO_lib" because the .so are in a directory with platform
69 # specific name like build/lib.linux-x86_64-3.3
71 python3_cflags = $(ZLIB_CFLAGS)
72 ifneq (,$(ENABLE_VALGRIND))
73 python3_cflags += $(VALGRIND_CFLAGS)
74 endif
76 # This happens to override the -O3 in the default OPT set in
77 # workdir/UnpackedTarball/python3/configure.ac while keeping the other content of that OPT intact:
78 ifeq ($(ENABLE_OPTIMIZED),)
79 python3_cflags += $(gb_COMPILERNOOPTFLAGS)
80 endif
82 $(call gb_ExternalProject_get_state_target,python3,build) :
83 $(call gb_Trace_StartRange,python3,EXTERNAL)
84 $(call gb_ExternalProject_run,build,\
85 $(if $(filter MACOSX,$(OS)), \
86 $(if $(filter 10.8 10.9 10.10 10.11,$(MACOSX_DEPLOYMENT_TARGET)), \
87 ac_cv_func_getentropy=no \
88 ac_cv_func_clock_gettime=no \
89 ) \
90 ) \
91 $(gb_RUN_CONFIGURE) ./configure \
92 $(gb_CONFIGURE_PLATFORMS) \
93 $(if $(ENABLE_VALGRIND),--with-valgrind) \
94 $(if $(ENABLE_DBGUTIL),--with-pydebug) \
95 --prefix=/python-inst \
96 --with-system-expat \
97 $(if $(filter MACOSX,$(OS)), \
98 $(if $(filter INTEL,$(CPUNAME)),--enable-universalsdk=$(MACOSX_SDK_PATH) \
99 --with-universal-archs=intel \
101 --enable-framework=/@__________________________________________________OOO --with-framework-name=LibreOfficePython, \
102 --enable-shared \
104 $(if $(ENABLE_OPENSSL),$(if $(SYSTEM_OPENSSL),,\
105 --with-openssl=$(gb_UnpackedTarball_workdir)/openssl \
106 ) ) \
107 $(if $(filter LINUX,$(OS)), \
108 PKG_CONFIG_LIBDIR="$(gb_UnpackedTarball_workdir)/libffi/$(HOST_PLATFORM)$${PKG_CONFIG_LIBDIR:+:$$PKG_CONFIG_LIBDIR}" \
110 CC="$(strip $(CC) \
111 $(if $(filter -fsanitize=undefined,$(CC)),-fno-sanitize=function) \
112 $(if $(SYSTEM_BZIP2),,-I$(gb_UnpackedTarball_workdir)/bzip2) \
113 $(if $(SYSTEM_EXPAT),,-I$(gb_UnpackedTarball_workdir)/expat/lib) \
114 $(if $(SYSBASE), -I$(SYSBASE)/usr/include) \
115 )" \
116 $(if $(python3_cflags),CFLAGS='$(python3_cflags)') \
117 $(if $(filter -fsanitize=%,$(CC)),LINKCC="$(CXX) -pthread") \
118 LDFLAGS="$(strip $(LDFLAGS) \
119 $(if $(filter LINUX,$(OS)),-L$(gb_UnpackedTarball_workdir)/libffi/$(HOST_PLATFORM)/.libs) \
120 $(if $(SYSTEM_BZIP2),,-L$(gb_UnpackedTarball_workdir)/bzip2) \
121 $(if $(SYSTEM_EXPAT),,-L$(gb_StaticLibrary_WORKDIR)) \
122 $(if $(SYSTEM_ZLIB),,-L$(gb_StaticLibrary_WORKDIR)) \
123 $(if $(SYSBASE), -L$(SYSBASE)/usr/lib) \
124 $(gb_LTOFLAGS) \
125 )" \
126 && MAKEFLAGS= $(MAKE) \
127 $(if $(filter MACOSX,$(OS)),DESTDIR=$(EXTERNAL_WORKDIR)/python-inst install) \
128 $(if $(SYSTEM_ZLIB),,ZLIB_INCDIR=$(WORKDIR)/UnpackedTarball/zlib) \
129 && ln -s build/lib.* LO_lib \
130 $(foreach i,$(python3_EXTENSION_MODULES), \
131 && { test -e $i || { printf 'Error: missing %s\n' $i; false; } }) \
133 $(call gb_Trace_EndRange,python3,EXTERNAL)
135 endif
137 # If you want to run Python's own unit tests, add this to the chain of commands above:
138 # && MAKEFLAGS= $(MAKE) \
139 # $(if $(filter MACOSX,$(OS)),DESTDIR=$(EXTERNAL_WORKDIR)/python-inst) \
140 # $(if $(SYSTEM_ZLIB),,ZLIB_INCDIR=$(WORKDIR)/UnpackedTarball/zlib) \
141 # test \
143 ifeq ($(OS),MACOSX)
145 python3_fw_prefix=$(gb_UnpackedTarball_workdir)/python3/python-inst/@__________________________________________________OOO/LibreOfficePython.framework
147 # rule to allow relocating the whole framework, removing reference to buildinstallation directory
148 # also scripts are not allowed to be signed as executables (with extended attributes), but need to
149 # be treated as data/put into Resources folder, see also
150 # https://developer.apple.com/library/archive/technotes/tn2206/_index.html
151 $(call gb_ExternalProject_get_state_target,python3,fixscripts) : $(call gb_ExternalProject_get_state_target,python3,build)
152 $(call gb_Output_announce,python3 - remove reference to installroot from scripts,build,CUS,5)
153 $(COMMAND_ECHO)cd $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin/ && \
154 for file in \
155 2to3-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
156 idle$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
157 pip$(PYTHON_VERSION_MAJOR) \
158 pip$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
159 pydoc$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) \
160 python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)-config \
161 ; do { rm "$$file" && $(gb_AWK) '\
162 BEGIN {print "#!/usr/bin/env bash\n\
163 origpath=$$(pwd)\n\
164 bindir=$$(cd $$(dirname \"$$0\") ; pwd)\n\
165 cd \"$$origpath\"\n\
166 \"$$bindir/../Resources/Python.app/Contents/MacOS/LibreOfficePython\" - $$@ <<EOF"} \
167 FNR==1{next} \
168 {print} \
169 END {print "EOF"}' > "../Resources/$$file" ; } < "$$file" && \
170 chmod +x "../Resources/$$file" && ln -s "../Resources/$$file" ; done
171 touch $@
173 $(call gb_ExternalProject_get_state_target,python3,fixinstallnames) : $(call gb_ExternalProject_get_state_target,python3,build) \
174 | $(call gb_ExternalProject_get_state_target,python3,removeunnecessarystuff)
175 $(INSTALL_NAME_TOOL) -change \
176 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/LibreOfficePython \
177 @executable_path/../../../../LibreOfficePython \
178 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/Resources/Python.app/Contents/MacOS/LibreOfficePython
179 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 \
180 $(INSTALL_NAME_TOOL) -change \
181 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/LibreOfficePython \
182 @loader_path/../../../LibreOfficePython $$file ; done
183 touch $@
185 $(call gb_ExternalProject_get_state_target,python3,executables) : $(call gb_ExternalProject_get_state_target,python3,build)
186 cd $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/bin ; \
187 $(INSTALL_NAME_TOOL) -change \
188 $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/LibreOfficePython \
189 @executable_path/../LibreOfficePython python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)
190 touch $@
192 # Remove modules (both Python and binary bits) of questionable usefulness that we don't ship on
193 # other platforms either. See the "packages not shipped" comment in ExternalPackage_python3.mk.
195 $(call gb_ExternalProject_get_state_target,python3,removeunnecessarystuff) : $(call gb_ExternalProject_get_state_target,python3,build)
196 $(call gb_Output_announce,python3 - remove the stuff we don't need to ship,build,CUS,5)
197 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/dbm
198 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/sqlite3
199 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/curses
200 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/idlelib
201 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/tkinter
202 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/turtledemo
203 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/test
204 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/venv
205 # Then the binary libraries
206 rm $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib-dynload/_dbm.cpython-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)*.so
207 rm $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib-dynload/_sqlite3.cpython-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)*.so
208 rm $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib-dynload/_curses.cpython-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)*.so
209 rm $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib-dynload/_curses_panel.cpython-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)*.so
210 rm $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib-dynload/_test*.cpython-$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)*.so
211 touch $@
213 endif
215 # vim: set noet sw=4 ts=4: