vfs: fix clobbering fd_nr
[minix.git] / share / mk / bsd.lua.mk
blob2f5a28418a3d4dc5f0f5b7c6045a41cdd9c4423c
1 # $NetBSD: bsd.lua.mk,v 1.4 2011/10/16 00:45:09 mbalmer 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>
52 ##### Basic targets
53 realinstall: .PHONY lua-install
54 realall: .PHONY lua-all
55 lint: .PHONY lua-lint
57 lua-install: .PHONY
59 lua-all: .PHONY
61 lua-lint: .PHONY
63 CLEANFILES+= a.out [Ee]rrs mklog core *.core
66 ##### Global variables
67 LUA_VERSION?= 5.1
68 LUA_LIBDIR?= ${LIBDIR}/lua/${LUA_VERSION}
69 LUAC?= /usr/bin/luac
72 ##### Build rules
74 # XX should these always be on?
75 CFLAGS+= -fPIC -DPIC
77 .SUFFIXES: .lua .luac
78 .lua.luac:
79 ${_MKTARGET_COMPILE}
80 ${LUAC} -o ${.TARGET} ${.IMPSRC}
83 ##### Libraries that modules may depend upon.
84 .for _lib _dir in ${LUA_DPLIBS}
85 .if !defined(LIBDO.${_lib})
86 LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR}
87 .MAKEOVERRIDES+=LIBDO.${_lib}
88 .endif
89 LDADD+=-L${LIBDO.${_lib}} -l${_lib}
90 DPADD+=${LIBDO.${_lib}}/lib${_lib}.so
91 .endfor
94 ##### Lua Modules
95 .for _M in ${LUA_MODULES}
96 LUA_SRCS.${_M}?=${_M:S/./_/g}.lua
97 LUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H}
99 .if !empty(LUA_SRCS.${_M}:M*.lua)
100 .if ${LUA_SRCS.${_M}:[\#]} > 1
101 .error Module "${_M}" has too many source files
102 .endif
103 .if defined(HAVE_LUAC)
105 ## The module has Lua source and needs to be compiled
106 LUA_TARG.${_M}=${_M:S/./_/g}.luac
107 LUA_NAME.${_M}=${_M:S/./\//g:T}.luac
108 CLEANFILES+=${LUA_TARG.${_M}}
109 DPSRCS+=${LUA_SRCS.${_M}}
111 .NOPATH: ${LUA_TARG.${_M}}
112 lua-all: ${LUA_TARG.${_M}}
113 ${LUA_TARG.${_M}}: ${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}}
114 .else
116 ## The module has Lua source and can be installed directly
117 LUA_TARG.${_M}=${LUA_SRCS.${_M}}
118 LUA_NAME.${_M}=${_M:S/./\//g:T}.lua
119 .endif
120 .else
122 ## The module has other language source and we must build ${_M}.so
123 LUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g}
124 LUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln}
125 LUA_TARG.${_M}=${_M:S/./_/g}.so
126 LUA_NAME.${_M}=${_M:S/./\//g:T}.so
127 CLEANFILES+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
128 DPSRCS+=${LUA_SRCS.${_M}}
129 SRCS+=${LUA_SRCS.${_M}}
131 .NOPATH: ${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
132 .if ${MKLINT} != "no"
133 ${LUA_TARG.${_M}}: ${LUA_LOBJ.${_M}}
134 .endif
135 lua-lint: ${LUA_LOBJ.${_M}}
136 lua-all: ${LUA_TARG.${_M}}
137 ${LUA_TARG.${_M}}: ${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}}
138 ${_MKTARGET_BUILD}
139 rm -f ${.TARGET}
140 ${CC} -Wl,--warn-shared-textrel \
141 -Wl,-x -shared ${LUA_OBJS.${_M}} \
142 -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \
143 ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}}
145 .endif
148 ## module install rules
149 lua-install: ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}
150 ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_M}}
151 ${_MKTARGET_INSTALL}
152 ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
153 ${.ALLSRC} ${.TARGET}
155 .endfor
157 ##### end of modules
159 .include <bsd.clean.mk>
160 .include <bsd.dep.mk>
161 .include <bsd.inc.mk>
162 .include <bsd.obj.mk>
163 .include <bsd.sys.mk>
164 .endif # ! defined(_BSD_LUA_MK_)