RT-N14U源码研究之——添加用户app(以zdclient为例)

在router目录下,仔细阅读README,里面有一段话:

To add a new user application to the package, edit config/Config and
name the module rule under the "Configuration" section of the
Makefile. If the module can be built, cleaned, and installed with the
generic rules located at the end of the Makefile, no further changes are
necessary. Otherwise, add additional rules for the module under the
"Overrides" section of the Makefile. "make <module>" should descend into
the module directory and compile the sources. "make <module>-install"
should install the appropriate binaries as if "$(INSTALLDIR)/<module>"
were the root directory. "make <module>-clean" should clean generated
files from the module directory.

但是很遗憾,可能是我没有搞明白,按照README的要求,往Config文件中加入了配置,但是make menuconfig并没有看到相应的东西。

没有办法,只好编辑config/config.in文件,加入:

config RTCONFIG_ZDCLIENT
	bool "ZDClient"
	default y
这样才能加入RTCONFIG_ZDCLIENT开关,然后,回到上层目录,修改Makefile文件:

先在前部加入编译开关

#
# configurable packages
#
RTCONFIG_PPP_BASE = y
obj-$(RTCONFIG_PPP_BASE) += pppd rp-pppoe
obj-$(RTCONFIG_L2TP) += rp-l2tp
obj-$(RTCONFIG_PPTP) += accel-pptp
obj-$(RTCONFIG_EAPOL) += wpa_supplicant
# manfeel, add zdcient support
obj-$(RTCONFIG_ZDCLIENT) += zdclient
然后仿照下面的格式:

wpa_supplicant-0.7.3/stamp-h1:
	touch $@

wpa_supplicant-0.7.3: $@/stamp-h1
	$(MAKE) -C $@/src/eap_peer

wpa_supplicant-0.7.3-install: wpa_supplicant-0.7.3
	install -D wpa_supplicant-0.7.3/src/eap_peer/libeap.so.0.0.0 $(INSTALLDIR)/wpa_supplicant-0.7.3/usr/lib/libeap.so.0.0.0
	$(STRIP) $(INSTALLDIR)/wpa_supplicant-0.7.3/usr/lib/libeap.so.0.0.0
	cd $(INSTALLDIR)/wpa_supplicant-0.7.3/usr/lib && \
	ln -sf libeap.so.0.0.0 $(INSTALLDIR)/wpa_supplicant-0.7.3/usr/lib/libeap.so.0
	ln -sf libeap.so.0.0.0 $(INSTALLDIR)/wpa_supplicant-0.7.3/usr/lib/libeap.so

wpa_supplicant-0.7.3-clean:
	-@$(MAKE) -C wpa_supplicant-0.7.3/src/eap_peer clean
	@rm -f wpa_supplicant-0.7.3/stamp-h1

gctwimax-0.0.3rc4/stamp-h1:
	touch $@

gctwimax-0.0.3rc4: $@/stamp-h1
	$(MAKE) -C $@

gctwimax-0.0.3rc4-install: gctwimax-0.0.3rc4
	install -D gctwimax-0.0.3rc4/gctwimax $(INSTALLDIR)/gctwimax-0.0.3rc4/usr/sbin/gctwimax
	$(STRIP) $(INSTALLDIR)/gctwimax-0.0.3rc4/usr/sbin/gctwimax
	#install -D gctwimax-0.0.3rc4/src/event.sh $(INSTALLDIR)/gctwimax-0.0.3rc4/usr/share/event.sh
	#install -D gctwimax-0.0.3rc4/src/gctwimax.conf $(INSTALLDIR)/gctwimax-0.0.3rc4/usr/share/gctwimax.conf

gctwimax-0.0.3rc4-clean:
	-@$(MAKE) -C gctwimax-0.0.3rc4 clean
	@rm -f gctwimax-0.0.3rc4/stamp-h1

感觉gctwimax的源码结构与zdclient比较类似(只有一个src目录),于是照着这个来编写:

#### manfeel zdclient begin ####
zdclient/stamp-h1:
	touch $@

zdclient: $@/stamp-h1
	$(MAKE) -C $@

zdclient-install: zdclient
	install -D zdclient/zdclient $(INSTALLDIR)/zdclient/usr/bin/zdclient
	$(STRIP) $(INSTALLDIR)/zdclient/usr/bin/zdclient

zdclient-clean:
	-@$(MAKE) -C zdclient clean
	@rm -f zdclient/stamp-h1
#### manfeel zdclient end ###### 


然后进入创建zdclient目录,进入并创建src目录,将zdclient源文件拷贝到该目录,返回上一层,创建Makefile,参照gctwimax的Makefile:

源码中关于 iconv相关的也可以删除,因为print_server_info要报错,一并删除!

仿照tcpdump(因为它也依赖libpcap)书写Makefile如下:

##### manfeel zdclient modification

ALL=zdclient

all: $(ALL)

ifndef CC
CC=gcc
endif

ifndef LDO
LDO=$(CC)
endif

FLAGS = -MMD -O2 -g -Wall

## include file
FLAGS += -I.
FLAGS += -I$(TOP)/libpcap

override CFLAGS += $(FLAGS)

# Standard LDFLAGS
LDFLAGS = 

# Standard LIBS
LIBS = $(TOP)/libpcap/libpcap.a

OBJS_ex = src/main.o src/md5.o src/zdclient.o

zdclient: $(OBJS_ex)
	$(LDO) $(LDFLAGS) -o zdclient $(OBJS_ex) $(LDFLAGS) $(LIBS)

install:
	cp ./zdclient /bin/zdclient

uninstall:
	rm /bin/zdclient

.PHONY: clean
clean:
	rm -f core src/*~ src/*.o src/*.d $(ALL)

-include $(OBJS:%.o=%.d)

发现libpcap默认是没有编译的,所以要在menuconfig里面打开

config RTCONFIG_TCPDUMP
	bool "tcpdump"
	default n
同时要修改Makefile对应的地方,install的地方被华硕官方注释掉了,不知为何


目前还有一个问题没有解决,libpcap不会自动拷贝到target目录,不知哪里还没有设置对。

只好按照Makefile中前部的帮助,这样操作:

make libpcap-clean mk-libpcap libpcap-install gen_target

然后进入到install目录(router/mips_uClib/install)手动拷贝libpcap到target目录对应的地方,然后

make image

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值