No empty .Rs/.Re
[netbsd-mini2440.git] / share / mk / bsd.kmodule.mk
blobaa6781d1f7a5442a1591244eee757f9add547f60
1 # $NetBSD: bsd.kmodule.mk,v 1.22 2009/12/14 01:00:46 matt Exp $
3 # We are not building this with PIE
4 MKPIE=no
6 .include <bsd.init.mk>
7 .include <bsd.klinks.mk>
8 .include <bsd.sys.mk>
10 ##### Basic targets
11 clean: cleankmod
12 realinstall: kmodinstall
14 KERN= $S/kern
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
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
26 _YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
27 DPSRCS+= ${_YKMSRCS}
28 CLEANFILES+= ${_YKMSRCS}
30 .if exists($S/../sys/modules/xldscripts/kmodule)
31 KMODSCRIPT= $S/../sys/modules/xldscripts/kmodule
32 .else
33 KMODSCRIPT= ${DESTDIR}/usr/libdata/ldscripts/kmodule
34 .endif
36 OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
37 PROG?= ${KMOD}.kmod
39 ##### Build rules
40 realall: ${PROG}
42 ${OBJS} ${LOBJS}: ${DPSRCS}
44 ${PROG}: ${OBJS} ${DPADD}
45 ${_MKTARGET_LINK}
46 ${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
47 -o ${.TARGET} ${OBJS}
49 ##### Install rules
50 .if !target(kmodinstall)
51 .if !defined(KMODULEDIR)
52 _OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh
53 # Ensure these are recorded properly in METALOG on unprived installes:
54 _INST_DIRS= ${DESTDIR}/stand/${MACHINE}
55 _INST_DIRS+= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}
56 _INST_DIRS+= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}/modules
57 KMODULEDIR= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}/modules/${KMOD}
58 .endif
59 _PROG:= ${KMODULEDIR}/${PROG} # installed path
61 .if ${MKUPDATE} == "no"
62 ${_PROG}! ${PROG} # install rule
63 .if !defined(BUILD) && !make(all) && !make(${PROG})
64 ${_PROG}! .MADE # no build at install
65 .endif
66 .else
67 ${_PROG}: ${PROG} # install rule
68 .if !defined(BUILD) && !make(all) && !make(${PROG})
69 ${_PROG}: .MADE # no build at install
70 .endif
71 .endif
72 ${_MKTARGET_INSTALL}
73 dirs=${_INST_DIRS:Q}; \
74 for d in $$dirs; do \
75 ${INSTALL_DIR} $$d; \
76 done
77 ${INSTALL_DIR} ${KMODULEDIR}
78 ${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
79 ${.ALLSRC} ${.TARGET}
81 kmodinstall:: ${_PROG}
82 .PHONY: kmodinstall
83 .PRECIOUS: ${_PROG} # keep if install fails
85 .undef _PROG
86 .endif # !target(kmodinstall)
88 ##### Clean rules
89 cleankmod: .PHONY
90 rm -f a.out [Ee]rrs mklog core *.core \
91 ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
93 ##### Custom rules
94 lint: ${LOBJS}
95 .if defined(LOBJS) && !empty(LOBJS)
96 ${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
97 .endif
99 ##### Pull in related .mk logic
100 LINKSOWN?= ${KMODULEOWN}
101 LINKSGRP?= ${KMODULEGRP}
102 LINKSMODE?= ${KMODULEMODE}
103 .include <bsd.man.mk>
104 .include <bsd.links.mk>
105 .include <bsd.dep.mk>
107 .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
108 .-include "$S/arch/${MACHINE}/include/Makefile.inc"