quilt.mk 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #
  2. # Copyright (C) 2007 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifeq ($(KERNEL_BUILD),1)
  8. PKG_BUILD_DIR:=$(LINUX_DIR)
  9. endif
  10. PATCH_DIR?=./patches
  11. ifeq ($(MAKECMDGOALS),refresh)
  12. override QUILT=1
  13. endif
  14. define Quilt/Patch
  15. @for patch in $$$$( (cd $(1) && ls) 2>/dev/null ); do ( \
  16. cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
  17. cd $(PKG_BUILD_DIR); \
  18. quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \
  19. quilt push -f >/dev/null 2>/dev/null; \
  20. rm -f "$$$$patch"; \
  21. ); done
  22. endef
  23. QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
  24. ifneq ($(QUILT),)
  25. STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q
  26. STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
  27. override CONFIG_AUTOREBUILD=
  28. define Build/Patch/Default
  29. rm -rf $(PKG_BUILD_DIR)/patches
  30. mkdir -p $(PKG_BUILD_DIR)/patches
  31. $(call Quilt/Patch,$(PATCH_DIR),)
  32. @echo
  33. touch $(PKG_BUILD_DIR)/.quilt_used
  34. endef
  35. $(STAMP_CONFIGURED): $(STAMP_PATCHED) FORCE
  36. prepare: $(STAMP_PATCHED)
  37. quilt-check: $(STAMP_PATCHED)
  38. else
  39. define Build/Patch/Default
  40. @if [ -d $(PATCH_DIR) -a "$$$$(ls $(PATCH_DIR) | wc -l)" -gt 0 ]; then \
  41. $(PATCH) $(PKG_BUILD_DIR) $(PATCH_DIR); \
  42. fi
  43. endef
  44. endif
  45. define Kernel/Patch/Default
  46. if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi
  47. if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
  48. $(if $(strip $(QUILT)),$(call Quilt/Patch,$(GENERIC_PATCH_DIR),generic/), \
  49. if [ -d $(GENERIC_PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(GENERIC_PATCH_DIR); fi \
  50. )
  51. $(if $(strip $(QUILT)),$(call Quilt/Patch,$(PATCH_DIR),platform/), \
  52. if [ -d $(PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(PATCH_DIR); fi \
  53. )
  54. $(if $(strip $(QUILT)),touch $(PKG_BUILD_DIR)/.quilt_used)
  55. endef
  56. $(STAMP_PATCHED): $(STAMP_PREPARED)
  57. @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
  58. (\
  59. cd $(PKG_BUILD_DIR)/patches; \
  60. find * -type f \! -name series | sort > series; \
  61. )
  62. if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
  63. touch $@
  64. define Quilt/RefreshDir
  65. mkdir -p $(1)
  66. -rm -f $(1)/* 2>/dev/null >/dev/null
  67. @( \
  68. for patch in $$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$1}'); do \
  69. $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" $(1); \
  70. done; \
  71. )
  72. endef
  73. define Quilt/Refresh/Package
  74. $(call Quilt/RefreshDir,$(PATCH_DIR))
  75. endef
  76. define Quilt/Refresh/Kernel
  77. @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
  78. echo "All kernel patches must start with either generic/ or platform/"; \
  79. false; \
  80. }
  81. $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
  82. $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
  83. endef
  84. quilt-check: $(STAMP_PREPARED) FORCE
  85. @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
  86. echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
  87. false; \
  88. }
  89. @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
  90. echo "The source directory contains no quilt patches."; \
  91. false; \
  92. }
  93. @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
  94. echo "The patches are not sorted in the right order. Please fix."; \
  95. false; \
  96. }
  97. refresh: quilt-check
  98. @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null
  99. @cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \
  100. quilt refresh; \
  101. done; ! quilt next 2>/dev/null >/dev/null
  102. $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
  103. update: quilt-check
  104. $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))