Danek Duvall
2011-04-08 93b18cd84bd33894f95ae20eaa71385096b5a645
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
6514ee 57 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/defaults
NJ 58 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/actuators
59 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/devel
60 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/docs
61 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/locale
62 PUBLISH_TRANSFORMS +=    $(PKGMOGRIFY_TRANSFORMS)
63 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/publish-cleanup
64
65 PKG_MACROS +=        MACH=$(MACH)
66 PKG_MACROS +=        MACH32=$(MACH32)
67 PKG_MACROS +=        MACH64=$(MACH64)
68 PKG_MACROS +=        PUBLISHER=$(PUBLISHER)
69 PKG_MACROS +=        CONSOLIDATION=$(CONSOLIDATION)
70 PKG_MACROS +=        BUILD_VERSION=$(BUILD_VERSION)
71 PKG_MACROS +=        SOLARIS_VERSION=$(SOLARIS_VERSION)
72 PKG_MACROS +=        OS_VERSION=$(OS_VERSION)
73 PKG_MACROS +=        IPS_COMPONENT_VERSION=$(IPS_COMPONENT_VERSION)
3f36e3 74 PKG_MACROS +=        COMPONENT_VERSION=$(COMPONENT_VERSION)
3a19d0 75 PKG_MACROS +=        COMPONENT_PROJECT_URL=$(COMPONENT_PROJECT_URL)
6514ee 76 PKG_MACROS +=        COMPONENT_ARCHIVE_URL=$(COMPONENT_ARCHIVE_URL)
NJ 77
78 PKG_OPTIONS +=        $(PKG_MACROS:%=-D %)
79
4158c0 80 MANGLED_DIR =    $(PROTO_DIR)/mangled
NJ 81
82 PKG_PROTO_DIRS += $(MANGLED_DIR) $(PROTO_DIR) $(@D) $(COMPONENT_DIR) $(COMPONENT_SRC)
35a012 83
74300c 84 MANIFEST_BASE =        $(BUILD_DIR)/manifest-$(MACH)
6514ee 85
ff17eb 86 CANONICAL_MANIFESTS =    $(wildcard *.p5m)
6514ee 87 GENERATED =        $(MANIFEST_BASE)-generated
NJ 88 COMBINED =        $(MANIFEST_BASE)-combined
89 MANIFESTS =        $(CANONICAL_MANIFESTS:%=$(MANIFEST_BASE)-%)
90
91
93b18c 92 DEPENDED=$(CANONICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend)
DD 93 RESOLVED=$(CANONICAL_MANIFESTS:%.p5m=$(MANIFEST_BASE)-%.depend.res)
94 PUBLISHED=$(RESOLVED:%.depend.res=%.published)
9c75c0 95
153732 96 COPYRIGHT_FILE =    $(COMPONENT_NAME)-$(COMPONENT_VERSION).copyright
d05a6f 97 IPS_COMPONENT_VERSION ?=    $(COMPONENT_VERSION)
153732 98
6514ee 99 .DEFAULT:        publish
153732 100
3dc823 101 .SECONDARY:
9c75c0 102
f1282e 103 publish:        build install $(BUILD_DIR)/.published-$(MACH)
9c75c0 104
ff17eb 105 sample-manifest:    $(GENERATED).p5m
9c75c0 106
ade6bb 107 $(GENERATED).p5m:    install
NJ 108     $(PKGSEND) generate $(PKG_HARDLINKS:%=--target %) $(PROTO_DIR) | \
109     $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 $(GENERATE_TRANSFORMS) | \
1932c6 110         sed -e '/^$$/d' -e '/^#.*$$/d' | $(PKGFMT) | \
MS 111         cat $(METADATA_TEMPLATE) - >$@
6514ee 112
ade6bb 113 # copy the canonical manifest(s) to the build tree
NJ 114 $(MANIFEST_BASE)-%.generate:    %.p5m canonical-manifests
115     cat $(METADATA_TEMPLATE) $< >$@
6514ee 116
ade6bb 117 # mogrify the manifest
70eebe 118 $(MANIFEST_BASE)-%.mogrified:    %.p5m canonical-manifests
NJ 119     $(PKGMOGRIFY) $(PKG_OPTIONS) $< \
ade6bb 120         $(PUBLISH_TRANSFORMS) | \
NJ 121         sed -e '/^$$/d' -e '/^#.*$$/d' | uniq >$@
6514ee 122
4158c0 123 # mangle the file contents
NJ 124 $(MANGLED_DIR):
125     $(MKDIR) $@
126
127 PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
128 $(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
129     $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
130
1aa2da 131 # generate dependencies
35a012 132 PKGDEPEND_GENERATE_OPTIONS = -m $(PKG_PROTO_DIRS:%=-d %)
4158c0 133 $(MANIFEST_BASE)-%.depend:    $(MANIFEST_BASE)-%.mangled
35a012 134     $(PKGDEPEND) generate $(PKGDEPEND_GENERATE_OPTIONS) $< >$@
6514ee 135
93b18c 136 # resolve the dependencies all at once
DD 137 $(BUILD_DIR)/.resolved-$(MACH):    $(DEPENDED)
138     $(PKGDEPEND) resolve -m $(DEPENDED)
d05a6f 139     $(TOUCH) $@
NJ 140
141 # lint the manifests all at once
142 $(BUILD_DIR)/.linted-$(MACH):    $(BUILD_DIR)/.resolved-$(MACH)
143     @echo "VALIDATING MANIFEST CONTENT: $(RESOLVED)"
8a6659 144     $(ENV) PYTHONPATH=$(WS_TOOLS)/python PROTO_PATH="$(PKG_PROTO_DIRS)"\
694ef3 145         $(PKGLINT) $(CANONICAL_REPO:%=-c $(WS_LINT_CACHE)) \
d05a6f 146             -f $(WS_TOOLS)/pkglintrc $(RESOLVED)
NJ 147     $(TOUCH) $@
148
3dc823 149
ade6bb 150 # published
35a012 151 PKGSEND_PUBLISH_OPTIONS = -s $(PKG_REPO) publish --fmri-in-manifest
NJ 152 PKGSEND_PUBLISH_OPTIONS += $(PKG_PROTO_DIRS:%=-d %)
93b18c 153 $(MANIFEST_BASE)-%.published:    $(MANIFEST_BASE)-%.depend.res $(BUILD_DIR)/.linted-$(MACH)
35a012 154     $(PKGSEND) $(PKGSEND_PUBLISH_OPTIONS) $<
ade6bb 155     $(PKGFMT) <$< >$@
6514ee 156
d05a6f 157 $(BUILD_DIR)/.published-$(MACH):    $(PUBLISHED)
6514ee 158     $(TOUCH) $@
NJ 159
a325d4 160 print-package-names:    canonical-manifests
NJ 161     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-pkgs | \
162         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
163          sed -e '/^$$/d' -e '/^#.*$$/d' | sort -u
164
165 print-package-paths:    canonical-manifests
166     @cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
167         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
168          sed -e '/^$$/d' -e '/^#.*$$/d' | sort -u
169
3dc823 170 install-packages:    publish
NJ 171     @if [ $(IS_GLOBAL_ZONE) = 0 -o x$(ROOT) != x ]; then \
172         cat $(CANONICAL_MANIFESTS) $(WS_TOP)/transforms/print-paths | \
173         $(PKGMOGRIFY) $(PKG_OPTIONS) /dev/fd/0 | \
174          sed -e '/^$$/d' -e '/^#.*$$/d' -e 's;/;;' | sort -u | \
175         (cd $(PROTO_DIR) ; pfexec /bin/cpio -dump $(ROOT)) ; \
176     else ; \
177         echo "unsafe to install package(s) automatically" ; \
178         fi
179
d05a6f 180 $(RESOLVED):    install
3dc823 181
NJ 182 canonical-manifests:    $(CANONICAL_MANIFESTS) Makefile $(PATCHES)
6514ee 183 ifeq    ($(strip $(CANONICAL_MANIFESTS)),)
NJ 184     # If there were no canonical manifests in the workspace, nothing will
185     # be published and we should fail.  A sample manifest can be generated
186     # with
187     #   $ gmake sample-manifest
188     # Once created, it will need to be reviewed, edited, and added to the
189     # workspace.
190     $(error Missing canonical manifest(s))
191 endif
a325d4 192
NJ 193 # This converts required paths to containing package names for be able to
194 # properly setup the build environment for a component.
195 required-pkgs.mk:    Makefile
196     @echo "generating $@ from Makefile REQUIRED_* data"
197     @pkg search -H -l '<$(DEPENDS:%=% OR) /bin/true>' \
198         | sed -e 's/pkg:\/\(.*\)@.*/REQUIRED_PKGS += \1/g' >$@
199
3dc823 200 pre-prep:    required-pkgs.mk
NJ 201
202
a325d4 203 CLEAN_PATHS +=    required-pkgs.mk