Conditional Compilation based on Environmental Variable in Unix

I want to be able to access an environment variable to control how a program is compiled.
So:
export MY_VERSN=9

Then ideally, within my C++ code, I would have

#if MY_VERSN = 9
iret = FRED9()
#else
iret = FRED()
#endif

The way I thought I could do it is that in the script that sets up the environmental variable MY_VERSN (which I need in any case) , I could also create an include file fred.h containing

#define MY_VERSN 9

and then include fred.h in my C++ code.

I think that my requirement to conditionally compile based on an env variable must be a common one; so I'd be grateful for sugestions on how it is usually achieved. Thanks

Apologies for answering my own question but I think that this is probably a reasonable solution:

Suppose you have an "env var" MY_VERSN

export MY_VERSN=9

In the makefile you can access this as $$MY_VERSN

and add a complier flag

-DMYVER=$$MY_VERSN

Then in the C++ code you can put

#if MYVERSN == 9
iret = routine_A()
#else
iret = routine_B()
#endif

Sorry if I have taken up anyones time.

It depends on how large the code base is and also a matter of personal style. For small programs I just plug in the preprocessor stuff into the source code itself and for large ones I use a header file but anyways you have indeed answered your own question :b: