1 # $NetBSD: bsd.kmodule.mk,v 1.55 2015/07/09 14:50:08 matt Exp $
3 # We are not building this with PIE
7 .
include <bsd.klinks.mk
>
11 realinstall
: kmodinstall
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
-DSYSCTL_INCLUDE_DESCR
21 # XXX until the kernel is fixed again...
22 CFLAGS
+= -fno-strict-aliasing
-Wno-pointer-sign
24 # XXX This is a workaround for platforms that have relative relocations
25 # that, when relocated by the module loader, result in addresses that
26 # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
27 # The real solution to this involves generating trampolines for those
28 # relocations inside the loader and removing this workaround, as the
29 # resulting code would be much faster.
30 .if
${MACHINE_CPU} == "arm"
31 CFLAGS
+= -fno-common
-fno-unwind-tables
32 .elif
${MACHINE_CPU} == "hppa"
34 .elif
${MACHINE_CPU} == "powerpc"
35 CFLAGS
+= ${${ACTIVE_CC} == "gcc":?
-mlongcall
:}
36 .elif
${MACHINE_CPU} == "vax"
38 .elif
${MACHINE_CPU} == "riscv"
39 CFLAGS
+= -fPIC
-Wa
,-fno-pic
40 .elif
${MACHINE_ARCH} == "mips64eb" && !defined
(BSD_MK_COMPAT_FILE
)
42 LDFLAGS
+= -Wl
,-m
,elf64btsmip
43 .elif
${MACHINE_ARCH} == "mips64el" && !defined
(BSD_MK_COMPAT_FILE
)
45 LDFLAGS
+= -Wl
,-m
,elf64ltsmip
48 .if
${MACHINE_CPU} == "sparc64"
49 # force same memory model as rest of the kernel
50 CFLAGS
+= ${${ACTIVE_CC} == "gcc":?
-mcmodel
=medlow
:}
51 CFLAGS
+= ${${ACTIVE_CC} == "clang":?
-mcmodel
=small
:}
54 # evbppc needs some special help
55 .if
${MACHINE} == "evbppc"
57 .
ifndef PPC_INTR_IMPL
58 PPC_INTR_IMPL
=\"powerpc
/intr.h
\"
60 .
ifndef PPC_PCI_MACHDEP_IMPL
61 PPC_PCI_MACHDEP_IMPL
=\"powerpc
/pci_machdep.h
\"
63 CPPFLAGS
+= -DPPC_INTR_IMPL
=${PPC_INTR_IMPL}
64 CPPFLAGS
+= -DPPC_PCI_MACHDEP_IMPL
=${DPPC_PCI_MACHDEP_IMPL}
67 CPPFLAGS
+= -DPPC_IBM4XX
69 CPPFLAGS
+= -DPPC_BOOKE
77 _YKMSRCS
= ${SRCS
:M
*.
[ly
]:C
/\..
$/.c
/} ${YHEADER
:D
${SRCS
:M
*.y
:.y
=.h
}}
79 CLEANFILES
+= ${_YKMSRCS}
81 .if exists
($S/..
/sys
/modules
/xldscripts
/kmodule
)
82 KMODSCRIPTSRC
= $S/..
/sys
/modules
/xldscripts
/kmodule
84 KMODSCRIPTSRC
= ${DESTDIR}/usr
/libdata
/ldscripts
/kmodule
86 .if
${MKLDSCRIPT} == "yes"
90 KMODSCRIPT
= ${KMODSCRIPTSRC}
98 .if
(defined
(USE_COMBINE
) && ${USE_COMBINE} != "no" && !commands
(${_P}) \
99 && !defined
(NOCOMBINE.
${_P}) && !defined
(NOCOMBINE
))
100 .for f in
${SRCS
:N
*.h
:N
*.sh
:N
*.fth
:C
/\.
[yl
]$/.c
/g
}
101 .if
(${CPPFLAGS.
$f:D1
} == "1" ||
${CPUFLAGS.
$f:D2
} == "2" \
102 ||
${COPTS.
$f:D3
} == "3" ||
${OBJCOPTS.
$f:D4
} == "4" \
103 ||
${CXXFLAGS.
$f:D5
} == "5") \
104 ||
("${f:M*.[cyl]}" == "" || commands
(${f
:R
:S
/$/.o
/}))
105 XOBJS
+= ${f
:R
:S
/$/.o
/}
116 .if
${MKLDSCRIPT} == "yes"
117 ${KMODSCRIPT}: ${KMODSCRIPTSRC} ${XOBJS} $S/conf
/mkldscript.sh
119 @OBJDUMP
=${OBJDUMP} ${HOST_SH} $S/conf
/mkldscript.sh \
120 -t
${KMODSCRIPTSRC} ${XOBJS} > ${.TARGET
}
123 ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD} ${KMODSCRIPT}
124 ${CC} ${LDFLAGS} -nostdlib
-MD
-combine
-r
-Wl
,-T
,${KMODSCRIPT},-d \
125 -Wl
,-Map
=${.TARGET
}.map \
126 -o
${.TARGET
} ${CFLAGS} ${CPPFLAGS} ${XOBJS} \
127 ${XSRCS
:@.SRC.@
${.ALLSRC
:M
*.c
:M
*${.SRC.
}}@
:O
:u
} && \
128 echo
'.-include "${KMOD}.d"' > .depend
131 OBJS
+= ${SRCS
:N
*.h
:N
*.sh
:R
:S
/$/.o
/g
}
133 ${OBJS} ${LOBJS}: ${DPSRCS}
135 .if
${MKLDSCRIPT} == "yes"
136 ${KMODSCRIPT}: ${KMODSCRIPTSRC} ${OBJS} $S/conf
/mkldscript.sh
138 @OBJDUMP
=${OBJDUMP} ${HOST_SH} $S/conf
/mkldscript.sh \
139 -t
${KMODSCRIPTSRC} ${OBJS} > ${.TARGET
}
142 .if
${MACHINE_CPU} == "arm"
143 # The solution to limited branch space involves generating trampolines for
144 # those relocations while creating the module, as the resulting code will
145 # be much faster and simplifies the loader.
146 ARCHDIR
= $S/modules
/arch
/${MACHINE_CPU}
147 ASM_H
= $S/arch
/${MACHINE_CPU}/include/asm.h
148 CLEANFILES
+= tmp.o tmp.S
${KMOD}_tmp.o
${KMOD}_tramp.o
${KMOD}_tramp.S
149 ${KMOD}_tmp.o
: ${OBJS} ${DPADD}
151 ${LD} -r
-o tmp.o
${OBJS}
153 `${OBJDUMP} --syms --reloc tmp.o | \
154 ${TOOL_AWK} -f ${ARCHDIR}/kmodwrap.awk` \
157 ${KMOD}_tramp.S
: ${KMOD}_tmp.o
${ARCHDIR}/kmodtramp.awk
${ASM_H}
159 ${OBJDUMP} --syms
--reloc
${KMOD}_tmp.o | \
160 ${TOOL_AWK} -f
${ARCHDIR}/kmodtramp.awk \
164 ${PROG}: ${KMOD}_tmp.o
${KMOD}_tramp.o
166 .if exists
(${ARCHDIR}/kmodhide.awk
)
167 ${LD} -r
-Map
=${.TARGET
}.map \
168 -o tmp.o
${KMOD}_tmp.o
${KMOD}_tramp.o
170 `${NM} tmp.o | ${TOOL_AWK} -f ${ARCHDIR}/kmodhide.awk` \
171 tmp.o
${.TARGET
} && \
174 ${LD} -r
-Map
=${.TARGET
}.map \
175 -o
${.TARGET
} ${KMOD}_tmp.o
${KMOD}_tramp.o
178 ${PROG}: ${OBJS} ${DPADD} ${KMODSCRIPT}
180 ${CC} ${LDFLAGS} -nostdlib
-r
-Wl
,-T
,${KMODSCRIPT},-d \
181 -Wl
,-Map
=${.TARGET
}.map \
182 -o
${.TARGET
} ${OBJS}
187 .if
!target
(kmodinstall
)
188 .if
!defined
(KMODULEDIR
)
189 _OSRELEASE
!= ${HOST_SH} $S/conf
/osrelease.sh
-k
190 # Ensure these are recorded properly in METALOG on unprived installes:
191 KMODULEARCHDIR?
= ${MACHINE}
192 _INST_DIRS
= ${DESTDIR}/stand
/${KMODULEARCHDIR}
193 _INST_DIRS
+= ${DESTDIR}/stand
/${KMODULEARCHDIR}/${_OSRELEASE}
194 _INST_DIRS
+= ${DESTDIR}/stand
/${KMODULEARCHDIR}/${_OSRELEASE}/modules
195 KMODULEDIR
= ${DESTDIR}/stand
/${KMODULEARCHDIR}/${_OSRELEASE}/modules
/${KMOD}
197 _PROG
:= ${KMODULEDIR}/${PROG} # installed path
199 .if
${MKUPDATE} == "no"
200 ${_PROG}! ${PROG} # install rule
201 .if
!defined
(BUILD
) && !make
(all) && !make
(${PROG})
202 ${_PROG}! .MADE
# no build at install
205 ${_PROG}: ${PROG} # install rule
206 .if
!defined
(BUILD
) && !make
(all) && !make
(${PROG})
207 ${_PROG}: .MADE
# no build at install
211 dirs
=${_INST_DIRS
:Q
}; \
212 for d in
$$dirs; do \
213 ${INSTALL_DIR} $$d; \
215 ${INSTALL_DIR} ${KMODULEDIR}
216 ${INSTALL_FILE} -o
${KMODULEOWN} -g
${KMODULEGRP} -m
${KMODULEMODE} \
217 ${.ALLSRC
} ${.TARGET
}
219 kmodinstall
:: ${_PROG}
221 .PRECIOUS
: ${_PROG} # keep if install fails
224 .
endif # !target(kmodinstall)
227 CLEANFILES
+= a.out
[Ee
]rrs mklog core
*.core
${PROG} ${OBJS} ${LOBJS}
228 CLEANFILES
+= ${PROG}.map
229 .if
${MKLDSCRIPT} == "yes"
230 CLEANFILES
+= kldscript
235 .if defined
(LOBJS
) && !empty
(LOBJS
)
236 ${LINT} ${LINTFLAGS} ${LDFLAGS
:C
/-L
[ ]*/-L
/Wg
:M-L
*} ${LOBJS} ${LDADD}
239 ##### Pull in related .mk logic
240 LINKSOWN?
= ${KMODULEOWN}
241 LINKSGRP?
= ${KMODULEGRP}
242 LINKSMODE?
= ${KMODULEMODE}
243 .
include <bsd.man.mk
>
244 .
include <bsd.links.mk
>
245 .
include <bsd.dep.mk
>
246 .
include <bsd.
clean.mk
>
248 .
-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
249 .
-include "$S/arch/${MACHINE}/include/Makefile.inc"