prep-patch.mk revision 7001
4194N/A#
4194N/A# CDDL HEADER START
4194N/A#
4194N/A# The contents of this file are subject to the terms of the
4194N/A# Common Development and Distribution License (the "License").
4194N/A# You may not use this file except in compliance with the License.
4194N/A#
4194N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4194N/A# or http://www.opensolaris.org/os/licensing.
4194N/A# See the License for the specific language governing permissions
4194N/A# and limitations under the License.
4194N/A#
4194N/A# When distributing Covered Code, include this CDDL HEADER in each
4194N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4194N/A# If applicable, add the following below this CDDL HEADER, with the
4194N/A# fields enclosed by brackets "[]" replaced with your own identifying
4194N/A# information: Portions Copyright [yyyy] [name of copyright owner]
4194N/A#
4194N/A# CDDL HEADER END
4194N/A#
5680N/A
5680N/A#
6909N/A# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
4194N/A#
4194N/A
7001N/AGPATCH = /usr/bin/patch
4194N/APATCH_LEVEL ?= 1
4194N/AGPATCH_BACKUP = --backup --version-control=numbered
4194N/AGPATCH_FLAGS = --strip=$(PATCH_LEVEL) $(GPATCH_BACKUP)
4194N/A
4194N/A#
4194N/A# Rules for patching source that is downloaded and unpacked or pulled from
4194N/A# a source repository. Patches should be named
4194N/A# patches/{patch-file-name}.patch{version} where {patch-file-name} is a
4194N/A# meaningful name for the patch contents and {version} corresponds to the
4194N/A# COMPONENT_NAME{version} of the source to be patched. Typically, version
4194N/A# would be something like "_1", "_2", ... After all {version} patches have
4194N/A# been applied, a final set of patches without a {version} suffix may be
4194N/A# applied.
4194N/A#
4194N/A# PATCH_DIR can be overridden to move patches to a different location
4194N/A# PATCH_PATTERN can be overridden to adjust the patch naming scheme that the
4194N/A# build recognizes.
4194N/A# EXTRA_PATCHES{version} can be defined in the component Makefile to include
4194N/A# additional patches.
4194N/A#
4194N/A
4194N/APATCH_PATTERN ?= *.patch*
4194N/A
4194N/APATCH_DIR ?= patches
4194N/A# patches specific to parfait builds.
4252N/Aifeq ($(strip $(PARFAIT_BUILD)),yes)
4194N/APARFAIT_PATCH_DIR = parfait
4252N/Aendif
4194N/A
7001N/APATCHES = $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f \
4194N/A -name '$(PATCH_PATTERN)' 2>/dev/null | \
4194N/A LC_COLLATE=C sort)
4194N/A
6867N/A# Patches for different source tarballs have _X filename extensions to
6867N/A# match the _X extensions to the COMPONENT_* make variables. Find these
6867N/A# extensions, using $(sort) to uniq them to prevent multiple rules from
6867N/A# getting generated.
7001N/APCH_SUFFIXES = $(sort $(patsubst .patch_%,%, $(filter-out .patch,$(suffix $(PATCHES)))))
4194N/A
6909N/Adefine patch-variables
4194N/A
4194N/Aifeq ($(1),_0)
4194N/APATCH_PATTERN$(1) ?= %.patch
7001N/APATCHES$(1) = $(filter %.patch,$(PATCHES))
4194N/Aelse
4194N/APATCH_PATTERN$(1) ?= %.patch$(1)
7001N/APATCHES$(1) = $(filter %.patch$(1),$(PATCHES))
4194N/Aendif
4194N/A
4194N/Aifneq ($$(PATCHES$(1)),)
4194N/APATCH_STAMPS$(1) += $$(PATCHES$(1):$(PATCH_DIR)/%=$$(SOURCE_DIR$(1))/.patched-%)
4252N/Aifeq ($(strip $(PARFAIT_BUILD)),yes)
4252N/APATCH_STAMPS$(1) += $$(PATCHES$(1):$(PARFAIT_PATCH_DIR)/%=$$(SOURCE_DIR$(1))/.patched-%)
4252N/Aendif
6909N/Aendif
6909N/Aendef
4194N/A
6909N/Adefine patch-rules
6909N/Aifneq ($$(PATCHES$(1)),)
4194N/A# We should unpack the source that we patch before we patch it.
4194N/A$$(PATCH_STAMPS$(1):: $$(UNPACK_STAMP$(1)) unpack
4194N/A
4355N/A# Adding MAKEFILE_PREREQ because gmake seems to evaluate the need to patch
4355N/A# before re-unpacking if the Makefile changed. The various stamps are
4355N/A# removed as part of the unpacking process, and it doesn't appear to
4355N/A# re-evaluate the need for patching. If we ever move the stamps to the build
4355N/A# directory, we may not need the dependency any more.
4355N/A$$(SOURCE_DIR$(1))/.patched-%: $(PATCH_DIR)/% $(MAKEFILE_PREREQ)
4194N/A $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
4194N/A $(TOUCH) $$(@)
4194N/A
4355N/A$$(SOURCE_DIR$(1))/.patched-%: $(PARFAIT_PATCH_DIR)/% $(MAKEFILE_PREREQ)
4252N/A $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
4252N/A $(TOUCH) $$(@)
4252N/A
4355N/A$$(SOURCE_DIR$(1))/.patched: $$(PATCH_STAMPS$(1))
4355N/A $(TOUCH) $$(@)
4355N/A
4355N/Apatch:: $$(SOURCE_DIR$(1))/.patched
4194N/A
4194N/AREQUIRED_PACKAGES += text/gnu-patch
4194N/A
4194N/Aendif
4194N/Aendef
4194N/A
6909N/A# Evaluate the variable assignments immediately.
6909N/A$(foreach suffix, $(PCH_SUFFIXES), $(eval $(call patch-variables,_$(suffix))))
6909N/A$(eval $(call patch-variables,)) # this must be last so we don't drop *.patch_%.
6909N/A
6909N/A# Put the rule evaluations in a variable for deferred evaluation.
6909N/Adefine eval-patch-rules
6909N/A$(foreach suffix, $(PCH_SUFFIXES), $(eval $(call patch-rules,_$(suffix))))
6909N/A$(eval $(call patch-rules,)) # this must be last so we don't drop *.patch_%.
6909N/Aendef