blob: a400edfaed41838fff98c089f0ddc0821e3aec5d [file] [log] [blame]
Joey Armstrong28eddda2023-01-10 03:09:34 -05001# -*- makefile -*-
2## -----------------------------------------------------------------------
Joey Armstrong518f3572024-02-11 07:56:25 -05003# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong28eddda2023-01-10 03:09:34 -05004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Joey Armstrongdd334492023-07-09 17:59:02 -040016# -----------------------------------------------------------------------
Joey Armstrongf3208602023-06-03 15:12:23 -040017# https://gerrit.opencord.org/plugins/gitiles/onf-make
Joey Armstrong4960ec92023-07-19 09:04:20 -040018# ONF.makefile.version = 1.2
Joey Armstrongf3208602023-06-03 15:12:23 -040019# -----------------------------------------------------------------------
Joey Armstrong28eddda2023-01-10 03:09:34 -050020
Joey Armstrong3f575f72023-01-15 23:49:19 -050021$(if $(DEBUG),$(warning ENTER))
Joey Armstrong28eddda2023-01-10 03:09:34 -050022
Joey Armstrong8384f8b2023-02-06 12:46:08 -050023##-------------------##
24##---] GLOBALS [---##
25##-------------------##
26.PHONY: venv
27
28##------------------##
29##---] LOCALS [---##
30##------------------##
Joey Armstrong980e37f2023-02-28 18:57:41 -050031venv-name ?= .venv# # default install directory
Joey Armstrong3f575f72023-01-15 23:49:19 -050032venv-abs-path := $(PWD)/$(venv-name)
Joey Armstrongdd334492023-07-09 17:59:02 -040033venv-activate-bin := $(venv-name)/bin
34venv-activate-script := $(venv-activate-bin)/activate# # dependency
Joey Armstrong980e37f2023-02-28 18:57:41 -050035
36# Intent: activate= is a macro for accessing the virtualenv activation script#
37# Usage: $(activate) && python
38activate ?= set +u && source $(venv-activate-script) && set -u
Joey Armstrong3f575f72023-01-15 23:49:19 -050039
40## -----------------------------------------------------------------------
41## Intent: Activate script path dependency
42## Usage:
43## o place on the right side of colon as a target dependency
44## o When the script does not exist install the virtual env and display.
45## -----------------------------------------------------------------------
46$(venv-activate-script):
Joey Armstrong980e37f2023-02-28 18:57:41 -050047 @echo
48 @echo "============================="
49 @echo "Installing python virtual env"
50 @echo "============================="
51 virtualenv -p python3 $(venv-name)
52 $(activate) && python -m pip install --upgrade pip
53 $(activate) && pip install --upgrade setuptools
Joey Armstrong4960ec92023-07-19 09:04:20 -040054 $(activate) && [[ -r requirements.txt ]] \
55 && { python -m pip install -r requirements.txt; } \
56 || { /bin/true; }
57
Joey Armstrong980e37f2023-02-28 18:57:41 -050058 $(activate) && python --version
Joey Armstrong3f575f72023-01-15 23:49:19 -050059
60## -----------------------------------------------------------------------
61## Intent: Explicit named installer target w/o dependencies.
62## Makefile targets should depend on venv-activate-script.
63## -----------------------------------------------------------------------
64venv: $(venv-activate-script)
65
66## -----------------------------------------------------------------------
67## Intent: Revert installation to a clean checkout
68## -----------------------------------------------------------------------
69sterile :: clean
70 $(RM) -r "$(venv-abs-path)"
71
72## -----------------------------------------------------------------------
73## -----------------------------------------------------------------------
74help ::
75 @echo
76 @echo '[VIRTUAL ENV]'
Joey Armstrong068d6452023-02-01 11:09:18 -050077 @echo ' venv Create a python virtual environment'
78 @echo ' venv-name= Subdir name for virtualenv install'
Joey Armstronga516c322023-01-25 17:40:42 -050079 @echo ' venv-activate-script make macro name'
80 @echo ' $$(target) dependency install python virtualenv'
81 @echo ' source $$(macro) && cmd configure env and run cmd'
Joey Armstrong3f575f72023-01-15 23:49:19 -050082
83$(if $(DEBUG),$(warning LEAVE))
Joey Armstrong28eddda2023-01-10 03:09:34 -050084
85# [EOF]