By liran bh | 5/16/2016 | Linux Kernel & Internals

Makefile Examples

In linux module development you should use the kernel Makefile to compile your source. You have to write a tiny Makefile to do it. Many times the module built from only one source file, but not always. To build a module download the kernel source and use the same toolchain you used in the kernel build process.

One source file (simple.c):

.PHONY: modules all

obj-m := simple.o
KERNELDIR := /path/to/linux/kernel/source
PWD := $(shell pwd)

all: modules

module:
       $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
       rm *.ko *.o

Makefile for many source files module

.PHONY: modules all

obj-m := multi.o
multi-objs := file1.o file2.o file3.o
KERNELDIR := /path/to/linux/kernel/source
PWD := $(shell pwd)

all: modules

module:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
        rm *.ko *.o

 

{{CommentsModel.TotalCount}} Comments

Your Comment

{{CommentsModel.Message}}

Recent Stories

Top DiscoverSDK Experts

User photo
3355
Ashton Torrence
Web and Windows developer
GUI | Web and 11 more
View Profile
User photo
3220
Mendy Bennett
Experienced with Ad network & Ad servers.
Mobile | Ad Networks and 1 more
View Profile
User photo
3060
Karen Fitzgerald
7 years in Cross-Platform development.
Mobile | Cross Platform Frameworks
View Profile
Show All
X

Compare Products

Select up to three two products to compare by clicking on the compare icon () of each product.

{{compareToolModel.Error}}

Now comparing:

{{product.ProductName | createSubstring:25}} X
Compare Now