📄 makefile
字号:
DEBUG = 0KSP := /lib/modules/$(shell uname -r)/build \ /usr/src/linux-$(shell uname -r) \ /usr/src/linux-$(shell uname -r | sed 's/-.*//') \ /usr/src/kernel-headers-$(shell uname -r) \ /usr/src/kernel-source-$(shell uname -r) \ /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \ /usr/src/linuxtest_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))KSP := $(foreach dir, $(KSP), $(test_dir))KSRC := $(firstword $(KSP))ifeq (,$(KSRC)) $(error Linux kernel source not found)endif# check kernel versionKVER := $(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')KERVER2=$(shell uname -r | cut -d. -f2)ifeq ($(KVER), 2.6) # 2.6 kernel TARGET = velocityget.ko BUILTIN = via-velocity.koelse TARGET = velocityget.o BUILTIN = via-velocity.oendifINSTDIR := $(shell find /lib/modules/$(shell uname -r) -name $(TARGET) -printf "%h\n" | sort | head -1)ifeq (,$(INSTDIR)) ifeq (,$(KERVER2)) ifneq (,$(wildcard /lib/modules/$(shell uname -r)/kernel)) INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net else INSTDIR := /lib/modules/$(shell uname -r)/net endif else ifneq ($(KERVER2),2) INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net else INSTDIR := /lib/modules/$(shell uname -r)/net endif endifendifSRC = velocity_main.c velocity_proc.c velocity_wol.c velocity_hw.c# build ruleifeq ($(KVER), 2.6)# 2.6 kernelobj-m += velocityget.ovelocityget-objs := velocity_main.o velocity_proc.o velocity_wol.o velocity_hw.odefault: make -C $(KSRC) SUBDIRS=$(shell pwd) moduleselse# 2.2/2.4 kernelOBJS := velocity_main.o velocity_proc.o velocity_wol.o velocity_hw.oVERSION_FILE := $(KSRC)/include/linux/version.hCONFIG_FILE := $(KSRC)/include/linux/config.hifeq (,$(wildcard $(VERSION_FILE))) $(error Linux kernel source not configured - missing version.h)endififeq (,$(wildcard $(CONFIG_FILE))) $(error Linux kernel source not configured - missing config.h)endififneq (,$(findstring egcs-2.91.66, $(shell cat /proc/version))) CC := kgcc gcc ccelse CC := gcc ccendiftest_cc = $(shell which $(cc) > /dev/null 2>&1 && echo $(cc))CC := $(foreach cc, $(CC), $(test_cc))CC := $(firstword $(CC))CFLAGS += -Wall -DLINUX -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -D__NO_VERSION__ -O2 -pipeCFLAGS += -I$(KSRC)/include -I. -Wstrict-prototypes -fomit-frame-pointerCFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \ echo "-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h").SILENT: $(TARGET) clean# look for SMP in config.hSMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \ grep CONFIG_SMP | awk '{ print $$3 }')ifneq ($(SMP),1) SMP := 0endififeq ($(DEBUG),1) CFLAGS += -DVELOCITY_DEBUGendififeq ($(SMP), 1) CFLAGS += -D__SMP__endif# check x86_64SUBARCH := $(shell uname -m)ifeq ($(SUBARCH),x86_64) CFLAGS += -mcmodel=kernel -mno-red-zoneendif$(TARGET): $(filter-out $(TARGET), $(SRC:.c=.o)) $(LD) -r $^ -o $@ echo; echo echo "**************************************************" echo "Build options:" echo " VERSION $(shell uname -r)" echo -n " SMP " if [ "$(SMP)" = "1" ]; \ then echo "Enabled"; else echo "Disabled"; fi echo "**************************************************"endif # ifeq ($(KVER),2.6)ifeq ($(KVER), 2.6) install: defaultelse install: clean $(TARGET)endif mkdir -p $(MOD_ROOT)$(INSTDIR) install -m 644 -o root $(TARGET) $(MOD_ROOT)$(INSTDIR) @if [ -f $(MOD_ROOT)$(INSTDIR)/$(BUILTIN) ] ; then \ echo "***** Move official driver $(BUILTIN) to $(BUILTIN).backup file" ; \ echo "mv $(MOD_ROOT)$(INSTDIR)/$(BUILTIN) $(MOD_ROOT)$(INSTDIR)/$(BUILTIN).backup";\ mv $(MOD_ROOT)$(INSTDIR)/$(BUILTIN) $(MOD_ROOT)$(INSTDIR)/$(BUILTIN).backup ; \ echo ;\ fi ; @if [ -f $(MOD_ROOT)$(INSTDIR)/linuxfet.o ] ; then \ echo "***** Move previous driver linuxfet.o to linuxfet.o.backup" ; \ echo "mv $(MOD_ROOT)$(INSTDIR)/linuxfet.o $(MOD_ROOT)$(INSTDIR)/linuxfet.o.backup";\ mv $(MOD_ROOT)$(INSTDIR)/linuxfet.o $(MOD_ROOT)$(INSTDIR)/linuxfet.o.backup ; \ echo ;\ fi ;ifeq (,$(MOD_ROOT)) /sbin/depmod -a || trueelse /sbin/depmod -b $(MOD_ROOT) -a || trueendifuninstall: rm -f $(INSTDIR)/$(TARGET) @if [ -f $(MOD_ROOT)$(INSTDIR)/$(BUILTIN).backup ] ; then \ echo "***** Restore official driver $(BUILTIN) from $(MOD_ROOT)$(INSTDIR)".; \ echo "mv $(MOD_ROOT)$(INSTDIR)/$(BUILTIN).backup $(MOD_ROOT)$(INSTDIR)/$(BUILTIN)";\ mv $(MOD_ROOT)$(INSTDIR)/$(BUILTIN).backup $(MOD_ROOT)$(INSTDIR)/$(BUILTIN) ;\ fi /sbin/depmod -aclean: rm -f $(SRC:.c=.o) velocityget.o velocityget.ko velocityget.mod.c velocityget.mod.o *~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -