Tuesday, February 16, 2010

Compiling vnStat on iPhone

vnStat is a neat little bandwidth monitoring cli utility for Linux and FreeBSD.

Actually the hardest part about this is just getting the toolchain running, after that it is a couple modifications to the Makefiles.

So there is quite a bit of documentation out there on how to get the toolchain running. The easiest way I found was on the device itself, using these instructions.

After you do that then you need to just change the top of the Makefile to:


CC=arm-apple-darwin9-g++
Sysroot=/var/toolchain/sys30

LDFLAGS= -multiply_defined suppress \
-L$(Sysroot)/usr/lib \
-Wall \
-Werror \
-march=armv6 \
-mcpu=arm1176jzf-s \

CFLAGS= -I$(Sysroot)/usr/include

# bin and man dirs for Linux
BIN = $(DESTDIR)/usr/bin
SBIN = $(DESTDIR)/usr/sbin
MAN = $(DESTDIR)/usr/share/man

# bin and man dirs for *BSD
BIN_BSD = $(DESTDIR)/usr/local/bin
SBIN_BSD = $(DESTDIR)/usr/local/sbin
MAN_BSD = $(DESTDIR)/usr/local/man

default: vnstat

...


This worked for vnStat 1.10 on an iPhone 3GS 3.0.1.

You also need to sign the files using ldid:


ldid -S src/vnstat
ldid -S src/vnstatd


Or you can just put them in the src/Makefile so it does it automatically for you:


...
all: vnstat vnstatd vnstati

vnstat: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o vnstat
ldid -S vnstat
vnstatd: $(DOBJS)
$(CC) $(LDFLAGS) $(DOBJS) $(LDLIBS) -o vnstatd
ldid -S vnstatd
...


The make install didn't work well for me so I just run it from my /var/root/vnstat directory. You also want to make your db directory and copy the rc file over:


mkdir ~/.vnstat
cp cfg/vnstat.config ~/.vnstatrc


Then modify the ~/.vnstatrc to set the DatabaseDirectory correctly:

# location of the database directory
DatabaseDir "/var/root/.vnstat"

1 comment:

Dustin said...

You should put this on Cydia. I'd love to be able to use this on my iPhone's term.

Thanks!