Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add different rules for specific files?

Tags:

makefile

I have a certain problem with my Makefile.

With this command, I can compile all my *.c files to *.o which works well:

$(OBJ) : %.o : %.c $(LDSCRIPT) Makefile
    $(CC) $(ARM9_INCLUDES) -c $(CFLAGS) $< -o $@

But now I'm wondering, what if I want to run -O3 optimization on just ONE particular file, and have -O0 on the rest?

Is there any command to add a different rule for a specific file?

What I'm doing right now is compiling each C file with its own rules, which is very annoying because I have around 30 files which makes the Makefile huge, and every time I change something in one file it compiles EVERYTHING again.

like image 856
MrGigu Avatar asked Jul 01 '11 09:07

MrGigu


1 Answers

particular_file.o : CFLAGS+=-O3

(assuming GNU make) see target-specific variable values in GNU Make manual (and the immediately following pattern-specific variable values, maybe).

Also note, that commands are used from the most specific rule for given file, so you can have in case target-specific variable value is not sufficient:

particular_file.o : particular_file.c
        completely_special_compiler -o $@ $<

%.o : %.c
        $(CC) $(CFLAGS) -o $@ $<
like image 55
Jan Hudec Avatar answered Oct 01 '22 21:10

Jan Hudec