bump product version to 4.1.6.2
[LibreOffice.git] / solenv / gbuild / ExternalExecutable.mk
blobd29a4fe5f504e5406c9c341acd96be8976a8a0f7
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 # class ExternalExecutable
12 # ExternalExecutable is a little helper for using executables that might
13 # either come from system or be built internally.
15 # === Setup ===
17 # An ExternalExecutable command consists of 4 parts:
18 # * precommand: any command line variables that need to be set
19 # * internal: unspecified command(s), possibly including calls of gdb,
20 # valgrind or icerun
21 # * executable: the executable, with or without path
22 # * arguments: command line arguments that are specific for either
23 # external or internal call, or that are common for _all_ uses of the
24 # executable
26 # The configuration is done in RepositoryExternal.mk by defining function
27 # gb_ExternalExecutable__register_EXECUTABLE, which can call up to 4
28 # functions:
29 # * gb_ExternalExecutable_set_external / gb_ExternalExecutable_set_internal
30 # * gb_ExternalExecutable_set_precommand
31 # * gb_ExternalExecutable_add_dependencies
32 # * gb_ExternalExecutable_add_arguments.
33 # If neither gb_ExternalExecutable_set_external nor
34 # gb_ExternalExecutable_set_internal is used, the executable defaults to
35 # the ExternalExecutable's name. Due to that, nothing needs to be set
36 # for an external executable in the typical case.
38 # All external executables must be registered (by listing the executable
39 # name in gb_ExternalExecutable_register_executables call). This is done in
40 # Repository.mk .
42 # === Usage ===
44 # The call site(s) should always use both of the following functions:
45 # * gb_ExternalExecutable_get_command: the complete command for the
46 # executable
47 # * gb_ExternalExecutable_get_dependencies: all run-time dependencies
48 # needed by the command.
50 ## Infrastructure functions
52 # The list of registered executables.
53 gb_ExternalExecutable_REGISTERED_EXECUTABLES :=
55 define gb_ExternalExecutable__add_executable
56 $(if $(filter $(executable),$(gb_ExternalExecutable_REGISTERED_EXECUTABLES)),\
57 $(call gb_Output_error,external executable $(executable) has already been registered) \
59 gb_ExternalExecutable_REGISTERED_EXECUTABLES += $(1)
61 endef
63 # Register one or more external executables.
65 # gb_ExternalExecutable_register_executables executable(s)
66 define gb_ExternalExecutable_register_executables
67 $(foreach executable,$(1),$(call gb_ExternalExecutable__add_executable,$(executable)))
69 endef
71 define gb_ExternalExecutable__process_registration
72 $(if $(filter undefined,$(origin gb_ExternalExecutable__register_$(executable))),\
73 $(call gb_Output_error,there is no definition for external executable $(executable)) \
75 $(call gb_ExternalExecutable__register_$(executable))
77 endef
79 # Collect definitions for registered executables.
81 # The registration functions will be run.
83 # gb_ExternalExecutable_collect_registrations
84 define gb_ExternalExecutable_collect_registrations
85 $(eval $(foreach executable,$(gb_ExternalExecutable_REGISTERED_EXECUTABLES),\
86 $(call gb_ExternalExecutable__process_registration,$(executable)))
89 endef
91 define gb_ExternalExecutale__check_registration
92 $(if $(filter $(1),$(gb_ExternalExecutable_REGISTERED_EXECUTABLES)),,\
93 $(call gb_Output_error,external executable $(1) has not been registered) \
96 endef
98 ## Setup functions
100 # Set the executable as external
102 # Optionally set a specific executable call to use.
103 # Example:
104 # $(call gb_ExternalExecutable_set_external,genbrk,$(SYSTEM_GENBRK))
106 # gb_ExternalExecutable_set_external executable call?
107 define gb_ExternalExecutable_set_external
108 $(if $(2),gb_ExternalExecutable_$(1)_EXECUTABLE := $(2))
110 endef
112 define gb_ExternalExecutable__set_internal
113 gb_ExternalExecutable_$(1)_EXECUTABLE := $(2)
114 gb_ExternalExecutable_$(1)_DEPENDENCIES := $(2)
115 gb_ExternalExecutable_$(1)_PRECOMMAND := $(gb_Helper_set_ld_path)
117 endef
119 # Set the executable as internal
121 # Optionally set a specific executable target to use (if the target
122 # returned by gb_Executable_get_target_for_build is not suitable).
124 # gb_ExternalExecutable_set_internal executable call?
125 define gb_ExternalExecutable_set_internal
126 $(call gb_ExternalExecutable__set_internal,$(1),$(if $(strip $(2)),$(2),$(call gb_Executable_get_target_for_build,$(1))))
128 endef
130 # Set pre-command for the executable
132 # This call should set any command line variables needed for the
133 # executable to run.
135 # gb_ExternalExecutable_set_precommand executable precommand
136 define gb_ExternalExecutable_set_precommand
137 gb_ExternalExecutable_$(1)_PRECOMMAND := $(2)
139 endef
141 # Add dependencies needed for running the executable
143 # Note that the dependencies should in most (if not all) cases be
144 # _for_build targets, or there might be problems in cross-compilation
145 # Specifically, not using _for_build target would mean either:
146 # * the target is built before the command even if it is not necessary
147 # (not really a problem, but might be a nuisance)
148 # * the build breaks because the target is not known. This might happen
149 # if there is a difference in configuration between build and host
150 # phases.
152 # gb_ExternalExecutable_add_dependencies executable dependencies
153 define gb_ExternalExecutable_add_dependencies
154 gb_ExternalExecutable_$(1)_DEPENDENCIES += $(2)
156 endef
158 # Add arguments needed for running the executable
160 # This should only contain arguments that differ between external and
161 # internal executable call or that are common for all call sites.
163 # gb_ExternalExecutable_add_arguments executable arguments
164 define gb_ExternalExecutable_add_arguments
165 gb_ExternalExecutable_$(1)_ARGUMENTS += $(2)
167 endef
169 ## User functions
171 gb_ExternalExecutable__get_internal := $(ICECREAM_RUN)
173 define gb_ExternalExecutable__get_executable
174 $(if $(gb_ExternalExecutable_$(1)_EXECUTABLE),$(gb_ExternalExecutable_$(1)_EXECUTABLE),$(1))
175 endef
177 define gb_ExternalExecutable__get_command
178 $(call gb_ExternalExecutale__check_registration,$(1))
179 $(gb_ExternalExecutable_$(1)_PRECOMMAND) \
180 $(call gb_ExternalExecutable__get_internal,$(1)) \
181 $(call gb_ExternalExecutable__get_executable,$(1)) \
182 $(gb_ExternalExecutable_$(1)_ARGUMENTS)
183 endef
185 # Return the command for running an external executable.
187 # The command includes the required shell variables, if any (e.g.,
188 # LD_LIBRARY_PATH for internally built executables), and icerun wrapper
189 # for limiting the maximum number of processes, if available.
191 # gb_ExternalExecutable_get_command executable
192 define gb_ExternalExecutable_get_command
193 $(strip $(call gb_ExternalExecutable__get_command,$(1)))
194 endef
196 define gb_ExternalExecutable__get_dependencies
197 $(call gb_ExternalExecutale__check_registration,$(1))
198 $(gb_ExternalExecutable_$(1)_DEPENDENCIES)
199 endef
201 # Return the dependencies needed for running an external executable.
203 # gb_ExternalExecutable_get_dependencies executable
204 define gb_ExternalExecutable_get_dependencies
205 $(strip $(call gb_ExternalExecutable__get_dependencies,$(1)))
206 endef
208 # vim: set noet sw=4 ts=4: