Skip to contentSkip to conversation

how about KBUILD_MODNAME

DISCUSSION hacklu 5 participants 10 messages Aug 3, 2010 1 message not in the archive

lore
Share & tools
lore

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

hacklu

author
#1 lore raw

I don't understand the macro KBUILD_MODNAME .
when I compile a driver program. It returns me "linux/pci.h:655: error: 'KBUILD_MODNAME' undeclared (first use in this function) "

In the makefile I had used the "-D" options

thanks a lot

2010-08-03

hacklu

#2 lore raw
Quoted 6 lines · hacklu

I don't understand the macro KBUILD_MODNAME .
when I compile a driver program. It returns me "linux/pci.h:655: error: 'KBUILD_MODNAME' undeclared (first use in this function) "

In the makefile I had used the "-D" options

You don't need to care about KBUILD_MODNAME, it is defined internally by kbuild and passed to your module via "-DKBUILD_MODNAME=XXX" automatically.

So, it looks like you didn't write your makefile correctly.

author
#3 lore raw
In reply to hacklu

I am compiling the boardcom's driver now.
the driver had defined EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) in the a.makefile.
and the a.makefile was included by b.makefile.
when in the b.makefile,
there is this command.
$(CC) $(DEPS_OPT) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $< ;)

I had add "echo $(EXTRA_CFLAGS)" before this line;but returns NULL;

so I suspicion the $(EXTRA_CFLAGS) hasn't been work.

I aslo try to add "export EXTRA_CFLAGS" in a.makefile,but it doesn't work either.

the problem has puzzled me for some days.

help me please~~

2010-08-03

hacklu

发件人: Américo Wang
发送时间: 2010-08-03 16:32:08
收件人: hacklu
抄送: linux-kernel
主题: Re: how about KBUILD_MODNAME

Quoted 6 lines · hacklu

I don't understand the macro KBUILD_MODNAME .
when I compile a driver program. It returns me "linux/pci.h:655: error: 'KBUILD_MODNAME' undeclared (first use in this function) "

In the makefile I had used the "-D" options

You don't need to care about KBUILD_MODNAME, it is defined
internally by kbuild and passed to your module via "-DKBUILD_MODNAME=XXX"
automatically.
So, it looks like you didn't write your makefile correctly. �翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m��� �鹅�⒏?朓�

#4 lore raw
Quoted 11 lines · hacklu

I am compiling the boardcom's driver now.
the driver had defined EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) in the a.makefile.
and the a.makefile was included by b.makefile.
when in the b.makefile,
there is this command.
$(CC) $(DEPS_OPT) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $< ;)

I had add "echo $(EXTRA_CFLAGS)" before this line;but returns NULL;

Quoted 7 lines

so I suspicion the $(EXTRA_CFLAGS) hasn't been work.

I aslo try to add "export EXTRA_CFLAGS" in a.makefile,but it doesn't work either.

the problem has puzzled me for some days.

help me please~~

It looks like the driver uses the old 2.4 way to define a Makefile. This will not work with 2.6.

What you need to do is to define a Makefile (*) like you would if the driver was included in the kernel and then build it using the following command:

make -C path/to/kernel/ M=pwd

The kernel shall be built before you do this as the method uses information from the buitl kernel.

(*) The Makefile may not refer to new CONFIG_ symbols. So it likely looks like this:

obj-m := foo.o bar.o

Do not be suprised that the Makefile becomes much much simpler - this is expected.

Sam

#5 lore raw
In reply to hacklu
Quoted 9 lines · hacklu

I am compiling the boardcom's driver now.
the driver had defined EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) in the a.makefile.
and the a.makefile was included by b.makefile.
when in the b.makefile,
there is this command.
$(CC) $(DEPS_OPT) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $< ;)

Quoted 4 lines

I had add "echo $(EXTRA_CFLAGS)" before this line;but returns NULL;

so I suspicion the $(EXTRA_CFLAGS) hasn't been work.

