quilt.mk 5.8 KB

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