fritzkink
2023-12-27 706019354bab81fc3f01995caf1ae1a2dfa346cf
commit | author | age
e28f4f 1 #
AP 2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21 # Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
22 #
23
24 GPATCH =    /usr/gnu/bin/patch
25 PATCH_LEVEL ?=    1
26 GPATCH_BACKUP =    --backup --version-control=numbered
27 GPATCH_FLAGS =    --strip=$(PATCH_LEVEL) $(GPATCH_BACKUP)
28
29 #
30 # Rules for patching source that is downloaded and unpacked or pulled from
31 # a source repository.  Patches should be named
32 # patches/{patch-file-name}.patch{version} where {patch-file-name} is a
33 # meaningful name for the patch contents and {version} corresponds to the
34 # COMPONENT_NAME{version} of the source to be patched.  Typically, version
35 # would be something like "_1", "_2", ...  After all {version} patches have
36 # been applied, a final set of patches without a {version} suffix may be
37 # applied.
38 #
39 # PATCH_DIR can be overridden to move patches to a different location
40 # PATCH_PATTERN can be overridden to adjust the patch naming scheme that the
41 #     build recognizes.
e1ec34 42 # ADDITIONAL_PATCHES can be defined in the component Makefile to include
e28f4f 43 #     additional patches.
AP 44 #
45
46 PATCH_PATTERN ?=    *.patch*
47
48 PATCH_DIR ?=        patches
49
d56e92 50 PATCHES =    $(shell find $(PATCH_DIR) -type f \
e28f4f 51              -name '$(PATCH_PATTERN)' 2>/dev/null | \
AP 52                 LC_COLLATE=C sort)
53
54 PCH_SUFFIXES = $(patsubst .patch_%,%, $(filter-out .patch,$(suffix $(PATCHES))))
55
56 define patch-rule
57
58 ifeq ($(1),_0)
59 PATCH_PATTERN$(1) ?=    %.patch
60 PATCHES$(1) = $(filter %.patch,$(PATCHES))
61 else
62 PATCH_PATTERN$(1) ?=    %.patch$(1)
63 PATCHES$(1) = $(filter %.patch$(1),$(PATCHES))
64 endif
65
e1ec34 66 ifneq ($(strip $(ADDITIONAL_PATCHES$(1))),)
K 67 PATCHES$(1) += $(ADDITIONAL_PATCHES$(1))
68 endif
69
e28f4f 70 ifneq ($$(PATCHES$(1)),)
AP 71 PATCH_STAMPS$(1) += $$(PATCHES$(1):$(PATCH_DIR)/%=$$(SOURCE_DIR$(1))/.patched-%)
72
73 # We should unpack the source that we patch before we patch it.
e20483 74 $$(PATCH_STAMPS$(1)):    unpack
e28f4f 75
AP 76 # Adding MAKEFILE_PREREQ because gmake seems to evaluate the need to patch
77 # before re-unpacking if the Makefile changed.  The various stamps are
78 # removed as part of the unpacking process, and it doesn't appear to
79 # re-evaluate the need for patching.  If we ever move the stamps to the build
80 # directory, we may not need the dependency any more.
81 $$(SOURCE_DIR$(1))/.patched-%:    $(PATCH_DIR)/% $(MAKEFILE_PREREQ)
82     $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
83     $(TOUCH) $$(@)
84
d56e92 85 $$(SOURCE_DIR$(1))/.patched-%:    $(MAKEFILE_PREREQ)
e28f4f 86     $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
AP 87     $(TOUCH) $$(@)
88
89 $$(SOURCE_DIR$(1))/.patched:    $$(PATCH_STAMPS$(1))
90     $(TOUCH) $$(@)
91
92 patch::    $$(SOURCE_DIR$(1))/.patched
93
1349f8 94 USERLAND_REQUIRED_PACKAGES += text/gnu-patch
e28f4f 95
AP 96 endif
97 endef
98
99 #
100 # Define the rules required to download any source archives and augment any
101 # cleanup macros.
102 #
103 $(foreach suffix, $(PCH_SUFFIXES), $(eval $(call patch-rule,_$(suffix))))
104 $(eval $(call patch-rule,))    # this must be last so we don't drop *.patch_%.
baff9a 105
MT 106 # Helper target for patches refresh
107 refresh-patches: $(QUILT) patch
108     # Unapply all patches
109     for p in $(PATCHES) ; do \
110         echo $$p ; \
111     done | $(TAC) | while read p ; do \
112         $(GPATCH) -d $(SOURCE_DIR) --strip=$(PATCH_LEVEL) --reverse < $$p ; \
113     done
114     # Make sure the series file does not exist
115     $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series
116     # Apply and refresh patches, then unapply them
117     cd $(SOURCE_DIR) ; for p in $(PATCHES) ; do \
118         QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) import --quiltrc /dev/null "../$$p" ; \
119         QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) push --quiltrc /dev/null -q ; \
120         QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) refresh --quiltrc /dev/null -p 1 --no-timestamps --no-index ; \
121     done ; \
122     [ ! -e $(COMPONENT_DIR)/$(PATCH_DIR)/series ] || QUILT_PATCHES=../$(PATCH_DIR) quilt pop --quiltrc /dev/null -a -q
123     # cleanup
124     $(RM) -r $(SOURCE_DIR)/.pc
125     $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series
126     # Apply and refresh patches again to get the desired patch format
127     for p in $(PATCHES) ; do \
128         QUILT_PATCHES=$(PATCH_DIR) $(QUILT) import --quiltrc /dev/null -p 0 "$$p" ; \
129         QUILT_PATCHES=$(PATCH_DIR) $(QUILT) push --quiltrc /dev/null -q ; \
130         QUILT_PATCHES=$(PATCH_DIR) $(QUILT) refresh --quiltrc /dev/null -p 0 --no-timestamps --no-index ; \
2c6f43 131     done
baff9a 132     # final cleanup
MT 133     $(RM) -r $(COMPONENT_DIR)/.pc
134     $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series