Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / gbuild / GeneratedPackage.mk
blob751e3296fb934dfc86df9b69e216cc11dd239f29
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 GeneratedPackage
12 # Enables to deliver whole directories (of generated files) to instdir.
14 # GeneratedPackage shall be used as a substitution for Package when the
15 # names of the produced files are not known in advance (in older times,
16 # we used Zip in these places). It shall only be used to deliver files
17 # for installation.
19 # If you know the filenames in advance, use Package. Laziness is not an
20 # excuse.
22 gb_GeneratedPackage__get_srcdir = $(lastword $(subst <>, ,$(1)))
23 gb_GeneratedPackage__get_destdir = $(firstword $(subst <>, ,$(1)))
25 define gb_GeneratedPackage__command_cp
26 mkdir -p $(dir $(2)) && \
27 cp -R $(PACKAGE_SOURCEDIR)/$(1) $(2)
28 endef
30 define gb_GeneratedPackage__command
31 $(call gb_Output_announce,$(2),$(true),GPK,2)
32 $(call gb_Helper_abbreviate_dirs,\
33 rm -rf $(foreach pair,$(PACKAGE_DIRS),$(call gb_GeneratedPackage__get_destdir,$(pair))) && \
34 $(foreach pair,$(PACKAGE_DIRS),\
35 $(call gb_GeneratedPackage__command_cp,$(call gb_GeneratedPackage__get_srcdir,$(pair)),$(call gb_GeneratedPackage__get_destdir,$(pair))) &&) \
36 find \
37 $(foreach pair,$(PACKAGE_DIRS),$(call gb_GeneratedPackage__get_destdir,$(pair))) \
38 \( -type f -o -type l \) -print \
39 > $(1) \
41 endef
43 define gb_GeneratedPackage__check_dirs
44 $(if $(PACKAGE_DIRS),,$(call gb_Ouput_error,no dirs were added))
45 $(foreach pair,$(PACKAGE_DIRS),\
46 $(if $(wildcard $(PACKAGE_SOURCEDIR)/$(call gb_GeneratedPackage__get_srcdir,$(pair))),,\
47 $(call gb_Output_error,source dir $(PACKAGE_SOURCEDIR)/$(call gb_GeneratedPackage__get_srcdir,$(pair)) does not exist) \
48 ) \
51 endef
53 $(dir $(call gb_GeneratedPackage_get_target,%)).dir :
54 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
56 $(dir $(call gb_GeneratedPackage_get_target,%))%.dir :
57 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
59 $(call gb_GeneratedPackage_get_target,%) :
60 $(call gb_GeneratedPackage__check_dirs,$*)
61 $(call gb_GeneratedPackage__command,$@,$*)
63 .PHONY : $(call gb_GeneratedPackage_get_clean_target,%)
64 $(call gb_GeneratedPackage_get_clean_target,%) :
65 $(call gb_Output_announce,$*,$(false),GPK,2)
66 rm -rf $(call gb_GeneratedPackage_get_target,$*) $(PACKAGE_DIRS)
68 # Create a generated package.
70 # gb_GeneratedPackage_GeneratedPackage package srcdir
71 define gb_GeneratedPackage_GeneratedPackage
72 $(call gb_GeneratedPackage_get_target,$(1)) : PACKAGE_DIRS :=
73 $(call gb_GeneratedPackage_get_target,$(1)) : PACKAGE_SOURCEDIR := $(2)
74 $(call gb_GeneratedPackage_get_clean_target,$(1)) : PACKAGE_DIRS :=
76 $(call gb_GeneratedPackage_get_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
77 $(call gb_GeneratedPackage_get_target,$(1)) :| $(dir $(call gb_GeneratedPackage_get_target,$(1))).dir
79 $$(eval $$(call gb_Module_register_target,$(call gb_GeneratedPackage_get_target,$(1)),$(call gb_GeneratedPackage_get_clean_target,$(1))))
80 $(call gb_Helper_make_userfriendly_targets,$(1),GeneratedPackage)
82 endef
84 # Depend on a custom target.
86 # gb_GeneratedPackage_use_customtarget package custom-target
87 define gb_GeneratedPackage_use_customtarget
88 $(call gb_GeneratedPackage_get_target,$(1)) : $(call gb_CustomTarget_get_target,$(2))
90 endef
92 # Depend on an unpacked tarball.
94 # gb_GeneratedPackage_use_unpacked package unpacked
95 define gb_GeneratedPackage_use_unpacked
96 $(call gb_GeneratedPackage_get_target,$(1)) : $(call gb_UnpackedTarball_get_target,$(2))
98 endef
100 # Depend on an external project.
102 # gb_GeneratedPackage_use_external_project package project
103 define gb_GeneratedPackage_use_external_project
104 $(call gb_GeneratedPackage_get_target,$(1)) : $(call gb_ExternalProject_get_target,$(2))
106 endef
108 # Add a dir to the package.
110 # The srcdir will be copied to instdir as destdir.
112 # gb_GeneratedPackage_add_dir package destdir srcdir
113 define gb_GeneratedPackage_add_dir
114 $(call gb_GeneratedPackage_get_target,$(1)) : PACKAGE_DIRS += $(strip $(2))<>$(strip $(3))
115 $(call gb_GeneratedPackage_get_clean_target,$(1)) : PACKAGE_DIRS += $(2)
117 endef
119 # vim: set noet sw=4 ts=4: