2

How to find out all #define used by arduino-cli in compile?

I had seen something some time ago, but I cannot find it again. I think that it was some option somewhere, and the result was that the compile did not end normally, but some generated file contained lots of useful and lots of obscure defined names.

I would like to find everything that's defined in my program, which I want to write, compile, and then run on different Arduinos, but it sometimes need different Serial to be used, different pin assignments, different internal buffer sizes and so on.

And I would like to organize the differences better, than just put all and everything to one big #ifdef - #endif for each extra platform.

Something like:

  • if it does not have Serial but Serial1, #define Serial Serial1
  • if it has 2kB RAM or less, set MY_BUF_SIZE to 10; if it has less than 3kB use 30, else use 100.
  • but if it is Micro Pro, use this pin assignment, else if it is Nano Every use that, else issue error/warning for user, that pins need to be assigned.

And many others...

Rohit Gupta
  • 618
  • 2
  • 5
  • 18
gilhad
  • 1,466
  • 2
  • 11
  • 20

1 Answers1

3

I am not familiar with arduino-cli. If you can manage to find the g++ command line it uses for compiling your sketch, then you can get the list you are looking for by using a modified version of that command:

  • add the options -E -dM
  • find the option -o output_file and change the name of the output file to something more appropriate.

Edit: Following a suggestion by @gilhad, you can build the required command line by piping the output of arduino-cli through sed:

arduino-cli compile | \
    sed -n '/g++.*\.ino\.cpp\.o/{s/-MMD//;s/-o .*/-E -dM -o defines.dump/;p}'
Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81