xref: /illumos-gate/usr/src/tools/Makefile.python (revision 70143b9f)
187ab3622SRichard Lowe#
287ab3622SRichard Lowe# CDDL HEADER START
387ab3622SRichard Lowe#
487ab3622SRichard Lowe# The contents of this file are subject to the terms of the
587ab3622SRichard Lowe# Common Development and Distribution License (the "License").
687ab3622SRichard Lowe# You may not use this file except in compliance with the License.
787ab3622SRichard Lowe#
887ab3622SRichard Lowe# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
987ab3622SRichard Lowe# or http://www.opensolaris.org/os/licensing.
1087ab3622SRichard Lowe# See the License for the specific language governing permissions
1187ab3622SRichard Lowe# and limitations under the License.
1287ab3622SRichard Lowe#
1387ab3622SRichard Lowe# When distributing Covered Code, include this CDDL HEADER in each
1487ab3622SRichard Lowe# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1587ab3622SRichard Lowe# If applicable, add the following below this CDDL HEADER, with the
1687ab3622SRichard Lowe# fields enclosed by brackets "[]" replaced with your own identifying
1787ab3622SRichard Lowe# information: Portions Copyright [yyyy] [name of copyright owner]
1887ab3622SRichard Lowe#
1987ab3622SRichard Lowe# CDDL HEADER END
2087ab3622SRichard Lowe#
2187ab3622SRichard Lowe
2287ab3622SRichard Lowe#
2387ab3622SRichard Lowe# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24ca13eaa5SAndy Fiddaman# Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
2587ab3622SRichard Lowe#
2687ab3622SRichard Lowe
2787ab3622SRichard Lowe#
2887ab3622SRichard Lowe# This Makefile provides a framework for building the onbld python
2987ab3622SRichard Lowe# modules with multiple versions of python.
3087ab3622SRichard Lowe#
3187ab3622SRichard Lowe# It expects as input:
3287ab3622SRichard Lowe#
3387ab3622SRichard Lowe#    PYSRCS   - List of python source files, these are also delivered as
3487ab3622SRichard Lowe#               build product.
35ca13eaa5SAndy Fiddaman#
3687ab3622SRichard Lowe#    PYOBJS   - List of compiled python (.pyc) files, with no directory prefix
37ca13eaa5SAndy Fiddaman#
3887ab3622SRichard Lowe#    PYTOPDIR - Absolute (including $(ROOT)) path to which files will
3987ab3622SRichard Lowe#               be installed, up until the version specific component.
40ca13eaa5SAndy Fiddaman#
4187ab3622SRichard Lowe#    PYMODDIR - Relative path to which files will be installed, below
4287ab3622SRichard Lowe#               the version specific component.
4387ab3622SRichard Lowe#
4487ab3622SRichard Lowe#    For example, to install to /opt/onbld/lib/onbld/python*/bar/
4587ab3622SRichard Lowe#
4687ab3622SRichard Lowe#          PYTOPDIR = $(ROOTONBLDLIB)
4787ab3622SRichard Lowe#          PYMODDIR = bar
4887ab3622SRichard Lowe#
4987ab3622SRichard Lowe#
5087ab3622SRichard Lowe# It provides as output:
5187ab3622SRichard Lowe#
5287ab3622SRichard Lowe#    ROOTPYFILES - The list of $(ROOT)-relative paths to which python
5387ab3622SRichard Lowe#                  source and binary files will be installed.  Your
5487ab3622SRichard Lowe#                  Makefile's 'install' target should depend upon
5587ab3622SRichard Lowe#                  this.
5687ab3622SRichard Lowe#
5787ab3622SRichard Lowe#    PYVERSOBJS  - The list of paths to compiled python build products,
5887ab3622SRichard Lowe#                  including their subdirectory.
5987ab3622SRichard Lowe#
6087ab3622SRichard Lowe#    pyclobber   - A target on which 'clobber' should depend, which
6187ab3622SRichard Lowe#                  removes the per-version python directories and the
6287ab3622SRichard Lowe#                  output within them.
6387ab3622SRichard Lowe#
6487ab3622SRichard Lowe
6587ab3622SRichard LowePYFILES = $(PYSRCS) $(PYOBJS)
6687ab3622SRichard Lowe
67ca13eaa5SAndy FiddamanROOTPYDIR = $(PYTOPDIR)/python$(PYVER)/$(PYMODDIR)
689f923083SAlexander PyhalovROOTPYFILES	= $(PYFILES:%=$(ROOTPYDIR)/%)
6987ab3622SRichard Lowe
7087ab3622SRichard Lowe$(ROOTPYFILES) := FILEMODE = 0444
7187ab3622SRichard Lowe
72ca13eaa5SAndy FiddamanPYVERSDIRS = python$(PYVER)
7387ab3622SRichard Lowe
74ca13eaa5SAndy FiddamanPYVERSOBJS = $(PYOBJS:%=python$(PYVER)/%)
7587ab3622SRichard Lowe
7687ab3622SRichard LoweCLOBBERFILES += $(PYVERSOBJS)
7787ab3622SRichard LoweCLOBBERDIRS += $(PYVERSDIRS)
7887ab3622SRichard Lowe
7987ab3622SRichard Lowe.KEEP_STATE:
8087ab3622SRichard Lowe
81ca13eaa5SAndy Fiddaman$(ROOTPYDIR)/%.py: ../%.py
82ca13eaa5SAndy Fiddaman	$(INS.pyfile)
83ca13eaa5SAndy Fiddaman
84ca13eaa5SAndy Fiddamanpyclobber:
85ca13eaa5SAndy Fiddaman	$(RM) $(CLOBBERFILES)
86ca13eaa5SAndy Fiddaman	$(RM) -rf $(CLOBBERDIRS)
87ca13eaa5SAndy Fiddaman
88*70143b9fSRichard Lowe# Python module compilation
89ca13eaa5SAndy Fiddamanpython$(PYVER)/__pycache__/%.cpython$(PYPKGVERS).pyc: ../%.py
90ca13eaa5SAndy Fiddaman	@[ -d $(@D) ] || mkdir -p $(@D)
91ca13eaa5SAndy Fiddaman	$(RM) $@
92ca13eaa5SAndy Fiddaman	$(PYTHON3) -mpy_compile $<
93ca13eaa5SAndy Fiddaman	$(MV) ../__pycache__/$(*).cpython$(PYPKGVERS).pyc $@
94ca13eaa5SAndy Fiddaman
95ca13eaa5SAndy Fiddaman$(ROOTPYDIR)/__pycache__/%.pyc: python$(PYVER)/__pycache__/%.pyc
9687ab3622SRichard Lowe	$(INS.pyfile)
97