Bump version to 6.4.7.2.M8
[LibreOffice.git] / solenv / gbuild / Package.mk
blob45a56ff4447814fbd606d7e00d5359847383db76
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/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 # PackagePart class
23 # a pattern rule with multiple targets is actually executed only once for each
24 # match, so define only pattern rules with one target here
25 # the .dir is for make 3.81, which ignores trailing /
26 define gb_PackagePart__rule
27 $(1)/.dir :
28 $$(if $$(wildcard $$(dir $$@)),,mkdir -p $$(dir $$@))
29 $(1)/%/.dir :
30 $$(if $$(wildcard $$(dir $$@)),,mkdir -p $$(dir $$@))
31 $(1)/% :
32 $$(call gb_Deliver_deliver,$$<,$$@)
33 endef
35 $(foreach destination,$(call gb_PackagePart_get_destinations),$(eval \
36 $(call gb_PackagePart__rule,$(destination))))
38 # Deliver one file to the output dir.
40 # gb_PackagePart_PackagePart destfile source prep-target outdir
41 define gb_PackagePart_PackagePart
42 $(4)/$(1) : $(2) | $(dir $(4)/$(1)).dir
43 $(2) :| $(3)
45 $(if $(gb_Package_PRESTAGEDIR),\
46 $(if $(wildcard $(gb_Package_PRESTAGEDIR)/$(1)),\
47 $(call gb_Deliver_add_deliverable,$(4)/$(1),$(gb_Package_PRESTAGEDIR)/$(1),$(3)),\
48 $(call gb_Deliver_add_deliverable,$(4)/$(1),$(2),$(3)) \
49 ),\
50 $(call gb_Deliver_add_deliverable,$(4)/$(1),$(2),$(3)) \
53 endef
56 # Package class
58 $(dir $(call gb_Package_get_target,%)).dir :
59 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
61 $(dir $(call gb_Package_get_target,%))%/.dir :
62 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
64 .PHONY : $(call gb_Package_get_clean_target,%)
65 $(call gb_Package_get_clean_target,%) :
66 $(call gb_Output_announce,$*,$(false),PKG,2)
67 RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),500,$(FILES)) \
68 && cat $${RESPONSEFILE} | $(if $(filter WNT,$(OS)),env -i PATH="$$PATH") xargs $(if $(filter MACOSX,$(OS_FOR_BUILD)),-n 1000) rm -f \
69 && rm -f $${RESPONSEFILE}
71 $(call gb_Package_get_preparation_target,%) :
72 mkdir -p $(dir $@) && touch $@
74 # NOTE: It is possible that a file has been added to the package more
75 # than once, so we must drop the duplicates, or Windows installer will
76 # be unhappy.
77 # TODO: this is only for convenience for impl. of gbuild classes. There
78 # should be check that it does not happen in "normal" use, i.e., in
79 # Package_foo makefiles.
80 $(call gb_Package_get_target,%) :
81 $(call gb_Output_announce,$*,$(true),PKG,2)
82 $(if $(PACKAGE_DEFINED),,$(call gb_Output_error,Something depends on package $* which does not exist.))
83 rm -f $@ && \
84 mv $(call var2file,$@.tmp,100,$(sort $(call gb_Package_get_files,$*))) $@
86 # for other targets that want to create Packages, does not register at Module
87 define gb_Package_Package_internal
88 gb_Package_SOURCEDIR_$(1) := $(2)
89 gb_Package_OUTDIR_$(1) := $(INSTROOT)
90 $(call gb_Package_get_target,$(1)) : PACKAGE_DEFINED := $(true)
91 gb_Package_$(1)_FILES :=
92 $(call gb_Package_get_clean_target,$(1)) : override FILES := $(call gb_Package_get_target,$(1)) $(call gb_Package_get_preparation_target,$(1))
93 $(call gb_Package_get_target,$(1)) : $(call gb_Package_get_preparation_target,$(1))
94 $(call gb_Package_get_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
95 $(call gb_Package_get_target,$(1)) :| $(dir $(call gb_Package_get_target,$(1))).dir
97 endef
99 define gb_Package_Package
100 $$(if $$(gb_Package_SOURCEDIR_$(1)),$$(call gb_Output_error,gb_Package__check: Package $(1) has already been defined))
101 $(if $(filter postprocess% instsetoo_native%,$(1)),,\
102 $(call gb_Postprocess_register_target,AllPackages,Package,$(1)))
103 ifeq (,$$(filter $(1),$$(gb_Package_REGISTERED)))
104 $$(eval $$(call gb_Output_info,Currently known packages are: $(sort $(gb_Package_REGISTERED)),ALL))
105 $$(eval $$(call gb_Output_error,Package $(1) must be registered in Repository.mk or RepositoryExternal.mk))
106 endif
107 $(call gb_Package_Package_internal,$(1),$(2))
108 $$(eval $$(call gb_Module_register_target,Package_$(1),$(call gb_Package_get_target,$(1)),$(call gb_Package_get_clean_target,$(1))))
109 $(call gb_Helper_make_userfriendly_targets,$(1),Package)
111 endef
113 # Ensure that the package is defined.
115 # gb_Package__check package
116 define gb_Package__check
117 $$(if $$(gb_Package_SOURCEDIR_$(1)),,$$(call gb_Output_error,gb_Package__check: Package $(1) has not been defined))
119 endef
121 # Set output dir for the package files.
123 # Default is $(INSTROOT).
125 # gb_Package_set_outdir package outdir
126 define gb_Package_set_outdir
127 $(call gb_Package__check,$(1))
128 gb_Package_OUTDIR_$(1) := $(2)
130 endef
132 # Add empty directory (if it's non-empty, don't use this, use
133 # gb_Package_add_file for the files in it instead!)
134 define gb_Package_add_empty_directory
135 $(call gb_Package__check,$(1))
136 $(if $(strip $(2)),,$(call gb_Output_error,gb_Package_add_directory requires 2 arguments))
137 $(call gb_Package_get_target,$(1)) :| $$(gb_Package_OUTDIR_$(1))/$(2)/.dir
138 gb_Package_$(1)_FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
139 $(call gb_Package_get_clean_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
141 endef
143 # Example:
144 # $(eval $(call gb_Package_add_empty_directories,foo_inc,inc/foo))
145 # # -> inc/foo
146 define gb_Package_add_empty_directories
147 $(call gb_Package__check,$(1))
148 $(foreach file,$(2),$(call gb_Package_add_empty_directory,$(1),$(file)))
150 endef
152 define gb_Package_add_symbolic_link
153 $(call gb_Package__check,$(1))
154 $(if $(strip $(3)),,$(call gb_Output_error,gb_Package_add_symbolic_link requires 3 arguments))
155 $(call gb_Package_get_target,$(1)) : $$(gb_Package_OUTDIR_$(1))/$(2)
156 $$(gb_Package_OUTDIR_$(1))/$(2) :| $$(dir $$(gb_Package_OUTDIR_$(1))/$(2)).dir
157 rm -f $$@ && ln -s $(3) $$@
159 gb_Package_$(1)_FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
160 $(call gb_Package_get_clean_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
162 endef
164 define gb_Package_add_file
165 $(call gb_Package__check,$(1))
166 $(if $(strip $(3)),,$(call gb_Output_error,gb_Package_add_file requires 3 arguments))
167 $(call gb_Package_get_target,$(1)) : $$(gb_Package_OUTDIR_$(1))/$(2)
168 gb_Package_$(1)_FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
169 $(call gb_Package_get_clean_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
170 $(call gb_PackagePart_PackagePart,$(2),$$(gb_Package_SOURCEDIR_$(1))/$(3),$(call gb_Package_get_preparation_target,$(1)),$$(gb_Package_OUTDIR_$(1)))
172 endef
174 # Returns the list of files of a package
175 gb_Package_get_files = $(gb_Package_$(1)_FILES)
177 # Adds several files at once.
179 # Files are copied directly into the specified directory.
181 # Example:
182 # $(eval $(call gb_Package_Package,foo_inc,$(SRCDIR)/foo/inc))
183 # $(eval $(call gb_Package_add_files,foo_inc,inc/foo,foo/bar/foo.hxx))
184 # # -> inc/foo/foo.hxx
185 define gb_Package_add_files
186 $(call gb_Package__check,$(1))
187 $(if $(strip $(3)),,$(if $(filter 1,$(words $(2))),,$(call gb_Output_error,gb_Package_add_files: it looks like either pkg name or dest. dir is missing)))
188 $(foreach file,$(3),$(call gb_Package_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
190 endef
192 # Adds several files at once.
194 # Files are copied including subdirectories.
196 # Example:
197 # $(eval $(call gb_Package_Package,foo_inc,$(SRCDIR)/foo/inc))
198 # $(eval $(call gb_Package_add_files,foo_inc,inc,foo/bar/foo.hxx))
199 # # -> inc/foo/bar/foo.hxx
200 define gb_Package_add_files_with_dir
201 $(call gb_Package__check,$(1))
202 $(if $(strip $(3)),,$(if $(filter 1,$(words $(2))),,$(call gb_Output_error,gb_Package_add_files: it looks like either pkg name or dest. dir is missing)))
203 $(foreach file,$(3),$(call gb_Package_add_file,$(1),$(2)/$(file),$(file)))
205 endef
207 # Package files from custom target
208 define gb_Package_use_custom_target
209 $(call gb_Package__check,$(1))
210 $(call gb_Package_get_preparation_target,$(1)) :| $(call gb_CustomTarget_get_target,$(2))
212 endef
214 # Package files from unpacked tarball of an external project
215 define gb_Package_use_unpacked
216 $(call gb_Package__check,$(1))
217 $(call gb_Package_get_preparation_target,$(1)) :| $(call gb_UnpackedTarball_get_target,$(2))
219 endef
221 # Package files from build of an external project
222 define gb_Package_use_external_project
223 $(call gb_Package__check,$(1))
224 $(call gb_Package_get_preparation_target,$(1)) :| $(call gb_ExternalProject_get_target,$(2))
226 endef
228 # vim: set noet sw=4: