Grant Likely | 0f91019 | 2007-09-24 09:05:31 -0600 | [diff] [blame] | 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_ |
Marcel Moolenaar | 0760ff9 | 2008-02-22 10:48:07 -0800 | [diff] [blame] | 10 | /^#define CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*/ { |
Grant Likely | 0f91019 | 2007-09-24 09:05:31 -0600 | [diff] [blame] | 11 | # Strip the #define prefix |
| 12 | s/#define *//; |
| 13 | # Change to form CONFIG_*=VALUE |
Marcel Moolenaar | 0760ff9 | 2008-02-22 10:48:07 -0800 | [diff] [blame] | 14 | s/ */=/; |
Grant Likely | 0f91019 | 2007-09-24 09:05:31 -0600 | [diff] [blame] | 15 | # Drop trailing spaces |
| 16 | s/ *$//; |
| 17 | # drop quotes around string values |
| 18 | s/="\(.*\)"$/=\1/; |
| 19 | # Concatenate string values |
| 20 | s/" *"//g; |
Wolfgang Denk | d52a799 | 2010-10-16 23:50:51 +0200 | [diff] [blame] | 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/; |
| 25 | # ... and from hex numbers |
| 26 | s/="\(0[Xx][0-9a-fA-F][0-9a-fA-F]*\)"/=\1/; |
Benoît Thébaudeau | 924e40c | 2013-04-11 09:35:48 +0000 | [diff] [blame] | 27 | # ... and from configs defined from other configs |
| 28 | s/="\(CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*\)"/=$(\1)/; |
Grant Likely | 0f91019 | 2007-09-24 09:05:31 -0600 | [diff] [blame] | 29 | # Change '1' and empty values to "y" (not perfect, but |
| 30 | # supports conditional compilation in the makefiles |
| 31 | s/=$/=y/; |
| 32 | s/=1$/=y/; |
| 33 | # print the line |
| 34 | p |
| 35 | } |