etc/protocols - sync with NetBSD-8
[minix.git] / share / mk / bsd.lua.mk
blobcf33880420bb5a672461d3971a34d555f0b694c9
1 # $NetBSD: bsd.lua.mk,v 1.7 2014/07/19 18:38:34 lneto Exp $
3 # Build rules and definitions for Lua modules
6 # Variables used
8 # LUA_VERSION currently installed version of Lua
9 # LUA_LIBDIR ${LIBDIR}/lua/${LUA_VERSION}
11 # LUA_MODULES list of Lua modules to build/installi
12 # LUA_DPLIBS shared library dependencies as per LIBDPLIBS
14 # LUA_SRCS.mod sources for each module (by default: "${mod:S/./_/g}.lua")
16 # DPADD additional dependencies for building modules
17 # DPADD.mod additional dependencies for a specific module
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.
25 # LUAC the luac compiler (by default: /usr/bin/luac)
28 # Notes:
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>.
34 # other language support for other than C is incomplete
36 # C language sources are passed though lint, when MKLINT != "no"
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/
44 .if !defined(_BSD_LUA_MK_)
45 _BSD_LUA_MK_=1
47 .include <bsd.init.mk>
48 .include <bsd.shlib.mk>
49 .include <bsd.gcc.mk>
51 #__MINIX: Not always included
52 .include <bsd.own.mk>
53 .if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
54 LDFLAGS+= -L${DESTDIR}/usr/lib
55 .endif # defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
58 ##### Basic targets
59 realinstall: .PHONY lua-install
60 realall: .PHONY lua-all
61 lint: .PHONY lua-lint
63 lua-install: .PHONY
65 lua-all: .PHONY
67 lua-lint: .PHONY
69 CLEANFILES+= a.out [Ee]rrs mklog core *.core
72 ##### Global variables
73 LUA_VERSION?= 5.3
74 LUA_LIBDIR?= ${LIBDIR}/lua/${LUA_VERSION}
75 LUAC?= /usr/bin/luac
78 ##### Build rules
80 # XX should these always be on?
81 CFLAGS+= -fPIC
83 .SUFFIXES: .lua .luac
84 .lua.luac:
85 ${_MKTARGET_COMPILE}
86 ${LUAC} -o ${.TARGET} ${.IMPSRC}
89 ##### Libraries that modules may depend upon.
90 .for _lib _dir in ${LUA_DPLIBS}
91 .if !defined(LIBDO.${_lib})
92 LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR}
93 .MAKEOVERRIDES+=LIBDO.${_lib}
94 .endif
95 LDADD+=-L${LIBDO.${_lib}} -l${_lib}
96 DPADD+=${LIBDO.${_lib}}/lib${_lib}.so
97 .endfor
100 ##### Lua Modules
101 .for _M in ${LUA_MODULES}
102 LUA_SRCS.${_M}?=${_M:S/./_/g}.lua
103 LUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H}
105 .if !empty(LUA_SRCS.${_M}:M*.lua)
106 .if ${LUA_SRCS.${_M}:[\#]} > 1
107 .error Module "${_M}" has too many source files
108 .endif
109 .if defined(HAVE_LUAC)
111 ## The module has Lua source and needs to be compiled
112 LUA_TARG.${_M}=${_M:S/./_/g}.luac
113 LUA_NAME.${_M}=${_M:S/./\//g:T}.luac
114 CLEANFILES+=${LUA_TARG.${_M}}
115 DPSRCS+=${LUA_SRCS.${_M}}
117 .NOPATH: ${LUA_TARG.${_M}}
118 lua-all: ${LUA_TARG.${_M}}
119 ${LUA_TARG.${_M}}: ${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}}
120 .else
122 ## The module has Lua source and can be installed directly
123 LUA_TARG.${_M}=${LUA_SRCS.${_M}}
124 LUA_NAME.${_M}=${_M:S/./\//g:T}.lua
125 .endif
126 .else
128 ## The module has other language source and we must build ${_M}.so
129 LUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g}
130 LUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln}
131 LUA_TARG.${_M}=${_M:S/./_/g}.so
132 LUA_NAME.${_M}=${_M:S/./\//g:T}.so
133 CLEANFILES+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
134 DPSRCS+=${LUA_SRCS.${_M}}
135 SRCS+=${LUA_SRCS.${_M}}
137 .NOPATH: ${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
138 .if ${MKLINT} != "no"
139 ${LUA_TARG.${_M}}: ${LUA_LOBJ.${_M}}
140 .endif
141 lua-lint: ${LUA_LOBJ.${_M}}
142 lua-all: ${LUA_TARG.${_M}}
143 ${LUA_TARG.${_M}}: ${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}}
144 ${_MKTARGET_BUILD}
145 rm -f ${.TARGET}
146 ${CC} -Wl,--warn-shared-textrel \
147 -Wl,-x -shared ${LUA_OBJS.${_M}} \
148 -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \
149 ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}}
151 .endif
153 DPADD+= ${LIBLUA}
154 LDADD+= -llua
157 ## module install rules
158 lua-install: ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}
159 ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_M}}
160 ${_MKTARGET_INSTALL}
161 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
162 ${.ALLSRC} ${.TARGET}
164 .endfor
166 ##### end of modules
168 .include <bsd.clean.mk>
169 .include <bsd.dep.mk>
170 .include <bsd.inc.mk>
171 .include <bsd.obj.mk>
172 .include <bsd.sys.mk>
173 .endif # ! defined(_BSD_LUA_MK_)