Marcel Telka
2011-05-23 7e871acb7298cef4e6dc2f3c09d48563f094f266
commit | author | age
9c75c0 1 #
NJ 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 #
74300c 21 # Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
9c75c0 22 #
NJ 23
24 #
25 # Rules and Macros for generating an IPS package manifest and publishing an
26 # IPS package to a pkg depot.
27 #
28 # To use these rules, include ../make-rules/ips.mk in your Makefile
29 # and define an "install" target appropriate to building your component.
30 # Ex:
31 #
74300c 32 #    install:    $(BUILD_DIR)/build/$(MACH32)/.installed \
NJ 33 #             $(BUILD_DIR)/build/$(MACH64)/.installed
9c75c0 34 #
NJ 35 # This set of rules makes the "publish" target the default target for make(1)
36 #
37
38 PKGDEPEND =    /usr/bin/pkgdepend
6514ee 39 PKGFMT =    /usr/bin/pkgfmt
NJ 40 PKGMOGRIFY =    /usr/bin/pkgmogrify
41 PKGSEND =    /usr/bin/pkgsend
3dc823 42 PKGLINT =    /usr/bin/pkglint
4158c0 43 PKGMANGLE =    $(WS_TOOLS)/userland-mangler
9c75c0 44
6514ee 45 # Package headers should all pretty much follow the same format
NJ 46 METADATA_TEMPLATE =        $(WS_TOP)/transforms/manifest-metadata-template
47 COPYRIGHT_TEMPLATE =        $(WS_TOP)/transforms/copyright-template
9c75c0 48
6514ee 49 # order is important
NJ 50 GENERATE_TRANSFORMS +=        $(WS_TOP)/transforms/generate-cleanup
5d461f 51
6514ee 52 COMPARISON_TRANSFORMS +=    $(WS_TOP)/transforms/comparison-cleanup
NJ 53 COMPARISON_TRANSFORMS +=    $(PKGMOGRIFY_TRANSFORMS)
9c75c0 54
6514ee 55 # order is important
9dfd18 56 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/variant-cleanup
3cec7d 57 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/autopyc
6514ee 58 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/defaults
NJ 59 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/actuators
60 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/devel
61 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/docs
62 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/locale
63 PUBLISH_TRANSFORMS +=    $(PKGMOGRIFY_TRANSFORMS)
64 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/publish-cleanup
65
66 PKG_MACROS +=        MACH=$(MACH)
67 PKG_MACROS +=        MACH32=$(MACH32)
68 PKG_MACROS +=        MACH64=$(MACH64)
69 PKG_MACROS +=        PUBLISHER=$(PUBLISHER)
70 PKG_MACROS +=        CONSOLIDATION=$(CONSOLIDATION)
71 PKG_MACROS +=        BUILD_VERSION=$(BUILD_VERSION)
72 PKG_MACROS +=        SOLARIS_VERSION=$(SOLARIS_VERSION)
73 PKG_MACROS +=        OS_VERSION=$(OS_VERSION)
74 PKG_MACROS +=        IPS_COMPONENT_VERSION=$(IPS_COMPONENT_VERSION)
3f36e3 75 PKG_MACROS +=        COMPONENT_VERSION=$(COMPONENT_VERSION)
3a19d0 76 PKG_MACROS +=        COMPONENT_PROJECT_URL=$(COMPONENT_PROJECT_URL)
6514ee 77 PKG_MACROS +=        COMPONENT_ARCHIVE_URL=$(COMPONENT_ARCHIVE_URL)
NJ 78
79 PKG_OPTIONS +=        $(PKG_MACROS:%=-D %)
80
4158c0 81 MANGLED_DIR =    $(PROTO_DIR)/mangled
NJ 82
83 PKG_PROTO_DIRS += $(MANGLED_DIR) $(PROTO_DIR) $(@D) $(COMPONENT_DIR) $(COMPONENT_SRC)
35a012 84
74300c 85 MANIFEST_BASE =        $(BUILD_DIR)/manifest-$(MACH)
6514ee 86
ff17eb 87 CANONICAL_MANIFESTS =    $(wildcard *.p5m)
6514ee 88 GENERATED =        $(MANIFEST_BASE)-generated
NJ 89 COMBINED =        $(MANIFEST_BASE)-combined
90 MANIFESTS =        $(CANONICAL_MANIFESTS:%=$(MANIFEST_BASE)-%)
91
92
93b18c 93 DEPENDED=$(CANONICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend)
DD 94 RESOLVED=$(CANONICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend.res)
95 PUBLISHED=$(RESOLVED:%.depend.res=%.published)
9c75c0 96
7e871a 97 COPYRIGHT_FILE ?=    $(COMPONENT_NAME)-$(COMPONENT_VERSION).copyright
d05a6f 98 IPS_COMPONENT_VERSION ?=    $(COMPONENT_VERSION)
153732 99
6514ee 100 .DEFAULT:        publish
153732 101
3dc823 102 .SECONDARY:
9c75c0 103
2ae1af 104 # allow publishing to be overridden, such as when
MS 105 # a package is for one architecture only.
106 PUBLISH_STAMP ?= $(BUILD_DIR)/.published-$(MACH)
107
108 publish:        build install $(PUBLISH_STAMP)
9c75c0 109
ff17eb 110 sample-manifest:    $(GENERATED).p5m
9c75c0 111
ade6bb 112 $(GENERATED).p5m:    install
NJ 113     $(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR) | \
114     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 $(GENERATE_TRANSFORMS) | \
1932c6 115         sed -e '/^$$/d' -e '/^#.*$$/d' | $(PKGFMT) | \
MS 116         cat $(METADATA_TEMPLATE) - >$@
6514ee 117
ade6bb 118 # copy the canonical manifest(s) to the build tree
NJ 119 $(MANIFEST_BASE)-%.generate:    %.p5m canonical-manifests
120     cat $(METADATA_TEMPLATE) $< >$@
6514ee 121
ade6bb 122 # mogrify the manifest
70eebe 123 $(MANIFEST_BASE)-%.mogrified:    %.p5m canonical-manifests
NJ 124     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
ade6bb 125         $(PUBLISH_TRANSFORMS) | \
NJ 126         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
6514ee 127
4158c0 128 # mangle the file contents
NJ 129 $(MANGLED_DIR):
130     $(MKDIR) $@
131
132 PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
133 $(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
134     $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
135
1aa2da 136 # generate dependencies
35a012 137 PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
4158c0 138 $(MANIFEST_BASE)-%.depend:    $(MANIFEST_BASE)-%.mangled
35a012 139     $(PKGDEPEND) generate $(PKGDEPEND_GENERATE_OPTIONS) $< >$@
6514ee 140
93b18c 141 # resolve the dependencies all at once
DD 142 $(BUILD_DIR)/.resolved-$(MACH):    $(DEPENDED)
143     $(PKGDEPEND) resolve -m $(DEPENDED)
d05a6f 144     $(TOUCH) $@
NJ 145
146 # lint the manifests all at once
147 $(BUILD_DIR)/.linted-$(MACH):    $(BUILD_DIR)/.resolved-$(MACH)
148     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
8a6659 149     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)"\
694ef3 150         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
d05a6f 151             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
NJ 152     $(TOUCH) $@
153
3dc823 154
ade6bb 155 # published
35a012 156 PKGSEND_PUBLISH_OPTIONS = -s $(PKG_REPO) publish --fmri-in-manifest
NJ 157 PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
abb76c 158 PKGSEND_PUBLISH_OPTIONS += -T \*.py
93b18c 159 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.depend.res $(BUILD_DIR)/.linted-$(MACH)
35a012 160     $(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
ade6bb 161     $(PKGFMT) <$< >$@
6514ee 162
d05a6f 163 $(BUILD_DIR)/.published-$(MACH):    $(PUBLISHED)
6514ee 164     $(TOUCH) $@
NJ 165
a325d4 166 print-package-names:    canonical-manifests
NJ 167     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-pkgs | \
168         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
169          sed -e '/^$$/d' -e '/^#.*$$/d' | sort -u
170
171 print-package-paths:    canonical-manifests
172     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
173         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
174          sed -e '/^$$/d' -e '/^#.*$$/d' | sort -u
175
3dc823 176 install-packages:    publish
NJ 177     @if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
178         cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
179         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
180          sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | sort -u | \
181         (cd $(PROTO_DIR) ; pfexec /bin/cpio -dump $(ROOT)) ; \
182     else ; \
183         echo "unsafe to install package(s) automatically" ; \
184         fi
185
d05a6f 186 $(RESOLVED):    install
3dc823 187
NJ 188 canonical-manifests:    $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
6514ee 189 ifeq    ($(strip $(CANONICAL_MANIFESTS)),)
NJ 190     # If there were no canonical manifests in the workspace, nothing will
191     # be published and we should fail.  A sample manifest can be generated
192     # with
193     #   $ gmake sample-manifest
194     # Once created, it will need to be reviewed, edited, and added to the
195     # workspace.
196     $(error Missing canonical manifest(s))
197 endif
a325d4 198
NJ 199 # This converts required paths to containing package names for be able to
200 # properly setup the build environment for a component.
201 required-pkgs.mk:    Makefile
202     @echo "generating $@ from Makefile REQUIRED_* data"
203     @pkg search -H -l '<$(DEPENDS:%=% OR) /bin/true>' \
204         | sed -e 's/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@
205
3dc823 206 pre-prep:    required-pkgs.mk
NJ 207
208
a325d4 209 CLEAN_PATHS +=    required-pkgs.mk