bsd.lua.mk revision 1.3
1#	$NetBSD: bsd.lua.mk,v 1.3 2011/10/08 08:35:56 mbalmer Exp $
2#
3# Build rules and definitions for Lua modules
4
5#
6# Variables used
7#
8# LUA_VERSION	currently installed version of Lua
9# LUA_LIBDIR	${LIBDIR}/lua/${LUA_VERSION}
10#
11# LUA_MODULES	list of Lua modules to build/installi
12# LUA_DPLIBS	shared library dependencies as per LIBDPLIBS
13#		(liblua is automatically included)
14#
15# LUA_SRCS.mod	sources for each module (by default: "${mod:S/./_/g}.lua")
16#
17# DPADD		additional dependencies for building modules
18# DPADD.mod	additional dependencies for a specific module
19#
20#
21# HAVE_LUAC	if defined, .lua source files will be compiled with ${LUAC}
22#		and installed as precompiled chunks for faster loading. Note
23#		that the luac file format is not yet standardised and may be
24#		subject to change.
25#
26# LUAC		the luac compiler (by default: /usr/bin/luac)
27#
28#
29# Notes:
30#
31# currently make(depend) and make(tags) do not support .lua sources; We
32# add Lua sources to DPSRCS when HAVE_LUAC is defined and other language
33# sources to SRCS for <bsd.dep.mk>.
34#
35# other language support for other than C is incomplete
36#
37# C language sources are passed though lint, when MKLINT != "no"
38#
39# The Lua binary searches /usr/share/lua/5.1/ at this time and we could
40# install .lua modules there which would mean slightly less duplication
41# in compat builds. However, MKSHARE=no would prevent such modules from
42# being installed so we just install everything under /usr/lib/lua/5.1/
43#
44
45.if !defined(_BSD_LUA_MK_)
46_BSD_LUA_MK_=1
47
48.include <bsd.init.mk>
49.include <bsd.shlib.mk>
50.include <bsd.gcc.mk>
51
52##
53##### Basic targets
54realinstall:	.PHONY lua-install
55realall:	.PHONY lua-all
56lint:		.PHONY lua-lint
57
58lua-install:	.PHONY
59
60lua-all:	.PHONY
61
62lua-lint:	.PHONY
63
64CLEANFILES+= a.out [Ee]rrs mklog core *.core
65
66##
67##### Global variables
68LUA_VERSION?=	5.1
69LUA_LIBDIR?=	${LIBDIR}/lua/${LUA_VERSION}
70LUAC?=		/usr/bin/luac
71
72##
73##### Build rules
74
75# XX should these always be on?
76CFLAGS+=	-fPIC -DPIC
77
78.SUFFIXES:	.lua .luac
79.lua.luac:
80	${_MKTARGET_COMPILE}
81	${LUAC} -o ${.TARGET} ${.IMPSRC}
82
83##
84##### Libraries that modules may depend upon.
85#.for _lib _dir in lua ${NETBSDSRCDIR}/external/mit/lua/lib/liblua ${LUA_DPLIBS}
86#.if !defined(LIBDO.${_lib})
87#LIBDO.${_lib}!=	cd "${_dir}" && ${PRINTOBJDIR}
88#.MAKEOVERRIDES+=LIBDO.${_lib}
89#.endif
90#LDADD+=-L${LIBDO.${_lib}} -l${_lib}
91#DPADD+=${LIBDO.${_lib}}/lib${_lib}.so
92#.endfor
93
94##
95##### Lua Modules
96.for _M in ${LUA_MODULES}
97LUA_SRCS.${_M}?=${_M:S/./_/g}.lua
98LUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H}
99
100.if !empty(LUA_SRCS.${_M}:M*.lua)
101.if ${LUA_SRCS.${_M}:[\#]} > 1
102.error Module "${_M}" has too many source files
103.endif
104.if defined(HAVE_LUAC)
105##
106## The module has Lua source and needs to be compiled
107LUA_TARG.${_M}=${_M:S/./_/g}.luac
108LUA_NAME.${_M}=${_M:S/./\//g:T}.luac
109CLEANFILES+=${LUA_TARG.${_M}}
110DPSRCS+=${LUA_SRCS.${_M}}
111
112.NOPATH:		${LUA_TARG.${_M}}
113lua-all:		${LUA_TARG.${_M}}
114${LUA_TARG.${_M}}:	${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}}
115.else
116##
117## The module has Lua source and can be installed directly
118LUA_TARG.${_M}=${LUA_SRCS.${_M}}
119LUA_NAME.${_M}=${_M:S/./\//g:T}.lua
120.endif
121.else
122##
123## The module has other language source and we must build ${_M}.so
124LUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g}
125LUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln}
126LUA_TARG.${_M}=${_M:S/./_/g}.so
127LUA_NAME.${_M}=${_M:S/./\//g:T}.so
128CLEANFILES+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
129DPSRCS+=${LUA_SRCS.${_M}}
130SRCS+=${LUA_SRCS.${_M}}
131
132.NOPATH:		${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
133.if ${MKLINT} != "no"
134${LUA_TARG.${_M}}:	${LUA_LOBJ.${_M}}
135.endif
136lua-lint:		${LUA_LOBJ.${_M}}
137lua-all:		${LUA_TARG.${_M}}
138${LUA_TARG.${_M}}:	${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}}
139	${_MKTARGET_BUILD}
140	rm -f ${.TARGET}
141	${CC} -Wl,--warn-shared-textrel \
142	    -Wl,-x -shared ${LUA_OBJS.${_M}} \
143	    -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \
144	    ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}}
145
146.endif
147
148##
149## module install rules
150lua-install:		${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}
151${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_M}}
152	${_MKTARGET_INSTALL}
153	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE}	\
154	    ${.ALLSRC} ${.TARGET}
155
156.endfor
157##
158##### end of modules
159
160.include <bsd.clean.mk>
161.include <bsd.dep.mk>
162.include <bsd.inc.mk>
163.include <bsd.obj.mk>
164.include <bsd.sys.mk>
165.endif	# ! defined(_BSD_LUA_MK_)
166