c - Linux makefile example -


hi newbie linux , working way through example http://www.linuxforu.com/2010/12/writing-your-first-linux-driver/ using ubuntu 12.04 , have created c code file called ofd.c (see below) , is saved in directory created @ ~/development/myprogs/myhelloworldlinuxmodule/v2. have created makefile (see below) in same directory.
hoping see .ko file generated in same directory when type make, message saying "nothing done default"

i don't understand makefile

should define kernelrelease somewhere,

what line @ default doing,does mean carry out make on kernel directory , working directory or supposed put code somewhere in particular.

there no usr/src/linux /usr/src/linux-headers-3.8.0-29, changed this, correct. (didn't seem make difference though).

any appreciated.

code:

/* ofd.c – our first driver code */ #include <linux/module.h> #include <linux/version.h> #include <linux/kernel.h>  static int __init ofd_init(void) /* constructor */ {     printk(kern_info "namaskar: ofd registered");     return 0; }  static void __exit ofd_exit(void) /* destructor */ {     printk(kern_info "alvida: ofd unregistered"); }  module_init(ofd_init); module_exit(ofd_exit);  module_license("gpl"); module_author("anil kumar pugalia <email_at_sarika-pugs_dot_com>"); module_description("our first driver");` 

makefile......

# makefile – makefile of our first driver  # if kernelrelease defined, we've been invoked # kernel build system , can use language. ifneq (${kernelrelease},)     obj-m := ofd.o # otherwise called directly command line. # invoke kernel build system. else     kernel_source := /usr/src/linux     pwd := $(shell pwd) default:     ${make} -c ${kernel_source} subdirs=${pwd} modules  clean:     ${make} -c ${kernel_source} subdirs=${pwd} clean endif 

the error due naming convention makefile not able find source code first check kernel running typing uname -a

then go cd /usr/src/

then check linux source-code name

for e.g

uname -a linux vinay-virtualbox 3.2.0-50-generic-pae #76-ubuntu smp tue jul 9 19:24:55 utc 2013 i686 i686 i386 gnu/linux

here source-code name linux-headers-3.2.0-50-generic-pae

so in makefile u need give correct name

kernel_source := /usr/src/linux-headers-3.2.0-50-generic-pae

to avoid above problem try makefile

# if kernelrelease defined, we've been invoked # kernel build system , can use language. ifneq ($(kernelrelease),)   obj-m := ofd.o # otherwise called directly command # line; invoke kernel build system. else     kerneldir ?= /lib/modules/$(shell uname -r)/build     pwd := $(shell pwd) default:     $(make) -c $(kerneldir) m=$(pwd) modules endif 

here uname -a resolves problem


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -