1 # $NetBSD: bsd.kmodule.mk,v 1.41 2013/11/09 22:40:15 jmcneill Exp $
3 # We are not building this with PIE
7 .
include <bsd.klinks.mk
>
11 realinstall
: kmodinstall
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"
33 .elif
${MACHINE_CPU} == "powerpc"
35 .elif
${MACHINE_CPU} == "vax"
39 .if
${MACHINE} == "sparc64"
40 # force same memory model as rest of the kernel
41 CFLAGS
+= -mcmodel
=medlow
44 # evbppc needs some special help
45 .if
${MACHINE} == "evbppc"
47 .
ifndef PPC_INTR_IMPL
48 PPC_INTR_IMPL
=\"powerpc
/intr.h
\"
50 .
ifndef PPC_PCI_MACHDEP_IMPL
51 PPC_PCI_MACHDEP_IMPL
=\"powerpc
/pci_machdep.h
\"
53 CPPFLAGS
+= -DPPC_INTR_IMPL
=${PPC_INTR_IMPL}
54 CPPFLAGS
+= -DPPC_PCI_MACHDEP_IMPL
=${DPPC_PCI_MACHDEP_IMPL}
57 CPPFLAGS
+= -DPPC_IBM4XX
59 CPPFLAGS
+= -DPPC_BOOKE
67 _YKMSRCS
= ${SRCS
:M
*.
[ly
]:C
/\..
$/.c
/} ${YHEADER
:D
${SRCS
:M
*.y
:.y
=.h
}}
69 CLEANFILES
+= ${_YKMSRCS}
71 .if exists
($S/..
/sys
/modules
/xldscripts
/kmodule
)
72 KMODSCRIPT
= $S/..
/sys
/modules
/xldscripts
/kmodule
74 KMODSCRIPT
= ${DESTDIR}/usr
/libdata
/ldscripts
/kmodule
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
/}
100 ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD}
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
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}
121 ${LD} -r
-o tmp.o
${OBJS}
123 `${OBJDUMP} --syms --reloc tmp.o | \
124 ${TOOL_AWK} -f ${ARCHDIR}/kmodwrap.awk` \
127 ${KMOD}_tramp.S
: ${KMOD}_tmp.o
${ARCHDIR}/kmodtramp.awk
${ASM_H}
129 ${OBJDUMP} --syms
--reloc
${KMOD}_tmp.o | \
130 ${TOOL_AWK} -f
${ARCHDIR}/kmodtramp.awk \
134 ${PROG}: ${KMOD}_tmp.o
${KMOD}_tramp.o
136 .if exists
(${ARCHDIR}/kmodhide.awk
)
137 ${LD} -r
-o tmp.o
${KMOD}_tmp.o
${KMOD}_tramp.o
139 `${NM} tmp.o | ${TOOL_AWK} -f ${ARCHDIR}/kmodhide.awk` \
140 tmp.o
${.TARGET
} && \
143 ${LD} -r
-o
${.TARGET
} ${KMOD}_tmp.o
${KMOD}_tramp.o
146 ${PROG}: ${OBJS} ${DPADD}
148 ${CC} ${LDFLAGS} -nostdlib
-r
-Wl
,-T
,${KMODSCRIPT},-d \
149 -o
${.TARGET
} ${OBJS}
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}
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
172 ${_PROG}: ${PROG} # install rule
173 .if
!defined
(BUILD
) && !make
(all) && !make
(${PROG})
174 ${_PROG}: .MADE
# no build at install
178 dirs
=${_INST_DIRS
:Q
}; \
179 for d in
$$dirs; do \
180 ${INSTALL_DIR} $$d; \
182 ${INSTALL_DIR} ${KMODULEDIR}
183 ${INSTALL_FILE} -o
${KMODULEOWN} -g
${KMODULEGRP} -m
${KMODULEMODE} \
184 ${.ALLSRC
} ${.TARGET
}
186 kmodinstall
:: ${_PROG}
188 .PRECIOUS
: ${_PROG} # keep if install fails
191 .
endif # !target(kmodinstall)
194 CLEANFILES
+= a.out
[Ee
]rrs mklog core
*.core
${PROG} ${OBJS} ${LOBJS}
198 .if defined
(LOBJS
) && !empty
(LOBJS
)
199 ${LINT} ${LINTFLAGS} ${LDFLAGS
:C
/-L
[ ]*/-L
/Wg
:M-L
*} ${LOBJS} ${LDADD}
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"