quilt.mk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 ($(TARGET_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) && if [ -f series ]; then grep -v '^#' series; else ls; fi; ) 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. ifeq ($(TARGET_BUILD),1)
  57. $(STAMP_PATCHED): $(STAMP_PREPARED)
  58. @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
  59. (\
  60. cd $(PKG_BUILD_DIR)/patches; \
  61. rm -f series; \
  62. for file in *; do \
  63. if [ -f $$file/series ]; then \
  64. echo "Converting $$file/series"; \
  65. awk -v file="$$file/" '$$0 !~ /^#/ { print file $$0 }' $$file/series >> series; \
  66. else \
  67. echo "Sorting patches in $$file"; \
  68. find $$file/* -type f \! -name series | sort >> series; \
  69. fi; \
  70. done; \
  71. )
  72. if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
  73. touch $@
  74. else
  75. $(STAMP_PATCHED): $(STAMP_PREPARED)
  76. @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
  77. (\
  78. cd $(PKG_BUILD_DIR)/patches; \
  79. find * -type f \! -name series | sort > series; \
  80. )
  81. if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
  82. touch $@
  83. endif
  84. define Quilt/RefreshDir
  85. mkdir -p $(1)
  86. -rm -f $(1)/* 2>/dev/null >/dev/null
  87. @( \
  88. for patch in $$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$1}'); do \
  89. $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" $(1); \
  90. done; \
  91. )
  92. endef
  93. define Quilt/Refresh/Package
  94. $(call Quilt/RefreshDir,$(PATCH_DIR))
  95. endef
  96. define Quilt/Refresh/Kernel
  97. @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
  98. echo "All kernel patches must start with either generic/ or platform/"; \
  99. false; \
  100. }
  101. $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
  102. $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
  103. endef
  104. quilt-check: $(STAMP_PREPARED) FORCE
  105. @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
  106. echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
  107. false; \
  108. }
  109. @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
  110. echo "The source directory contains no quilt patches."; \
  111. false; \
  112. }
  113. @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
  114. echo "The patches are not sorted in the right order. Please fix."; \
  115. false; \
  116. }
  117. refresh: quilt-check
  118. @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null
  119. @cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \
  120. quilt refresh; \
  121. done; ! quilt next 2>/dev/null >/dev/null
  122. $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
  123. update: quilt-check
  124. $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))