⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makefile

📁 联想网卡驱动 linux环境下编写 初写驱动的同志参考以下
💻
字号:
VMNS	=	1OBJS	:= 	rhine_main.o rhine_proc.oSRC		=	rhine_main.c rhine_proc.cTARGET	=	rhinefet.oKSP :=  /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/linuxifeq ($(VMNS),1)OBJS+=rhine_vmns.oSRC+=rhine_vmns.cendiftest_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))KSP := $(foreach dir, $(KSP), $(test_dir))KSRC := $(firstword $(KSP))#KSRC :=/usr/src/ksrc/RedHat/7.2/linux-2.4.7-10alt-entifeq (,$(KSRC))  $(error Linux kernel source not found)endifVERSION_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")KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \          awk '{ print $$3 }' | sed 's/\"//g')KERVER2=$(shell uname -r | cut -d. -f2).SILENT: $(TARGET) cleanifeq ($(TARGET), rhinefet.o)	ifneq ($(KVER),$(shell uname -r))		$(warning ***)		$(warning *** Warning: kernel source version ($(KVER)))		$(warning *** does not match running kernel  ($(shell uname -r)))		$(warning *** Continuing with build,)		$(warning *** resulting driver may not be what you want)		$(warning ***)	endifendifINSTDIR := $(shell find /lib/modules/$(KVER) -name $(TARGET) -printf "%h\n" | sort | head -1)ifeq (,$(INSTDIR))	ifeq (,$(KERVER2))		ifneq (,$(wildcard /lib/modules/$(KVER)/kernel))    		INSTDIR := /lib/modules/$(KVER)/kernel/drivers/net		else    		INSTDIR := /lib/modules/$(KVER)/net  		endif	else		ifneq ($(KERVER2),2)    		INSTDIR := /lib/modules/$(KVER)/kernel/drivers/net		else    		INSTDIR := /lib/modules/$(KVER)/net  		endif	endifendif# look for SMP in config.hSMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \         grep CONFIG_SMP | awk '{ print $$3 }')ifneq ($(SMP),1)  SMP := 0endififeq ($(VMNS), 1)	CFLAGS +=	-DVMNSendififeq ($(TARGET), rhinefet.o)ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))  $(warning ***)ifeq ($(SMP),1)  $(warning *** Warning: kernel source configuration (SMP))  $(warning *** does not match running kernel (UP))else  $(warning *** Warning: kernel source configuration (UP))  $(warning *** does not match running kernel (SMP))endif  $(warning *** Continuing with build,)  $(warning *** resulting driver may not be what you want)  $(warning ***)endifendififeq ($(SMP), 1)  CFLAGS += -D__SMP__endif$(TARGET): $(filter-out $(TARGET), $(SRC:.c=.o))	$(LD) -r $^ -o $@	echo; echo	echo "**************************************************"	echo "Build options:"	echo "   VERSION    $(KVER)"	echo -n "   SMP             "	if [ "$(SMP)" = "1" ]; \		then echo "Enabled"; else echo "Disabled"; fi	echo -n "   VMNS            "	if [ "$(VMNS)" = "1" ]; \		then echo "Enabled"; else echo "Disabled"; fi	echo "***************************************************"install: clean $(TARGET)	mkdir -p $(MOD_ROOT)$(INSTDIR)	install -m 644 -o root $(TARGET) $(MOD_ROOT)$(INSTDIR)	@if [ -f $(MOD_ROOT)$(INSTDIR)/via-rhine.o ] ; then \		echo "*****  Move official driver via-rhine.o to via-rhine.o.backup" ; \		echo "mv $(MOD_ROOT)$(INSTDIR)/via-rhine.o $(MOD_ROOT)$(INSTDIR)/via-rhine.o.backup";\		mv $(MOD_ROOT)$(INSTDIR)/via-rhine.o $(MOD_ROOT)$(INSTDIR)/via-rhine.o.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)/via-rhine.o.backup ] ; then \	    echo "*****  Restore official driver vai-rhine.o from $(MOD_ROOT)$(INSTDIR)".; \		echo "mv $(MOD_ROOT)$(INSTDIR)/via-rhine.o.backup $(MOD_ROOT)$(INSTDIR)/via-rhine.o";\	    mv $(MOD_ROOT)$(INSTDIR)/via-rhine.o.backup $(MOD_ROOT)$(INSTDIR)/via-rhine.o ;\	fi	/sbin/depmod -aclean:	rm -f $(TARGET) $(SRC:.c=.o) *~-include .depend.mak

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -