summaryrefslogtreecommitdiff
path: root/tools/meson-apply-m4.sh
blob: 6c5726a7d5343ebf5fa516529622dfdd40be578a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eu

CONFIG="${1:?Missing path to config.h}"
TARGET="${2:?Missing target m4 file}"

if [ ! -f "$CONFIG" ]; then
    echo "$CONFIG not found."
    exit 2
fi

if [ ! -f "$TARGET" ]; then
    echo "$TARGET not found."
    exit 3
fi

DEFINES=()
mapfile -t DEFINES < <(awk '$1 == "#define" && $3 == "1" { printf "-D%s\n", $2 }' "$CONFIG")

m4 -P "${DEFINES[@]}" "$TARGET"