xref: /rk3399_rockchip-uboot/tools/scripts/define2mk.sed (revision 2bad5df7274dd2802ba9526ea7218e9c09d3f89c)
12f155f6cSGrant Likely#
22f155f6cSGrant Likely# Sed script to parse CPP macros and generate output usable by make
32f155f6cSGrant Likely#
42f155f6cSGrant Likely# It is expected that this script is fed the output of 'gpp -dM'
52f155f6cSGrant Likely# which preprocesses the common.h header files and outputs the final
62f155f6cSGrant Likely# list of CPP macros (and whitespace is sanitized)
72f155f6cSGrant Likely#
82f155f6cSGrant Likely
92f155f6cSGrant Likely# Only process values prefixed with #define CONFIG_
1002409f8cSMarcel Moolenaar/^#define CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*/ {
112f155f6cSGrant Likely	# Strip the #define prefix
122f155f6cSGrant Likely	s/#define *//;
132f155f6cSGrant Likely	# Change to form CONFIG_*=VALUE
1402409f8cSMarcel Moolenaar	s/  */=/;
152f155f6cSGrant Likely	# Drop trailing spaces
162f155f6cSGrant Likely	s/ *$//;
172f155f6cSGrant Likely	# drop quotes around string values
182f155f6cSGrant Likely	s/="\(.*\)"$/=\1/;
192f155f6cSGrant Likely	# Concatenate string values
202f155f6cSGrant Likely	s/" *"//g;
21*2bad5df7SWolfgang Denk	# Assume strings as default - add quotes around values
22*2bad5df7SWolfgang Denk	s/=\(..*\)/="\1"/;
23*2bad5df7SWolfgang Denk	# but remove again from decimal numbers
24*2bad5df7SWolfgang Denk	s/="\([0-9][0-9]*\)"/=\1/;
25*2bad5df7SWolfgang Denk	# ... and from hex numbers
26*2bad5df7SWolfgang Denk	s/="\(0[Xx][0-9a-fA-F][0-9a-fA-F]*\)"/=\1/;
272f155f6cSGrant Likely	# Change '1' and empty values to "y" (not perfect, but
282f155f6cSGrant Likely	# supports conditional compilation in the makefiles
292f155f6cSGrant Likely	s/=$/=y/;
302f155f6cSGrant Likely	s/=1$/=y/;
312f155f6cSGrant Likely	# print the line
322f155f6cSGrant Likely	p
332f155f6cSGrant Likely}
34