📄 makefile
字号:
## Makefile## Written by Jari Ruusu, June 13 2007## Copyright 2001-2007 by Jari Ruusu.# Redistribution of this file is permitted under the GNU Public License.## To compile and install, use commands: make clean; make# This Makefile tries to locate running kernel source directory and# steal definitions from kernel Makefile. Note: kernel must be properly# configured and compiled in order for this to work.# You can override the kernel source directory by defining LINUX_SOURCE# like this: make LINUX_SOURCE=/usr/src/linux-2.2.20aa1## Both LINUX_SOURCE and KBUILD_OUTPUT must be defined when# compiling for 2.6.x kernel with separate object directory.#KR:=$(shell uname -r)ifdef LINUX_SOURCE LS:=$(LINUX_SOURCE)else LS:=$(shell if [ -f /lib/modules/$(KR)/source/Makefile ]; then cd /lib/modules/$(KR)/source && /bin/pwd; \ else if [ -f /lib/modules/$(KR)/build/include/linux/version.h ]; then cd /lib/modules/$(KR)/build && /bin/pwd; \ else if [ -f /usr/src/linux/include/linux/version.h ]; then cd /usr/src/linux && /bin/pwd; \ else if [ -f /usr/src/linux-$(KR)/include/linux/version.h ]; then cd /usr/src/linux-$(KR) && /bin/pwd; \ else if [ -f /usr/src/kernel-source-$(KR)/include/linux/version.h ]; then cd /usr/src/kernel-source-$(KR) && /bin/pwd; \ else echo unable-to-guess-source-dir; fi; fi; fi; fi; fi)endififdef KBUILD_OUTPUT OD1:=$(KBUILD_OUTPUT)elseifdef LINUX_SOURCE OD1:=$(LS)else OD1:=$(shell if [ -f /lib/modules/$(KR)/build/include/linux/version.h ]; then cd /lib/modules/$(KR)/build && /bin/pwd; else echo $(LS); fi)endifendifOD2:=ifneq ($(LS),$(OD1)) OD2:= O=$(OD1)endifTD:=$(shell /bin/pwd)MODINST:=yKEYSCRUB:=nPADLOCK:=nBUILD_LOOP:=yEXTRA_CIPHERS:=nVERSION:=$(shell if test -r $(LS)/Makefile; then grep '^VERSION' $(LS)/Makefile | head -n 1 | sed -e 's/[^0-9]//g'; fi)PATCHLEVEL:=$(shell if test -r $(LS)/Makefile; then grep '^PATCHLEVEL' $(LS)/Makefile | head -n 1 | sed -e 's/[^0-9]//g'; fi)SUBLEVEL:=$(shell if test -r $(LS)/Makefile; then grep '^SUBLEVEL' $(LS)/Makefile | head -n 1 | sed -e 's/[^0-9]//g'; fi)PATCHNAME:=loop.c-$(VERSION).$(PATCHLEVEL).diffORIGNAME:=loop.c-$(VERSION).$(PATCHLEVEL).originalPREPATCHED:=loop.c-$(VERSION).$(PATCHLEVEL).patchedEF:=LF:=-rifeq ($(shell if [ "$(VERSION)$(PATCHLEVEL)0" -lt 260 ]; then echo y; fi),y) OD1:=$(LS)endififeq ($(VERSION).$(PATCHLEVEL),2.0) # Use optimized assembler implementation if target is x86 processor X86_ASM:=$(shell if grep -q -s "define CONFIG_M[3456]86" $(LS)/include/linux/autoconf.h; then echo y; fi) # kernel v2.0 doesn't have u_int32_t and u_int64_t EF += -Du_int32_t=__u32 -Du_int64_t=__u64ifndef KERNELRELEASE # some older 2.0 kernels don't define KERNELRELEASE KERNELRELEASE:=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)endifendififeq ($(VERSION).$(PATCHLEVEL),2.2) # Use optimized assembler implementation if target is x86 processor X86_ASM:=$(shell if grep -q -s "define CONFIG_M[3456]86" $(LS)/include/linux/autoconf.h; then echo y; fi)endififeq ($(VERSION).$(PATCHLEVEL),2.4) EF += $(kbuild_2_4_nostdinc) # Use optimized assembler implementation if target is x86 processor X86_ASM:=$(shell if grep -q -s "define CONFIG_X86 1" $(LS)/include/linux/autoconf.h; then if ! grep -q -s "define CONFIG_X86_64" $(LS)/include/linux/autoconf.h; then echo y; fi; fi) # Use optimized assembler implementation if target is AMD64 or compatible processor AMD64_ASM:=$(shell if grep -q -s "define CONFIG_X86_64" $(LS)/include/linux/autoconf.h; then echo y; fi) # some older 2.4 kernels don't have struct block_device_operations.owner EF += $(shell if test -r $(LS)/include/linux/fs.h; then if ! sed -e '1,/^struct block_device_operations {$$/ d' $(LS)/include/linux/fs.h | sed -e '/^};$$/,$$ d' | grep -q -s 'struct module.*owner;'; then echo "-DNO_BLOCK_DEVICE_OPERATIONS_OWNER"; fi; fi) # some older 2.4 kernels don't have reparent_to_init() EF += $(shell if ! grep -q -s "extern void reparent_to_init" $(LS)/include/linux/sched.h; then echo "-DNO_REPARENT_TO_INIT"; fi) # some 2.4 kernels don't have struct task_struct.sigmask_lock EF += $(shell if ! grep -q -s "spinlock_t sigmask_lock" $(LS)/include/linux/sched.h; then if grep -q -s 'struct sighand_struct \*sighand;' $(LS)/include/linux/sched.h; then echo '-DNO_TASK_STRUCT_SIGMASK_LOCK=1'; else echo '-DNO_TASK_STRUCT_SIGMASK_LOCK=2'; fi; fi)endififeq ($(shell if [ "$(VERSION)$(PATCHLEVEL)0" -ge 260 ]; then echo y; fi),y) # Use optimized assembler implementation if target is x86 processor X86_ASM:=$(shell if grep -q -s "define CONFIG_X86 1" $(OD1)/include/linux/autoconf.h; then if ! grep -q -s "define CONFIG_X86_64" $(OD1)/include/linux/autoconf.h; then echo y; fi; fi) # Use optimized assembler implementation if target is AMD64 or compatible processor AMD64_ASM:=$(shell if grep -q -s "define CONFIG_X86_64" $(OD1)/include/linux/autoconf.h; then echo y; fi) # some older 2.6 kernels have different request_module interface EF += $(shell if test -r $(LS)/drivers/block/genhd.c; then if ! grep -q -s "request_module.*block-major-.*MAJOR.*MINOR" $(LS)/drivers/block/genhd.c; then echo "-DOLD_REQUEST_MODULE_INTERFACE"; fi; fi) # some older 2.6 kernels have per thread resource limits EF += $(shell if test -r $(LS)/include/linux/sched.h; then if sed -e '1,/^struct task_struct {$$/ d' $(LS)/include/linux/sched.h | sed -e '/^};$$/,$$ d' | grep -q -s 'struct rlimit rlim.RLIM_NLIMITS.;'; then echo "-DOLD_PER_THREAD_RLIMITS"; fi; fi) # some 2.6 kernels may have void* timer callback parameter EF += $(shell if test -r $(LS)/include/linux/timer.h; then if ! sed -e '1,/^struct timer_list {$$/ d' $(LS)/include/linux/timer.h | sed -e '/^};$$/,$$ d' | grep -q -s 'unsigned long data;'; then echo "-DNEW_TIMER_VOID_PTR_PARAM"; fi; fi) # some older 2.6 kernels may have two invalidate_bdev() parameters EF += $(shell if test -r $(LS)/include/linux/buffer_head.h; then if grep -q -s '^void invalidate_bdev.*struct block_device.*int' $(LS)/include/linux/buffer_head.h; then echo "-DOLD_INVALIDATE_BDEV_INTERFACE"; fi; fi)endififeq ($(KEYSCRUB),y)ifeq ($(shell if [ "$(VERSION)$(PATCHLEVEL)0" -ge 240 ]; then echo y; fi),y) EF += -DCONFIG_BLK_DEV_LOOP_KEYSCRUB=1endifendififeq ($(PADLOCK),y)ifeq ($(shell if [ "$(VERSION)$(PATCHLEVEL)0" -ge 240 ]; then echo y; fi),y) EF += -DCONFIG_BLK_DEV_LOOP_PADLOCK=1endifendif# Some distros include "" characters in KERNELRELEASE stringKERNELRELEASE_clean:=$(shell echo $(KERNELRELEASE))AES_OBJ_CODE:=aes.oMD5_OBJ_CODE:=md5.oifeq ($(X86_ASM),y) AES_OBJ_CODE:=aes-x86.o MD5_OBJ_CODE:=md5-x86.o EF += -DX86_ASMendififeq ($(AMD64_ASM),y) AES_OBJ_CODE:=aes-amd64.o MD5_OBJ_CODE:=md5-amd64.o EF += -DAMD64_ASMendif# check if depmod supports -F and -b optionsifeq ($(shell if [ "$(VERSION)$(PATCHLEVEL)0" -ge 260 ]; then echo y; fi),y) DMOK:=yelse DMOK:=$(shell if [ `/sbin/insmod -V 2>&1 | head -n 1 | awk '/^insmod version /{split($$3, a, /\./); printf "%d%03d%03d\n", a[1], a[2], a[3];}'`0 -ge 20020020 ]; then echo y; fi)endififndef DEPMOD DEPMOD:=/sbin/depmodendif# check if kernel source has System.mapSYSM:=$(shell if [ -r $(OD1)/System.map ]; then echo y; fi)RUNDM:=DMOPTS:=ifeq ($(DMOK),y)ifneq "$(strip $(INSTALL_MOD_PATH))" "" DMOPTS += -b $(INSTALL_MOD_PATH)endififeq ($(SYSM),y) RUNDM:=y DMOPTS += -F $(OD1)/System.map $(KERNELRELEASE_clean)endifendififeq ($(KERNELRELEASE_clean),$(KR))ifeq "$(strip $(INSTALL_MOD_PATH))" "" RUNDM:=yendifendifall:ifeq ($(LS),unable-to-guess-source-dir) @echo "Unable to guess linux kernel source directory. Please specify" @echo "directory like this: make LINUX_SOURCE=/usr/src/linux-2.2.20aa1" @exit 1endififeq ($(shell if [ "$(VERSION)$(PATCHLEVEL)0" -ge 260 ]; then echo y; fi),y) rm -r -f *.ko tmp-d-kbuild mkdir tmp-d-kbuild echo 'obj-m:=' >>tmp-d-kbuild/Makefileifeq ($(BUILD_LOOP),y) cd tmp-d-kbuild && ln -s ../loop.c-$(VERSION).$(PATCHLEVEL).patched patched-loop.c && ln -s ../glue.c ../aes.h ../md5.h . echo 'obj-m += loop.o' >>tmp-d-kbuild/Makefileifeq ($(X86_ASM),y) cd tmp-d-kbuild && ln -s ../aes-x86.S ../md5-x86.S . echo 'loop-y:=patched-loop.o glue.o aes-x86.o md5-x86.o' >>tmp-d-kbuild/Makefileelseifeq ($(AMD64_ASM),y) cd tmp-d-kbuild && ln -s ../aes-amd64.S ../md5-amd64.S . echo 'loop-y:=patched-loop.o glue.o aes-amd64.o md5-amd64.o' >>tmp-d-kbuild/Makefileelse cd tmp-d-kbuild && ln -s ../aes.c ../md5.c . echo 'loop-y:=patched-loop.o glue.o aes.o md5.o' >>tmp-d-kbuild/Makefile echo 'CFLAGS_aes.o := -DDATA_ALWAYS_ALIGNED=1' >>tmp-d-kbuild/Makefileendifendifendififeq ($(EXTRA_CIPHERS),y) cd tmp-d-kbuild && ln -s ../loop_twofish.c ../loop_serpent.c ../loop_blowfish.c . echo 'obj-m += loop_twofish.o loop_serpent.o loop_blowfish.o' >>tmp-d-kbuild/Makefileendif echo 'EXTRA_CFLAGS:= $(EF)' >>tmp-d-kbuild/Makefile cd $(LS) && make SUBDIRS=$(TD)/tmp-d-kbuild modules $(OD2)ifeq ($(MODINST),y)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -