So say I have something like the following in a makefile.def:
MODLIST = src/main
CPPFLAGS = -DCFG0=0 -DCFG1=1
cfg0.elf: CPPFLAGS = -DCFG=CFG0
cfg0.elf: $(addprefix $(ODIR)/, $(addsuffix .o, $(MODLIST)))
cfg1.elf: CPPFLAGS = -DCFG=CFG1
cfg1.elf: $(addprefix $(ODIR)/, $(addsuffix .o, $(MODLIST)))
and we have a dummy main.c with the following:
#if CFG == CFG0
printf("CFG0");
#elif CFG == CFG1
printf("CFG1");
#endif
The issue seems to be since they are being overwritten during compilation, (at least what I had thought but could be wrong) when both configurations get to that statement, they both print out the same "CFG0" in this case.
A couple ideas I had but ran into issues while trying to link...
- Append something to the suffix like
cfg0.elf: $(addprefix $(ODIR)/, $(addsuffix _cfg0.o, $(MODLIST)))
- Append something to the output directory like
cfg0.elf: $(addprefix $(ODIR)/CFG0/, $(addsuffix .o, $(MODLIST)))
I tried to modify the LDFLAGS but I didn't find a way to get it to compile correctly. Not sure if I was heading in the right direction or if there is a better way to go about something like this.
CodePudding user response:
Be aware when you using option -DCFG=xxx
if the output .o
are in same position because:
cfg0.elf
require all.o
files in compile with-DCFG0=0
cfg1.elf
require all similar.o
files but compiler detect that it was compiled already event with-DCFG0=0
(because depend does not apply over compiler option. Then thecfg1.elf
is linked with same file withcfg0.elf
.
Your idea about Append something to the suffix
or Append something to the output directory
are all the right approach. Actually, I prefer Append something to the output directory
. If you have problem with linking, I think you should raise question specifically for your linking issue.