cross-lua.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. local args = { ... }
  2. local b = require "tools.build"
  3. local builder = b.new_builder( ".build/cross-lua" )
  4. local utils = b.utils
  5. local sf = string.format
  6. if not (_VERSION == "Lua 5.1" and pcall(require,"lfs")) then
  7. print [[
  8. cross_lua.lua must be run within Lua 5.1 and it requires the Lua Filesystem to be installed.
  9. On most *nix distrubitions youwill find a packages lua-5.1 and lua-filesystem, or
  10. alternalively you can install lua-rocks and use the Rocks package manager to install lfs.
  11. ]]
  12. os.exit(1)
  13. end
  14. builder:init( args )
  15. builder:set_build_mode( builder.BUILD_DIR_LINEARIZED )
  16. local output = 'luac.cross'
  17. local cdefs = '-DLUA_CROSS_COMPILER -Ddbg_printf=printf'
  18. -- Lua source files and include path
  19. local lua_files = [[
  20. lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ldo.c ldump.c
  21. lfunc.c lgc.c llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c
  22. lparser.c lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c
  23. ltm.c lundump.c lvm.c lzio.c
  24. luac_cross/luac.c luac_cross/loslib.c luac_cross/print.c
  25. ../modules/linit.c
  26. ../libc/c_stdlib.c
  27. ]]
  28. lua_files = lua_files:gsub( "\n" , "" )
  29. local lua_full_files = utils.prepend_path( lua_files, "app/lua" )
  30. local local_include = "-Iapp/include -Iinclude -Iapp/lua"
  31. -- Compiler/linker options
  32. builder:set_compile_cmd( sf( "gcc -O2 %s -Wall %s -c $(FIRST) -o $(TARGET)", local_include, cdefs ) )
  33. builder:set_link_cmd( "gcc -o $(TARGET) $(DEPENDS) -lm" )
  34. -- Build everything
  35. builder:make_exe_target( output, lua_full_files )
  36. builder:build()