blob: 52e8f53e50cd81b666bba9ffa632e351e7c8d680 [file] [log] [blame]
Joey Armstrong78fca2d2024-05-01 16:51:58 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2022-2024 Open Networking Foundation 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: 2022-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20# Intent: This makefile will gather sources from the filesystem and
21# dynamically enable targets and functionality based on extension.
22# -----------------------------------------------------------------------
23
24$(if $(DEBUG),$(warning ENTER))
25
26##-------------------##
27##---] GLOBALS [---##
28##-------------------##
29
30##--------------------##
31##---] INCLUDES [---##
32##--------------------##
33
34##---------------------##
35##---] FUNCTIONS [---##
36##---------------------##
37
38# -----------------------------------------------------------------------
39# Intent: Given a source type determine if sources are available:
40# -----------------------------------------------------------------------
41# Given:
42# scalar One of {GO,PYTHON,RST} - patterns from detect/src-by-ext.mk
43# Return:
44# array - a list of files matching pattern:
45# TRUE - when files match pattern
46# FALSE - otherwise (NULL/empty list)
47# -----------------------------------------------------------------------
48# Usage:
49# getfiles() - Raise an execption when files are unavailable.
50# getfiles_noerr() - Used for iteration, NOP when source unavailable.
51#
52# $(call getfiles,GO)
53# files := $(call getfiles,GO)
54#
55# $(foreach src,$(call getfiles_noerr,PYTHON),$(info ** SOURCE: $(src)))
56# -----------------------------------------------------------------------
57getfiles_noerr = $(filter $($(1)_ext),$(_raw_))
58getfiles = $(or $(filter $($(1)_ext),$(_raw_)),\
59 $(error File by extension $(1)=[$($(1)_ext)] not found))
60
61# -----------------------------------------------------------------------
62# Intent: Conditionally invoke a make function when sources are available
63# -----------------------------------------------------------------------
64# Usage:
65# $(call if_enabled_call,GO,$(shell $(MAKE) lint-golang))
66# -----------------------------------------------------------------------
67if_enabled_call = $(if $(USE_$(1)),$(call $(2)))
68
69# -----------------------------------------------------------------------
70# Intent: Define a named variable when sources are detected.
71# - If source type 'GO' define USE_GO=
72# - If source type 'PYTHON' define USE_PYTHON=
73# -----------------------------------------------------------------------
74# Usage:
75# $(call useEnable,GO)
76# $(info ** Golang source detection: USE_GO=$(USE_GO))
77# -----------------------------------------------------------------------
78useEnable = $(if $(call getfiles_noerr,$(1))$(USE_$(1)),$(eval USE_$(1):=1))
79
80# [EOF]