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 )
88cmake_minimum_required ( VERSION 2.8 )
99include ( dist.cmake )
1010
11- find_package ( Lua51 REQUIRED )
1211find_program ( LUA NAMES lua lua.bat )
1312find_program ( LUAC NAMES luac luac.bat )
1413
1514set ( SRC ${CMAKE_CURRENT_SOURCE_DIR} /src )
1615set ( BIN ${CMAKE_CURRENT_BINARY_DIR} )
1716set ( 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
5031file ( GLOB_RECURSE SRCS RELATIVE ${LIB} "${LIB} /*.mlua" )
5132foreach ( 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 )
6142install ( DIRECTORY ${LIB} / DESTINATION ${INSTALL_LMOD} PATTERN "*.in" EXCLUDE )
6243install_doc ( doc / )
6344install_foo ( junk/ )
0 commit comments