1*0a6a1f1dSLionel Sambuc# $NetBSD: bsd.lua.mk,v 1.7 2014/07/19 18:38:34 lneto Exp $ 29152e1c5SLionel Sambuc# 39152e1c5SLionel Sambuc# Build rules and definitions for Lua modules 49152e1c5SLionel Sambuc 59152e1c5SLionel Sambuc# 69152e1c5SLionel Sambuc# Variables used 79152e1c5SLionel Sambuc# 89152e1c5SLionel Sambuc# LUA_VERSION currently installed version of Lua 99152e1c5SLionel Sambuc# LUA_LIBDIR ${LIBDIR}/lua/${LUA_VERSION} 109152e1c5SLionel Sambuc# 119152e1c5SLionel Sambuc# LUA_MODULES list of Lua modules to build/installi 129152e1c5SLionel Sambuc# LUA_DPLIBS shared library dependencies as per LIBDPLIBS 139152e1c5SLionel Sambuc# 149152e1c5SLionel Sambuc# LUA_SRCS.mod sources for each module (by default: "${mod:S/./_/g}.lua") 159152e1c5SLionel Sambuc# 169152e1c5SLionel Sambuc# DPADD additional dependencies for building modules 179152e1c5SLionel Sambuc# DPADD.mod additional dependencies for a specific module 189152e1c5SLionel Sambuc# 199152e1c5SLionel Sambuc# 209152e1c5SLionel Sambuc# HAVE_LUAC if defined, .lua source files will be compiled with ${LUAC} 219152e1c5SLionel Sambuc# and installed as precompiled chunks for faster loading. Note 229152e1c5SLionel Sambuc# that the luac file format is not yet standardised and may be 239152e1c5SLionel Sambuc# subject to change. 249152e1c5SLionel Sambuc# 259152e1c5SLionel Sambuc# LUAC the luac compiler (by default: /usr/bin/luac) 269152e1c5SLionel Sambuc# 279152e1c5SLionel Sambuc# 289152e1c5SLionel Sambuc# Notes: 299152e1c5SLionel Sambuc# 309152e1c5SLionel Sambuc# currently make(depend) and make(tags) do not support .lua sources; We 319152e1c5SLionel Sambuc# add Lua sources to DPSRCS when HAVE_LUAC is defined and other language 329152e1c5SLionel Sambuc# sources to SRCS for <bsd.dep.mk>. 339152e1c5SLionel Sambuc# 349152e1c5SLionel Sambuc# other language support for other than C is incomplete 359152e1c5SLionel Sambuc# 369152e1c5SLionel Sambuc# C language sources are passed though lint, when MKLINT != "no" 379152e1c5SLionel Sambuc# 389152e1c5SLionel Sambuc# The Lua binary searches /usr/share/lua/5.1/ at this time and we could 399152e1c5SLionel Sambuc# install .lua modules there which would mean slightly less duplication 409152e1c5SLionel Sambuc# in compat builds. However, MKSHARE=no would prevent such modules from 419152e1c5SLionel Sambuc# being installed so we just install everything under /usr/lib/lua/5.1/ 429152e1c5SLionel Sambuc# 439152e1c5SLionel Sambuc 449152e1c5SLionel Sambuc.if !defined(_BSD_LUA_MK_) 459152e1c5SLionel Sambuc_BSD_LUA_MK_=1 469152e1c5SLionel Sambuc 479152e1c5SLionel Sambuc.include <bsd.init.mk> 489152e1c5SLionel Sambuc.include <bsd.shlib.mk> 499152e1c5SLionel Sambuc.include <bsd.gcc.mk> 509152e1c5SLionel Sambuc 51*0a6a1f1dSLionel Sambuc#__MINIX: Not always included 52*0a6a1f1dSLionel Sambuc.include <bsd.own.mk> 534684ddb6SLionel Sambuc.if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes" 544684ddb6SLionel SambucLDFLAGS+= -L${DESTDIR}/usr/lib 554684ddb6SLionel Sambuc.endif # defined(__MINIX) && ${USE_BITCODE:Uno} == "yes" 564684ddb6SLionel Sambuc 579152e1c5SLionel Sambuc## 589152e1c5SLionel Sambuc##### Basic targets 599152e1c5SLionel Sambucrealinstall: .PHONY lua-install 609152e1c5SLionel Sambucrealall: .PHONY lua-all 619152e1c5SLionel Sambuclint: .PHONY lua-lint 629152e1c5SLionel Sambuc 639152e1c5SLionel Sambuclua-install: .PHONY 649152e1c5SLionel Sambuc 659152e1c5SLionel Sambuclua-all: .PHONY 669152e1c5SLionel Sambuc 679152e1c5SLionel Sambuclua-lint: .PHONY 689152e1c5SLionel Sambuc 699152e1c5SLionel SambucCLEANFILES+= a.out [Ee]rrs mklog core *.core 709152e1c5SLionel Sambuc 719152e1c5SLionel Sambuc## 729152e1c5SLionel Sambuc##### Global variables 73*0a6a1f1dSLionel SambucLUA_VERSION?= 5.3 749152e1c5SLionel SambucLUA_LIBDIR?= ${LIBDIR}/lua/${LUA_VERSION} 759152e1c5SLionel SambucLUAC?= /usr/bin/luac 769152e1c5SLionel Sambuc 779152e1c5SLionel Sambuc## 789152e1c5SLionel Sambuc##### Build rules 799152e1c5SLionel Sambuc 809152e1c5SLionel Sambuc# XX should these always be on? 8184d9c625SLionel SambucCFLAGS+= -fPIC 829152e1c5SLionel Sambuc 839152e1c5SLionel Sambuc.SUFFIXES: .lua .luac 849152e1c5SLionel Sambuc.lua.luac: 859152e1c5SLionel Sambuc ${_MKTARGET_COMPILE} 869152e1c5SLionel Sambuc ${LUAC} -o ${.TARGET} ${.IMPSRC} 879152e1c5SLionel Sambuc 889152e1c5SLionel Sambuc## 899152e1c5SLionel Sambuc##### Libraries that modules may depend upon. 909152e1c5SLionel Sambuc.for _lib _dir in ${LUA_DPLIBS} 919152e1c5SLionel Sambuc.if !defined(LIBDO.${_lib}) 929152e1c5SLionel SambucLIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR} 939152e1c5SLionel Sambuc.MAKEOVERRIDES+=LIBDO.${_lib} 949152e1c5SLionel Sambuc.endif 959152e1c5SLionel SambucLDADD+=-L${LIBDO.${_lib}} -l${_lib} 969152e1c5SLionel SambucDPADD+=${LIBDO.${_lib}}/lib${_lib}.so 979152e1c5SLionel Sambuc.endfor 989152e1c5SLionel Sambuc 999152e1c5SLionel Sambuc## 1009152e1c5SLionel Sambuc##### Lua Modules 1019152e1c5SLionel Sambuc.for _M in ${LUA_MODULES} 1029152e1c5SLionel SambucLUA_SRCS.${_M}?=${_M:S/./_/g}.lua 1039152e1c5SLionel SambucLUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H} 1049152e1c5SLionel Sambuc 1059152e1c5SLionel Sambuc.if !empty(LUA_SRCS.${_M}:M*.lua) 1069152e1c5SLionel Sambuc.if ${LUA_SRCS.${_M}:[\#]} > 1 1079152e1c5SLionel Sambuc.error Module "${_M}" has too many source files 1089152e1c5SLionel Sambuc.endif 1099152e1c5SLionel Sambuc.if defined(HAVE_LUAC) 1109152e1c5SLionel Sambuc## 1119152e1c5SLionel Sambuc## The module has Lua source and needs to be compiled 1129152e1c5SLionel SambucLUA_TARG.${_M}=${_M:S/./_/g}.luac 1139152e1c5SLionel SambucLUA_NAME.${_M}=${_M:S/./\//g:T}.luac 1149152e1c5SLionel SambucCLEANFILES+=${LUA_TARG.${_M}} 1159152e1c5SLionel SambucDPSRCS+=${LUA_SRCS.${_M}} 1169152e1c5SLionel Sambuc 1179152e1c5SLionel Sambuc.NOPATH: ${LUA_TARG.${_M}} 1189152e1c5SLionel Sambuclua-all: ${LUA_TARG.${_M}} 1199152e1c5SLionel Sambuc${LUA_TARG.${_M}}: ${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}} 1209152e1c5SLionel Sambuc.else 1219152e1c5SLionel Sambuc## 1229152e1c5SLionel Sambuc## The module has Lua source and can be installed directly 1239152e1c5SLionel SambucLUA_TARG.${_M}=${LUA_SRCS.${_M}} 1249152e1c5SLionel SambucLUA_NAME.${_M}=${_M:S/./\//g:T}.lua 1259152e1c5SLionel Sambuc.endif 1269152e1c5SLionel Sambuc.else 1279152e1c5SLionel Sambuc## 1289152e1c5SLionel Sambuc## The module has other language source and we must build ${_M}.so 1299152e1c5SLionel SambucLUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g} 1309152e1c5SLionel SambucLUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln} 1319152e1c5SLionel SambucLUA_TARG.${_M}=${_M:S/./_/g}.so 1329152e1c5SLionel SambucLUA_NAME.${_M}=${_M:S/./\//g:T}.so 1339152e1c5SLionel SambucCLEANFILES+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}} 1349152e1c5SLionel SambucDPSRCS+=${LUA_SRCS.${_M}} 1359152e1c5SLionel SambucSRCS+=${LUA_SRCS.${_M}} 1369152e1c5SLionel Sambuc 1379152e1c5SLionel Sambuc.NOPATH: ${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}} 1389152e1c5SLionel Sambuc.if ${MKLINT} != "no" 1399152e1c5SLionel Sambuc${LUA_TARG.${_M}}: ${LUA_LOBJ.${_M}} 1409152e1c5SLionel Sambuc.endif 1419152e1c5SLionel Sambuclua-lint: ${LUA_LOBJ.${_M}} 1429152e1c5SLionel Sambuclua-all: ${LUA_TARG.${_M}} 1439152e1c5SLionel Sambuc${LUA_TARG.${_M}}: ${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}} 1449152e1c5SLionel Sambuc ${_MKTARGET_BUILD} 1459152e1c5SLionel Sambuc rm -f ${.TARGET} 1469152e1c5SLionel Sambuc ${CC} -Wl,--warn-shared-textrel \ 1479152e1c5SLionel Sambuc -Wl,-x -shared ${LUA_OBJS.${_M}} \ 1489152e1c5SLionel Sambuc -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \ 1499152e1c5SLionel Sambuc ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}} 1509152e1c5SLionel Sambuc 1519152e1c5SLionel Sambuc.endif 1529152e1c5SLionel Sambuc 15384d9c625SLionel SambucDPADD+= ${LIBLUA} 15484d9c625SLionel SambucLDADD+= -llua 15584d9c625SLionel Sambuc 1569152e1c5SLionel Sambuc## 1579152e1c5SLionel Sambuc## module install rules 1589152e1c5SLionel Sambuclua-install: ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}} 1599152e1c5SLionel Sambuc${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_M}} 1609152e1c5SLionel Sambuc ${_MKTARGET_INSTALL} 1619152e1c5SLionel Sambuc ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 1629152e1c5SLionel Sambuc ${.ALLSRC} ${.TARGET} 1639152e1c5SLionel Sambuc 1649152e1c5SLionel Sambuc.endfor 1659152e1c5SLionel Sambuc## 1669152e1c5SLionel Sambuc##### end of modules 1679152e1c5SLionel Sambuc 1689152e1c5SLionel Sambuc.include <bsd.clean.mk> 1699152e1c5SLionel Sambuc.include <bsd.dep.mk> 1709152e1c5SLionel Sambuc.include <bsd.inc.mk> 1719152e1c5SLionel Sambuc.include <bsd.obj.mk> 1729152e1c5SLionel Sambuc.include <bsd.sys.mk> 1739152e1c5SLionel Sambuc.endif # ! defined(_BSD_LUA_MK_) 174