tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Lua modules, paths, man pages etc.



On Fri, 7 Oct 2011, Adam Hamsik wrote:

> > Since this will be the first Lua module in our tree, it will set the
> > standard for further modules, so I think we should briefly think about
> > what to put where.
> >
> > We need a place for the source code.
> >
> > Is src/lib/lua<whatever>/ rasonable?  (Lua modules that are written in
> > C are shared objects.).  Or should it be src/lua/<whatever>/?  I tend
> > to prefer the latter.
>
> Because destination dir is /usr/lib I would prefer to see lua modules in
> src/lib. To have them better organized I would like to have them in
> their own subdir src/lib/lua/<whatever>.

Actually, I have been thinking that it would be best to place the Lua
sources in the place where they are relevant just like we do for C
sources. This means that for instance a Lua module that interfaces with
libbluetooth (I have made some of that) should be in src/lib/libbluetooth,
and the Makefile just includes <bsd.lua.mk> and defines the appropriate
variables.

This means dependencies will be simpler to handle too, since it is
unlikely that an interface module will need to depend on libraries that
the library it interfaces to does not.

For a scriptable program that might want to provide a module then it works
similarly, just add <bsd.lua.mk> and name the modules

> > We need bsd.lua.mk.  Ideas about that one?

I have one that works well (have built several architectures without
incident), except that bsd.lib.mk does not coexist well since it dirties
its environment by redefining some suffix rules. I have not looked at it
deeply, but I thought perhaps it would be better to move the .pico, .po
etc rules into bsd.sys.mk so that eg bsd.lua.mk can use the correct flags
without needing to duplicate the logic behind them

what I did in the meantime for libbluetooth is, added the module sources
as eg lib/libbluetooth/Lbluetooth.c, and pushed the build into SUBDIRs to
keep them separate for now

eg

src/lib/libbluetooth/Makefile

  SUBDIR+= library .WAIT modules

src/lib/libbluetooth/library/Makefile

  (the original Makefile, with .PATH ${.CURDIR}/..)

src/lib/libbluetooth/modules/Makefile

  (the Lua module Makefile, with .PATH ${.CURDIR}/..)

iain
#       $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_SRCS.mod  sources for each module (by default: "${mod:S/./_/g}.lua")
#
# DPADD         additional dependencies for building modules
# DPADD.mod     additional dependencies for a specific module
#
#
# 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)
#
#
# Notes:
#
# 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>.
#
# other language support for other than C is incomplete
#
# C language sources are passed though lint, when MKLINT != "no"
#
# The Lua binary searches /usr/share/lua/5.1/ at this time and we could
# install .lua modules there which would mean slightly less duplication
# in compat builds. However, MKSHARE=no would prevent such modules from
# being installed so we just install everything under /usr/lib/lua/5.1/
#

.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
lint:           .PHONY lua-lint
clean:          .PHONY lua-clean

lua-install:    .PHONY

lua-all:        .PHONY

lua-lint:       .PHONY

lua-clean:      .PHONY
        rm -f a.out [Ee]rrs mklog core *.core ${LUA_CLEAN}

##
##### Global variables
LUA_VERSION?=   5.1
LUA_LIBDIR?=    ${LIBDIR}/lua/${LUA_VERSION}
LUAC?=          /usr/bin/luac

##
##### Build rules

# XX should these always be on?
CFLAGS+=        -fPIC -DPIC

.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_SRCS.${_M}?=${_M:S/./_/g}.lua
LUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H}

.if !empty(LUA_SRCS.${_M}:M*.lua)
.if ${LUA_SRCS.${_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_TARG.${_M}=${_M:S/./_/g}.luac
LUA_NAME.${_M}=${_M:S/./\//g:T}.luac
LUA_CLEAN+=${LUA_TARG.${_M}}
DPSRCS+=${LUA_SRCS.${_M}}

.NOPATH:                ${LUA_TARG.${_M}}
lua-all:                ${LUA_TARG.${_M}}
${LUA_TARG.${_M}}:      ${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}}
.else
##
## The module has Lua source and can be installed directly
LUA_TARG.${_M}=${LUA_SRCS.${_M}}
LUA_NAME.${_M}=${_M:S/./\//g:T}.lua
.endif
.else
##
## The module has other language source and we must build ${_M}.so
LUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g}
LUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln}
LUA_TARG.${_M}=${_M:S/./_/g}.so
LUA_NAME.${_M}=${_M:S/./\//g:T}.so
LUA_CLEAN+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
DPSRCS+=${LUA_SRCS.${_M}}
SRCS+=${LUA_SRCS.${_M}}

.NOPATH:                ${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}}
.if ${MKLINT} != "no"
${LUA_TARG.${_M}}:      ${LUA_LOBJ.${_M}}
.endif
lua-lint:               ${LUA_LOBJ.${_M}}
lua-all:                ${LUA_TARG.${_M}}
${LUA_TARG.${_M}}:      ${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}}
        ${_MKTARGET_BUILD}
        rm -f ${.TARGET}
        ${CC} -Wl,--warn-shared-textrel \
            -Wl,-x -shared ${LUA_OBJS.${_M}} \
            -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \
            ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}}

.endif

##
## module install rules
lua-install:            ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}
${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_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