Linux 内核编译,驱动编译
1 == 关于linux内核Build 2 首先整一个 Makefile 例子 3 4 ---------------------------------------------------------------------------------------- 5 ifeq ($(KERNELRELEASE),) 6 7 KERNELDIR ?=/lib/modules/$(shell uname -r)/build 8 PWD := $(shell pwd) 9 10 modules: 11 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules 12 13 modules_install: 14 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install 15 16 clean: 17 rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules* Module* 18 19 .PHONY: modules modules_install clean 20 21 else 22 obj-m += kprobe_.o 23 kprobe_-objs := kprobe.o 24 endif 25 ----------------------------------------------------------------------------------------- 26 KERNELDIR 是内核构建build路径 27 PWD 是当前路径 28 29 obj-m 是构建模块的 30 kprobe_.o 是模块的名字+.o 31 kprobe_-objs := kprobe.o 32 xxx-objs 是模块依赖的文件 33 KBUILD_EXTMOD:= modules path 34 35 KCPPFLAGS:预处理传递的附加选项,预处理选项用在kbuild预处理包含编译C文件和汇编文件。 36 37 KAFLAGS:汇编(内核和模块)的附加选项 38 39 AFLAGS_MODULE:$(AS)的附加模块指定选项 40 41 AFLAGS_KERNEL:$(AS)用汇编代码编译为内建的附加选项 42 43 KCFLAGS:C编译的附加选项 44 45 CFLAGS_KERNEL:$(CC)编译为内部的选项 46 47 CFLAGS_MODULE:$(CC)的附加指定选项
gcc -Wp,-MD,net/bridge/netfilter/.nf_tables_bridge.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include -I./arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated -Iinclude -I./arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_X86_X32_ABI -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -gdwarf-4 -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(nf_tables_bridge)" -D"KBUILD_MODNAME=KBUILD_STR(nf_tables_bridge)" -c -o net/bridge/netfilter/.tmp_nf_tables_bridge.o net/bridge/netfilter/nf_tables_bridge.c ld -r -m elf_x86_64 -T ./scripts/module-common.lds --build-id -o drivers/hwmon/ibmaem.ko drivers/hwmon/ibmaem.o drivers/hwmon/ibmaem.mod.o