Reputation: 1
I'm trying to compile several .c files through assembler:
%.S: %.c
$(XCC) -S -o $@ $(XCFLAGS) -c $<
%.o: %.S
$(XCC) -o $@ $(XCFLAGS) -c $<
test.a: test.o foo.o
$(LD) -o $@ $^ $(XLDFLAGS)
$(XCC) is a cross-compile tool.
Actually, I see:
cc -c -o test0.o test0.c
cc -c -o foo.o foo.c
Native compilation runs instead of required cross compilation. I looks like some default rule for %.c to %.o translation is used instead of described chain rule.
If I change one pattern to direct description, compilation is ok:
test.S: test.c
$(XCC) -S -o $@ $(XCFLAGS) -c $<
foo.S: foo.c
$(XCC) -S -o $@ $(XCFLAGS) -c $<
%.o: %.S
$(XCC) -o $@ $(XCFLAGS) -c $<
What is wrong with pattern chain? Is it possible to disable default rule for %.o ?
Upvotes: 0
Views: 265
Reputation: 206627
There is a default rule to generate .o
files from .c
files. That rule gets invoked when the first makefile is used.
You could add the following to the makefile to override the default rule:
%.o: %.c
$(XCC) -S -o $*.S $(XCFLAGS) -c $<
$(XCC) -o $@ $(XCFLAGS) -c $*.S
You can also use:
%.o: %.c
without any recipes under it. This will invoke the other two rules to create the .S file and the .o file from there. However, it will delete the intermediate .S file after the .o is created. To prevent the .S file from getting deleted, you can use:
.PRECIOUS: test.S foo.S
You can read more on this subject at https://www.gnu.org/software/make/manual/html_node/Implicit-Rules.html#Implicit-Rules.
Upvotes: 3
Reputation: 1686
You can keep your rules and just cancel the builtin rule with %.o: %.c
. See also this answer.
Upvotes: 0