unixodbc: Fix dependency to library/readline-8 library/readline-8/32
[oi-userland.git] / make-rules / prep-patch.mk
blob03186c689d6dc8e3b6c7542cfcaf15187c7866ff
2 # CDDL HEADER START
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.
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.
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]
19 # CDDL HEADER END
21 # Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
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)
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.
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.
42 # ADDITIONAL_PATCHES can be defined in the component Makefile to include
43 # additional patches.
46 PATCH_PATTERN ?= *.patch*
48 PATCH_DIR ?= patches
50 PATCHES = $(wildcard $(PATCH_DIR)/$(PATCH_PATTERN))
52 PCH_SUFFIXES = $(patsubst .patch_%,%, $(filter-out .patch,$(suffix $(PATCHES))))
54 define patch-rule
56 ifeq ($(1),_0)
57 PATCH_PATTERN$(1) ?= %.patch
58 PATCHES$(1) = $(filter %.patch,$(PATCHES))
59 else
60 PATCH_PATTERN$(1) ?= %.patch$(1)
61 PATCHES$(1) = $(filter %.patch$(1),$(PATCHES))
62 endif
64 ifneq ($(strip $(ADDITIONAL_PATCHES$(1))),)
65 PATCHES$(1) += $(ADDITIONAL_PATCHES$(1))
66 endif
68 ifneq ($$(PATCHES$(1)),)
69 PATCH_STAMPS$(1) += $$(PATCHES$(1):$(PATCH_DIR)/%=$$(SOURCE_DIR$(1))/.patched-%)
71 # We should unpack the source that we patch before we patch it.
72 $$(PATCH_STAMPS$(1)): unpack
74 # Adding MAKEFILE_PREREQ because gmake seems to evaluate the need to patch
75 # before re-unpacking if the Makefile changed. The various stamps are
76 # removed as part of the unpacking process, and it doesn't appear to
77 # re-evaluate the need for patching. If we ever move the stamps to the build
78 # directory, we may not need the dependency any more.
79 $$(SOURCE_DIR$(1))/.patched-%: $(PATCH_DIR)/% $(MAKEFILE_PREREQ)
80 $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
81 $(TOUCH) $$(@)
83 $$(SOURCE_DIR$(1))/.patched-%: $(MAKEFILE_PREREQ)
84 $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
85 $(TOUCH) $$(@)
87 $$(SOURCE_DIR$(1))/.patched: $$(PATCH_STAMPS$(1))
88 $(TOUCH) $$(@)
90 patch:: $$(SOURCE_DIR$(1))/.patched
92 USERLAND_REQUIRED_PACKAGES += text/gnu-patch
94 endif
95 endef
98 # Define the rules required to download any source archives and augment any
99 # cleanup macros.
101 $(foreach suffix, $(PCH_SUFFIXES), $(eval $(call patch-rule,_$(suffix))))
102 $(eval $(call patch-rule,)) # this must be last so we don't drop *.patch_%.
104 # Helper target for patches refresh
105 refresh-patches: $(QUILT) patch
106 # Unapply all patches
107 for p in $(PATCHES) ; do \
108 echo $$p ; \
109 done | $(TAC) | while read p ; do \
110 $(GPATCH) -d $(SOURCE_DIR) --strip=$(PATCH_LEVEL) --reverse < $$p \
111 && continue ; \
112 exit 1 ; \
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 to prepare the tree for
117 # the next quilt run loop
118 cd $(SOURCE_DIR) ; for p in $(PATCHES) ; do \
119 QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) import --quiltrc /dev/null -p $(PATCH_LEVEL) "../$$p" \
120 && QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) push --quiltrc /dev/null -q \
121 && QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) refresh --quiltrc /dev/null -p $(if $(filter 0,$(PATCH_LEVEL)),0,1) --no-timestamps --no-index \
122 && continue ; \
123 exit 1 ; \
124 done ; \
125 [ ! -e $(COMPONENT_DIR)/$(PATCH_DIR)/series ] || (($(PATCH_LEVEL) == 0)) || QUILT_PATCHES=../$(PATCH_DIR) quilt pop --quiltrc /dev/null -a -q
126 # Remove unneeded quilt files
127 $(RM) -r $(SOURCE_DIR)/.pc
128 $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series
129 # Apply and refresh patches again to get the desired patch format
130 # (needed only with non-zero PATCH_LEVEL)
131 (($(PATCH_LEVEL) == 0)) || for p in $(PATCHES) ; do \
132 QUILT_PATCHES=$(PATCH_DIR) $(QUILT) import --quiltrc /dev/null -p 0 "$$p" \
133 && QUILT_PATCHES=$(PATCH_DIR) $(QUILT) push --quiltrc /dev/null -q \
134 && QUILT_PATCHES=$(PATCH_DIR) $(QUILT) refresh --quiltrc /dev/null -p 0 --no-timestamps --no-index \
135 && continue ; \
136 exit 1 ; \
137 done
138 # Remove unneeded quilt files
139 (($(PATCH_LEVEL) == 0)) || $(RM) -r $(COMPONENT_DIR)/.pc
140 (($(PATCH_LEVEL) == 0)) || $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series