Compatibility with tolua++ 1.0.93
[fawkes.git] / etc / buildsys / lua.mk
1 #*****************************************************************************
2 #                 Makefile Build System for Fawkes: Lua bits
3 #                            -------------------
4 #   Created on Wed Mar 12 19:15:54 2008
5 #   Copyright (C) 2006-2008 by Tim Niemueller, AllemaniACs RoboCup Team
6 #
7 #*****************************************************************************
8 #
9 #   This program is free software; you can redistribute it and/or modify
10 #   it under the terms of the GNU General Public License as published by
11 #   the Free Software Foundation; either version 2 of the License, or
12 #   (at your option) any later version.
13 #
14 #*****************************************************************************
15
16 ifndef __buildsys_lua_mk_
17 __buildsys_lua_mk_ := 1
18
19 include $(BASEDIR)/etc/buildsys/config.mk
20
21 LUA_VERSION = 5.1
22
23 # Check for Lua (Fedora packages lua and lua-devel)
24 ifneq ($(PKGCONFIG),)
25   LUA_PACKAGE = $(firstword $(foreach P,lua lua$(LUA_VERSION) lua-$(LUA_VERSION),$(if $(shell $(PKGCONFIG) --atleast-version $(LUA_VERSION) $(P); echo $${?/1/}),$(P))))
26   HAVE_LUA = $(if $(LUA_PACKAGE),1,0)
27 endif
28
29 ifeq ($(HAVE_LUA),1)
30   LUADIR = $(abspath $(BASEDIR)/src/lua)
31   LUALIBDIR = $(abspath $(LIBDIR)/lua)
32   EXEC_LUADIR    ?= $(abspath $(EXEC_BASEDIR)/src/lua)
33   EXEC_LUALIBDIR ?= $(abspath $(EXEC_LIBDIR)/lua)
34   CFLAGS_LUA = $(shell $(PKGCONFIG) --cflags '$(LUA_PACKAGE)') -DHAVE_LUA -DLUADIR=\"$(EXEC_LUADIR)\" -DLUALIBDIR=\"$(EXEC_LUALIBDIR)\"
35   LDFLAGS_LUA = $(shell $(PKGCONFIG) --libs '$(LUA_PACKAGE)')
36   ifneq ($(wildcard $(SYSROOT)/usr/include/tolua++.h),)
37     HAVE_TOLUA = 1
38     TOLUAPP=tolua++
39     TOLUA_LIBS=tolua++-$(LUA_VERSION)
40   endif
41   ifneq ($(wildcard $(SYSROOT)/usr/local/include/lua$(subst .,,$(LUA_VERSION))/tolua++.h),)
42     HAVE_TOLUA = 1
43     TOLUAPP=/usr/local/bin/lua$(subst .,,$(LUA_VERSION))/tolua++
44     TOLUA_LIBS=tolua++
45   endif
46   CLEAN_FILES=*_tolua.{pkg,cpp}
47
48   ifeq ($(HAVE_TOLUA),1)
49 .SECONDEXPANSION:
50 %_tolua.cpp: $$(TOLUA_$$(subst /,_,$$*))
51         $(SILENT) echo "$(INDENT_PRINT)--- Generating Lua package C++ file $(@F)"
52         $(SILENT)cat $(addprefix $(SRCDIR)/,$(subst $(SRCDIR)/,,$(filter %.tolua,$^))) > $(patsubst %.cpp,%.pkg,$@)
53         $(SILENT)$(TOLUAPP) -n $(TOLUA_PKGPREFIX_$(subst /,_,$*))$(notdir $*) $(patsubst %.cpp,%.pkg,$@) | \
54         sed -e 's/^\(.*Generated automatically .*\) on .*$$/\1/' | \
55         awk '/^#if defined/ { f=1 }; f { t = t "\n" $$0 }; !f {print}; f && /^#endif/ {print "extern \"C\" {" t "\n}\n"; f=0}' | \
56         awk '/^\*\/$$/ { print; while ((getline line < "$(BASEDIR)/doc/headers/lichead_c.GPL_WRE") > 0) print line }; ! /^\*\/$$/ { print }' \
57         > $@
58
59   endif # HAVE_TOLUA is 1
60 endif # HAVE_LUA is 1
61
62 ifeq ($(OBJSSUBMAKE),1)
63 .PHONY: warning_tolua_wrapper
64 warning_tolua_wrapper:
65         $(SILENT)echo -e "$(INDENT_PRINT)--> $(TRED)Omitting Lua compatibility wrapper$(TNORMAL) (tolua++[-devel] not installed)"
66 endif # OBJSSUBMAKE is 1
67
68 endif # __buildsys_lua_mk_
69