kbuild generating prefix-foo.o from foo.c
hi,
I have a kernel module Makefile requirement as follows (unavoidable) prefix-foo.o should be generated by foo.c using Kbuild
Right now I am doing the following
=====
$(obj-m:%.o=%)-objs += $(MORE_OBJS:%=prefix-%)
$(obj)/prefix-%.o : $(src)/%.c # prefix-foo.o from foo.c $(CC) $(c_flags) -c -o $@ $< #line3
=====
Is there is a better kernel builtin way to write line-3
without module Makefile having quiet_cmd_* and cmd_* stuff,
some thing like
$(obj)/prefix-%.o : $(src)/%.c
$(call cmd,prefix-$@) #without quiet_cmd_*,cmd_* in module Makefile
kartikeyan
Signature · 1 line
S.Kartikeyan
Quoted 16 lines · kartikeyan sadasivuni
hi,
I have a kernel module
Makefilerequirement as follows (unavoidable) prefix-foo.o should be generated byfoo.cusingKbuild
Right now I am doing the following
=====
$(obj-m:%.o=%)-objs += $(MORE_OBJS:%=prefix-%)
$(obj)/prefix-%.o : $(src)/%.c # prefix-foo.o fromfoo.c$(CC) $(c_flags) -c -o $@ $< #line3
=====
Is there is a better kernel builtin way to write line-3
without moduleMakefilehaving quiet_cmd_* and cmd_* stuff,
some thing like
$(obj)/prefix-%.o : $(src)/%.c
$(call cmd,prefix-$@) #without quiet_cmd_*,cmd_* in moduleMakefile
Quoted 1 line
kartikeyan
Is it an option for you to create a copy of said file? Something like this (untested).
$(obj)/prefix-foo.c: $(src)/foo.c
cat $< > $@ || (rm $@ && flase)
obj-m += prefix.o
Notes: Use cat rather than copy to avoid potential umask related issues.
(rm $@ && false) delte the file if something went wrong and we only piped half the file.
Sam
hi,
Quoted 2 lines
Is it an option for you to create a copy of said file?
I could do this but just looking for a cleaner approach. I have a working solution but looking for better ways.
I wanted to avoid using the line (as kbuild can change in future and so c_flags var)
$(CC) $(c_flags) -c -o $@ $<
and call something Kbuild already has
but with changed prerequisite/dependency.
kartikeyan
Quoted 5 lines · kartikeyan sadasivuni
hi,
Quoted 2 lines
Is it an option for you to create a copy of said file?
Quoted 7 lines
I could do this but just looking for a cleaner approach. I have a working solution but looking for better ways.
I wanted to avoid using the line (as kbuild can change in future and soc_flagsvar)
$(CC) $(c_flags) -c -o $@ $<
and call somethingKbuildalready has
but with changed prerequisite/dependency.
Did you read what I suggested at all?
From your answer I think not.
Please go re-read my answer and realize that it is _kbuild_ that reates the copy of the file and thus things *just works*.
kbuild (make) will see that foo.c is missing
and create is using the rule I suggested:
$(obj)/foo: $(src)/foo-prefix.c
cat $< > $@ || (rm $@ && false)
So you do _not_ have to specify c_flags or anything like that to make it work.
Sam