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