Different flags for different Object in Makefile

Hello Guys, im going crazy because i cant tell to my Makefile to build a specific object with a different CFLAGS if i use a specifit rule.

I need a Macro defined only for a specific Object file, but i can't do it..

For example:


CFLAGS = -std=c89 -pedantic
TARGET = Try

OBJ = no_need_macro.o
OBJ_2 = need_a_macro.o

/* Build without any macro */
normal_rule: $(OBJ) $(OBJ_2)
                gcc $(OBJ2) $(CFLAGS) -o
                gcc $(OBJ) $(CFLAGS) -o $(TARGET)

specific_rule: ???? I have to build like the normal rule but the OBJ_2 need a macro..


How can i do it?
Thanks guys.
Last edited on
You use the -D flag to specify a macro at the command line. Is that what you're asking?
https://www.rapidtables.com/code/linux/gcc/gcc-d.html
gcc -Dname [options] [source files] [-o output file]
gcc -Dname=definition [options] [source files] [-o output file]


So, for example, doing: -DTHINGY would #define THINGY.
Doing -DTHINGY=3 would #define THINGY 3.
Last edited on
Topic archived. No new replies allowed.