You don't need to write this line by yourself, you just need to provide a correct: obj-$(XXXXX) += your_module.o, kbuild will automatically compile it with proper flags. (If not, try CFLAGS_MODULE.)

If you insist to do this, I think you can just append -D"KBUILD_MODNAME=your_module" to that line by hand.

Hope this helps.

#6 lore raw
In reply to hacklu
Quoted 4 lines · hacklu

I don't understand the macro KBUILD_MODNAME .
when I compile a driver program. It returns me "linux/pci.h:655: error: 'KBUILD_MODNAME' undeclared (first use in this function) "

Quoted 8 lines

In the makefile I had used the "-D" options

thanks a lot

2010-08-03

hacklu

The KBUILD_MODNAME fails to be set when there are two drivers built from the same directory. There are many directories in the source tree with more then one driver but they don't use the pr_debug macro.

Cheers
Boaz

#7 lore raw
Quoted 14 lines · Boaz Harrosh
Quoted 4 lines · hacklu

I don't understand the macro KBUILD_MODNAME .
when I compile a driver program. It returns me "linux/pci.h:655: error: 'KBUILD_MODNAME' undeclared (first use in this function) "

Quoted 8 lines

In the makefile I had used the "-D" options

thanks a lot

2010-08-03

hacklu

Quoted 6 lines

The KBUILD_MODNAME fails to be set when there are two drivers built from the same directory. There are many directories in the source tree with more then one driver but they don't use the pr_debug macro.

Cheers
Boaz

Rrr it was a long time since I fought this. Maybe it's not the problem with two drivers in same dir, maybe it's when two drivers share the same foo.c file.

Boaz

#8 lore raw
Quoted 19 lines · Boaz Harrosh
Quoted 18 lines · Boaz Harrosh
Quoted 4 lines · hacklu

I don't understand the macro KBUILD_MODNAME .
when I compile a driver program. It returns me "linux/pci.h:655: error: 'KBUILD_MODNAME' undeclared (first use in this function) "

Quoted 8 lines

In the makefile I had used the "-D" options

thanks a lot

2010-08-03

hacklu

The KBUILD_MODNAME fails to be set when there are two drivers built from the same directory. There are many directories in the source tree with more then one driver but they don't use the pr_debug macro.

Quoted 6 lines
Quoted 2 lines

Cheers
Boaz

Rrr it was a long time since I fought this. Maybe it's not the problem with two drivers in same dir, maybe it's when two drivers share the same foo.c file.

No, it is not, you can find many drivers under drivers/net/. ;)

And it doesn't make sense to hold two drivers in one .c file.

#9 lore raw
Quoted 3 lines · Américo Wang

And it doesn't make sense to hold two drivers in one .c file.

I meant when two drivers share the same .c file. But instead of using a third common module they just share it by duplicating the code. example:

<Kbuild>
drv1-y := drv-one.o common.o
obj-$(CONFIG_DRV1) += drv1.o

drv2-y := drv-two.o common.o
obj-$(CONFIG_DRV2) += drv2.o
</Kbuild>

When compiling common.o the KBUILD_MODNAME fails to be set

Cheers
Boaz

#10 lore raw
Quoted 13 lines · Boaz Harrosh
Quoted 3 lines · Américo Wang

And it doesn't make sense to hold two drivers in one .c file.

I meant when two drivers share the same .c file. But instead of using a third common module they just share it by duplicating the code. example:

<Kbuild>
drv1-y := drv-one.o common.o
obj-$(CONFIG_DRV1) += drv1.o

Quoted 5 lines

drv2-y := drv-two.o common.o
obj-$(CONFIG_DRV2) += drv2.o
</Kbuild>

When compiling common.o the KBUILD_MODNAME fails to be set

Correct - but I do not think this is relavent in this case. The code snippet shown clearly indicates that the drivers uses a 2.4 style Makefile. This will not work with 2.6.

Sam