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