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