lua發布的代碼中,本身提供了makefile用來在多個平台上編譯lua,但是針對windows,它提供的是mingw:
mingw: $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \ "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe $(MAKE) "LUAC_T=luac.exe" luac.exe
本質上來講,還是GNU那套工具鏈。
這不是native的windows的做法 - 真正native的做法是用Visual Studio編譯,鏈接到微軟提供的crt庫。
有人提供了一套visual studio的solution:http://lua-users.org/wiki/BuildingLua, 如此你不但要維護多個工程文件,還要維護多個visual studio的版本(或者自動migration), 既然premake繼承了lua的良好傳統,用簡潔而又優美的方式實現跨平台的編譯;lua理應享受這一自己帶來的便利:
solution 'lua' configurations {'Debug', 'Release'} platforms {'x32', 'x64'} if os.get() == "windows" then defines '_CRT_SECURE_NO_WARNINGS' end -- the lua library project 'lualib' targetname 'lua' -- rename the target library to lua kind 'StaticLib' language 'C' files {'lapi.c', 'lcode.c', 'ldebug.c', 'ldo.c', 'ldump.c', 'lfunc.c', 'lgc.c', 'llex.c', 'lmem.c', 'lobject.c', 'lopcodes.c', 'lparser.c', 'lstate.c', 'lstring.c', 'ltable.c', 'ltm.c', 'lundump.c', 'lvm.c', 'lzio.c', 'lauxlib.c', 'lbaselib.c', 'lbitlib.c', 'lcorolib.c', 'ldblib.c', 'liolib.c', 'lmathlib.c', 'loslib.c', 'lstrlib.c', 'ltablib.c', 'loadlib.c', 'linit.c'} -- the lua interpret project 'lua' kind 'ConsoleApp' language 'C' links 'lualib' if os.get() == "linux" then links {'m'} end files 'lua.c' -- the lua compiler project 'luac' kind 'ConsoleApp' language 'C' links 'lualib' files 'luac.c'
編譯lua一般需要知道下面幾個文件:
- Makefile, src/Makefile - 編譯配置
- doc/readme.html - 編譯說明
- src/luaconf.h - lua特性配置
lua一般編譯成三個部分,lua庫, lua解釋器與luac編譯器,這些target的source在doc/readme.html中都有說明:
library:
lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c
interpreter:
library, lua.c
compiler:
library, luac.c
好了,據此寫出一個極其簡單的premake4 solution:
在windows下編譯:
premake4 vs2008
vcbuild lua.sln "Debug|Win32"
linux下:
premake4 gmake
make