From b6573586951fbeceaab6cba48ca502dbfa24e320 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 2 Jan 2010 15:27:48 +0000 Subject: moved from include to own object for lua bytecode --- src/Makefile | 42 +++++++++++++++++++----------------------- src/anylike.c | 5 +++-- tools/bin2c.lua | 5 ++++- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Makefile b/src/Makefile index e90edb3..208b35b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,8 +34,6 @@ include include.mk endif EXECUTABLE := anylike -LUA_OBJ := $(EXECUTABLE).lc -LUA_OBJ_INCLUDE := $(EXECUTABLE)_lua_bytecode.h # sysexec.o \ @@ -53,41 +51,38 @@ C_SRCS := $(C_OBJS:%.o=%.c) LUA_SRCS := main_loop.lua \ echo_server.lua -.PHONY: clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge - -all: $(EXECUTABLE) $(LUA_OBJ) +LUA_BYTECODE := $(EXECUTABLE).lc +LUA_BYTECODE_OBJ := $(EXECUTABLE)_lua_bytecode.o -define create-d-file - @set -e; rm -f $1; \ - $(CC) -MM $(CFLAGS) $2 > $1.$$$$; \ - sed 's,\($*\)\.o[ :]*,\1.o $1 : ,g' < $1.$$$$ > $1; \ - rm -f $1.$$$$; echo '(re)building $1' -endef +.PHONY: clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge -anylike.d: anylike.c $(LUA_OBJ_INCLUDE) - $(call create-d-file,$@,$<) +all: $(EXECUTABLE) %.d: %.c - $(call create-d-file,$@,$<) + @set -e; rm -f $@; \ + $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$; echo '(re)building $@' ifneq ($(MAKECMDGOALS),distclean) -include $(C_SRCS:%.c=%.d) endif -$(EXECUTABLE): $(C_OBJS) - $(CC) $(C_OBJS) -o $@ $(LDFLAGS) +$(EXECUTABLE): $(C_OBJS) $(LUA_BYTECODE_OBJ) + $(CC) $(C_OBJS) $(LUA_BYTECODE_OBJ) -o $@ $(LDFLAGS) %.o: %.c $(CC) $(CFLAGS) -c $< -$(LUA_OBJ): $(LUA_SRCS) +$(LUA_BYTECODE): $(LUA_SRCS) $(LUAC) -o $@ $(LUA_SRCS) -$(LUA_OBJ_INCLUDE): $(LUA_OBJ) - $(LUA) ../tools/bin2c.lua $(LUA_OBJ) $(LUA_OBJ_INCLUDE:%.h=%) > $@ +$(LUA_BYTECODE_OBJ): $(LUA_BYTECODE) + $(LUA) ../tools/bin2c.lua $(LUA_BYTECODE) $(@:%.o=%) > $(@:%.o=%.c) + $(CC) $(@:%.o=%.c) -c -o $@ -strip: $(EXECUTABLE) $(LUA_OBJ) - $(LUAC) -s -o $(LUA_OBJ) $(LUA_OBJ) +strip: $(EXECUTABLE) $(LUA_BYTECODE) + $(LUAC) -s -o $(LUA_BYTECODE) $(LUA_BYTECODE) $(MAKE) $(STRIP) -s $(EXECUTABLE) @@ -102,8 +97,9 @@ clean: rm -f *.o rm -f *.d rm -f *.d.* - rm -f *.lc - rm -f $(LUA_OBJ_INCLUDE) + rm -f $(LUA_BYTECODE) + rm -f $(LUA_BYTECODE_OBJ) + rm -f $(LUA_BYTECODE_OBJ:%.o=%.c) rm -f $(EXECUTABLE) cleanall: clean diff --git a/src/anylike.c b/src/anylike.c index b154c45..86d055d 100644 --- a/src/anylike.c +++ b/src/anylike.c @@ -89,7 +89,8 @@ void cleanup_crypt() #endif } -#include "anylike_lua_bytecode.h" +extern const u_int8_t anylike_lua_bytecode[]; +extern const u_int32_t anylike_lua_bytecode_len; #define LUA_MAIN_LOOP_FUNC "main_loop" @@ -114,7 +115,7 @@ int init_main_loop(lua_State *L) lua_call(L, 1, 0); } - int ret = luaL_loadbuffer(L, anylike_lua_bytecode, sizeof(anylike_lua_bytecode), "anylike"); + int ret = luaL_loadbuffer(L, anylike_lua_bytecode, anylike_lua_bytecode_len, "anylike"); if(ret) { const char* err_str = luaL_checkstring(L, -1); switch(ret) { diff --git a/tools/bin2c.lua b/tools/bin2c.lua index 47d0dd9..c473832 100644 --- a/tools/bin2c.lua +++ b/tools/bin2c.lua @@ -52,8 +52,11 @@ end io.write([=[ /* code automatically generated by bin2c -- DO NOT EDIT */ -static const u_int8_t ]=] , c_var_name, [=[[]={ +#include "datatypes.h" + +const u_int8_t ]=] , c_var_name, [=[[]={ ]=], dump(content), [=[ }; +const u_int32_t ]=] , c_var_name, [=[_len = sizeof(]=] , c_var_name, [=[); ]=]) -- cgit v1.2.3