xref: /rk3399_rockchip-uboot/tools/scripts/define2mk.sed (revision a52142855a1345c233af8bb76fb1ad4d3048e008)
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;
212bad5df7SWolfgang Denk	# Assume strings as default - add quotes around values
222bad5df7SWolfgang Denk	s/=\(..*\)/="\1"/;
232bad5df7SWolfgang Denk	# but remove again from decimal numbers
242bad5df7SWolfgang Denk	s/="\([0-9][0-9]*\)"/=\1/;
25*cd51878eSMasahiro Yamada	# ... and from negative decimal numbers
26*cd51878eSMasahiro Yamada	s/="\(-[1-9][0-9]*\)"/=\1/;
272bad5df7SWolfgang Denk	# ... and from hex numbers
282bad5df7SWolfgang Denk	s/="\(0[Xx][0-9a-fA-F][0-9a-fA-F]*\)"/=\1/;
292979b263SBenoît Thébaudeau	# ... and from configs defined from other configs
302979b263SBenoît Thébaudeau	s/="\(CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*\)"/=$(\1)/;
312f155f6cSGrant Likely	# Change '1' and empty values to "y" (not perfect, but
322f155f6cSGrant Likely	# supports conditional compilation in the makefiles
332f155f6cSGrant Likely	s/=$/=y/;
342f155f6cSGrant Likely	s/=1$/=y/;
352f155f6cSGrant Likely	# print the line
362f155f6cSGrant Likely	p
372f155f6cSGrant Likely}
38