Porting Lua to ARM

Development:
    kernel:2.6.31-14-generic ubuntu9.10
    cross-tools:arm-linux-gcc version 4.1.2
Target
    kernel: 2.6.28.9 MOZART380 armv5tejl

下载Lua:
    lua-5.1.4.tar.gz

    http://iask.sina.com.cn/u/ish
解压:
    tar -xzvf lua-5.1.4.tar.gz
    cd lua-5.1.4
修改

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Way1:
    gedit src/Makefile

    PLAT= none     --> PLAT= ansi
    CC= gcc     --> CC= arm-linux-gcc
    AR= ar         --> AR=arm-linux-ar
    RANLIB=ranlib     --> RANLIB=arm-linux-ranlib
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Way2:
    gedit src/Makefile

    PLAT= none         --> PLAT= linux
    CC= gcc         --> CC= arm-linux-gcc
    AR= ar             --> AR=arm-linux-ar
    RANLIB=ranlib         --> RANLIB=arm-linux-ranlib
    LIBS= -lm $(MYLIBS)     --> LIBS= -lm $(MYLIBS) -static
    $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
                --->
    $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl "

    gedit src/luaconf.h
    注释掉以下内容
    #define LUA_USE_READLINE
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

bean推荐采用Way2

make
其中对我们有意义的是*.o lua luac

copy
拷贝lua至开发板相应目录

编写 test
////////////////////////////////////////////////////////////////////
-- bisection method for solving non-linear equations

delta=1e-6      --tolerance                                                                                                                                     
functionbisect(f,a,b,fa,fb)                                                                                                                                        
          localc=(a+b)/2                                                                                                                                                    
          io.write(n," c=",c," a=",a,"b=",b,"\n")                                                                                                                           
          if c==a or c==b or math.abs(a-b)<delta then

                   return c,b-a 

          end                                                                                                        
         n=n+1                                                                                                                                                              
         localfc=f(c)                                                                                                                                                      
         if fa*fc<0 then

                   return bisect(f,a,c,fa,fc)

         else

                   return bisect(f,c,b,fc,fb) 

         end                                                                                      
end                                                                                                                                                                 
                                                                                                                                                                    
-- find root of f in the inverval [a,b]. needsf(a)*f(b)<0                                                                                                          
functionsolve(f,a,b)                                                                                                                                               
         n=0                                                                                                                                                                
          localz,e=bisect(f,a,b,f(a),f(b))                                                                                                                                  
         io.write(string.format("after %d steps, root is %.17gwith error %.1e,f=%.1e\n",n,z,e,f(z)))                                                                      end                                                                                                                                                                 
                                                                                                                                                                    
-- ourfunction                                                                                                                                                     
functionf(x)                                                                                                                                                       
          returnx*x*x-x-1                                                                                                                                                   
end                                                                                                                                                                 
                                                                                                                                                                    
-- find zero in[1,2]                                                                                                                                               
solve(f,1,2)   
////////////////////////////////////////////////////////////////////

测试
    ./lua /path/to/test/lua

参考:
http://www.huomo.cn/developer/article-17ac9.html


你可能感兴趣的:(c,linux,测试,gcc,ubuntu,lua)