quilt.mk 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #
  2. # Copyright (C) 2007-2009 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. ifneq ($(if $(DUMP),1,$(__quilt_inc)),1)
  7. __quilt_inc:=1
  8. ifeq ($(TARGET_BUILD),1)
  9. PKG_BUILD_DIR:=$(LINUX_DIR)
  10. endif
  11. PATCH_DIR?=./patches
  12. FILES_DIR?=./files
  13. HOST_PATCH_DIR?=$(PATCH_DIR)
  14. HOST_FILES_DIR?=$(FILES_DIR)
  15. ifeq ($(MAKECMDGOALS),refresh)
  16. override QUILT=1
  17. endif
  18. QUILT_CMD:=quilt --quiltrc=-
  19. define filter_series
  20. sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
  21. endef
  22. define PatchDir/Quilt
  23. @mkdir -p "$(1)/patches$(if $(3),/$(patsubst %/,%,$(3)))"
  24. @if [ -s "$(2)/series" ]; then \
  25. mkdir -p "$(1)/patches/$(3)"; \
  26. cp "$(2)/series" "$(1)/patches/$(3)"; \
  27. fi
  28. @for patch in $$$$( (cd "$(2)" && if [ -f series ]; then $(call filter_series,series); else ls | sort; fi; ) 2>/dev/null ); do ( \
  29. cp "$(2)/$$$$patch" "$(1)/patches/$(3)"; \
  30. echo "$(3)$$$$patch" >> "$(1)/patches/series"; \
  31. ); done
  32. $(if $(3),@echo $(3) >> "$(1)/patches/.subdirs")
  33. endef
  34. define PatchDir/Default
  35. @if [ -d "$(2)" ] && [ "$$$$(ls $(2) | wc -l)" -gt 0 ]; then \
  36. export PATCH="$(PATCH)"; \
  37. if [ -s "$(2)/series" ]; then \
  38. $(call filter_series,$(2)/series) | xargs -n1 \
  39. $(KPATCH) "$(1)" "$(2)"; \
  40. else \
  41. $(KPATCH) "$(1)" "$(2)"; \
  42. fi; \
  43. fi
  44. endef
  45. define PatchDir
  46. $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
  47. endef
  48. define HostPatchDir
  49. $(call PatchDir/$(if $(strip $(HOST_QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
  50. endef
  51. ifneq ($(PKG_BUILD_DIR),)
  52. QUILT?=$(if $(wildcard $(PKG_BUILD_DIR)/.quilt_used),y)
  53. ifneq ($(QUILT),)
  54. STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
  55. override CONFIG_AUTOREBUILD=
  56. quilt-check: $(STAMP_CHECKED)
  57. endif
  58. endif
  59. ifneq ($(HOST_BUILD_DIR),)
  60. HOST_QUILT?=$(if $(findstring command,$(origin QUILT)),$(QUILT),$(if $(wildcard $(HOST_BUILD_DIR)/.quilt_used),y))
  61. ifneq ($(HOST_QUILT),)
  62. HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
  63. override CONFIG_AUTOREBUILD=
  64. host-quilt-check: $(HOST_STAMP_CHECKED)
  65. endif
  66. endif
  67. define Host/Patch/Default
  68. $(if $(HOST_QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
  69. $(call HostPatchDir,$(HOST_BUILD_DIR),$(HOST_PATCH_DIR),)
  70. $(if $(HOST_QUILT),touch $(HOST_BUILD_DIR)/.quilt_used)
  71. endef
  72. define Build/Patch/Default
  73. $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
  74. $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
  75. $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used)
  76. endef
  77. kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
  78. define Kernel/Patch/Default
  79. rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
  80. $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
  81. find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
  82. $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
  83. $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
  84. endef
  85. define Quilt/RefreshDir
  86. mkdir -p $(2)
  87. -rm -f $(2)/* 2>/dev/null >/dev/null
  88. @( \
  89. for patch in $$$$($(if $(3),grep "^$(3)",cat) $(1)/patches/series | awk '{print $$$$1}'); do \
  90. $(CP) -v "$(1)/patches/$$$$patch" $(2); \
  91. done; \
  92. )
  93. endef
  94. define Quilt/Refresh/Host
  95. $(call Quilt/RefreshDir,$(HOST_BUILD_DIR),$(PATCH_DIR))
  96. endef
  97. define Quilt/Refresh/Package
  98. $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR))
  99. endef
  100. define Quilt/Refresh/Kernel
  101. @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
  102. echo "All kernel patches must start with either generic/ or platform/"; \
  103. false; \
  104. }
  105. $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
  106. $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
  107. endef
  108. define Quilt/Template
  109. $($(2)STAMP_CONFIGURED): $($(2)STAMP_CHECKED)
  110. $(if $(NO_RECONFIGURE),$($(2)STAMP_BUILT),$($(2)STAMP_CONFIGURED)): FORCE
  111. $($(2)STAMP_CHECKED): $($(2)STAMP_PREPARED)
  112. if [ -s "$(1)/patches/series" ]; then \
  113. (cd "$(1)"; \
  114. if $(QUILT_CMD) next >/dev/null 2>&1; then \
  115. $(QUILT_CMD) push -a; \
  116. else \
  117. $(QUILT_CMD) top >/dev/null 2>&1; \
  118. fi \
  119. ); \
  120. fi
  121. touch "$$@"
  122. $(3)quilt-check: $($(2)STAMP_PREPARED) FORCE
  123. @[ -f "$(1)/.quilt_used" ] || { \
  124. echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
  125. false; \
  126. }
  127. @[ -f "$(1)/patches/series" ] || { \
  128. echo "The source directory contains no quilt patches."; \
  129. false; \
  130. }
  131. @[ -n "$$$$(ls $(1)/patches/series)" -o "$$$$(cat $(1)/patches/series | md5sum)" = "$$(sort $(1)/patches/series | md5sum)" ] || { \
  132. echo "The patches are not sorted in the right order. Please fix."; \
  133. false; \
  134. }
  135. $(3)refresh: $(3)quilt-check
  136. @cd "$(1)"; $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
  137. @cd "$(1)"; while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
  138. QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
  139. done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
  140. $(Quilt/Refresh/$(4))
  141. $(3)update: $(3)quilt-check
  142. $(Quilt/Refresh/$(4))
  143. endef
  144. Build/Quilt=$(call Quilt/Template,$(PKG_BUILD_DIR),,,$(if $(TARGET_BUILD),Kernel,Package))
  145. Host/Quilt=$(call Quilt/Template,$(HOST_BUILD_DIR),HOST_,host-,Host)
  146. endif