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