]> git.ipfire.org Git - thirdparty/u-boot.git/blame - tools/scripts/define2mk.sed
tools: fix define2mk.sed to not add quotes around negative integers
[thirdparty/u-boot.git] / tools / scripts / define2mk.sed
CommitLineData
2f155f6c
GL
1#
2# Sed script to parse CPP macros and generate output usable by make
3#
4# It is expected that this script is fed the output of 'gpp -dM'
5# which preprocesses the common.h header files and outputs the final
6# list of CPP macros (and whitespace is sanitized)
7#
8
9# Only process values prefixed with #define CONFIG_
02409f8c 10/^#define CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*/ {
2f155f6c
GL
11 # Strip the #define prefix
12 s/#define *//;
13 # Change to form CONFIG_*=VALUE
02409f8c 14 s/ */=/;
2f155f6c
GL
15 # Drop trailing spaces
16 s/ *$//;
17 # drop quotes around string values
18 s/="\(.*\)"$/=\1/;
19 # Concatenate string values
20 s/" *"//g;
2bad5df7
WD
21 # Assume strings as default - add quotes around values
22 s/=\(..*\)/="\1"/;
23 # but remove again from decimal numbers
24 s/="\([0-9][0-9]*\)"/=\1/;
cd51878e
MY
25 # ... and from negative decimal numbers
26 s/="\(-[1-9][0-9]*\)"/=\1/;
2bad5df7
WD
27 # ... and from hex numbers
28 s/="\(0[Xx][0-9a-fA-F][0-9a-fA-F]*\)"/=\1/;
2979b263
BT
29 # ... and from configs defined from other configs
30 s/="\(CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*\)"/=$(\1)/;
2f155f6c
GL
31 # Change '1' and empty values to "y" (not perfect, but
32 # supports conditional compilation in the makefiles
33 s/=$/=y/;
34 s/=1$/=y/;
35 # print the line
36 p
37}