1# $NetBSD: bsd.kmodule.mk,v 1.18 2009/01/24 22:14:45 rmind Exp $ 2 3# We are not building this with PIE 4MKPIE=no 5 6.include <bsd.init.mk> 7.include <bsd.klinks.mk> 8.include <bsd.sys.mk> 9 10##### Basic targets 11clean: cleankmod 12realinstall: kmodinstall 13 14KERN= $S/kern 15 16CFLAGS+= -ffreestanding ${COPTS} 17CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch 18CPPFLAGS+= -isystem ${S}/../common/include 19CPPFLAGS+= -D_KERNEL -D_LKM -D_MODULE 20 21# XXX until the kernel is fixed again... 22.if (defined(HAVE_GCC) && ${HAVE_GCC} == 4) || defined(HAVE_PCC) 23CFLAGS+= -fno-strict-aliasing -Wno-pointer-sign 24.endif 25 26_YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 27DPSRCS+= ${_YKMSRCS} 28CLEANFILES+= ${_YKMSRCS} 29 30.if exists($S/../gnu/usr.bin/binutils/ld/xldscripts/kmodule) 31KMODSCRIPT= $S/../gnu/usr.bin/binutils/ld/xldscripts/kmodule 32.else 33KMODSCRIPT= ${DESTDIR}/usr/libdata/ldscripts/kmodule 34.endif 35 36OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g} 37PROG?= ${KMOD}.kmod 38 39##### Build rules 40realall: ${PROG} 41 42${OBJS} ${LOBJS}: ${DPSRCS} 43 44${PROG}: ${OBJS} ${DPADD} 45 ${_MKTARGET_LINK} 46 ${LD} -T ${KMODSCRIPT} -r -d -o ${.TARGET} ${OBJS} 47 48##### Install rules 49.if !target(kmodinstall) 50.if !defined(KMODULEDIR) 51_OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh 52# Ensure these are recorded properly in METALOG on unprived installes: 53_INST_DIRS= ${DESTDIR}/stand/${MACHINE} 54_INST_DIRS+= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE} 55_INST_DIRS+= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}/modules 56KMODULEDIR= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}/modules/${KMOD} 57.endif 58_PROG:= ${KMODULEDIR}/${PROG} # installed path 59 60.if ${MKUPDATE} == "no" 61${_PROG}! ${PROG} # install rule 62.if !defined(BUILD) && !make(all) && !make(${PROG}) 63${_PROG}! .MADE # no build at install 64.endif 65.else 66${_PROG}: ${PROG} # install rule 67.if !defined(BUILD) && !make(all) && !make(${PROG}) 68${_PROG}: .MADE # no build at install 69.endif 70.endif 71 ${_MKTARGET_INSTALL} 72 dirs=${_INST_DIRS:Q}; \ 73 for d in $$dirs; do \ 74 ${INSTALL_DIR} $$d; \ 75 done 76 ${INSTALL_DIR} ${KMODULEDIR} 77 ${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \ 78 ${.ALLSRC} ${.TARGET} 79 80kmodinstall:: ${_PROG} 81.PHONY: kmodinstall 82.PRECIOUS: ${_PROG} # keep if install fails 83 84.undef _PROG 85.endif # !target(kmodinstall) 86 87##### Clean rules 88cleankmod: .PHONY 89 rm -f a.out [Ee]rrs mklog core *.core \ 90 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 91 92##### Custom rules 93lint: ${LOBJS} 94.if defined(LOBJS) && !empty(LOBJS) 95 ${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD} 96.endif 97 98##### Pull in related .mk logic 99.include <bsd.man.mk> 100.include <bsd.links.mk> 101.include <bsd.dep.mk> 102 103.-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc" 104.-include "$S/arch/${MACHINE}/include/Makefile.inc" 105