1# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
2#
3# SPDX-License-Identifier: BSD-3-Clause
4#
5
6.SUFFIXES:
7.SUFFIXES: .j2
8
9# Disable parallel execution for this makefile.
10.NOTPARALLEL:
11
12TEMPLATES:=$(wildcard *.j2)
13OUTPUTS:=$(TEMPLATES:%.j2=%)
14
15FILTER_PATTERN ?=
16
17ifneq (,${FILTER_PATTERN})
18RUN_SH_ARGS += -p "${FILTER_PATTERN}"
19endif
20
21ifneq (,${INSTALL_PREFIX})
22RUN_SH_ARGS += -i ${INSTALL_PREFIX}
23endif
24
25ifneq (,${BUILD_PREFIX})
26RUN_SH_ARGS += -b ${BUILD_PREFIX}
27endif
28
29ifneq (,${LOGDIR_ROOT})
30RUN_SH_ARGS += -l ${LOGDIR_ROOT}
31endif
32
33all:
34	${MAKE} config
35	bash run.sh ${RUN_SH_ARGS}
36
37config: ${OUTPUTS}
38
39list:
40	${MAKE} config
41	bash run.sh ${RUN_SH_ARGS} help
42
43# run a command of the generated script
44r-%:
45	${MAKE} config
46	bash run.sh ${RUN_SH_ARGS} "$*"
47
48define help_msg
49*************************************************************
50Variables:
51  Variables can be passed as arguments (make <var>=<value>)
52  or be set in the environment (e.g. export <var>=<value>;
53  make ...).
54
55  BUILD_PREFIX   - Directory for build directories
56  FILTER_PATTERN - grep regexp to limit test scope to tests
57                   whose name matches. To see the selected tests
58                   run: make FILTER_PATTERN=<pattern> list
59  INSTALL_PREFIX - Directory to install projects
60  LOGDIR_ROOT    - Directory to save build logs
61
62Available targets:
63  all          - generate and run test script
64  config       - run script generation only
65  clean        - remove intermediate files
66  list         - run config and list test cases
67  p-<variable> - print value of make variable (for debugging)
68  r-<test>     - run a command of the generated script. Allow
69                 executing a single test case. Use
70                    make r-help
71                 to get the list of tests.
72*************************************************************
73endef
74
75export help_msg
76help:
77	@echo "$$help_msg"
78
79# remove intermediate output
80clean:
81ifneq ($(wildcard ./run.sh),)
82	bash run.sh clean
83endif
84	-rm -rf ${OUTPUTS}
85
86# Convert template to shell script
87%.sh : %.sh.j2 test_data.yaml
88	yasha -v test_data.yaml $<
89
90# print variable value (i.e. make p-TEMPLATES)
91p-%:
92	@echo $*=${$*}
93