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