quilt.mk 3.5 KB

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