Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 3 | # Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 4 | # |
| 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. |
| 16 | ## ----------------------------------------------------------------------- |
Joey Armstrong | f320860 | 2023-06-03 15:12:23 -0400 | [diff] [blame] | 17 | # https://gerrit.opencord.org/plugins/gitiles/onf-make |
| 18 | # ONF.makefile.version = 1.0 |
| 19 | # ----------------------------------------------------------------------- |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 20 | |
Joey Armstrong | 3f575f7 | 2023-01-15 23:49:19 -0500 | [diff] [blame] | 21 | $(if $(DEBUG),$(warning ENTER)) |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 22 | |
Joey Armstrong | 8384f8b | 2023-02-06 12:46:08 -0500 | [diff] [blame] | 23 | ##-------------------## |
| 24 | ##---] GLOBALS [---## |
| 25 | ##-------------------## |
| 26 | .PHONY: venv |
| 27 | |
| 28 | ##------------------## |
| 29 | ##---] LOCALS [---## |
| 30 | ##------------------## |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 31 | venv-name ?= .venv# # default install directory |
Joey Armstrong | 3f575f7 | 2023-01-15 23:49:19 -0500 | [diff] [blame] | 32 | venv-abs-path := $(PWD)/$(venv-name) |
| 33 | |
| 34 | venv-activate-script := $(venv-name)/bin/activate# # dependency |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 35 | |
| 36 | # Intent: activate= is a macro for accessing the virtualenv activation script# |
| 37 | # Usage: $(activate) && python |
| 38 | activate ?= set +u && source $(venv-activate-script) && set -u |
Joey Armstrong | 3f575f7 | 2023-01-15 23:49:19 -0500 | [diff] [blame] | 39 | |
| 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 Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 47 | @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 |
| 54 | $(activate) && { [[ -r requirements.txt ]] && python -m pip install -r requirements.txt; } |
| 55 | $(activate) && python --version |
Joey Armstrong | 3f575f7 | 2023-01-15 23:49:19 -0500 | [diff] [blame] | 56 | |
| 57 | ## ----------------------------------------------------------------------- |
| 58 | ## Intent: Explicit named installer target w/o dependencies. |
| 59 | ## Makefile targets should depend on venv-activate-script. |
| 60 | ## ----------------------------------------------------------------------- |
| 61 | venv: $(venv-activate-script) |
| 62 | |
| 63 | ## ----------------------------------------------------------------------- |
| 64 | ## Intent: Revert installation to a clean checkout |
| 65 | ## ----------------------------------------------------------------------- |
| 66 | sterile :: clean |
| 67 | $(RM) -r "$(venv-abs-path)" |
| 68 | |
| 69 | ## ----------------------------------------------------------------------- |
| 70 | ## ----------------------------------------------------------------------- |
| 71 | help :: |
| 72 | @echo |
| 73 | @echo '[VIRTUAL ENV]' |
Joey Armstrong | 068d645 | 2023-02-01 11:09:18 -0500 | [diff] [blame] | 74 | @echo ' venv Create a python virtual environment' |
| 75 | @echo ' venv-name= Subdir name for virtualenv install' |
Joey Armstrong | a516c32 | 2023-01-25 17:40:42 -0500 | [diff] [blame] | 76 | @echo ' venv-activate-script make macro name' |
| 77 | @echo ' $$(target) dependency install python virtualenv' |
| 78 | @echo ' source $$(macro) && cmd configure env and run cmd' |
Joey Armstrong | 3f575f7 | 2023-01-15 23:49:19 -0500 | [diff] [blame] | 79 | |
| 80 | $(if $(DEBUG),$(warning LEAVE)) |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 81 | |
| 82 | # [EOF] |