Andreas Wacknitz
2024-04-04 5e5f64b64ea30050f76f29d5ad52fa5d0e089301
commit | author | age
12abf9 1 #
CG 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
22 #
23 # Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
24 #
25
26 HG =        /usr/bin/hg
27 MKTEMP =     /usr/gnu/bin/mktemp
28
ed1293 29 COMPONENT_PREP_HG?=yes
AL 30 ifeq ($(strip $(COMPONENT_PREP_HG)), yes)
31
12abf9 32 #
CG 33 # Anything that we pull from a Mercurial repo must have a HG_REPO{_[0-9]+} and
34 # HG_REV{_[0-9]+} to match.
35 #
36
37 HG_SUFFIXES = $(subst HG_REPO_,, $(filter HG_REPO_%, $(.VARIABLES)))
38
39 # Templates for download variables and rules.  We separate the variable
40 # assignments from the rules so that all the variable assignments are given a
41 # chance to complete before those variables are used in targets or
42 # prerequisites, where they'll be expanded immediately.
43 define hg-variables
44 ifdef HG_REPO$(1)
45 ifdef HG_REV$(1)
46
47 # If the label is not already defined (including to empty), set it to the version.
48 COMPONENT_LABEL$(1) ?= $$(COMPONENT_VERSION$(1))
49 # The source directory is <name>-(<label>|<version>)[-(<tag>|<branch>)][-<commit].
50 COMPONENT_SRC$(1) ?= $$(COMPONENT_NAME$(1))$$(COMPONENT_LABEL$(1):%=-%)$$($$(or $$(HG_TAG$(1)),$$(HG_BRANCH$(1))))$$(HG_REV$(1):%=-%)
51 COMPONENT_ARCHIVE$(1) ?= $$(COMPONENT_SRC$(1)).tar.gz
52 COMPONENT_ARCHIVE_SRC$(1) = hg
53
54 CLEAN_PATHS += $$(COMPONENT_SRC$(1))
55 CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
ca8acb 56 SOURCE_DIR$(1) = $$(COMPONENT_DIR)/$$(COMPONENT_SRC$(1))
12abf9 57 endif
CG 58 endif
59 endef
60
61 define hg-rules
62 ifdef HG_REPO$(1)
63 ifdef HG_REV$(1)
64 download::    $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
65
66 # First attempt to download a cached archive of the SCM repo at the proper
67 # changeset ID.  If that fails, create an archive by cloning the SCM repo,
68 # updating to the selected changeset, archiving that directory, and cleaning up
69 # when complete.
70 $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)):    $(MAKEFILE_PREREQ)
71     $$(FETCH) --file $$@ $$(HG_HASH$(1):%=--hash %)  --url HG || \
72     (TMP_REPO=$$$$($(MKTEMP) --directory) && \
73      $(HG) clone $$(HG_REPO$(1)) $$(HG_REV$(1):%=--rev %) \
74          $$(HG_REV$(1):%=--updaterev %) \
75          $$(HG_BRANCH$(1):%=--branch %) \
76             $$$${TMP_REPO} && \
77      $(HG) -R $$$${TMP_REPO} archive --prefix $$(COMPONENT_SRC$(1)) $$@ && \
78      $(RM) -rf $${TMP_REPO} && \
79      HG_HASH=$$$$(digest -a sha256 $$@) && \
80      $(GSED) -i \
81         -e "s/\(HG_HASH$(1)[[:space:]]*=[[:space:]]*\).*/\1sha256:$$$${HG_HASH}/" \
82         Makefile)
83
1349f8 84 USERLAND_REQUIRED_PACKAGES += developer/versioning/mercurial
12abf9 85
CG 86 endif
87 endif
88 endef
89
90 # Evaluate the variable assignments immediately.
91 $(eval $(call hg-variables,))
92 $(foreach suffix, $(HG_SUFFIXES), $(eval $(call hg-variables,_$(suffix))))
93
94 $(eval $(call hg-rules,))
95 $(foreach suffix, $(HG_SUFFIXES), $(eval $(call hg-rules,_$(suffix))))
ed1293 96
AL 97 endif