同步源码
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial
╰─➤
检查README
####如果提示缺少libpcap.so.0.x而在/usr/lib/目录下已存在一个libpcap.so.0.x.y
sudo ln -s libpcap.so.0.x.y /usr/lib/libpcap.so.0.x
否则请安装libpcap。
得知还需要libpcap(其实这个项目的文档做的不是特别好……如果需要完整功能(正确显示系统消息)还需要libiconv)
下载libpcap和libiconv
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial
╰─➤ http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
正在解析主机 ftp.gnu.org (ftp.gnu.org)... 208.118.235.20
正在连接 ftp.gnu.org (ftp.gnu.org)|208.118.235.20|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:4984397 (4.8M) [application/x-gzip]
正在保存至: “libiconv-1.14.tar.gz”
libiconv-1.14.tar.g 100%[=====================>] 4.75M 1.55MB/s 用时 3.1s
2016-04-22 23:52:56 (1.55 MB/s) - 已保存 “libiconv-1.14.tar.gz” [4984397/4984397])
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial
╰─➤ tar xf libiconv-1.14.tar.gz
首先编译libpcap
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libpcap ‹master›
╰─➤ export PATH=$PATH:/project/hnd/tools/linux/hndtools-arm-linux-2.6.36-uclibc-4.5.3/bin
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libpcap ‹master›
╰─➤ ./configure --host=arm-brcm-linux-uclibcgnueabi --with-pcap=linux
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-brcm-linux-uclibcgnueabi
checking target system type... arm-brcm-linux-uclibcgnueabi
config.status: creating pcap_set_tstamp_type.3pcap
config.status: creating config.h
config.status: executing default-1 commands
注意:最后那个--with-pcap=linux是直接运行./configure --host=arm-brcm-linux-uclibcgnueabi后报错才知道要加的。谷歌一下就好。
编译
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libpcap ‹master›
╰─➤ make
arm-brcm-linux-uclibcgnueabi-gcc -fvisibility=hidden -fpic -I. -DBUILDING_PCAP -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -g -O2 -c ./pcap-linux.c
arm-brcm-linux-uclibcgnueabi-gcc -fvisibility=hidden -fpic -I. -DBUILDING_PCAP -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -g -O2 -c ./pcap-usb-linux.c
config.status: creating pcap-config.tmp
mv pcap-config.tmp pcap-config
chmod a+x pcap-config
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libpcap ‹master›
╰─➤ find . -name "*.a"
./libpcap.a
可以看到库文件就在根目录底下
再编译libiconv,因为是同一个shell,所以不需要再次export PATH
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libiconv-1.14
╰─➤ ./configure --host=arm-brcm-linux-uclibcgnueabi --enable-static=yes
configure: WARNING: if you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used
checking for a BSD-compatible install... /usr/bin/install -c
configure: creating ./config.status
config.status: creating Makefile
config.status: executing libtool commands
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libiconv-1.14
╰─➤ make
builddir="`pwd`"; cd libcharset && make all && make install-lib libdir="$builddir/lib" includedir="$builddir/lib"
make[1]: Entering directory '/media/hamster/Android/Tutorial/libiconv-1.14/libcharset'
cd lib && make all
make[1]: Entering directory '/media/hamster/Android/Tutorial/libiconv-1.14/tests'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/media/hamster/Android/Tutorial/libiconv-1.14/tests'
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/libiconv-1.14
╰─➤ find . -name "*.a"
./srclib/libicrt.a
./lib/.libs/libiconv.a
./lib/libcharset.a
./libcharset/lib/.libs/libcharset.a
可以看到库文件在./lib/.libs/libiconv.a
回来编译主程序了
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/mentohust ‹master›
╰─➤ ./autogen.sh
+ autopoint
Copying file ABOUT-NLS
Copying file config.rpath
Makefile.am: for your code, to avoid questions about which license your project uses
src/Makefile.am: installing './depcomp'
+ autoconf
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/mentohust ‹master›
╰─➤ LIBS=/media/hamster/Android/Tutorial/libiconv-1.14/lib/.libs/libiconv.a ./configure --host=arm-brcm-linux-uclibcgnueabi --with-pcap=/media/hamster/Android/Tutorial/libpcap/libpcap.a --disable-notify
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-brcm-linux-uclibcgnueabi
checking for a BSD-compatible install... /usr/bin/install -c
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
注意:--with-pcap也是经过报错才知道要加的。而LIBS是因为这个configure没有提供指定libiconv位置的参数,故手动加上。
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/mentohust ‹master›
╰─➤ make
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /media/hamster/Android/Tutorial/mentohust/missing autoheader)
rm -f stamp-h1
touch config.h.in
make[2]: Entering directory '/media/hamster/Android/Tutorial/mentohust'
make[2]: Leaving directory '/media/hamster/Android/Tutorial/mentohust'
make[1]: Leaving directory '/media/hamster/Android/Tutorial/mentohust'
找一下可以发现生成的文件在src/mentohust。经过strip以后大小会小很多,可以放在路由器上用了(其实不strip也一样,反正128M Flash用不完)
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/mentohust ‹master*›
╰─➤ ls -la src/mentohust
-rwxr-xr-x 1 hamster hamster 629932 4月 23 00:10 src/mentohust
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/mentohust ‹master*›
╰─➤ arm-brcm-linux-uclibcgnueabi-strip src/mentohust
╭─hamster@Hamster-PC /media/hamster/Android/Tutorial/mentohust ‹master*›
╰─➤ ls -la src/mentohust
-rwxr-xr-x 1 hamster hamster 230544 4月 23 00:14 src/mentohust