# Altering #ifdef in c file from port make...



## JamesElstone (May 4, 2015)

Hi All,

Basic 101 question:

I have a c file which is compiled in a port via the ports Makefile, by running `make`.

In the c file are numerous #ifdef var evaluations:


```
void report(char *msg)
{
#ifdef DEBUG
  # ifndef DEBUG_MW
    fprintf(stderr, msg);
  # else
    mexPrintf( msg );
  # endif /* DEBUG_MW */
#endif /* DEBUG */
}
```
How from the make command line can I set these variables to be true?

Kr,

James


----------



## SirDice (May 4, 2015)

`make -DDEBUG`

make(1):

```
-D variable
             Define variable to be 1, in the global context.
```


----------



## JamesElstone (May 4, 2015)

Ta,

Is there a way to list all defined vars?

James


----------



## kpa (May 4, 2015)

JamesElstone said:


> Ta,
> 
> Is there a way to list all defined vars?
> 
> James



I found this with a google search:

http://stackoverflow.com/questions/2421499/listing-c-constants-macros

Simplest way seems to be:

`cpp -dM /dev/null`


----------



## wblock@ (May 4, 2015)

JamesElstone said:


> Is there a way to list all defined vars?



In ports, there are a lot.  First, `cd` to the port directory.  Then:
For csh(1): `make -Ndg1 |& grep = | sort -u | less`
For sh(1): `make -Ndg1 2>&1 grep = | sort -u | less`

Some of those are not variables, the `grep =` is the weak spot.  Suggestions for a better way would be welcome.


----------

