Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 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. |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 24 | # Copyright 2018 OmniOS Community Edition (OmniOSce) Association. |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 25 | # |
| 26 | |
| 27 | # |
| 28 | # This Makefile provides a framework for building the onbld python |
| 29 | # modules with multiple versions of python. |
| 30 | # |
| 31 | # It expects as input: |
| 32 | # |
| 33 | # PYSRCS - List of python source files, these are also delivered as |
| 34 | # build product. |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 35 | # |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 36 | # PYOBJS - List of compiled python (.pyc) files, with no directory prefix |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 37 | # |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 38 | # PYTOPDIR - Absolute (including $(ROOT)) path to which files will |
| 39 | # be installed, up until the version specific component. |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 40 | # |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 41 | # PYMODDIR - Relative path to which files will be installed, below |
| 42 | # the version specific component. |
| 43 | # |
| 44 | # For example, to install to /opt/onbld/lib/onbld/python*/bar/ |
| 45 | # |
| 46 | # PYTOPDIR = $(ROOTONBLDLIB) |
| 47 | # PYMODDIR = bar |
| 48 | # |
| 49 | # |
| 50 | # It provides as output: |
| 51 | # |
| 52 | # ROOTPYFILES - The list of $(ROOT)-relative paths to which python |
| 53 | # source and binary files will be installed. Your |
| 54 | # Makefile's 'install' target should depend upon |
| 55 | # this. |
| 56 | # |
| 57 | # PYVERSOBJS - The list of paths to compiled python build products, |
| 58 | # including their subdirectory. |
| 59 | # |
| 60 | # pyclobber - A target on which 'clobber' should depend, which |
| 61 | # removes the per-version python directories and the |
| 62 | # output within them. |
| 63 | # |
| 64 | |
| 65 | PYFILES = $(PYSRCS) $(PYOBJS) |
| 66 | |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 67 | ROOTPYDIR = $(PYTOPDIR)/python$(PYVER)/$(PYMODDIR) |
Alexander Pyhalov | 9f92308 | 2016-08-30 12:55:15 +0300 | [diff] [blame] | 68 | ROOTPYFILES = $(PYFILES:%=$(ROOTPYDIR)/%) |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 69 | |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 70 | $(ROOTPYFILES) := FILEMODE = 0444 |
| 71 | |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 72 | PYVERSDIRS = python$(PYVER) |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 73 | |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 74 | PYVERSOBJS = $(PYOBJS:%=python$(PYVER)/%) |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 75 | |
| 76 | CLOBBERFILES += $(PYVERSOBJS) |
| 77 | CLOBBERDIRS += $(PYVERSDIRS) |
| 78 | |
| 79 | .KEEP_STATE: |
| 80 | |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 81 | $(ROOTPYDIR)/%.py: ../%.py |
Richard Lowe | 87ab362 | 2010-04-22 10:13:38 -0700 | [diff] [blame] | 82 | $(INS.pyfile) |
| 83 | |
| 84 | pyclobber: |
| 85 | $(RM) $(CLOBBERFILES) |
| 86 | $(RM) -rf $(CLOBBERDIRS) |
Andy Fiddaman | b9219c8 | 2018-11-15 10:17:46 +0000 | [diff] [blame^] | 87 | |
| 88 | # Python 2 module compilation |
| 89 | |
| 90 | python$(PYVER)/%.pyc: ../%.py |
| 91 | @[ -d $(@D) ] || mkdir $(@D) |
| 92 | $(RM) $@ |
| 93 | $(PYTHON) -mpy_compile $< |
| 94 | $(MV) ../$(*).pyc $@ |
| 95 | |
| 96 | $(ROOTPYDIR)/%.pyc: python$(PYVER)/%.pyc |
| 97 | $(INS.pyfile) |
| 98 | |
| 99 | # Python 3 module compilation |
| 100 | |
| 101 | python$(PYVER)/__pycache__/%.cpython$(PYPKGVERS).pyc: ../%.py |
| 102 | @[ -d $(@D) ] || mkdir -p $(@D) |
| 103 | $(RM) $@ |
| 104 | $(PYTHON3) -mpy_compile $< |
| 105 | $(MV) ../__pycache__/$(*).cpython$(PYPKGVERS).pyc $@ |
| 106 | |
| 107 | $(ROOTPYDIR)/__pycache__/%.pyc: python$(PYVER)/__pycache__/%.pyc |
| 108 | $(INS.pyfile) |
| 109 | |