pkg-utils.mk 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. define pkgdir
  46. $(dir $(lastword $(MAKEFILE_LIST)))
  47. endef
  48. define pkgname
  49. $(lastword $(subst /, ,$(call pkgdir)))
  50. endef
  51. define pkgparentdir
  52. $(patsubst %$(call pkgname)/,%,$(call pkgdir))
  53. endef
  54. # Define extractors for different archive suffixes
  55. INFLATE.bz2 = $(BZCAT)
  56. INFLATE.gz = $(ZCAT)
  57. INFLATE.tbz = $(BZCAT)
  58. INFLATE.tbz2 = $(BZCAT)
  59. INFLATE.tgz = $(ZCAT)
  60. INFLATE.xz = $(XZCAT)
  61. INFLATE.tar = cat
  62. # MESSAGE Macro -- display a message in bold type
  63. MESSAGE = echo "$(TERM_BOLD)>>> $($(PKG)_NAME) $($(PKG)_VERSION) $(1)$(TERM_RESET)"
  64. TERM_BOLD := $(shell tput smso)
  65. TERM_RESET := $(shell tput rmso)
  66. # Needed for the foreach loops to loop over the list of hooks, so that
  67. # each hook call is properly separated by a newline.
  68. define sep
  69. endef