xref: /titanic_51/usr/src/tools/Makefile.python (revision 61dc244f52b4962ea505abec7e6cbade980d3c53)
1#
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, Oracle and/or its affiliates. All rights reserved.
24#
25
26#
27# This Makefile provides a framework for building the onbld python
28# modules with multiple versions of python.
29#
30# It expects as input:
31#
32#    PYSRCS   - List of python source files, these are also delivered as
33#               build product.
34#
35#    PYOBJS   - List of compiled python (.pyc) files, with no directory prefix
36#
37#    PYTOPDIR - Absolute (including $(ROOT)) path to which files will
38#               be installed, up until the version specific component.
39#
40#    PYMODDIR - Relative path to which files will be installed, below
41#               the version specific component.
42#
43#    For example, to install to /opt/onbld/lib/onbld/python*/bar/
44#
45#          PYTOPDIR = $(ROOTONBLDLIB)
46#          PYMODDIR = bar
47#
48#
49# It provides as output:
50#
51#    ROOTPYFILES - The list of $(ROOT)-relative paths to which python
52#                  source and binary files will be installed.  Your
53#                  Makefile's 'install' target should depend upon
54#                  this.
55#
56#    PYVERSOBJS  - The list of paths to compiled python build products,
57#                  including their subdirectory.
58#
59#    pyclobber   - A target on which 'clobber' should depend, which
60#                  removes the per-version python directories and the
61#                  output within them.
62#
63
64PYFILES = $(PYSRCS) $(PYOBJS)
65
66ROOTPYDIR_24 = $(PYTOPDIR)/python2.4/$(PYMODDIR)
67ROOTPYFILES_24 = $(PYFILES:%=$(ROOTPYDIR_24)/%)
68
69ROOTPYDIR_26 = $(PYTOPDIR)/python2.6/$(PYMODDIR)
70ROOTPYFILES_26	= $(PYFILES:%=$(ROOTPYDIR_26)/%)
71
72ROOTPYFILES = $(ROOTPYFILES_24) $(ROOTPYFILES_26)
73$(ROOTPYFILES) := FILEMODE = 0444
74
75PYVERSDIRS = python2.4 python2.6
76
77PY24OBJS = $(PYOBJS:%=python2.4/%)
78$(PY24OBJS) := PYTHON = $(PYTHON_24)
79
80PY26OBJS = $(PYOBJS:%=python2.6/%)
81$(PY26OBJS) := PYTHON = $(PYTHON_26)
82
83PYVERSOBJS = $(PY24OBJS) $(PY26OBJS)
84
85CLOBBERFILES += $(PYVERSOBJS)
86CLOBBERDIRS += $(PYVERSDIRS)
87
88.KEEP_STATE:
89
90python2.4/%.pyc python2.6/%.pyc: %.py
91	@[ -d $(@D) ] || mkdir $(@D)
92	$(RM) $@
93	$(PYTHON) -mpy_compile $<
94	$(MV) $(*).pyc $@
95
96$(ROOTPYDIR_24)/%.pyc: python2.4/%.pyc
97	$(INS.pyfile)
98
99$(ROOTPYDIR_26)/%.pyc: python2.6/%.pyc
100	$(INS.pyfile)
101
102$(ROOTPYDIR_24)/%.py $(ROOTPYDIR_26)/%.py: %.py
103	$(INS.pyfile)
104
105pyclobber:
106	$(RM) $(CLOBBERFILES)
107	$(RM) -rf $(CLOBBERDIRS)
108