1 1.3 mbalmer # $NetBSD: bsd.lua.mk,v 1.3 2011/10/08 08:35:56 mbalmer 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.3 mbalmer # LUA_MODULES list of Lua modules to build/installi 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 58 1.1 plunky lua-install: .PHONY 59 1.1 plunky 60 1.1 plunky lua-all: .PHONY 61 1.1 plunky 62 1.1 plunky lua-lint: .PHONY 63 1.1 plunky 64 1.2 apb CLEANFILES+= a.out [Ee]rrs mklog core *.core 65 1.1 plunky 66 1.1 plunky ## 67 1.1 plunky ##### Global variables 68 1.1 plunky LUA_VERSION?= 5.1 69 1.1 plunky LUA_LIBDIR?= ${LIBDIR}/lua/${LUA_VERSION} 70 1.1 plunky LUAC?= /usr/bin/luac 71 1.1 plunky 72 1.1 plunky ## 73 1.1 plunky ##### Build rules 74 1.1 plunky 75 1.1 plunky # XX should these always be on? 76 1.1 plunky CFLAGS+= -fPIC -DPIC 77 1.1 plunky 78 1.1 plunky .SUFFIXES: .lua .luac 79 1.1 plunky .lua.luac: 80 1.1 plunky ${_MKTARGET_COMPILE} 81 1.1 plunky ${LUAC} -o ${.TARGET} ${.IMPSRC} 82 1.1 plunky 83 1.1 plunky ## 84 1.1 plunky ##### Libraries that modules may depend upon. 85 1.3 mbalmer #.for _lib _dir in lua ${NETBSDSRCDIR}/external/mit/lua/lib/liblua ${LUA_DPLIBS} 86 1.3 mbalmer #.if !defined(LIBDO.${_lib}) 87 1.3 mbalmer #LIBDO.${_lib}!= cd "${_dir}" && ${PRINTOBJDIR} 88 1.3 mbalmer #.MAKEOVERRIDES+=LIBDO.${_lib} 89 1.3 mbalmer #.endif 90 1.3 mbalmer #LDADD+=-L${LIBDO.${_lib}} -l${_lib} 91 1.3 mbalmer #DPADD+=${LIBDO.${_lib}}/lib${_lib}.so 92 1.3 mbalmer #.endfor 93 1.1 plunky 94 1.1 plunky ## 95 1.1 plunky ##### Lua Modules 96 1.1 plunky .for _M in ${LUA_MODULES} 97 1.1 plunky LUA_SRCS.${_M}?=${_M:S/./_/g}.lua 98 1.1 plunky LUA_DEST.${_M}=${LUA_LIBDIR}${_M:S/./\//g:S/^/\//:H} 99 1.1 plunky 100 1.1 plunky .if !empty(LUA_SRCS.${_M}:M*.lua) 101 1.1 plunky .if ${LUA_SRCS.${_M}:[\#]} > 1 102 1.1 plunky .error Module "${_M}" has too many source files 103 1.1 plunky .endif 104 1.1 plunky .if defined(HAVE_LUAC) 105 1.1 plunky ## 106 1.1 plunky ## The module has Lua source and needs to be compiled 107 1.1 plunky LUA_TARG.${_M}=${_M:S/./_/g}.luac 108 1.1 plunky LUA_NAME.${_M}=${_M:S/./\//g:T}.luac 109 1.2 apb CLEANFILES+=${LUA_TARG.${_M}} 110 1.1 plunky DPSRCS+=${LUA_SRCS.${_M}} 111 1.1 plunky 112 1.1 plunky .NOPATH: ${LUA_TARG.${_M}} 113 1.1 plunky lua-all: ${LUA_TARG.${_M}} 114 1.1 plunky ${LUA_TARG.${_M}}: ${LUA_SRCS.${_M}} ${DPADD} ${DPADD.${_M}} 115 1.1 plunky .else 116 1.1 plunky ## 117 1.1 plunky ## The module has Lua source and can be installed directly 118 1.1 plunky LUA_TARG.${_M}=${LUA_SRCS.${_M}} 119 1.1 plunky LUA_NAME.${_M}=${_M:S/./\//g:T}.lua 120 1.1 plunky .endif 121 1.1 plunky .else 122 1.1 plunky ## 123 1.1 plunky ## The module has other language source and we must build ${_M}.so 124 1.1 plunky LUA_OBJS.${_M}=${LUA_SRCS.${_M}:N*.lua:R:S/$/.o/g} 125 1.1 plunky LUA_LOBJ.${_M}=${LUA_SRCS.${_M}:M*.c:.c=.ln} 126 1.1 plunky LUA_TARG.${_M}=${_M:S/./_/g}.so 127 1.1 plunky LUA_NAME.${_M}=${_M:S/./\//g:T}.so 128 1.2 apb CLEANFILES+=${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}} 129 1.1 plunky DPSRCS+=${LUA_SRCS.${_M}} 130 1.1 plunky SRCS+=${LUA_SRCS.${_M}} 131 1.1 plunky 132 1.1 plunky .NOPATH: ${LUA_OBJS.${_M}} ${LUA_LOBJ.${_M}} ${LUA_TARG.${_M}} 133 1.1 plunky .if ${MKLINT} != "no" 134 1.1 plunky ${LUA_TARG.${_M}}: ${LUA_LOBJ.${_M}} 135 1.1 plunky .endif 136 1.1 plunky lua-lint: ${LUA_LOBJ.${_M}} 137 1.1 plunky lua-all: ${LUA_TARG.${_M}} 138 1.1 plunky ${LUA_TARG.${_M}}: ${LUA_OBJS.${_M}} ${DPADD} ${DPADD.${_M}} 139 1.1 plunky ${_MKTARGET_BUILD} 140 1.1 plunky rm -f ${.TARGET} 141 1.1 plunky ${CC} -Wl,--warn-shared-textrel \ 142 1.1 plunky -Wl,-x -shared ${LUA_OBJS.${_M}} \ 143 1.1 plunky -Wl,-soname,${LUA_NAME.${_M}} -o ${.TARGET} \ 144 1.1 plunky ${LDADD} ${LDADD.${_M}} ${LDFLAGS} ${LDFLAGS.${_M}} 145 1.1 plunky 146 1.1 plunky .endif 147 1.1 plunky 148 1.1 plunky ## 149 1.1 plunky ## module install rules 150 1.1 plunky lua-install: ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}} 151 1.1 plunky ${DESTDIR}${LUA_DEST.${_M}}/${LUA_NAME.${_M}}! ${LUA_TARG.${_M}} 152 1.1 plunky ${_MKTARGET_INSTALL} 153 1.1 plunky ${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 154 1.1 plunky ${.ALLSRC} ${.TARGET} 155 1.1 plunky 156 1.1 plunky .endfor 157 1.1 plunky ## 158 1.1 plunky ##### end of modules 159 1.1 plunky 160 1.2 apb .include <bsd.clean.mk> 161 1.1 plunky .include <bsd.dep.mk> 162 1.1 plunky .include <bsd.inc.mk> 163 1.1 plunky .include <bsd.obj.mk> 164 1.1 plunky .include <bsd.sys.mk> 165 1.1 plunky .endif # ! defined(_BSD_LUA_MK_) 166