Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 3 | # Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -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. |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
Joey Armstrong | 64b8249 | 2023-06-01 17:34:39 -0400 | [diff] [blame] | 17 | # https://gerrit.opencord.org/plugins/gitiles/onf-make |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 18 | # ONF.makefile.version = 1.2 |
Joey Armstrong | 64b8249 | 2023-06-01 17:34:39 -0400 | [diff] [blame] | 19 | # ----------------------------------------------------------------------- |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 20 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 21 | $(if $(DEBUG),$(warning ENTER)) |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 22 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 23 | ##-------------------## |
| 24 | ##---] GLOBALS [---## |
| 25 | ##-------------------## |
| 26 | .PHONY: venv |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 27 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 28 | ##------------------## |
| 29 | ##---] LOCALS [---## |
| 30 | ##------------------## |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 31 | venv-name ?= .venv# # default install directory |
| 32 | venv-abs-path := $(PWD)/$(venv-name) |
| 33 | venv-activate-bin := $(venv-name)/bin |
| 34 | venv-activate-script := $(venv-activate-bin)/activate# # dependency |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -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 |
| 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. |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 45 | ## ---------------------------------------------------------------------- |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 46 | $(venv-activate-script): |
| 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 |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 54 | $(activate) && [[ -r requirements.txt ]] \ |
| 55 | && { python -m pip install -r requirements.txt; } \ |
| 56 | || { /bin/true; } |
| 57 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 58 | $(activate) && python --version |
| 59 | |
Joey Armstrong | 449ce7a | 2023-07-18 18:32:24 -0400 | [diff] [blame] | 60 | ## ----------------------------------------------------------------------- |
| 61 | ## Intent: Explicit named installer target w/o dependencies. |
| 62 | ## Makefile targets should depend on venv-activate-script. |
| 63 | ## ----------------------------------------------------------------------- |
| 64 | venv-activate-patched := $(venv-activate-script).patched |
| 65 | venv-activate-patched : $(venv-activate-patched) |
| 66 | $(venv-activate-patched) : $(venv-activate-script) |
| 67 | $(call banner-enter,Target $@) |
| 68 | $(onf-mk-top)/../patches/python_310_migration.sh |
| 69 | touch $@ |
| 70 | $(call banner-leave,Target $@) |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 71 | |
| 72 | ## ----------------------------------------------------------------------- |
| 73 | ## Intent: Explicit named installer target w/o dependencies. |
| 74 | ## Makefile targets should depend on venv-activate-script. |
| 75 | ## ----------------------------------------------------------------------- |
| 76 | venv: $(venv-activate-script) |
| 77 | |
| 78 | ## ----------------------------------------------------------------------- |
| 79 | ## Intent: Revert installation to a clean checkout |
| 80 | ## ----------------------------------------------------------------------- |
| 81 | sterile :: clean |
| 82 | $(RM) -r "$(venv-abs-path)" |
| 83 | |
| 84 | ## ----------------------------------------------------------------------- |
| 85 | ## ----------------------------------------------------------------------- |
| 86 | help :: |
Joey Armstrong | 0cbee51 | 2023-10-18 15:39:24 -0400 | [diff] [blame] | 87 | @printf '\n[VIRTUAL ENV]\n' |
| 88 | @printf ' %-25.25s %s\n' 'venv' \ |
| 89 | 'Create a python virtual environment' |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 90 | @echo ' venv-name= Subdir name for virtualenv install' |
Joey Armstrong | 0cbee51 | 2023-10-18 15:39:24 -0400 | [diff] [blame] | 91 | @printf ' %-25.25s %s\n' 'venv-activate-script' \ |
| 92 | 'venv make-once target dependency' |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 93 | @echo ' $$(target) dependency install python virtualenv' |
| 94 | @echo ' source $$(macro) && cmd configure env and run cmd' |
Joey Armstrong | 0cbee51 | 2023-10-18 15:39:24 -0400 | [diff] [blame] | 95 | @printf ' %-25.25s %s\n' 'venv-activate-patched' \ |
| 96 | 'venv-activate-script patched for python v3.10+' |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 97 | |
| 98 | $(if $(DEBUG),$(warning LEAVE)) |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 99 | |
| 100 | # [EOF] |