The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / pkg-utils.mk
1 ################################################################################
2 #
3 # This file contains various utility functions used by the package
4 # infrastructure, or by the packages themselves.
5 #
6 ################################################################################
7
8 # Case conversion macros. This is inspired by the 'up' macro from gmsl
9 # (http://gmsl.sf.net). It is optimised very heavily because these macros
10 # are used a lot. It is about 5 times faster than forking a shell and tr.
11 #
12 # The caseconvert-helper creates a definition of the case conversion macro.
13 # After expansion by the outer $(eval ), the UPPERCASE macro is defined as:
14 # $(strip $(eval __tmp := $(1))  $(eval __tmp := $(subst a,A,$(__tmp))) ... )
15 # In other words, every letter is substituted one by one.
16 #
17 # The caseconvert-helper allows us to create this definition out of the
18 # [FROM] and [TO] lists, so we don't need to write down every substition
19 # manually. The uses of $ and $$ quoting are chosen in order to do as
20 # much expansion as possible up-front.
21 #
22 # Note that it would be possible to conceive a slightly more optimal
23 # implementation that avoids the use of __tmp, but that would be even
24 # more unreadable and is not worth the effort.
25
26 [FROM] := a b c d e f g h i j k l m n o p q r s t u v w x y z - .
27 [TO]   := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ _
28
29 define caseconvert-helper
30 $(1) = $$(strip \
31         $$(eval __tmp := $$(1))\
32         $(foreach c, $(2),\
33                 $$(eval __tmp := $$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$$(__tmp))))\
34         $$(__tmp))
35 endef
36
37 $(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO]))))
38 $(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))
39
40 # Sanitize macro cleans up generic strings so it can be used as a filename
41 # and in rules. Particularly useful for VCS version strings, that can contain
42 # slashes, colons (OK in filenames but not in rules), and spaces.
43 sanitize = $(subst $(space),_,$(subst :,_,$(subst /,_,$(strip $(1)))))
44
45 #
46 # Manipulation of .config files based on the Kconfig
47 # infrastructure. Used by the BusyBox package, the Linux kernel
48 # package, and more.
49 #
50
51 define KCONFIG_ENABLE_OPT # (option, file)
52         $(SED) "/\\<$(1)\\>/d" $(2)
53         echo '$(1)=y' >> $(2)
54 endef
55
56 define KCONFIG_SET_OPT # (option, value, file)
57         $(SED) "/\\<$(1)\\>/d" $(3)
58         echo '$(1)=$(2)' >> $(3)
59 endef
60
61 define KCONFIG_DISABLE_OPT # (option, file)
62         $(SED) "/\\<$(1)\\>/d" $(2)
63         echo '# $(1) is not set' >> $(2)
64 endef
65
66 # Helper functions to determine the name of a package and its
67 # directory from its makefile directory, using the $(MAKEFILE_LIST)
68 # variable provided by make. This is used by the *-package macros to
69 # automagically find where the package is located.
70 pkgdir = $(dir $(lastword $(MAKEFILE_LIST)))
71 pkgname = $(lastword $(subst /, ,$(pkgdir)))
72
73 # Define extractors for different archive suffixes
74 INFLATE.bz2  = $(BZCAT)
75 INFLATE.gz   = $(ZCAT)
76 INFLATE.tbz  = $(BZCAT)
77 INFLATE.tbz2 = $(BZCAT)
78 INFLATE.tgz  = $(ZCAT)
79 INFLATE.xz   = $(XZCAT)
80 INFLATE.tar  = cat
81 # suitable-extractor(filename): returns extractor based on suffix
82 suitable-extractor = $(INFLATE$(suffix $(1)))
83
84 # MESSAGE Macro -- display a message in bold type
85 MESSAGE = echo "$(TERM_BOLD)>>> $($(PKG)_NAME) $($(PKG)_VERSION) $(call qstrip,$(1))$(TERM_RESET)"
86 TERM_BOLD := $(shell tput smso)
87 TERM_RESET := $(shell tput rmso)
88
89 # Utility functions for 'find'
90 # findfileclauses(filelist) => -name 'X' -o -name 'Y'
91 findfileclauses = $(call notfirstword,$(patsubst %,-o -name '%',$(1)))
92 # finddirclauses(base, dirlist) => -path 'base/dirX' -o -path 'base/dirY'
93 finddirclauses = $(call notfirstword,$(patsubst %,-o -path '$(1)/%',$(2)))
94
95 # Miscellaneous utility functions
96 # notfirstword(wordlist): returns all but the first word in wordlist
97 notfirstword = $(wordlist 2,$(words $(1)),$(1))
98
99 # Needed for the foreach loops to loop over the list of hooks, so that
100 # each hook call is properly separated by a newline.
101 define sep
102
103
104 endef
105
106 # check-deprecated-variable -- throw an error on deprecated variables
107 # example:
108 #   $(eval $(call check-deprecated-variable,FOO_MAKE_OPT,FOO_MAKE_OPTS))
109 define check-deprecated-variable # (deprecated var, new var)
110 ifneq ($$(origin $(1)),undefined)
111 $$(error Package error: use $(2) instead of $(1). Please fix your .mk file)
112 endif
113 endef
114
115 #
116 # legal-info helper functions
117 #
118 LEGAL_INFO_SEPARATOR = "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
119
120 define legal-warning # text
121         echo "WARNING: $(1)" >>$(LEGAL_WARNINGS)
122 endef
123
124 define legal-warning-pkg # pkg, text
125         echo "WARNING: $(1): $(2)" >>$(LEGAL_WARNINGS)
126 endef
127
128 define legal-warning-nosource # pkg, {local|override}
129         $(call legal-warning-pkg,$(1),sources not saved ($(2) packages not handled))
130 endef
131
132 define legal-manifest # pkg, version, license, license-files, source, url, {HOST|TARGET}
133         echo '"$(1)","$(2)","$(3)","$(4)","$(5)","$(6)"' >>$(LEGAL_MANIFEST_CSV_$(7))
134 endef
135
136 define legal-license-header # pkg, license-file, {HOST|TARGET}
137         printf "$(LEGAL_INFO_SEPARATOR)\n\t$(1):\
138                 $(2)\n$(LEGAL_INFO_SEPARATOR)\n\n\n" >>$(LEGAL_LICENSES_TXT_$(3))
139 endef
140
141 define legal-license-nofiles # pkg, {HOST|TARGET}
142         $(call legal-license-header,$(1),unknown license file(s),$(2))
143 endef
144
145 define legal-license-file # pkg, filename, file-fullpath, {HOST|TARGET}
146         $(call legal-license-header,$(1),$(2) file,$(4)) && \
147         cat $(3) >>$(LEGAL_LICENSES_TXT_$(4)) && \
148         echo >>$(LEGAL_LICENSES_TXT_$(4)) && \
149         mkdir -p $(LICENSE_FILES_DIR_$(4))/$(1)/$(dir $(2)) && \
150         cp $(3) $(LICENSE_FILES_DIR_$(4))/$(1)/$(2)
151 endef