pkg-utils.mk 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ############################################################################
  2. #
  3. # This file contains various utility functions used by the package
  4. # infrastructure, or by the packages themselves.
  5. #
  6. ############################################################################
  7. # UPPERCASE Macro -- transform its argument to uppercase and replace dots and
  8. # hyphens to underscores
  9. # Heavily inspired by the up macro from gmsl (http://gmsl.sf.net)
  10. # This is approx 5 times faster than forking a shell and tr, and
  11. # as this macro is used a lot it matters
  12. # This works by creating translation character pairs (E.G. a:A b:B)
  13. # and then looping though all of them running $(subst from,to,text)
  14. [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 . -
  15. [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 _ _
  16. UPPERCASE = $(strip $(eval __tmp := $1) \
  17. $(foreach c, $(join $(addsuffix :,$([FROM])),$([TO])), \
  18. $(eval __tmp := \
  19. $(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),\
  20. $(__tmp)))) \
  21. $(__tmp))
  22. #
  23. # Manipulation of .config files based on the Kconfig
  24. # infrastructure. Used by the Busybox package, the Linux kernel
  25. # package, and more.
  26. #
  27. define KCONFIG_ENABLE_OPT
  28. $(SED) "/\\<$(1)\\>/d" $(2)
  29. echo "$(1)=y" >> $(2)
  30. endef
  31. define KCONFIG_SET_OPT
  32. $(SED) "/\\<$(1)\\>/d" $(3)
  33. echo "$(1)=$(2)" >> $(3)
  34. endef
  35. define KCONFIG_DISABLE_OPT
  36. $(SED) "/\\<$(1)\\>/d" $(2)
  37. echo "# $(1) is not set" >> $(2)
  38. endef
  39. # Helper functions to determine the name of a package and its
  40. # directory from its makefile directory, using the $(MAKEFILE_LIST)
  41. # variable provided by make. This is used by the *TARGETS macros to
  42. # automagically find where the package is located. Note that the
  43. # pkgdir macro is carefully written to handle the case of the Linux
  44. # package, for which the package directory is an empty string.
  45. pkgdir = $(dir $(lastword $(MAKEFILE_LIST)))
  46. pkgname = $(lastword $(subst /, ,$(call pkgdir)))
  47. pkgparentdir = $(patsubst %$(call pkgname)/,%,$(call pkgdir))
  48. # Define extractors for different archive suffixes
  49. INFLATE.bz2 = $(BZCAT)
  50. INFLATE.gz = $(ZCAT)
  51. INFLATE.tbz = $(BZCAT)
  52. INFLATE.tbz2 = $(BZCAT)
  53. INFLATE.tgz = $(ZCAT)
  54. INFLATE.xz = $(XZCAT)
  55. INFLATE.tar = cat
  56. # MESSAGE Macro -- display a message in bold type
  57. MESSAGE = echo "$(TERM_BOLD)>>> $($(PKG)_NAME) $($(PKG)_VERSION) $(1)$(TERM_RESET)"
  58. TERM_BOLD := $(shell tput smso)
  59. TERM_RESET := $(shell tput rmso)
  60. # Utility functions for 'find'
  61. # findfileclauses(filelist) => -name 'X' -o -name 'Y'
  62. findfileclauses = $(call notfirstword,$(patsubst %,-o -name '%',$(1)))
  63. # finddirclauses(base, dirlist) => -path 'base/dirX' -o -path 'base/dirY'
  64. finddirclauses = $(call notfirstword,$(patsubst %,-o -path '$(1)/%',$(2)))
  65. # Miscellaneous utility functions
  66. # notfirstword(wordlist): returns all but the first word in wordlist
  67. notfirstword = $(wordlist 2,$(words $(1)),$(1))
  68. # Needed for the foreach loops to loop over the list of hooks, so that
  69. # each hook call is properly separated by a newline.
  70. define sep
  71. endef
  72. #
  73. # legal-info helper functions
  74. #
  75. LEGAL_INFO_SEPARATOR="::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
  76. legal-warning=echo "WARNING: $(1)" >>$(LEGAL_WARNINGS)
  77. legal-warning-pkg=echo "WARNING: $(1): $(2)" >>$(LEGAL_WARNINGS)
  78. define legal-warning-pkg-savednothing # pkg, {local|override}
  79. $(call legal-warning-pkg,$(1),sources and license files not saved ($(2) packages not handled))
  80. endef
  81. legal-manifest=echo '"$(1)","$(2)","$(3)","$(4)","$(5)"' >>$(LEGAL_MANIFEST_CSV)
  82. define legal-license-header
  83. echo -e "$(LEGAL_INFO_SEPARATOR)\n\t$(1):" \
  84. "$(2)\n$(LEGAL_INFO_SEPARATOR)\n\n" >>$(LEGAL_LICENSES_TXT)
  85. endef
  86. define legal-license-nofiles
  87. $(call legal-license-header,$(1),unknown license file(s))
  88. endef
  89. define legal-license-file # pkg, filename, file-fullpath
  90. $(call legal-license-header,$(1),$(2) file) && \
  91. cat $(3) >>$(LEGAL_LICENSES_TXT) && \
  92. echo >>$(LEGAL_LICENSES_TXT) && \
  93. mkdir -p $(LICENSE_FILES_DIR)/$(1)/ && \
  94. cp $(3) $(LICENSE_FILES_DIR)/$(1)/
  95. endef