Conditional defines based on selected port

Hi.

I have several micro controllers that support over the air flashing of firmware, which allows me to wirelessly update the software on the controllers.

They all run a similar program, but are slightly different based on there location (their assigned IP address, their port name, and mqtt client name, for instance).

What i would like to do is enable defines in the software based on which upload port i have selected. I know that this is not in the arduino IDE but i was wondering if anyone has ever heard of software that would enable this, or if there was a way to modify the arduino compiler to accomplish this?

If anyone has any ideas i would appreciate hearing them.

What OS? I've done something like that to get the git hash for a code onto the board so I could print it out and know which version of code was on which boards.

I have a header file with just one #define statement that is the hash string. I have a bash script that I set Eclipse up to run every time I compile and it basically grabs the hash and alters that one header file before the code goes to the compiler.

I am using mac os right now, but i have a windows pc as well and i could run linux if i had too.

Qdeathstar:
I am using mac os right now, but i have a windows pc as well and i could run linux if i had too.

I'm reverse that order. Linux always. Can do windows pretty well if it comes to that. Mac if I must.

I've found that when you get a little further along with this sort of stuff, you start to find things where the linux instructions are "run this command, then this one, then this one, and viola! and the Windows instructions are all "Well technically it can't be done with Windows but if you download SpybotViroSpam from this link it will allow you to do it once with the example and then never be able to figure out all the settings or where to set them." Once you use something like Ubuntu for a while, you don't really miss the others. And it's FREE. That's a big plus.

But I digress, you should be able to do something similar with a piece of fruit but I would be the last person to ask how.

Qdeathstar:
What i would like to do is enable defines in the software based on which upload port i have selected. I know that this is not in the arduino IDE

Where do you have this upload port selected? It sounds like you're not talking about the Tools > Port menu in the Arduino IDE.

The Arduino IDE does pass the port name to the upload recipes as {serial.port}. I added -D{serial.port} to the recipe.cpp.o.pattern in platform.txt but it was not expanded as I had hoped so it seems that is not available during the compilation process, only during upload at which time it's already too late to define a macro.

Recent versions of the Arduino IDE do have hooks that make it easy to add extra build steps: