You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mxe.patch.mk 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # This file is part of MXE. See LICENSE.md for licensing information.
  2. GIT_DIR = $(if $(patsubst .,,$($(1)_SUBDIR)) \
  3. ,$(GITS_DIR)/$($(1)_SUBDIR),$(GITS_DIR)/$(1))
  4. GIT_CMD = git \
  5. --work-tree='$(call GIT_DIR,$(1))' \
  6. --git-dir='$(call GIT_DIR,$(1))'/.git
  7. PATCH_NAME = 1-fixes
  8. # can't use PKG_PATCHES here, because it returns existing patches
  9. # while export-patch creates new patch
  10. PATCH_BY_NAME = $(patsubst %.mk,%-$(2).patch,$($(1)_MAKEFILE))
  11. define INIT_GIT
  12. # unpack to gits/tmp/pkg
  13. rm -rf '$(GITS_DIR)/tmp'
  14. mkdir -p '$(GITS_DIR)/tmp/$(1)'
  15. cd '$(GITS_DIR)/tmp/$(1)' && $(call UNPACK_PKG_ARCHIVE,$(1))
  16. # if PKG_SUBDIR is ".", the following will move gits/tmp/pkg
  17. mv '$(abspath $(GITS_DIR)/tmp/$(1)/$($(1)_SUBDIR))' '$(call GIT_DIR,$(1))'
  18. rm -rf '$(GITS_DIR)/tmp'
  19. # rename existing .git directories if any
  20. find '$(call GIT_DIR,$(1))' -name .git -prune -exec sh -c 'mv "$$0" "$$0"_' {} \;
  21. # initialize git
  22. $(call GIT_CMD,$(1)) init
  23. $(call GIT_CMD,$(1)) add -A -f
  24. $(call GIT_CMD,$(1)) commit -m "init"
  25. $(call GIT_CMD,$(1)) tag dist
  26. endef
  27. define IMPORT_PATCH
  28. cd '$(call GIT_DIR,$(1))' \
  29. && cat '$(2)' \
  30. | $(SED) '/^From/,$$ !d' \
  31. | $(SED) s/'^From: MXE'/"From: fix@me"/'g;' \
  32. | $(call GIT_CMD,$(1)) am --keep-cr ;
  33. endef
  34. define EXPORT_PATCH
  35. cd '$(call GIT_DIR,$(1))' \
  36. && ( \
  37. echo 'This file is part of MXE. See LICENSE.md for licensing information.'; \
  38. echo ''; \
  39. echo 'Contains ad hoc patches for cross building.'; \
  40. echo ''; \
  41. $(call GIT_CMD,$(1)) format-patch \
  42. --numbered \
  43. -p \
  44. --no-signature \
  45. --stdout \
  46. --text \
  47. -M9 \
  48. dist..HEAD \
  49. | $(SED) 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' \
  50. | $(SED) 's/^index .......*\.\........* /index 1111111..2222222 /' \
  51. ) > '$(PATCH_BY_NAME)'
  52. endef
  53. _init-git-%: TIMESTAMP = patch
  54. _init-git-%: download-only-%
  55. $(if $(call set_is_member,$*,$(PKGS)), \
  56. $(if $(wildcard $(call GIT_DIR,$*)), \
  57. $(error $(call GIT_DIR,$*) already exists), \
  58. $(call INIT_GIT,$*)), \
  59. $(error Package $* not found))
  60. _import-patch-%:
  61. $(if $(call set_is_member,$*,$(PKGS)), \
  62. $(if $(wildcard $(call GIT_DIR,$*)), \
  63. $(call IMPORT_PATCH,$*,$(call PATCH_BY_NAME,$*,$(PATCH_NAME))), \
  64. $(error $(call GIT_DIR,$*) does not exist)), \
  65. $(error Package $* not found))
  66. _import-all-patches-%:
  67. $(if $(call set_is_member,$*,$(PKGS)), \
  68. $(if $(wildcard $(call GIT_DIR,$*)), \
  69. $(foreach PKG_PATCH,$(call PKG_PATCHES,$*), \
  70. $(call IMPORT_PATCH,$*,$(PKG_PATCH))), \
  71. $(error $(call GIT_DIR,$*) does not exist)), \
  72. $(error Package $* not found))
  73. _export-patch-%:
  74. $(if $(call set_is_member,$*,$(PKGS)), \
  75. $(if $(wildcard $(call GIT_DIR,$*)), \
  76. $(call EXPORT_PATCH,$*,$(PATCH_NAME)), \
  77. $(error $(call GIT_DIR,$*) does not exist)), \
  78. $(error Package $* not found))
  79. # use .SECONDARY: when refreshing all patches if you don't
  80. # want to unpack everything every time
  81. #.SECONDARY:
  82. init-git-%: $(PREFIX)/installed/patch/init-git-% ;
  83. import-patch-%: $(PREFIX)/installed/patch/import-patch-% ;
  84. import-all-patches-%: $(PREFIX)/installed/patch/import-all-patches-% ;
  85. export-patch-%: $(PREFIX)/installed/patch/export-patch-% ;
  86. refresh-patch-%: $(PREFIX)/installed/patch/refresh-patch-% ;
  87. $(PREFIX)/installed/patch/refresh-patch-%:
  88. @rm -rf $(PWD)/tmp-patch/$*
  89. @$(MAKE) -f '$(MAKEFILE)' init-git-$* GITS_DIR=$(PWD)/tmp-patch/$*
  90. @$(MAKE) -f '$(MAKEFILE)' import-patch-$* GITS_DIR=$(PWD)/tmp-patch/$*
  91. @$(MAKE) -f '$(MAKEFILE)' export-patch-$* GITS_DIR=$(PWD)/tmp-patch/$*
  92. @# darwin sometimes chokes deleting large git repos
  93. @rm -rf $(PWD)/tmp-patch/$* || sleep 5; rm -rf $(PWD)/tmp-patch/$*
  94. +@mkdir -p '$(dir $@)'
  95. @touch '$@'
  96. $(PREFIX)/installed/patch/%:
  97. @echo '[$*]'
  98. @[ -d '$(LOG_DIR)/patch' ] || mkdir -p '$(LOG_DIR)/patch'
  99. @(time $(MAKE) -f '$(MAKEFILE)' _$*) &> '$(LOG_DIR)/patch/$*'
  100. +@mkdir -p '$(dir $@)'
  101. @touch '$@'
  102. PATCH_FORMAT_PATCHES := $(shell find $(MXE_PLUGIN_DIRS) plugins -name "*-$(PATCH_NAME).patch")
  103. PATCH_FORMAT_PKGS := $(sort $(subst -$(PATCH_NAME),,$(basename $(notdir $(PATCH_FORMAT_PATCHES)))))
  104. PATCH_FORMAT_DIRS := $(sort $(basename $(dir $(PATCH_FORMAT_PATCHES))))
  105. .PHONY: refresh-patches
  106. refresh-patches:
  107. @$(MAKE) -f '$(MAKEFILE)' -j '$(JOBS)'\
  108. $(addprefix refresh-patch-,$(PATCH_FORMAT_PKGS)) \
  109. MXE_PLUGIN_DIRS='$(PATCH_FORMAT_DIRS)'