tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: A place for Lua module sources
On Mon, 17 Jan 2011, Marc Balmer wrote:
> > I started constructing a generic <bsd.lua.mk> file that takes eg
>
> Maybe you could committ your Makefile stubs, so we can work on them (and
> use them...)
Sorry I got lost with some other stuff and never came back to this. I am a
bit hesitant to commit since its somewhat of a work in progress although I
didn't see any objections to your suggestion (bsd.lua.mk attached - any?)
> > For the Lua POSIX module then, we would use src/external/mit/lua-posix/
> > with dist/ and lib/ subdirs as normal, and a native Lua Bluetooth module
> > would be in src/lib/lua-bluetooth so it can be scheduled after
> > dependencies (it cannot go under libbluetooth/ since SUBDIR is processed
> > first)
>
> Thats sounds almost fine, though I'd rather leave out the dash, i.e.
> src/external/mit/luaposix etc. This should be documented somewehere, imo.
that naming is fine with me, though I think 'prior art' generally counts
as good practice so explicit documentation is probably not required once a
few modules are in place..
iain
Index: Makefile
===================================================================
RCS file: /cvsroot/src/share/mk/Makefile,v
retrieving revision 1.43
diff -u -r1.43 Makefile
--- Makefile 7 Aug 2010 21:50:51 -0000 1.43
+++ Makefile 1 Feb 2011 20:58:45 -0000
@@ -9,7 +9,8 @@
FILES= bsd.README bsd.dep.mk bsd.doc.mk bsd.endian.mk bsd.files.mk \
bsd.gcc.mk bsd.hostlib.mk bsd.hostprog.mk bsd.inc.mk bsd.info.mk \
bsd.init.mk bsd.ioconf.mk bsd.kernobj.mk bsd.kinc.mk bsd.klinks.mk \
- bsd.kmodule.mk bsd.lib.mk bsd.links.mk bsd.man.mk bsd.nls.mk \
+ bsd.kmodule.mk bsd.lib.mk bsd.links.mk bsd.lua.mk \
+ bsd.man.mk bsd.nls.mk \
bsd.obj.mk bsd.own.mk bsd.prog.mk bsd.rpc.mk bsd.shlib.mk \
bsd.subdir.mk bsd.sys.mk bsd.test.mk bsd.x11.mk sys.mk
Index: bsd.lua.mk
===================================================================
RCS file: bsd.lua.mk
diff -N bsd.lua.mk
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ bsd.lua.mk 1 Feb 2011 20:59:00 -0000
@@ -0,0 +1,151 @@
+# $NetBSD$
+#
+# Build rules and definitions for Lua modules
+
+#
+# Variables used
+#
+# LUA_VERSION currently installed version of Lua
+# LUA_LIBDIR ${LIBDIR}/lua/${LUA_VERSION}
+#
+# LUA_MODULES list of Lua modules to build/install
+# LUA_DPLIBS shared library dependencies as per LIBDPLIBS
+# (liblua is automatically included)
+#
+# LUA_SRC.mod sources for each module (by default: "${mod:S/./_/g}.lua")
+#
+#
+# HAVE_LUAC if defined, .lua source files will be compiled with ${LUAC}
+# and installed as precompiled chunks for faster loading. Note
+# that the luac file format is not yet standardised and may be
+# subject to change.
+#
+# LUAC the luac compiler (by default: /usr/bin/luac)
+#
+#
+# currently make(depend) and make(tags) do not support .lua sources; We
+# add Lua sources to DPSRCS when HAVE_LUAC is defined and other language
+# sources to SRCS for <bsd.dep.mk>
+#
+
+.if !defined(_BSD_LUA_MK_)
+_BSD_LUA_MK_=1
+
+.include <bsd.init.mk>
+.include <bsd.shlib.mk>
+.include <bsd.gcc.mk>
+
+##### Basic targets
+realinstall: .PHONY lua-install
+realall: .PHONY lua-all
+clean: .PHONY lua-clean
+
+lua-install: .PHONY
+
+lua-all: .PHONY
+
+lua-clean: .PHONY
+ rm -f ${LUA_CLEAN}
+
+##### Global variables
+LUA_VERSION?= 5.1
+LUA_LIBDIR?= ${LIBDIR}/lua/${LUA_VERSION}
+LUAC?= /usr/bin/luac
+
+##### Build rules
+.if empty(CPPFLAGS:M-nostdinc)
+CPPFLAGS+= ${DESTDIR:D-nostdinc ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include}
+.endif
+.if empty(CXXFLAGS:M-nostdinc++)
+CXXFLAGS+= ${DESTDIR:D-nostdinc++ ${CXXFLAG_ISYSTEM}
${DESTDIR}/usr/include/g++}
+.endif
+
+.SUFFIXES: .lua .luac
+.lua.luac:
+ ${_MKTARGET_COMPILE}
+ ${LUAC} -o ${.TARGET} ${.IMPSRC}
+
+##### Libraries that modules may depend upon.
+.for _lib _dir in lua ${NETBSDSRCDIR}/external/mit/lua/lib/liblua ${LUA_DPLIBS}
+.if !defined(LIBDO.${_lib})
+LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR}
+.MAKEOVERRIDES+=LIBDO.${_lib}
+.endif
+LDADD+=-L${LIBDO.${_lib}} -l${_lib}
+DPADD+=${LIBDO.${_lib}}/lib${_lib}.so
+.endfor
+
+##### Lua Modules
+.for _M in ${LUA_MODULES}
+LUA_SRC.${_M}?=${_M:S/./_/g}.lua
+LUA_DEST.${_M}=${LUA_LIBDIR}/${_M:S/./\//g:H}
+
+.if !empty(LUA_SRC.${_M}:M*.lua)
+.if ${LUA_SRC.${_M}:[\#]} > 1
+.error Module "${_M}" has too many source files
+.endif
+.if defined(HAVE_LUAC)
+##
+## The module has Lua source and needs to be compiled
+LUA_TGT.${_M}=${_M:S/./_/g}.luac
+LUA_NAME.${_M}=${_M:S/./\//g:T}.luac
+LUA_CLEAN+=${LUA_TGT.${_M}}
+DPSRCS+=${LUA_SRC.${_M}}
+
+.NOPATH: ${LUA_TGT.${_M}}
+lua-all: ${LUA_TGT.${_M}}
+${LUA_TGT.${_M}}: ${LUA_SRC.${_M}}
+.else
+##
+## The module has Lua source and can be installed directly
+LUA_TGT.${_M}=${LUA_SRC.${_M}}
+LUA_NAME.${_M}=${_M:S/./\//g:T}.lua
+.endif
+.else
+##
+## The module has other language source and we must build ${_M}.so
+LUA_OBJ.${_M}=${LUA_SRC.${_M}:N*.lua:R:S/$/.o/g}
+LUA_TGT.${_M}=${_M:S/./_/g}.so
+LUA_NAME.${_M}=${_M:S/./\//g:T}.so
+LUA_CLEAN+=${LUA_OBJ.${_M}} ${LUA_TGT.${_M}}
+DPSRCS+=${LUA_SRC.${_M}}
+SRCS+=${LUA_SRC.${_M}}
+
+# XX should we provide a lint rule?
+# XX using CC might not be right (could be CXX)
+# XX should we make PIC files ,and use -Wl,--warn-shared-textrel?
+# XX what about the -nostdlib/-L${_GCC_LIBGCCDIR}
+
+.NOPATH: ${LUA_TGT.${_M}} ${LUA_OBJ.${_M}}
+lua-all: ${LUA_TGT.${_M}}
+${LUA_TGT.${_M}}: ${LUA_OBJ.${_M}} ${DPADD} ${DPADD.${_M}}
+ ${_MKTARGET_BUILD}
+ rm -f ${.TARGET}
+ ${CC} \
+ -Wl,-nostdlib -B${_GCC_CRTDIR}/ -B${DESTDIR}${SHLIBDIR}/ \
+ -Wl,-x -shared \
+ -Wl,-soname,${LUA_NAME.${_M}} \
+ ${LUA_OBJ.${_M}} \
+ ${LDADD} ${LDADD.${_M}} \
+ ${LDFLAGS} ${LDFLAGS.${_M}} \
+ -o ${.TARGET} \
+ -L${_GCC_LIBGCCDIR}
+
+.endif
+
+##
+## module install rules
+lua-install: ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}
+${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TGT.${_M}}
+ ${_MKTARGET_INSTALL}
+ ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${.ALLSRC} ${.TARGET}
+
+.endfor
+##### end of modules
+
+.include <bsd.dep.mk>
+.include <bsd.inc.mk>
+.include <bsd.obj.mk>
+.include <bsd.sys.mk>
+.endif # ! defined(_BSD_LUA_MK_)
Home |
Main Index |
Thread Index |
Old Index