summaryrefslogtreecommitdiff
path: root/cleopatre/application/config_to_header
blob: 8d8c4ee9f222e7466ca890c510d5631fa798acea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /bin/bash

# Takes a config file and generates the corresponding ".h" header file.

if [ $# -lt 3 ]
then
    echo "Usage: $0 input_config_file output_header_file header_guard"
    exit 1
fi

# The input config file
config="$1"

# The path and name of the output header file.
header="$2"

# The name of the macro to use as a guard for the output header file.
guard="$3"

echo \
"#ifndef ${guard}
#define ${guard}
" > "${header}"

sed -r \
    -e "/^#/d" \
    -e "s/^CONFIG_(.*)=y/#define CONFIG_\1 1/" \
    -e "/^CONFIG_(.*)=n/d" \
    -e "s/^CONFIG_(.*)=(.*)/#define CONFIG_\1 \2/" \
    "${config}" >> "${header}"

echo "
#endif /* ${guard} */" >> ${header}