Thursday, May 17, 2012
Makefile and defines with a value.
Have you ever wanted to change some code without changing the code? I did this in the Makefile. I did this with a define from the compiler command line. A subset of the Makefiles follows:
<makefile>
# this is the top of the Makefile. I put switches here.
# comment out PRODVER if you want the original
PRODVER := MODIFIED
#MODIFIED Threshold for lower bounds
MODIFIED_THRESHOLD :=30000
#...
CFLAGS = -Wall -mlong-calls -ffunction-sections
ifeq ($(PRODVER),MODIFIED)
CFLAGS += -DMODIFIED=$(MODIFIED_THRESHOLD)
endif
CFLAGS += $(OPTIMIZATION) $(INCLUDES)
</makefile>
The Makefile makes the same thing as:
#define MODIFIED 30000
but it does it as -DMODIFIED=30000 when the line is passed to gcc.
I want to set the minimum value of bounds
The C code looks like this:
<main.c>
/*This is the modification the code based on code from the makefile*/
#ifdef MODIFIED //this is defined in the Makefile
if(bounds < MODIFIED) //for our current Makefile, this will become (bounds<30000)
{
bounds=MODIFIED; //this sets the minimum value to be whatever is in the makefile.
} //this line turns into bounds=30000;
#endif
</main.c>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment