Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit 92d178a

Browse files
committed
Works on OSX/Linux. Tweaked Michals build
1 parent e9a0cca commit 92d178a

File tree

5 files changed

+23
-49
lines changed

5 files changed

+23
-49
lines changed

CMakeLists.txt

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (C) 2011 LuaDist.
2-
# Submited by Michal Kottman
2+
# Submited by Michal Kottman, Peter Drahos
33
# Redistribution and use of this file is allowed according to the terms of the MIT license.
44
# For details see the COPYRIGHT file distributed with LuaDist.
55
# Please note that the package source code is licensed under its own license.
@@ -8,56 +8,37 @@ project ( metalua NONE )
88
cmake_minimum_required ( VERSION 2.8 )
99
include ( dist.cmake )
1010

11-
find_package ( Lua51 REQUIRED )
1211
find_program ( LUA NAMES lua lua.bat )
1312
find_program ( LUAC NAMES luac luac.bat )
1413

1514
set ( SRC ${CMAKE_CURRENT_SOURCE_DIR}/src )
1615
set ( BIN ${CMAKE_CURRENT_BINARY_DIR})
1716
set ( LIB ${BIN}/lib )
1817

19-
message ( STATUS "Preparing the metalua libraries" )
18+
file ( COPY ${SRC}/lib/ DESTINATION ${LIB} )
2019

21-
file ( COPY ${SRC}/lib/ DESTINATION ${LIB} PATTERN ".in" EXCLUDE )
22-
configure_file ( ${SRC}/lib/metalua/package2.lua.in ${LIB}/metalua/package2.lua )
23-
configure_file ( ${SRC}/compiler/metalua.mlua.in ${LIB}/metalua.mlua )
24-
25-
message ( STATUS "Compiling the parts of the compiler written in plain Lua" )
26-
27-
execute_process (
28-
COMMAND ${LUAC} -o ${LIB}/metalua/bytecode.luac
29-
lopcodes.lua lcode.lua ldump.lua compile.lua
30-
COMMAND ${LUAC} -o ${LIB}/metalua/mlp.luac
31-
lexer.lua gg.lua mlp_lexer.lua mlp_misc.lua mlp_table.lua mlp_meta.lua mlp_expr.lua mlp_stat.lua mlp_ext.lua
32-
WORKING_DIRECTORY ${SRC}/compiler )
33-
34-
message ( STATUS "Bootstrap the parts of the compiler written in metalua" )
35-
36-
execute_process (
37-
COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${SRC}/compiler/mlc.mlua output=${LIB}/metalua/mlc.luac
38-
COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${LIB}/metalua.mlua output=${LIB}/metalua.luac
39-
WORKING_DIRECTORY ${LIB} )
40-
41-
message ( STATUS "Finish the bootstrap: recompile the metalua parts of the compiler with itself" )
42-
43-
execute_process (
44-
COMMAND ${LUA} ${LIB}/metalua.luac -vb -f ${SRC}/compiler/mlc.mlua -o ${LIB}/metalua/mlc.luac
45-
COMMAND ${LUA} ${LIB}/metalua.luac -vb -f ${LIB}/metalua.mlua -o ${LIB}/metalua.luac
46-
WORKING_DIRECTORY ${LIB} )
47-
48-
message ( STATUS "Precompile metalua libraries" )
20+
add_custom_target ( bootstrap ALL
21+
COMMAND ${LUAC} -o ${LIB}/metalua/bytecode.lua
22+
${SRC}/compiler/lopcodes.lua ${SRC}/compiler/lcode.lua ${SRC}/compiler/ldump.lua ${SRC}/compiler/compile.lua
23+
COMMAND ${LUAC} -o ${LIB}/metalua/mlp.lua
24+
${SRC}/compiler/lexer.lua ${SRC}/compiler/gg.lua ${SRC}/compiler/mlp_lexer.lua ${SRC}/compiler/mlp_misc.lua ${SRC}/compiler/mlp_table.lua ${SRC}/compiler/mlp_meta.lua ${SRC}/compiler/mlp_expr.lua ${SRC}/compiler/mlp_stat.lua ${SRC}/compiler/mlp_ext.lua
25+
COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${SRC}/compiler/mlc.mlua output=${LIB}/metalua/mlc.lua
26+
COMMAND ${LUA} ${SRC}/build-utils/bootstrap.lua ${SRC}/compiler/metalua.mlua output=${LIB}/metalua.lua
27+
COMMAND ${LUA} ${LIB}/metalua.lua -vb -f ${SRC}/compiler/mlc.mlua -o ${LIB}/metalua/mlc.lua
28+
COMMAND ${LUA} ${LIB}/metalua.lua -vb -f ${SRC}/compiler/metalua.mlua -o ${LIB}/metalua.lua
29+
WORKING_DIRECTORY ${LIB} VERBATIM)
4930

