1 ################################################################################
3 # This file contains various utility functions used by the package
4 # infrastructure, or by the packages themselves.
6 ################################################################################
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.
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.
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.
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.
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 _ _
29 define caseconvert-helper
31 $$(eval __tmp := $$(1))\
33 $$(eval __tmp := $$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$$(__tmp))))\
37 $(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO]))))
38 $(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))
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)))))
46 # Manipulation of .config files based on the Kconfig
47 # infrastructure. Used by the BusyBox package, the Linux kernel
51 define KCONFIG_ENABLE_OPT # (option, file)
52 $(SED) "/\\<$(1)\\>/d" $(2)
56 define KCONFIG_SET_OPT # (option, value, file)
57 $(SED) "/\\<$(1)\\>/d" $(3)
58 echo '$(1)=$(2)' >> $(3)
61 define KCONFIG_DISABLE_OPT # (option, file)
62 $(SED) "/\\<$(1)\\>/d" $(2)
63 echo '# $(1) is not set' >> $(2)
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)))
73 # Define extractors for different archive suffixes
74 INFLATE.bz2 = $(BZCAT)
76 INFLATE.tbz = $(BZCAT)
77 INFLATE.tbz2 = $(BZCAT)
81 # suitable-extractor(filename): returns extractor based on suffix
82 suitable-extractor = $(INFLATE$(suffix $(1)))
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)
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)))
95 # Miscellaneous utility functions
96 # notfirstword(wordlist): returns all but the first word in wordlist
97 notfirstword = $(wordlist 2,$(words $(1)),$(1))
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.
106 # check-deprecated-variable -- throw an error on deprecated variables
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)
116 # legal-info helper functions
118 LEGAL_INFO_SEPARATOR = "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
120 define legal-warning # text
121 echo "WARNING: $(1)" >>$(LEGAL_WARNINGS)
124 define legal-warning-pkg # pkg, text
125 echo "WARNING: $(1): $(2)" >>$(LEGAL_WARNINGS)
128 define legal-warning-nosource # pkg, {local|override}
129 $(call legal-warning-pkg,$(1),sources not saved ($(2) packages not handled))
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))
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))
141 define legal-license-nofiles # pkg, {HOST|TARGET}
142 $(call legal-license-header,$(1),unknown license file(s),$(2))
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)