custom message type for VM_INFO
[minix3.git] / share / mk / bsd.kmodule.mk
blob8c42228f82e60075ad497a04dc48d0cc5e4f9566
1 # $NetBSD: bsd.kmodule.mk,v 1.41 2013/11/09 22:40:15 jmcneill 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 realinstall: kmodinstall
13 KERN= $S/kern
15 CFLAGS+= -ffreestanding ${COPTS}
16 CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
17 CPPFLAGS+= -isystem ${S}/../common/include
18 CPPFLAGS+= -D_KERNEL -D_LKM -D_MODULE -DSYSCTL_INCLUDE_DESCR
20 # XXX until the kernel is fixed again...
21 CFLAGS+= -fno-strict-aliasing -Wno-pointer-sign
23 # XXX This is a workaround for platforms that have relative relocations
24 # that, when relocated by the module loader, result in addresses that
25 # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
26 # The real solution to this involves generating trampolines for those
27 # relocations inside the loader and removing this workaround, as the
28 # resulting code would be much faster.
29 .if ${MACHINE_CPU} == "arm"
30 CFLAGS+= -fno-common -fno-unwind-tables
31 .elif ${MACHINE_CPU} == "hppa"
32 CFLAGS+= -mlong-calls
33 .elif ${MACHINE_CPU} == "powerpc"
34 CFLAGS+= -mlongcall
35 .elif ${MACHINE_CPU} == "vax"
36 CFLAGS+= -fno-pic
37 .endif
39 .if ${MACHINE} == "sparc64"
40 # force same memory model as rest of the kernel
41 CFLAGS+= -mcmodel=medlow
42 .endif
44 # evbppc needs some special help
45 .if ${MACHINE} == "evbppc"
47 . ifndef PPC_INTR_IMPL
48 PPC_INTR_IMPL=\"powerpc/intr.h\"
49 . endif
50 . ifndef PPC_PCI_MACHDEP_IMPL
51 PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\"
52 . endif
53 CPPFLAGS+= -DPPC_INTR_IMPL=${PPC_INTR_IMPL}
54 CPPFLAGS+= -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL}
56 . ifdef PPC_IBM4XX
57 CPPFLAGS+= -DPPC_IBM4XX
58 . elifdef PPC_BOOKE
59 CPPFLAGS+= -DPPC_BOOKE
60 . else
61 CPPFLAGS+= -DPPC_OEA
62 . endif
64 .endif
67 _YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
68 DPSRCS+= ${_YKMSRCS}
69 CLEANFILES+= ${_YKMSRCS}
71 .if exists($S/../sys/modules/xldscripts/kmodule)
72 KMODSCRIPT= $S/../sys/modules/xldscripts/kmodule
73 .else
74 KMODSCRIPT= ${DESTDIR}/usr/libdata/ldscripts/kmodule
75 .endif
77 PROG?= ${KMOD}.kmod
79 ##### Build rules
80 realall: ${PROG}
82 .if (defined(USE_COMBINE) && ${USE_COMBINE} != "no" && !commands(${_P}) \
83 && !defined(NOCOMBINE.${_P}) && !defined(NOCOMBINE))
84 .for f in ${SRCS:N*.h:N*.sh:N*.fth:C/\.[yl]$/.c/g}
85 .if (${CPPFLAGS.$f:D1} == "1" || ${CPUFLAGS.$f:D2} == "2" \
86 || ${COPTS.$f:D3} == "3" || ${OBJCOPTS.$f:D4} == "4" \
87 || ${CXXFLAGS.$f:D5} == "5") \
88 || ("${f:M*.[cyl]}" == "" || commands(${f:R:S/$/.o/}))
89 XOBJS+= ${f:R:S/$/.o/}
90 .else
91 XSRCS+= ${f}
92 NODPSRCS+= ${f}
93 .endif
94 .endfor
96 .if !empty(XOBJS)
97 ${XOBJS}: ${DPSRCS}
98 .endif
100 ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD}
101 ${_MKTARGET_LINK}
102 ${CC} ${LDFLAGS} -nostdlib -MD -combine -r -Wl,-T,${KMODSCRIPT},-d \
103 -o ${.TARGET} ${CFLAGS} ${CPPFLAGS} ${XOBJS} \
104 ${XSRCS:@.SRC.@${.ALLSRC:M*.c:M*${.SRC.}}@:O:u} && \
105 echo '.-include "${KMOD}.d"' > .depend
107 .else
108 OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
110 ${OBJS} ${LOBJS}: ${DPSRCS}
112 .if ${MACHINE_CPU} == "arm"
113 # The solution to limited branch space involves generating trampolines for
114 # those relocations while creating the module, as the resulting code will
115 # be much faster and simplifies the loader.
116 ARCHDIR= $S/modules/arch/${MACHINE_CPU}
117 ASM_H= $S/arch/${MACHINE_CPU}/include/asm.h
118 CLEANFILES+= tmp.o tmp.S ${KMOD}_tmp.o ${KMOD}_tramp.o ${KMOD}_tramp.S
119 ${KMOD}_tmp.o: ${OBJS} ${DPADD}
120 ${_MKTARGET_LINK}
121 ${LD} -r -o tmp.o ${OBJS}
122 ${LD} -r \
123 `${OBJDUMP} --syms --reloc tmp.o | \
124 ${TOOL_AWK} -f ${ARCHDIR}/kmodwrap.awk` \
125 -o ${.TARGET} tmp.o
127 ${KMOD}_tramp.S: ${KMOD}_tmp.o ${ARCHDIR}/kmodtramp.awk ${ASM_H}
128 ${_MKTARGET_CREATE}
129 ${OBJDUMP} --syms --reloc ${KMOD}_tmp.o | \
130 ${TOOL_AWK} -f ${ARCHDIR}/kmodtramp.awk \
131 > tmp.S && \
132 mv tmp.S ${.TARGET}
134 ${PROG}: ${KMOD}_tmp.o ${KMOD}_tramp.o
135 ${_MKTARGET_LINK}
136 .if exists(${ARCHDIR}/kmodhide.awk)
137 ${LD} -r -o tmp.o ${KMOD}_tmp.o ${KMOD}_tramp.o
138 ${OBJCOPY} \
139 `${NM} tmp.o | ${TOOL_AWK} -f ${ARCHDIR}/kmodhide.awk` \
140 tmp.o ${.TARGET} && \
141 rm tmp.o
142 .else
143 ${LD} -r -o ${.TARGET} ${KMOD}_tmp.o ${KMOD}_tramp.o
144 .endif
145 .else
146 ${PROG}: ${OBJS} ${DPADD}
147 ${_MKTARGET_LINK}
148 ${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
149 -o ${.TARGET} ${OBJS}
150 .endif
151 .endif
153 ##### Install rules
154 .if !target(kmodinstall)
155 .if !defined(KMODULEDIR)
156 _OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh -k
157 # Ensure these are recorded properly in METALOG on unprived installes:
158 KMODULEARCHDIR?= ${MACHINE}
159 _INST_DIRS= ${DESTDIR}/stand/${KMODULEARCHDIR}
160 _INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}
161 _INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules
162 KMODULEDIR= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
163 .endif
164 _PROG:= ${KMODULEDIR}/${PROG} # installed path
166 .if ${MKUPDATE} == "no"
167 ${_PROG}! ${PROG} # install rule
168 .if !defined(BUILD) && !make(all) && !make(${PROG})
169 ${_PROG}! .MADE # no build at install
170 .endif
171 .else
172 ${_PROG}: ${PROG} # install rule
173 .if !defined(BUILD) && !make(all) && !make(${PROG})
174 ${_PROG}: .MADE # no build at install
175 .endif
176 .endif
177 ${_MKTARGET_INSTALL}
178 dirs=${_INST_DIRS:Q}; \
179 for d in $$dirs; do \
180 ${INSTALL_DIR} $$d; \
181 done
182 ${INSTALL_DIR} ${KMODULEDIR}
183 ${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
184 ${.ALLSRC} ${.TARGET}
186 kmodinstall:: ${_PROG}
187 .PHONY: kmodinstall
188 .PRECIOUS: ${_PROG} # keep if install fails
190 .undef _PROG
191 .endif # !target(kmodinstall)
193 ##### Clean rules
194 CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS}
196 ##### Custom rules
197 lint: ${LOBJS}
198 .if defined(LOBJS) && !empty(LOBJS)
199 ${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
200 .endif
202 ##### Pull in related .mk logic
203 LINKSOWN?= ${KMODULEOWN}
204 LINKSGRP?= ${KMODULEGRP}
205 LINKSMODE?= ${KMODULEMODE}
206 .include <bsd.man.mk>
207 .include <bsd.links.mk>
208 .include <bsd.dep.mk>
209 .include <bsd.clean.mk>
211 .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
212 .-include "$S/arch/${MACHINE}/include/Makefile.inc"