blob: 6e181661fa3c11357d766766e387fa9ab6eec23e [file] [log] [blame]
Joey Armstrongccab2cf2024-04-06 18:00:59 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2024 Open Networking Foundation (ONF) and the ONF Contributors
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# -----------------------------------------------------------------------
17# SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20
21$(if $(DEBUG),$(warning ENTER))
22
23## -----------------------------------------------------------------------
24## Intent: Helper method, return path to an installed node package command
25## -----------------------------------------------------------------------
26node-get-tool-path = $(node-modules-root)/.bin/$(1)
27
28## -----------------------------------------------------------------------
29## Intent: Define a user function template that will dynamically
30## generate makfile targets and dependencies used to install
31## npm/node/node-js pacakges.
32## -----------------------------------------------------------------------
33## - Dependency driven so packages are only installed when needed.
34## - Define package name as a target so it can be used as a makefile dependency
35## [makefile] install : npm-groovy-lint
36## % make install -- install tool npm-groovy-lint
37## -----------------------------------------------------------------------
38define npm-install-tmpl
39
40# npm-groovy-lint : $(npm-groovy-lint)
41$(1) : $(node-modules-root)/.bin/$(1)
42
43# bin/npm-groovy-lint : NODE_DIR/nvm.sh
44$(node-modules-root)/.bin/$(1) : $(nvm-sh)
45$(tab)$(activate-npm) && $(npm-install-cmd) "$(1)"
46$(tab)$(activate-npm) && "$(node-modules-root)/.bin/$(1)" --version
47endef
48
49## -----------------------------------------------------------------------
50## Intent: Front end for making a parametierzed template call.
51## - create named local vars.
52## - [debug] display target rule generated.
53## - use $(eval) to create an installer target.
54## -----------------------------------------------------------------------
55## Usage: $(call gen-npm-install,npm-groovy-lint)
56## -----------------------------------------------------------------------
57gen-npm-install=\
58 $(foreach package,$(1),\
59 $(if $(DEBUG),$(info ** $(eval $(call npm-install-tmpl,$(package)))))\
60 $(eval $(call npm-install-tmpl,$(package)))\
61)
62
63## -----------------------------------------------------------------------
64## Intent: Map function used to install a list of node modules
65## -----------------------------------------------------------------------
66## Usage:
67## packages += npm-groovy-lint
68## packages += another-npm-package
69## $(call gen-npm-installs,packages)
70## -----------------------------------------------------------------------
71gen-npm-installs = $(forach pkg,$($(1)),$(call gen-npm-install,$(pkg)))
72
73$(if $(DEBUG),$(warning LEAVE))
74
75# [EOF]