Skip to contentSkip to conversation

kbuild generating prefix-foo.o from foo.c

DISCUSSION kartikeyan sadasivuni 2 participants 4 messages Oct 9, 2009 – Oct 11, 2009 1 message not in the archive Kbuild

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

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
#2 lore raw
Quoted 16 lines · kartikeyan sadasivuni

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

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

#3 lore raw

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

#4 lore raw
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 so c_flags var)
$(CC) $(c_flags) -c -o $@ $<
and call something Kbuild already 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