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