1*2ffa4e20Slukem# $NetBSD: bsd.lua.mk,v 1.10 2023/06/03 21:24:57 lukem Exp $ 28b59e810Splunky# 38b59e810Splunky# Build rules and definitions for Lua modules 48b59e810Splunky 58b59e810Splunky# 68b59e810Splunky# Variables used 78b59e810Splunky# 88b59e810Splunky# LUA_VERSION currently installed version of Lua 98b59e810Splunky# LUA_LIBDIR ${LIBDIR}/lua/${LUA_VERSION} 108b59e810Splunky# 1182b798e8Smbalmer# LUA_MODULES list of Lua modules to build/installi 128b59e810Splunky# LUA_DPLIBS shared library dependencies as per LIBDPLIBS 138b59e810Splunky# 148b59e810Splunky# LUA_SRCS.mod sources for each module (by default: "${mod:S/./_/g}.lua") 158b59e810Splunky# 168b59e810Splunky# DPADD additional dependencies for building modules 178b59e810Splunky# DPADD.mod additional dependencies for a specific module 188b59e810Splunky# 198b59e810Splunky# 208b59e810Splunky# HAVE_LUAC if defined, .lua source files will be compiled with ${LUAC} 218b59e810Splunky# and installed as precompiled chunks for faster loading. Note 228b59e810Splunky# that the luac file format is not yet standardised and may be 238b59e810Splunky# subject to change. 248b59e810Splunky# 258b59e810Splunky# LUAC the luac compiler (by default: /usr/bin/luac) 268b59e810Splunky# 278b59e810Splunky# 288b59e810Splunky# Notes: 298b59e810Splunky# 308b59e810Splunky# currently make(depend) and make(tags) do not support .lua sources; We 318b59e810Splunky# add Lua sources to DPSRCS when HAVE_LUAC is defined and other language 328b59e810Splunky# sources to SRCS for <bsd.dep.mk>. 338b59e810Splunky# 348b59e810Splunky# other language support for other than C is incomplete 358b59e810Splunky# 368b59e810Splunky# C language sources are passed though lint, when MKLINT != "no" 378b59e810Splunky# 38f0dad708Snikita# The Lua binary searches /usr/share/lua/5.4/ at this time and we could 398b59e810Splunky# install .lua modules there which would mean slightly less duplication 408b59e810Splunky# in compat builds. However, MKSHARE=no would prevent such modules from 41f0dad708Snikita# being installed so we just install everything under /usr/lib/lua/5.4/ 428b59e810Splunky# 438b59e810Splunky 448b59e810Splunky.if !defined(_BSD_LUA_MK_) 458b59e810Splunky_BSD_LUA_MK_=1 468b59e810Splunky 478b59e810Splunky.include <bsd.init.mk> 488b59e810Splunky.include <bsd.shlib.mk> 498b59e810Splunky.include <bsd.gcc.mk> 508b59e810Splunky 518b59e810Splunky## 528b59e810Splunky##### Basic targets 538b59e810Splunkyrealinstall: .PHONY lua-install 548b59e810Splunkyrealall: .PHONY lua-all 558b59e810Splunkylint: .PHONY lua-lint 568b59e810Splunky 578b59e810Splunkylua-install: .PHONY 588b59e810Splunky 598b59e810Splunkylua-all: .PHONY 608b59e810Splunky 618b59e810Splunkylua-lint: .PHONY 628b59e810Splunky 635181f2fcSapbCLEANFILES+= a.out [Ee]rrs mklog core *.core 648b59e810Splunky 658b59e810Splunky## 668b59e810Splunky##### Global variables 67f0dad708SnikitaLUA_VERSION?= 5.4 688b59e810SplunkyLUA_LIBDIR?= ${LIBDIR}/lua/${LUA_VERSION} 698b59e810SplunkyLUAC?= /usr/bin/luac 708b59e810Splunky 718b59e810Splunky## 728b59e810Splunky##### Build rules 738b59e810Splunky 748b59e810Splunky# XX should these always be on? 754d12bfcdSjoergCFLAGS+= -fPIC 768b59e810Splunky 778b59e810Splunky.SUFFIXES: .lua .luac 788b59e810Splunky.lua.luac: 798b59e810Splunky ${_MKTARGET_COMPILE} 808b59e810Splunky ${LUAC} -o ${.TARGET} ${.IMPSRC} 818b59e810Splunky 828b59e810Splunky## 838b59e810Splunky##### Libraries that modules may depend upon. 846ec0bc56Smbalmer.for _lib _dir in ${LUA_DPLIBS} 856ec0bc56Smbalmer.if !defined(LIBDO.${_lib}) 866ec0bc56SmbalmerLIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR} 876ec0bc56Smbalmer.MAKEOVERRIDES+=LIBDO.${_lib} 886ec0bc56Smbalmer.endif 896ec0bc56SmbalmerLDADD+=-L${LIBDO.${_lib}} -l${_lib} 906ec0bc56SmbalmerDPADD+=${LIBDO.${_lib}}/lib${_lib}.so 916ec0bc56Smbalmer.endfor 928b59e810Splunky 938b59e810Splunky## 948b59e810Splunky##### Lua Modules 958b59e810Splunky.for _M in ${LUA_MODULES} 968b59e810SplunkyLUA_SRCS.${_M}?=${_M:S/./_/g}.lua 978b59e810SplunkyLUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H} 988b59e810Splunky 998b59e810Splunky.if !empty(LUA_SRCS.${_M}:M*.lua) 1008b59e810Splunky.if ${LUA_SRCS.${_M}:[\#]} > 1 1018b59e810Splunky.error Module "${_M}" has too many source files 1028b59e810Splunky.endif 1038b59e810Splunky.if defined(HAVE_LUAC) 1048b59e810Splunky## 1058b59e810Splunky## The module has Lua source and needs to be compiled 1068b59e810SplunkyLUA_TARG.${_M}=${_M:S/./_/g}.luac 1078b59e810SplunkyLUA_NAME.${_M}=${_M:S/./\//g:T}.luac 1085181f2fcSapbCLEANFILES+=${LUA_TARG.${_M}} 1098b59e810SplunkyDPSRCS+=${LUA_SRCS.${_M}} 1108b59e810Splunky 1118b59e810Splunky.NOPATH: ${LUA_TARG.${_M}} 1128b59e810Splunkylua-all: ${LUA_TARG.${_M}} 1138b59e810Splunky${LUA_TARG.${_M}}: ${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}} 1148b59e810Splunky.else 1158b59e810Splunky## 1168b59e810Splunky## The module has Lua source and can be installed directly 1178b59e810SplunkyLUA_TARG.${_M}=${LUA_SRCS.${_M}} 1188b59e810SplunkyLUA_NAME.${_M}=${_M:S/./\//g:T}.lua 1198b59e810Splunky.endif 1208b59e810Splunky.else 1218b59e810Splunky## 1228b59e810Splunky## The module has other language source and we must build ${_M}.so 1238b59e810SplunkyLUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g} 1248b59e810SplunkyLUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln} 1258b59e810SplunkyLUA_TARG.${_M}=${_M:S/./_/g}.so 1268b59e810SplunkyLUA_NAME.${_M}=${_M:S/./\//g:T}.so 1275181f2fcSapbCLEANFILES+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}} 1288b59e810SplunkyDPSRCS+=${LUA_SRCS.${_M}} 1298b59e810SplunkySRCS+=${LUA_SRCS.${_M}} 1308b59e810Splunky 13113001884Sozaki-rLUA_LDOPTS= -Wl,--warn-shared-textrel 132*2ffa4e20Slukem.if ${MKSTRIPSYM} != "no" 13313001884Sozaki-rLUA_LDOPTS+= -Wl,-x 13413001884Sozaki-r.else 13513001884Sozaki-rLUA_LDOPTS+= -Wl,-X 13613001884Sozaki-r.endif 13713001884Sozaki-r 1388b59e810Splunky.NOPATH: ${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}} 1398b59e810Splunky.if ${MKLINT} != "no" 1408b59e810Splunky${LUA_TARG.${_M}}: ${LUA_LOBJ.${_M}} 1418b59e810Splunky.endif 1428b59e810Splunkylua-lint: ${LUA_LOBJ.${_M}} 1438b59e810Splunkylua-all: ${LUA_TARG.${_M}} 1448b59e810Splunky${LUA_TARG.${_M}}: ${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}} 1458b59e810Splunky ${_MKTARGET_BUILD} 1468b59e810Splunky rm -f ${.TARGET} 14713001884Sozaki-r ${CC} ${LUA_LDOPTS} -shared ${LUA_OBJS.${_M}} \ 1488b59e810Splunky -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \ 1498b59e810Splunky ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}} 1508b59e810Splunky 1518b59e810Splunky.endif 1528b59e810Splunky 153975a152cSjoergDPADD+= ${LIBLUA} 154975a152cSjoergLDADD+= -llua 155975a152cSjoerg 1568b59e810Splunky## 1578b59e810Splunky## module install rules 1588b59e810Splunkylua-install: ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}} 1598b59e810Splunky${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_M}} 1608b59e810Splunky ${_MKTARGET_INSTALL} 1618b59e810Splunky ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 1628b59e810Splunky ${.ALLSRC} ${.TARGET} 1638b59e810Splunky 1648b59e810Splunky.endfor 1658b59e810Splunky## 1668b59e810Splunky##### end of modules 1678b59e810Splunky 1685181f2fcSapb.include <bsd.clean.mk> 1698b59e810Splunky.include <bsd.dep.mk> 1708b59e810Splunky.include <bsd.inc.mk> 1718b59e810Splunky.include <bsd.obj.mk> 1728b59e810Splunky.include <bsd.sys.mk> 1738b59e810Splunky.endif # ! defined(_BSD_LUA_MK_) 174