5031
file ( GLOB_RECURSE SRCS RELATIVE ${LIB} "${LIB}/*.mlua")
5132
foreach ( S ${SRCS} )
5233
get_filename_component ( P ${S} PATH )
5334
get_filename_component ( D ${S} NAME_WE )
54-
message ( STATUS "Compiling ${S} to ${P}/${D}.luac" )
55-
execute_process (
56-
COMMAND ${LUA} ${LIB}/metalua.luac ${S} -o ${P}/${D}.luac
57-
WORKING_DIRECTORY ${LIB} )
58-
endforeach ( S )
35+
add_custom_command ( OUTPUT ${P}/${D}.lua
36+
COMMAND ${LUA} ${LIB}/metalua.lua ${S} -o ${P}/${D}.lua
37+
WORKING_DIRECTORY ${LIB}
38+
DEPENDS bootstrap )
39+
endforeach ()
5940

60-
install_lua_executable ( metalua ${LIB}/metalua.luac )
41+
install_lua_executable ( metalua ${LIB}/metalua.lua )
6142
install ( DIRECTORY ${LIB}/ DESTINATION ${INSTALL_LMOD} PATTERN "*.in" EXCLUDE)
6243
install_doc ( doc/ )
6344
install_foo ( junk/ )
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
--*-lua-*- Set as a metalua file because it requires some metalua libs
2-
3-
package.path = './?.luac;'..(_PROGDIR or "") .. "/../@INSTALL_LMOD@/?.luac;"..package.path
4-
52
--require 'verbose_require'
63

74
require 'metalua.compiler'

src/compiler/mlc.mlua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ function mlc.convert (x, src_fmt, dst_fmt, name)
7070
-- printf(" *** Convert a %s into a %s", src_fmt, dst_fmt)
7171

7272
-{ jump_to_point }
73-
7473
error "Can't perform this conversion (bad src name)"
7574

7675
POINT 'luafile', 'string' -- x is the src file's name

src/lib/metalua/mlc_xcall.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function mlc_xcall.client_file (luafile)
8282

8383
local tmpfilename = os.tmpname()
8484
local cmd = string.format (
85-
[=[lua -l metalua.mlc_xcall -e "mlc_xcall.server([[%s]], [[%s]], %s)"]=],
86-
luafile, tmpfilename, mlc.metabugs and "true" or "false")
85+
[=[%s -l metalua.mlc_xcall -e "mlc_xcall.server([[%s]], [[%s]], %s)"]=],
86+
(_PROGDIR and _PROGDIR.."/lua" or "lua"), luafile, tmpfilename, mlc.metabugs and "true" or "false")
8787

8888
-- printf("os.execute [[%s]]\n\n", cmd)
8989

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ require 'metalua.mlc'
44

55
package.metalua_extension_prefix = 'metalua.extension.'
66

7-
local dir = (_PROGDIR or "") .. "/@INSTALL_LMOD@"
8-
package.mpath = os.getenv 'LUA_MPATH' or
9-
'./?.mlua;'..dir..'/?.mlua;'..dir..'/?/init.mlua'
10-
7+
package.mpath = os.getenv 'LUA_MPATH' or string.gsub( package.path or "./?.mlua", "%.lua", "%.mlua")
118

129
----------------------------------------------------------------------
1310
-- resc(k) returns "%"..k if it's a special regular expression char,
@@ -52,9 +49,9 @@ end
5249
local function spring_load(filename)
5350
-- FIXME: handle compilation errors
5451
local pattern =
55-
[=[lua -l metalua.compiler -l serialize -e ]=]..
52+
[=[%s -l metalua.compiler -l serialize -e ]=]..
5653
[=["print(serialize(mlc.ast_of_luafile [[%s]]))"]=]
57-
local cmd = string.format (pattern, filename)
54+
local cmd = string.format (pattern, (_PROGDIR and _PROGDIR.."/lua" or "lua"), filename)
5855
--print ("running command: ``" .. cmd .. "''")
5956
local fd = io.popen (cmd)
6057
local ast_src = fd:read '*a'

0 commit comments

Comments
 (0)