define2mk.sed 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. # Only process values prefixed with #define CONFIG_
  9. /^#define CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*/ {
  10. # Strip the #define prefix
  11. s/#define *//;
  12. # Change to form CONFIG_*=VALUE
  13. s/ */=/;
  14. # Drop trailing spaces
  15. s/ *$//;
  16. # drop quotes around string values
  17. s/="\(.*\)"$/=\1/;
  18. # Concatenate string values
  19. s/" *"//g;
  20. # Assume strings as default - add quotes around values
  21. s/=\(..*\)/="\1"/;
  22. # but remove again from decimal numbers
  23. s/="\([0-9][0-9]*\)"/=\1/;
  24. # ... and from negative decimal numbers
  25. s/="\(-[1-9][0-9]*\)"/=\1/;
  26. # ... and from hex numbers
  27. s/="\(0[Xx][0-9a-fA-F][0-9a-fA-F]*\)"/=\1/;
  28. # ... and from configs defined from other configs
  29. s/="\(CONFIG_[A-Za-z0-9_][A-Za-z0-9_]*\)"/=$(\1)/;
  30. # Change '1' and empty values to "y" (not perfect, but
  31. # supports conditional compilation in the makefiles
  32. s/=$/=y/;
  33. s/=1$/=y/;
  34. # print the line
  35. p
  36. }