Home | History | Annotate | Line # | Download | only in mk
bsd.kmodule.mk revision 1.18
      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
      4 MKPIE=no
      5 
      6 .include <bsd.init.mk>
      7 .include <bsd.klinks.mk>
      8 .include <bsd.sys.mk>
      9 
     10 ##### Basic targets
     11 clean:		cleankmod
     12 realinstall:	kmodinstall
     13 
     14 KERN=		$S/kern
     15 
     16 CFLAGS+=	-ffreestanding ${COPTS}
     17 CPPFLAGS+=	-nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
     18 CPPFLAGS+=	-isystem ${S}/../common/include
     19 CPPFLAGS+=	-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)
     23 CFLAGS+=	-fno-strict-aliasing -Wno-pointer-sign
     24 .endif
     25 
     26 _YKMSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
     27 DPSRCS+=	${_YKMSRCS}
     28 CLEANFILES+=	${_YKMSRCS}
     29 
     30 .if exists($S/../gnu/usr.bin/binutils/ld/xldscripts/kmodule)
     31 KMODSCRIPT=	$S/../gnu/usr.bin/binutils/ld/xldscripts/kmodule
     32 .else
     33 KMODSCRIPT=	${DESTDIR}/usr/libdata/ldscripts/kmodule
     34 .endif
     35 
     36 OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
     37 PROG?=		${KMOD}.kmod
     38 
     39 ##### Build rules
     40 realall:	${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
     56 KMODULEDIR=	${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 
     80 kmodinstall::	${_PROG}
     81 .PHONY:		kmodinstall
     82 .PRECIOUS:	${_PROG}				# keep if install fails
     83 
     84 .undef _PROG
     85 .endif # !target(kmodinstall)
     86 
     87 ##### Clean rules
     88 cleankmod: .PHONY
     89 	rm -f a.out [Ee]rrs mklog core *.core \
     90 		${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
     91 
     92 ##### Custom rules
     93 lint: ${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