bump product version to 4.1.6.2
[LibreOffice.git] / solenv / gbuild / ExternalProject.mk
blob1749e9ac4d742c37dc823bc1ae8948a284b27e3d
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 ExternalProject
12 # Handles build of an external project
14 # Build of an external typically uses three gbuild classes:
15 # ExternalProject, ExternalPackage or Package, and UnpackedTarball. The
16 # first step is to prepare sources using UnpackedTarball. The tarball is
17 # passed to an ExternalProject, which handles the build proper and the
18 # results are delivered by an ExternalPackage (or Package, again;
19 # Package is sufficient if no files--e.g., headers--from the unpacked
20 # tarball need to be delivered.)
22 # An ExternalProject always uses one UnpackedTarball with the same name.
23 # The dependency strucure ensures that any change on a dependency
24 # of the ExternalProject will cause the UnpackedTarball to be unpacked
25 # again, so the ExternalProject always does a clean build and is not at
26 # the mercy of the external's build system's dubious incremental builds.
28 # ExternalProject target
29 # => ExternalProject state target(s) (these actually build stuff)
30 # => UnpackedTarball target (unpack the tarball)
31 # => UnpackedTarball prepare target
32 # => ExternalProject prepare target
33 # => stuff the external depends upon
35 # ExternalProject has no gbuild abstraction for actually building the
36 # external code, so it is necessary to define rule(s) and recipe(s) to
37 # handle it. It does not matter if there are several rules handling
38 # separate phases of the build (e.g., configure, build, install) or if
39 # the whole build is handled by one rule.
41 # ExternalProject uses two directories during the build: state dir
42 # serves to keep file targets that mark state of the build progress
43 # (e.g., "configure done", "build done") and the targets are accessible
44 # via gb_ExternalProject_get_state_target. It is highly advised to
45 # register them using gb_ExternalProject_register_targets. The second
46 # directory is work dir, accessible only from recipes via variable
47 # $(EXTERNAL_WORKDIR).
49 $(dir $(call gb_ExternalProject_get_statedir,%))%/.dir :
50 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
52 $(dir $(call gb_ExternalProject_get_target,%)).dir :
53 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
55 $(call gb_ExternalProject_get_preparation_target,%) :
56 touch $@
58 $(call gb_ExternalProject_get_target,%) :
59 $(call gb_Output_announce,$*,$(true),PRJ,3)
60 touch $@
62 .PHONY : $(call gb_ExternalProject_get_clean_target,%)
63 $(call gb_ExternalProject_get_clean_target,%) :
64 $(call gb_Output_announce,$*,$(false),PRJ,3)
65 $(call gb_Helper_abbreviate_dirs,\
66 rm -rf \
67 $(call gb_ExternalProject_get_target,$*) \
68 $(call gb_ExternalProject_get_statedir,$*) \
71 # Define a new external project, using an unpacked tarball of the same name
73 # gb_ExternalProject_ExternalProject project
74 define gb_ExternalProject_ExternalProject
75 $(call gb_ExternalProject_get_target,$(1)) : EXTERNAL_WORKDIR := $(call gb_UnpackedTarball_get_dir,$(1))
77 $(call gb_ExternalProject_get_preparation_target,$(1)) :| $(dir $(call gb_ExternalProject_get_target,$(1))).dir
78 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(call gb_ExternalProject_get_preparation_target,$(1))
79 $(call gb_ExternalProject_get_clean_target,$(1)) : $(call gb_UnpackedTarball_get_clean_target,$(1))
80 $(call gb_ExternalProject_get_target,$(1)) : $(call gb_UnpackedTarball_get_target,$(1))
81 $(call gb_ExternalProject_get_target,$(1)) :| $(dir $(call gb_ExternalProject_get_target,$(1))).dir
83 $$(eval $$(call gb_Module_register_target,$(call gb_ExternalProject_get_target,$(1)),$(call gb_ExternalProject_get_clean_target,$(1))))
84 $(call gb_Helper_make_userfriendly_targets,$(1),ExternalProject)
86 endef
88 # replaced by second parameter to ctor
89 define gb_ExternalProject_use_unpacked
90 $(call gb_Output_error,gb_ExternalProject_use_unpacked was removed)
91 endef
93 # Register a target in state directory
95 # This function defines proper dependencies for the target to ensure
96 # that:
97 # * the main target is updated if this target is updated
98 # * this target is updated if the unpacked tarball has changed.
100 # gb_ExternalProject_register_target project target
101 define gb_ExternalProject_register_target
102 $(call gb_ExternalProject_get_target,$(1)) : $(call gb_ExternalProject_get_state_target,$(1),$(2))
103 $(call gb_ExternalProject_get_state_target,$(1),$(2)) : $(call gb_UnpackedTarball_get_target,$(1))
104 $(call gb_ExternalProject_get_state_target,$(1),$(2)) :| $(dir $(call gb_ExternalProject_get_state_target,$(1),$(2))).dir
106 endef
108 # Register several targets at once
110 # gb_ExternalProject_register_targets project target(s)
111 define gb_ExternalProject_register_targets
112 $(foreach target,$(2),$(call gb_ExternalProject_register_target,$(1),$(target)))
114 endef
116 # Make an external Project depend on another ExternalProject
117 define gb_ExternalProject_use_external_project
118 $(call gb_ExternalProject_get_preparation_target,$(1)) : $(call gb_ExternalProject_get_target,$(2))
120 endef
122 # Make an ExternalProject depend on an external
124 # this forwards to functions that must be defined in RepositoryExternal.mk.
125 # $(eval $(call gb_ExternalProject_use_external,library,external))
126 define gb_ExternalProject_use_external
127 $(if $(filter undefined,$(origin gb_ExternalProject__use_$(2))),\
128 $(error gb_ExternalProject_use_external: unknown external: $(2)),\
129 $(call gb_ExternalProject__use_$(2),$(1)))
130 endef
132 define gb_ExternalProject_use_externals
133 $(foreach external,$(2),$(call gb_ExternalProject_use_external,$(1),$(external)))
134 endef
136 # Make an external project depend on a package
138 # This is most useful for depending on output files created by another
139 # ExternalProject.
141 # gb_ExternalProject_use_package external package
142 define gb_ExternalProject_use_package
143 $(call gb_ExternalProject_get_preparation_target,$(1)) : $(call gb_Package_get_target,$(2))
145 endef
147 # Make an external project depend on several packages at once
149 # gb_ExternalProject_use_packages external package(s)
150 define gb_ExternalProject_use_packages
151 $(foreach package,$(2),$(call gb_ExternalProject_use_package,$(1),$(package)))
153 endef
155 # Make an external project depend on a StaticLibrary
157 # Realistically there are some externals that do not have a usable build
158 # system, and other externals that do may depend on those.
160 # gb_ExternalProject_use_static_libraries external staticlibraries
161 define gb_ExternalProject_use_static_libraries
162 ifneq (,$$(filter-out $(gb_StaticLibrary_KNOWNLIBS),$(2)))
163 $$(eval $$(call gb_Output_info, currently known static libraries are: $(sort $(gb_StaticLibrary_KNOWNLIBS)),ALL))
164 $$(eval $$(call gb_Output_error,Cannot link against static library/libraries $$(filter-out $(gb_StaticLibrary_KNOWNLIBS),$(2)). Static libraries must be registered in Repository.mk))
165 endif
167 $(call gb_ExternalProject_get_preparation_target,$(1)) : \
168 $(foreach lib,$(2),$(call gb_StaticLibrary_get_target,$(lib)))
170 endef
172 # Make an external project depend on a Library
174 # Realistically there are some externals that do not have a usable build
175 # system, and other externals that do may depend on those.
177 # gb_ExternalProject_use_libraries external libraries
178 define gb_ExternalProject_use_libraries
179 ifneq (,$$(filter-out $(gb_Library_KNOWNLIBS),$(2)))
180 $$(eval $$(call gb_Output_info,currently known libraries are: $(sort $(gb_Library_KNOWNLIBS)),ALL))
181 $$(eval $$(call gb_Output_error,Cannot link against library/libraries $$(filter-out $(gb_Library_KNOWNLIBS),$(2)). Libraries must be registered in Repository.mk))
182 endif
183 ifneq (,$$(filter $$(gb_MERGEDLIBS),$(2)))
184 $$(eval $$(call gb_Output_error,Cannot link against library/libraries $$(filter $$(gb_MERGEDLIBS),$(2)) because they are merged.))
185 endif
187 $(call gb_ExternalProject_get_preparation_target,$(1)) : \
188 $(foreach lib,$(2),$(call gb_Library_get_target,$(lib)))
190 endef
192 # Run a target command
194 # This provides a wrapper that changes to the right directory,
195 # touches the 'target' if sucessful and also provides
196 # the ability to hide the output if there is no failure
197 # gb_ExternalProject_run,run_target,command,optional_extra_sub_directory,optional_log_filename)
198 # default log_filename is <run_target>.log
201 define gb_ExternalProject_run
202 $(call gb_Helper_print_on_error,cd $(EXTERNAL_WORKDIR)/$(3) && \
203 $(if $(WRAPPERS),export $(WRAPPERS) &&) \
204 $(2) && touch $@,$(EXTERNAL_WORKDIR)/$(if $(3),$(3)/,)$(if $(4),$(4),$(1).log))
205 endef
207 # vim: set noet sw=4 ts=4: