Skip to content
Snippets Groups Projects
Commit baa03bea authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Darwin port: avoid the clumsy scheme with box.lua as a resource.

Convert box.lua to box.lua.c and compile it in.
Fix broken out-of-source build of luajit, by adding
a few more generated files to touch-nocreate rule.
parent 69720f21
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,8 @@ third_party/luajit/src/lj_vm.s
test/connector_c/tt
test/connector_c/update
*.reject
extra/txt2c
mod/box/box.lua.c
doc/www-data/*.html
doc/www-data/*.ru.html
doc/www-data.in/download
......
......@@ -282,11 +282,11 @@ add_subdirectory(third_party)
add_subdirectory(cfg)
add_subdirectory(connector)
add_subdirectory(src)
add_subdirectory(extra)
add_subdirectory(mod)
add_subdirectory(client)
add_subdirectory(test)
add_subdirectory(doc)
add_subdirectory(extra)
install (FILES README LICENSE doc/box-protocol.txt
DESTINATION share/doc/tarantool)
......
......@@ -21,3 +21,5 @@ if ("${CPACK_GENERATOR}" STREQUAL "RPM")
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
endif()
ADD_EXECUTABLE(txt2c txt2c.c)
/*
* txt2c: Converts text files to C strings
*
* Compile with:
* gcc txt2cs.c -o txt2cs
*
* Public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv) {
const char *prefix = "";
const char *suffix = "\n";
int no_quote = 0; /* if 1, do not prepend and append quotation marks (") */
FILE *in = stdin;
FILE *out = stdout;
int c;
while ((c = getopt(argc, argv, "np:s:h")) != -1) {
switch (c) {
case 'n':
no_quote = 1;
break;
case 'p':
prefix = optarg;
break;
case 's':
suffix = optarg;
break;
case 'h':
printf("Usage: %s [-n] [-p prefix] [-s suffix] [infile] [outfile]\n", argv[0]);
exit(0);
break;
}
}
if (optind < argc) {
if (strcmp(argv[optind], "-") != 0) {
if (!(in = fopen(argv[optind], "r"))) {
fprintf(stderr, "Can't open %s\n",
argv[optind]);
perror(argv[0]);
exit(1);
}
}
if (optind + 1 < argc) {
if (strcmp(argv[optind + 1], "-") != 0) {
if (!(out = fopen(argv[optind + 1], "w"))) {
fprintf(stderr, "Can't open %s\n",
argv[optind + 1]);
perror(argv[0]);
exit(1);
}
}
}
}
fputs(prefix, out);
if (!no_quote)
fputs("\"", out);
while ((c = fgetc(in)) != -1) {
switch (c) {
case '\0': fputs("\\0", out); break;
case '\t': fputs("\\t", out); break;
case '\n': fputs("\\n\"\n\"", out); break;
case '\r': fputs("\\r", out); break;
case '\\': fputs("\\\\", out); break;
case '\"': fputs("\\\"", out); break;
default: fputc(c, out); break;
}
}
if (!no_quote)
fputs("\"", out);
fputs(suffix, out);
return 0;
}
......@@ -5,7 +5,7 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/mod/box/memcached-grammar.m
DEPENDS ${CMAKE_SOURCE_DIR}/mod/box/memcached-grammar.rl)
# Do not clean memcached-grammar.m in 'make clean'.
set_property(DIRECTORY PROPERTY CLEAN_NO_CUSTOM true)
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES box.lua.o)
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES tmp.c box.lua.c)
add_custom_target(generate_memcached_grammar_m DEPENDS
${CMAKE_SOURCE_DIR}/mod/box/memcached-grammar.m)
......@@ -15,12 +15,18 @@ add_custom_target(generate_memcached_grammar_m DEPENDS
execute_process(COMMAND ${CMAKE_COMMAND} -E touch_nocreate
${CMAKE_SOURCE_DIR}/mod/box/memcached-grammar.m)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/box.lua.o
COMMAND cd ${CMAKE_SOURCE_DIR}/mod/box && ${LD} -r -b binary box.lua -o ${CMAKE_CURRENT_BINARY_DIR}/box.lua.o
DEPENDS box.lua)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_BINARY_DIR}/mod/box/box.lua.c
COMMAND ${ECHO} 'const char box_lua[] =' > tmp.c
COMMAND ${CMAKE_BINARY_DIR}/extra/txt2c
${CMAKE_SOURCE_DIR}/mod/box/box.lua >> tmp.c
COMMAND ${ECHO} '\;' >> tmp.c
COMMAND ${CMAKE_COMMAND} -E copy_if_different tmp.c
${CMAKE_BINARY_DIR}/mod/box/box.lua.c
COMMAND ${CMAKE_COMMAND} -E remove tmp.c
DEPENDS ${CMAKE_SOURCE_DIR}/mod/box/box.lua)
set_source_files_properties(box.lua.o
PROPERTIES EXTERNAL_OBJECT true)
add_custom_target(generate_box_lua_c
DEPENDS ${CMAKE_BINARY_DIR}/mod/box/box.lua.c)
set_source_files_properties(memcached-grammar.m
PROPERTIES HEADER_FILE_ONLY true)
......@@ -28,6 +34,5 @@ set_source_files_properties(memcached-grammar.m
set_source_files_properties(memcached.m
PROPERTIES COMPILE_FLAGS "-Wno-uninitialized")
tarantool_module("box" tuple.m index.m tree.m box.m box_lua.m
memcached.m memcached-grammar.m
box.lua.o)
tarantool_module("box" tuple.m index.m tree.m box.m box.lua.c box_lua.m
memcached.m memcached-grammar.m)
-- This function create new table with constants members. The run-time error
-- will be raised if attempting to change table members.
-- This function creates a new table with constant members.
-- A run-time error will be raised on attempt to change
-- table members.
local function create_const_table(table)
return setmetatable ({}, {
__index = table,
......
......@@ -45,7 +45,7 @@
#include "tuple.h"
/* contents of box.lua */
extern const char _binary_box_lua_start;
extern const char box_lua[];
/**
* All box connections share the same Lua state. We use
......@@ -823,7 +823,7 @@ mod_lua_init(struct lua_State *L)
lua_pop(L, 1);
tarantool_lua_register_type(L, iteratorlib_name, lbox_iterator_meta);
/* Load box.lua */
if (luaL_dostring(L, &_binary_box_lua_start))
if (luaL_dostring(L, box_lua))
panic("Error loading box.lua: %s", lua_tostring(L, -1));
assert(lua_gettop(L) == 0);
return L;
......
......@@ -31,7 +31,8 @@ macro (luajit_build)
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/third_party/luajit
COMMAND $(MAKE) clean
COMMAND $(MAKE) -C src -t buildvm_x86.h buildvm_arm.h
buildvm_x64.h buildvm_x64win.h
buildvm_x64.h buildvm_x64win.h buildvm_ppc.h
buildvm_ppcspe.h
COMMAND $(MAKE) -C src ${luajit_buildoptions}
DEPENDS ${CMAKE_SOURCE_DIR}/CMakeCache.txt
)
......@@ -44,7 +45,8 @@ macro (luajit_build)
COMMAND cp -r ${PROJECT_SOURCE_DIR}/third_party/luajit/* .
COMMAND $(MAKE) clean
COMMAND $(MAKE) -C src -t buildvm_x86.h buildvm_arm.h
buildvm_x64.h buildvm_x64win.h
buildvm_x64.h buildvm_x64win.h buildvm_ppc.h
buildvm_ppcspe.h
COMMAND $(MAKE) -C src ${luajit_buildoptions}
DEPENDS ${PROJECT_BINARY_DIR}/CMakeCache.txt ${PROJECT_BINARY_DIR}/third_party/luajit
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment