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