quilt.mk 5.0 KB

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