Re: Trouble making module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/12/2010 04:40 PM, Dave Hylands wrote:
> Hi guys,
> 
> On Tue, Oct 12, 2010 at 6:46 AM, Wouter Simons <lkml@xxxxxxxxxxxxxxxx> wrote:
>> On 10/12/2010 12:30 PM, shivanth m p wrote:
> ...snip...
>> all:
>>        obj-m           += modname.o
>>        modname-y       := mydriver.o
> 
> That's definitely not going to work.

Perhaps that is my mistake indeed. As I said I create makefiles that
will work if you just run make inside the project folder by checking if
I am in the kernel build system or not. Basically I use this template:

ifneq ($(KERNELRELEASE),)
	obj-m := composite_driver.o
	composite_driver-y := file1.o file2.o

else
	KERNELDIR ?= ~/Kernel/linux-2.6.35-rc6/
	PWD := $(shell pwd)

default:
	make -C $(KERNELDIR) M=$(PWD) modules

clean:
	make -C $(KERNELDIR) M=$(PWD) clean

endif

This way the correct make command is executed when using 'make' or 'make
clean' from the command line and otherwise the files are built according
to the documentation in kbuild.

Excerpt from Documentation/kbuild/makefiles.txt:
Kbuild needs to know which the parts that you want to build your
module from, so you have to tell it by setting an
$(<module_name>-objs) variable.

Example:
	#drivers/isdn/i4l/Makefile
	obj-$(CONFIG_ISDN) += isdn.o
	isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o

In this example, the module name will be isdn.o. Kbuild will
compile the objects listed in $(isdn-objs) and then run
"$(LD) -r" on the list of these files to generate isdn.o.

Kbuild recognises objects used for composite objects by the suffix
-objs, and the suffix -y. This allows the Makefiles to use
the value of a CONFIG_ symbol to determine if an object is part
of a composite object.

Therefore, because $(KERNELRELEASE) will not be empty when kbuild parses
the makefile it will only see the first part of the makefile which
specifies what to build. Otherwise the targets are build from the
command line.

Alternatively, you can run the make commands from the command line and
only put this in your makefile only:

obj-m := composite_driver.o
composite_driver-y := file1.o file2.o

The command on the command line then becomes something like:
make -C ~/mykernel/path -M=`pwd` modules

But as said, make sure that the folder gets cleaned where your driver is
to make sure something is to be done.

(did I get it right the second time around? ;-)

Wouter

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux