newlisp and openwrt

Q&A's, tips, howto's
Locked
dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

newlisp and openwrt

Post by dexter »

As the title
I am porting newlisp to openwrt.

My device is TP-LINK TL_WR703N
MIPS with linux kernel 3.3.8

I cloned openwrt svn trunk, builded toolchain and SDK

My problem is ,Is there a way to reduce the size of newlisp binary file ?

As far as now, it is 284k, But my device only left 502kb
I found out that lua is about 150kb
Anyone can help me a little?

Code: Select all

OBJS = newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \
    nl-sock.o nl-import.o nl-xml.o nl-web.o nl-matrix.o nl-debug.o nl-utf8.o pcre.o

CFLAGS = -Wall -ffunction-sections -fdata-sections  -c -Os   -DLINUX -I$(TARGET_DIR)/usr/include/
LDFLAGS = -L$(TARGET_DIR)/usr/lib/  -W1,--gc-sections -lm -ldl 
CC = mips-openwrt-linux-gcc
LD = mips-openwrt-linux-ld


default: $(OBJS)
    $(CC) $(OBJS)  -o newlisp $(LDFLAGS)   #for openwrt 
#    $(CC) $(OBJS) -g -lm -ldl -lreadline -ltermcap -o newlisp # slackware
#    $(CC) $(OBJS) -g -lm -ldl -lreadline -lncurses -o newlisp # other Linux Dist
#    $(CC) $(OBJS) -g -lm -ldl -o newlisp # without readline support
    $(STRIP) newlisp

.c.o:
    $(CC) $(CFLAGS) $<

$(OBJS): primes.h protos.h makefile_linux_openwrt

And, I also cut the readline library to save space, Is this ok for the newlisp's performence?


Thanks

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: newlisp and openwrt

Post by cormullion »

I can't answer your question, but I'm wondering whether comparing to Lua makes sense. Last time I looked, a basic Lua binary didn't have the overheads (features) of a newLisp binary, ie file system interface, networking, maths, statistics, financials, XML, web server, parallel and distributed computing, PCRE regular expressions, step debugger, and so on. These were installable extras for Lua. Has that changed? (I like Lua, by the way, and the modular approach works well.)

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: newlisp and openwrt

Post by dexter »

No mean to compare

Just wonder if there is way to reduce the binary file size.

As smaller as we can

jopython
Posts: 123
Joined: Tue Sep 14, 2010 3:08 pm

Re: newlisp and openwrt

Post by jopython »

Did you strip your newlisp executable?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: newlisp and openwrt

Post by Lutz »

280k seems a lot to me without readline and utf8, but I don't know OpenWrt and don't have a Linux system handy at the moment to check. Perhaps somebody else can report numbers on Linux or other Mips CPU systems.

On FreeBSD, I get 211k when compiling without -DSUPPORT_UTF8 and -DREADLINE. I suggest taking out nl-utf8.o of the OBJS definition, because you haven't specified SUPPORT_UTF8. On FreeBSD both options account for about 20k.

I don't think stripping the executable will bring anything because you didn't specify the -g (debugging) flag in CFLAGS, which stores symbol names in the executable.

As Cormullion pointed out, there is a lot of highlevel stuff already built into the newlisp executable which you would have to store as modules on your system when using Lua or any other scripting language. Also consider that the simple built-in ffi with 'import' lets you do 95% of function imports from other C-libraries on your OpenWrt system.

I believe, user Kanen has some experience with OpenWrt systems, perhaps he as some suggestions.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: newlisp and openwrt

Post by cormullion »

user Kanen has some experience with OpenWrt systems
ah yes, I remember the Kane box...

jopython
Posts: 123
Joined: Tue Sep 14, 2010 3:08 pm

Re: newlisp and openwrt

Post by jopython »

In order to shave kilobytes, will it be possible to remove compilation options for the matrix, financial, trigonometry functions?
I am not sure why this decision to add these functions to the 'core' of a general purpose language.

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: newlisp and openwrt

Post by dexter »

Thanks all guys

I will look at kane.

I stripped newlisp

removed nl-utf8.o

Now it is 280k

I am still working on reducing it.

I think it is possible to be less than 200k

kanen
Posts: 145
Joined: Thu Mar 25, 2010 6:24 pm
Contact:

Re: newlisp and openwrt

Post by kanen »

Actually, if you go to https://github.com/kanendosei/kane-box/ ... er/openwrt -- you will see a Makefile for OpenWRT which works and creates a semi-reasonable version of newLisp.

You just have to put the newlisp Makefile in the right place ( ~/openwrt/package/newlisp directory ) and it will grab and compile the proper source files (from kane-box.com, actually). I don't have it working with 10.4.x of newLisp, but that can be done, if anyone needs it.
cormullion wrote:
user Kanen has some experience with OpenWrt systems
ah yes, I remember the Kane box...
. Kanen Flowers http://kanen.me .

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: newlisp and openwrt

Post by dexter »

It seems kane-box have not been updated for a while

I could not download the kane-box newlisp

But I just did what you said ,with newlisp 10.4.4

it works just fine

Continue to reduce the size

Locked