Chinaunix

标题: 急:内核模块Makefile问题 [打印本页]

作者: lichking_wang    时间: 2009-11-19 22:47
标题: 急:内核模块Makefile问题
.EXPORT_ALL_VARIABLES:

-include $(ROOTDIR)/modules/.config


IXCFLAGS += -D__linux

ifeq ($(CONFIG_IXP425_IXP_AS_ETH),y)
IXCFLAGS += -DCONFIG_IXP425_IXP_AS_ETH=1
endif
ifeq ($(CONFIG_MACH_IXDP465),y)
IXCFLAGS += -D__ixp46X
IXPLATFORM := ixp465
else
IXCFLAGS += -D__ixp42X
IXPLATFORM := ixp425
endif

CSRDIR := $(ROOTDIR)/modules/ixp425/ixp400-2.0
IXCFLAGS += -I$(ROOTDIR)
IXCFLAGS += -I$(CSRDIR)/ixp400_xscale_sw/src/include
IXCFLAGS += -I$(CSRDIR)/ixp_osal
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/core
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/modules
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/modules/ioMem
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/modules/bufferMgt
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/platforms
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/platforms/ixp400
IXCFLAGS += -I$(CSRDIR)/ixp_osal/os/linux/include/platforms/ixp400/$(IXPLATFORM)
IXCFLAGS += -I$(CSRDIR)/ixp_osal/include
IXCFLAGS += -I$(CSRDIR)/ixp_osal/include/modules
IXCFLAGS += -I$(CSRDIR)/ixp_osal/include/modules/bufferMgt
IXCFLAGS += -I$(CSRDIR)/ixp_osal/include/modules/ioMem
IXCFLAGS += -I$(CSRDIR)/ixp_osal/include/platforms
IXCFLAGS += -I$(CSRDIR)/ixp_osal/include/platforms/ixp400

CFLAGS += $(IX_CFLAGS)
EXTRA_CFLAGS += $(IXCFLAGS)

obj-$(CONFIG_IXP400_ETH) += ixp400_eth.o

obj-m  := $(obj-y) $(obj-m)
M_OBJS := $(obj-m)
obj-y  :=

ifdef TOPDIR
-include $(TOPDIR)/Rules.make
endif

.PHONY: clean mrproper distclean

clean:
        rm -f .*o.cmd .*.o.flags *.mod.c *.ko *.o

mrproper: clean
        rm -f .depend

distclean: mrproper

上面是原本模块的Makefile,只有一个ixp400_eth.c源文件,现在我新加了个C文件应该怎么修改?
作者: accessory    时间: 2009-11-20 00:30
我猜的:
把 obj-$(CONFIG_IXP400_ETH) += ixp400_eth.o
改成:
obj-$(CONFIG_IXP400_ETH) += ixp400_eth.o, new_c_file.o
作者: lichking_wang    时间: 2009-11-20 08:54
标题: 回复 #2 accessory 的帖子
那样会生成ixp400_eth.o和new_c_file.o这两个文件
可是我这只有一个模块啊!
作者: dreamice    时间: 2009-11-20 09:00
标题: 回复 #3 lichking_wang 的帖子
如果你有一个模块名为 module.ko, 是来自 2 个源文件( 姑且称之为, file1.c 和 file2.c ), 正确的书写应当是:

obj-m := module.o
module-objs := file1.o file2.o
作者: lichking_wang    时间: 2009-11-20 10:35
标题: 回复 #4 dreamice 的帖子
我用的2.4内核,
刚才按你说的做,编译错误是
No rule to make target 'module.c' need by 'module.o' stop.
我的两个源文件生成了两个.o文件
我添加了对module.o的规则定义啊,怎么说没规则呢?
作者: lichking_wang    时间: 2009-11-20 10:47
list-multi += module.o
module.o-objs := a.o b.o
obj-m += module.o
module.o : $(module-objs)
                $(LD) -r -o $@ $(module-objs)
作者: lichking_wang    时间: 2009-11-20 10:50
上面打错了,应该是
module-objs += a.o b.o
多打了个.o
作者: Godbach    时间: 2009-11-20 15:27
六楼的做法很对啊。
作者: dreamice    时间: 2009-11-20 16:19
2.6和2.4差别还真不少啊
作者: T-Bagwell    时间: 2009-11-20 17:03
原帖由 dreamice 于 2009-11-20 16:19 发表
2.6和2.4差别还真不少啊



非常之多
不单单是这么一点点,进程间通信就做了很大的改动
作者: Godbach    时间: 2009-11-21 10:39
2.6做的更人性化一些




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2