quilt.mk 5.2 KB

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