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
,\
15 $(if
$(filter WNT LINUX
,$(OS
)),libffi
) \
20 $(eval
$(call gb_ExternalProject_register_targets
,python3
,\
22 $(if
$(filter MACOSX
,$(OS
)),\
26 removeunnecessarystuff \
32 # TODO: using Debug configuration and related mangling of pyconfig.h
34 # at least for MSVC 2008 it is necessary to clear MAKEFLAGS because
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 \
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
; } }) \
52 $(call gb_Trace_EndRange
,python3
,EXTERNAL
)
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
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
)
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
)
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 \
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 \
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
, \
104 $(if
$(ENABLE_OPENSSL
),$(if
$(SYSTEM_OPENSSL
),,\
105 --with-openssl
=$(gb_UnpackedTarball_workdir
)/openssl \
107 $(if
$(filter LINUX
,$(OS
)), \
108 PKG_CONFIG_LIBDIR
="$(gb_UnpackedTarball_workdir)/libffi/$(HOST_PLATFORM)$${PKG_CONFIG_LIBDIR:+:$$PKG_CONFIG_LIBDIR}" \
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) \
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) \
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
)
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) \
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
/ && \
155 2to3-
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
) \
156 easy_install-
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
) \
157 idle
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
) \
158 pip
$(PYTHON_VERSION_MAJOR
) \
159 pip
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
) \
160 pydoc
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
) \
161 python
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)-config \
162 ; do
{ rm "$$file" && $(gb_AWK
) '\
163 BEGIN {print "#!/usr/bin/env bash\n\
165 bindir=$$(cd $$(dirname \"$$0\") ; pwd)\n\
167 \"$$bindir/../Resources/Python.app/Contents/MacOS/LibreOfficePython\" - $$@ <<EOF"} \
170 END {print "EOF"}' > "../Resources/$$file" ; } < "$$file" && \
171 chmod
+x
"../Resources/$$file" && ln
-s
"../Resources/$$file" ; done
174 $(call gb_ExternalProject_get_state_target
,python3
,fixinstallnames
) : $(call gb_ExternalProject_get_state_target
,python3
,build
) \
175 |
$(call gb_ExternalProject_get_state_target
,python3
,removeunnecessarystuff
)
176 $(INSTALL_NAME_TOOL
) -change \
177 $(python3_fw_prefix
)/Versions
/$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)/LibreOfficePython \
178 @executable_path
/..
/..
/..
/..
/LibreOfficePython \
179 $(python3_fw_prefix
)/Versions
/$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)/Resources
/Python.app
/Contents
/MacOS
/LibreOfficePython
180 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 \
181 $(INSTALL_NAME_TOOL
) -change \
182 $(python3_fw_prefix
)/Versions
/$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)/LibreOfficePython \
183 @loader_path
/..
/..
/..
/LibreOfficePython
$$file ; done
186 $(call gb_ExternalProject_get_state_target
,python3
,executables
) : $(call gb_ExternalProject_get_state_target
,python3
,build
)
187 cd
$(python3_fw_prefix
)/Versions
/$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)/bin
; \
188 $(INSTALL_NAME_TOOL
) -change \
189 $(python3_fw_prefix
)/Versions
/$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)/LibreOfficePython \
190 @executable_path
/..
/LibreOfficePython python
$(PYTHON_VERSION_MAJOR
).
$(PYTHON_VERSION_MINOR
)
193 # Remove modules (both Python and binary bits) of questionable usefulness that we don't ship on
194 # other platforms either. See the "packages not shipped" comment in ExternalPackage_python3.mk.
196 $(call gb_ExternalProject_get_state_target
,python3
,removeunnecessarystuff
) : $(call gb_ExternalProject_get_state_target
,python3
,build
)
197 $(call gb_Output_announce
,python3
- remove the stuff we don
't need to ship,build,CUS,5)
198 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/dbm
199 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/sqlite3
200 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/curses
201 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/idlelib
202 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/tkinter
203 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/turtledemo
204 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/test
205 rm -r $(python3_fw_prefix)/Versions/$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/lib/python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR)/venv
206 # Then the binary libraries
207 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
208 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
209 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
210 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
211 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
216 # vim: set noet sw=4 ts=4: