1 # $NetBSD: bsd.kmodule.mk,v 1.37 2012/08/10 16:34:23 joerg 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"
31 .elif
${MACHINE_CPU} == "powerpc"
33 .elif
${MACHINE_CPU} == "vax"
37 # evbppc needs some special help
38 .if
${MACHINE} == "evbppc"
40 .
ifndef PPC_INTR_IMPL
41 PPC_INTR_IMPL
=\"powerpc
/intr.h
\"
43 .
ifndef PPC_PCI_MACHDEP_IMPL
44 PPC_PCI_MACHDEP_IMPL
=\"powerpc
/pci_machdep.h
\"
46 CPPFLAGS
+= -DPPC_INTR_IMPL
=${PPC_INTR_IMPL}
47 CPPFLAGS
+= -DPPC_PCI_MACHDEP_IMPL
=${DPPC_PCI_MACHDEP_IMPL}
50 CPPFLAGS
+= -DPPC_IBM4XX
52 CPPFLAGS
+= -DPPC_BOOKE
60 _YKMSRCS
= ${SRCS
:M
*.
[ly
]:C
/\..
$/.c
/} ${YHEADER
:D
${SRCS
:M
*.y
:.y
=.h
}}
62 CLEANFILES
+= ${_YKMSRCS}
64 .if exists
($S/..
/sys
/modules
/xldscripts
/kmodule
)
65 KMODSCRIPT
= $S/..
/sys
/modules
/xldscripts
/kmodule
67 KMODSCRIPT
= ${DESTDIR}/usr
/libdata
/ldscripts
/kmodule
75 .if
(defined
(USE_COMBINE
) && ${USE_COMBINE} != "no" && !commands
(${_P}) \
76 && !defined
(NOCOMBINE.
${_P}) && !defined
(NOCOMBINE
))
77 .for f in
${SRCS
:N
*.h
:N
*.sh
:N
*.fth
:C
/\.
[yl
]$/.c
/g
}
78 .if
(${CPPFLAGS.
$f:D1
} == "1" ||
${CPUFLAGS.
$f:D2
} == "2" \
79 ||
${COPTS.
$f:D3
} == "3" ||
${OBJCOPTS.
$f:D4
} == "4" \
80 ||
${CXXFLAGS.
$f:D5
} == "5") \
81 ||
("${f:M*.[cyl]}" == "" || commands
(${f
:R
:S
/$/.o
/}))
82 XOBJS
+= ${f
:R
:S
/$/.o
/}
93 ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD}
95 ${CC} ${LDFLAGS} -nostdlib
-MD
-combine
-r
-Wl
,-T
,${KMODSCRIPT},-d \
96 -o
${.TARGET
} ${CFLAGS} ${CPPFLAGS} ${XOBJS} \
97 ${XSRCS
:@.SRC.@
${.ALLSRC
:M
*.c
:M
*${.SRC.
}}@
:O
:u
} && \
98 echo
'.-include "${KMOD}.d"' > .depend
101 OBJS
+= ${SRCS
:N
*.h
:N
*.sh
:R
:S
/$/.o
/g
}
103 ${OBJS} ${LOBJS}: ${DPSRCS}
105 ${PROG}: ${OBJS} ${DPADD}
107 ${CC} ${LDFLAGS} -nostdlib
-r
-Wl
,-T
,${KMODSCRIPT},-d \
108 -o
${.TARGET
} ${OBJS}
112 .if
!target
(kmodinstall
)
113 .if
!defined
(KMODULEDIR
)
114 _OSRELEASE
!= ${HOST_SH} $S/conf
/osrelease.sh
-k
115 # Ensure these are recorded properly in METALOG on unprived installes:
116 KMODULEARCHDIR?
= ${MACHINE}
117 _INST_DIRS
= ${DESTDIR}/stand
/${KMODULEARCHDIR}
118 _INST_DIRS
+= ${DESTDIR}/stand
/${KMODULEARCHDIR}/${_OSRELEASE}
119 _INST_DIRS
+= ${DESTDIR}/stand
/${KMODULEARCHDIR}/${_OSRELEASE}/modules
120 KMODULEDIR
= ${DESTDIR}/stand
/${KMODULEARCHDIR}/${_OSRELEASE}/modules
/${KMOD}
122 _PROG
:= ${KMODULEDIR}/${PROG} # installed path
124 .if
${MKUPDATE} == "no"
125 ${_PROG}! ${PROG} # install rule
126 .if
!defined
(BUILD
) && !make
(all) && !make
(${PROG})
127 ${_PROG}! .MADE
# no build at install
130 ${_PROG}: ${PROG} # install rule
131 .if
!defined
(BUILD
) && !make
(all) && !make
(${PROG})
132 ${_PROG}: .MADE
# no build at install
136 dirs
=${_INST_DIRS
:Q
}; \
137 for d in
$$dirs; do \
138 ${INSTALL_DIR} $$d; \
140 ${INSTALL_DIR} ${KMODULEDIR}
141 ${INSTALL_FILE} -o
${KMODULEOWN} -g
${KMODULEGRP} -m
${KMODULEMODE} \
142 ${.ALLSRC
} ${.TARGET
}
144 kmodinstall
:: ${_PROG}
146 .PRECIOUS
: ${_PROG} # keep if install fails
149 .
endif # !target(kmodinstall)
152 CLEANFILES
+= a.out
[Ee
]rrs mklog core
*.core
${PROG} ${OBJS} ${LOBJS}
156 .if defined
(LOBJS
) && !empty
(LOBJS
)
157 ${LINT} ${LINTFLAGS} ${LDFLAGS
:C
/-L
[ ]*/-L
/Wg
:M-L
*} ${LOBJS} ${LDADD}
160 ##### Pull in related .mk logic
161 LINKSOWN?
= ${KMODULEOWN}
162 LINKSGRP?
= ${KMODULEGRP}
163 LINKSMODE?
= ${KMODULEMODE}
164 .
include <bsd.man.mk
>
165 .
include <bsd.links.mk
>
166 .
include <bsd.dep.mk
>
167 .
include <bsd.
clean.mk
>
169 .
-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
170 .
-include "$S/arch/${MACHINE}/include/Makefile.inc"