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