Hi all,
I'm having some trouble with a Macro defined by passing a -D option into gcc through a Makefile. I have two options that I need to include, so I call make like this:
make RANDOM=1 DEBUG=ARM LIST=1
(LIST is so that the Makefile will print which CFLAGS I have called, see code below
A snippet of my Makefile is like this:
Code:
CFLAGS=-g -O3 -Wall -Wextra -Wwrite-strings -Wmissing-prototypes -Wno-missing-field-initializers -O0

ifeq ($(FREQ_BLOCK),1)
CFLAGS+=-DFREQ_BLOCK
endif
ifeq ($(SP_CH_CHANGE),1)
CFLAGS+=-DSP_CH_CHANGE
endif
ifeq ($(RANDOM),1)
CFLAGS+=-D "RANDOM=1"
endif
ifeq ($(RUN_ALL),1)
CFLAGS+=-DRUN_ALL
endif

ifneq ($(DEBUG),)
CFLAGS+= -D "DEBUG_$(DEBUG)=1"
endif

# Make everything

all: $(EXE)
ifeq ($(LIST),1)
	@echo "CFLAGS applied "$(CFLAGS)
endif
RANDOM defines which version of my program I want to compile (one that does random tests) and DEBUG=ARM specifies that I need debug output for ARM (one of my functions within program).
when I run make, it prints this:
CFLAGS applied -g -O3 -Wall -Wextra -Wwrite-strings -Wmissing-prototypes -Wno-missing-field-initializers -O0 -D RANDOM=1 -D DEBUG_ARM=1
I orginally had it so that the CFLAGS were just -DRANDOM and -DDEBUG_ARM, but I had exactly the same problem that I'm having now.
What is this problem? Well, RANDOM does its job properly, and runs the RANDOM test. If I compile without it, it returns the expected error message "no test function called" when I try and run the program.
However, DEBUG_ARM does not seem to be recognised. Here is a snippet of the file where I use DEBUG_ARM:
Code:
#include "Utils/debug.h"

#ifdef DEBUG_ALL
#define DEBUG_ARM 1
#endif
#ifdef NO_DEBUG
#undef DEBUG_ARM
#endif

static int Func_ARM(void)
{


#ifdef DEBUG_ARM
if(print_debug()!=0){
die(__FILE__,__LINE__,"could not open debug file");
}
#endif

...some tests...
if(fail_test){
#ifdef DEBUG_ARM
fprintf(DEBUG,"DEBUG_ARM: Aborted line %d\n",__LINE__);
#endif
 goto Abort;
}
Abort:
return(-1);
}
If I manually define DEBUG_ARM in Utils/debug.h (as I had been doing before I tried this method with the Makefile) it works fine. However, passing it in through gcc doesn't seem to work! Does anyone have ANY clue why? I can't find much literature on the internet or anywhere else and I'm at a total loss. I can't even find of a way to 'debug' preprocessor directives. Any suggestions would be really useful, chances are I've done something stupid, or something that 'everyone knows' I don't know, please help if you can!!
thanks,
why_bird
p.s. I realise I haven't pasted fully functional code here, I haven't been able to replicate the problem on a small scale which is what leads me to think I've overlooked something minor but equally I can't post my entire project here (am not allowed as well as is not feasible!)