blob: 110732ee3966a191730562e3196306edde903dfa [file] [log] [blame]
Joey Armstronga6890342023-06-01 17:07:51 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong78fca2d2024-05-01 16:51:58 -04003# Copyright 2022-2024 Open Networking Foundation Contributors
Joey Armstronga6890342023-06-01 17:07:51 -04004#
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 Armstrong78fca2d2024-05-01 16:51:58 -040016# -----------------------------------------------------------------------
17# SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
Joey Armstronga6890342023-06-01 17:07:51 -040018# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
Joey Armstrong78fca2d2024-05-01 16:51:58 -040020# Intent: This makefile will gather available sources from a filesystem
21# then enable targets and functionality based on extensions.
22# -----------------------------------------------------------------------
Joey Armstronga6890342023-06-01 17:07:51 -040023
24$(if $(DEBUG),$(warning ENTER))
25
Joey Armstrong78fca2d2024-05-01 16:51:58 -040026##-------------------##
27##---] GLOBALS [---##
28##-------------------##
29
30##--------------------##
31##---] INCLUDES [---##
32##--------------------##
33
Joey Armstronga6890342023-06-01 17:07:51 -040034# usage: $(call if-not,false,5)
35if-not = $(info 1=$(1), 2=$(2), 3=$(3))\
36 $(if $(1),$(null),$(2))
37
Joey Armstronga3f9aca2024-02-11 11:58:11 -050038## -----------------------------------------------------------------------
39## Intent: Derive a filesystem path relative to the active makefile.
40## Primary use is loading adjacent tool config files.
41## Immediate evaluation (:=) needed to preserve path context.
42## Note: We could pass in var=MAKEFILE_LIST
43## -----------------------------------------------------------------------
44## Given:
45## scalar Filename to construct a path for
46## Return:
47## scalar Constructed path for the given filename
48## -----------------------------------------------------------------------
49## Usage:
50## groovy-check-conf := $(call path-by-makefile,.groovylintrc.json)
51## groovy-cmd = npm-groovy-lint --config "$(groovy-check-conf)"
52## -----------------------------------------------------------------------
Joey Armstrong7ebfb1f2024-02-29 12:24:08 -050053path-by-makefilepath-by-makefile = $(strip \
Joey Armstronga3f9aca2024-02-11 11:58:11 -050054 $(foreach filename,$(1),\
55 $(foreach makefile,$(lastword $(MAKEFILE_LIST)),\
Joey Armstrong7ebfb1f2024-02-29 12:24:08 -050056 $(foreach makedir,$(dir $(makefile)),\
57 $(makedir)$(filename)\
Joey Armstronga3f9aca2024-02-11 11:58:11 -050058 )\
59 ))\
60)
61
Joey Armstrong7ebfb1f2024-02-29 12:24:08 -050062## -----------------------------------------------------------------------
63## Intent: Improve function usability for path-by-makefilepath-by-makefile
64## -----------------------------------------------------------------------
65## Given:
66## scalar A makefile variable name to define
67## scalar Path within a makefile subdirectory to construct
68## Return:
69## scalar Constructed path for the given filename
70## -----------------------------------------------------------------------
71## Usage:
72## $(call genpath-makefiles,tox-ini,tox.ini)
73## $(info tox-ini = $(tox-ini))
74## -----------------------------------------------------------------------
75genpath-makefiles = $(strip \
76\
77 $(foreach var,$(1),\
78 $(foreach fyl,$(2),\
Joey Armstrong7ebfb1f2024-02-29 12:24:08 -050079 $(eval $(var) := $(call path-by-makefilepath-by-makefile,$(fyl)))\
80 ))\
81 $(var)\
82)
83
Joey Armstronga6890342023-06-01 17:07:51 -040084$(if $(DEBUG),$(warning LEAVE))
85
86# [EOF]