2019-12-01 23:24:47 +03:00
|
|
|
# $NetBSD: bsd.kmodule.mk,v 1.63 2019/12/01 20:24:47 jmcneill Exp $
|
2008-11-05 03:54:25 +03:00
|
|
|
|
|
|
|
# We are not building this with PIE
|
|
|
|
MKPIE=no
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
.include <bsd.init.mk>
|
|
|
|
.include <bsd.klinks.mk>
|
2016-01-30 07:07:27 +03:00
|
|
|
|
|
|
|
.if ${MKCTF:Uno} == "yes"
|
|
|
|
CFLAGS+= -g
|
|
|
|
# Only need symbols for ctf, strip them after converting to CTF
|
|
|
|
CTFFLAGS= -L VERSION
|
2016-02-02 21:38:10 +03:00
|
|
|
CTFMFLAGS= -t -L VERSION
|
2019-07-05 11:28:16 +03:00
|
|
|
# Keep symbols if built with "-g"
|
|
|
|
.if !empty(COPTS:M*-g*)
|
|
|
|
CTFFLAGS+= -g
|
|
|
|
CTFMFLAGS+= -g
|
|
|
|
.endif
|
2016-01-30 07:07:27 +03:00
|
|
|
.endif
|
|
|
|
|
2008-05-20 23:01:10 +04:00
|
|
|
.include <bsd.sys.mk>
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
##### Basic targets
|
|
|
|
realinstall: kmodinstall
|
|
|
|
|
|
|
|
KERN= $S/kern
|
2014-11-12 05:19:28 +03:00
|
|
|
MKLDSCRIPT?= no
|
2008-05-02 18:20:50 +04:00
|
|
|
|
2008-05-20 16:18:45 +04:00
|
|
|
CFLAGS+= -ffreestanding ${COPTS}
|
2008-05-02 18:20:50 +04:00
|
|
|
CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
|
|
|
|
CPPFLAGS+= -isystem ${S}/../common/include
|
2011-09-11 22:38:02 +04:00
|
|
|
CPPFLAGS+= -D_KERNEL -D_LKM -D_MODULE -DSYSCTL_INCLUDE_DESCR
|
2008-05-02 18:20:50 +04:00
|
|
|
|
2017-01-11 15:19:43 +03:00
|
|
|
CWARNFLAGS.clang+= -Wno-error=address-of-packed-member -Wno-error=constant-conversion
|
|
|
|
|
2008-05-02 18:20:50 +04:00
|
|
|
# XXX until the kernel is fixed again...
|
|
|
|
CFLAGS+= -fno-strict-aliasing -Wno-pointer-sign
|
|
|
|
|
2010-01-19 02:39:07 +03:00
|
|
|
# XXX This is a workaround for platforms that have relative relocations
|
|
|
|
# that, when relocated by the module loader, result in addresses that
|
|
|
|
# overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
|
|
|
|
# The real solution to this involves generating trampolines for those
|
|
|
|
# relocations inside the loader and removing this workaround, as the
|
|
|
|
# resulting code would be much faster.
|
2019-12-01 23:24:47 +03:00
|
|
|
.if ${MACHINE_CPU} == "aarch64"
|
|
|
|
CFLAGS+= -march=armv8-a+nofp+nosimd
|
|
|
|
.elif ${MACHINE_CPU} == "arm"
|
2013-11-10 02:40:15 +04:00
|
|
|
CFLAGS+= -fno-common -fno-unwind-tables
|
2013-08-06 10:08:39 +04:00
|
|
|
.elif ${MACHINE_CPU} == "hppa"
|
|
|
|
CFLAGS+= -mlong-calls
|
2010-01-19 02:39:07 +03:00
|
|
|
.elif ${MACHINE_CPU} == "powerpc"
|
2014-08-10 21:44:26 +04:00
|
|
|
CFLAGS+= ${${ACTIVE_CC} == "gcc":? -mlongcall :}
|
2011-07-14 22:12:35 +04:00
|
|
|
.elif ${MACHINE_CPU} == "vax"
|
|
|
|
CFLAGS+= -fno-pic
|
2014-09-19 21:45:42 +04:00
|
|
|
.elif ${MACHINE_CPU} == "riscv"
|
|
|
|
CFLAGS+= -fPIC -Wa,-fno-pic
|
2015-06-24 16:42:53 +03:00
|
|
|
.elif ${MACHINE_ARCH} == "mips64eb" && !defined(BSD_MK_COMPAT_FILE)
|
2015-05-02 21:18:13 +03:00
|
|
|
CFLAGS+= -mabi=64
|
|
|
|
LDFLAGS+= -Wl,-m,elf64btsmip
|
2015-06-24 16:42:53 +03:00
|
|
|
.elif ${MACHINE_ARCH} == "mips64el" && !defined(BSD_MK_COMPAT_FILE)
|
2015-05-02 21:18:13 +03:00
|
|
|
CFLAGS+= -mabi=64
|
|
|
|
LDFLAGS+= -Wl,-m,elf64ltsmip
|
2010-01-19 02:39:07 +03:00
|
|
|
.endif
|
|
|
|
|
2014-03-10 16:13:14 +04:00
|
|
|
.if ${MACHINE_CPU} == "sparc64"
|
2013-09-18 13:25:20 +04:00
|
|
|
# force same memory model as rest of the kernel
|
2014-02-22 00:44:03 +04:00
|
|
|
CFLAGS+= ${${ACTIVE_CC} == "gcc":? -mcmodel=medlow :}
|
|
|
|
CFLAGS+= ${${ACTIVE_CC} == "clang":? -mcmodel=small :}
|
2013-09-18 13:25:20 +04:00
|
|
|
.endif
|
|
|
|
|
2011-04-17 13:47:40 +04:00
|
|
|
# evbppc needs some special help
|
|
|
|
.if ${MACHINE} == "evbppc"
|
|
|
|
|
|
|
|
. ifndef PPC_INTR_IMPL
|
|
|
|
PPC_INTR_IMPL=\"powerpc/intr.h\"
|
|
|
|
. endif
|
|
|
|
. ifndef PPC_PCI_MACHDEP_IMPL
|
|
|
|
PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\"
|
|
|
|
. endif
|
|
|
|
CPPFLAGS+= -DPPC_INTR_IMPL=${PPC_INTR_IMPL}
|
|
|
|
CPPFLAGS+= -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL}
|
|
|
|
|
|
|
|
. ifdef PPC_IBM4XX
|
|
|
|
CPPFLAGS+= -DPPC_IBM4XX
|
|
|
|
. elifdef PPC_BOOKE
|
|
|
|
CPPFLAGS+= -DPPC_BOOKE
|
|
|
|
. else
|
|
|
|
CPPFLAGS+= -DPPC_OEA
|
|
|
|
. endif
|
|
|
|
|
|
|
|
.endif
|
|
|
|
|
|
|
|
|
2008-05-02 18:20:50 +04:00
|
|
|
_YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
|
|
|
|
DPSRCS+= ${_YKMSRCS}
|
|
|
|
CLEANFILES+= ${_YKMSRCS}
|
2008-05-20 23:01:10 +04:00
|
|
|
|
2009-11-10 17:47:52 +03:00
|
|
|
.if exists($S/../sys/modules/xldscripts/kmodule)
|
2014-11-12 05:19:28 +03:00
|
|
|
KMODSCRIPTSRC= $S/../sys/modules/xldscripts/kmodule
|
2008-05-20 23:01:10 +04:00
|
|
|
.else
|
2014-11-12 05:19:28 +03:00
|
|
|
KMODSCRIPTSRC= ${DESTDIR}/usr/libdata/ldscripts/kmodule
|
|
|
|
.endif
|
|
|
|
.if ${MKLDSCRIPT} == "yes"
|
|
|
|
KMODSCRIPT= kldscript
|
2014-11-13 05:31:24 +03:00
|
|
|
MKLDSCRIPTSH=
|
2014-11-12 05:19:28 +03:00
|
|
|
.else
|
|
|
|
KMODSCRIPT= ${KMODSCRIPTSRC}
|
2008-05-20 23:01:10 +04:00
|
|
|
.endif
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
PROG?= ${KMOD}.kmod
|
|
|
|
|
|
|
|
##### Build rules
|
|
|
|
realall: ${PROG}
|
|
|
|
|
2012-02-20 03:19:37 +04:00
|
|
|
OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
|
|
|
|
|
2008-05-02 18:20:50 +04:00
|
|
|
${OBJS} ${LOBJS}: ${DPSRCS}
|
|
|
|
|
2014-11-13 05:31:24 +03:00
|
|
|
.if ${MKLDSCRIPT} == "yes"
|
|
|
|
${KMODSCRIPT}: ${KMODSCRIPTSRC} ${OBJS} $S/conf/mkldscript.sh
|
|
|
|
@rm -f ${.TARGET}
|
|
|
|
@OBJDUMP=${OBJDUMP} ${HOST_SH} $S/conf/mkldscript.sh \
|
|
|
|
-t ${KMODSCRIPTSRC} ${OBJS} > ${.TARGET}
|
|
|
|
.endif
|
|
|
|
|
2013-08-07 21:36:11 +04:00
|
|
|
.if ${MACHINE_CPU} == "arm"
|
|
|
|
# The solution to limited branch space involves generating trampolines for
|
|
|
|
# those relocations while creating the module, as the resulting code will
|
|
|
|
# be much faster and simplifies the loader.
|
|
|
|
ARCHDIR= $S/modules/arch/${MACHINE_CPU}
|
|
|
|
ASM_H= $S/arch/${MACHINE_CPU}/include/asm.h
|
|
|
|
CLEANFILES+= tmp.o tmp.S ${KMOD}_tmp.o ${KMOD}_tramp.o ${KMOD}_tramp.S
|
|
|
|
${KMOD}_tmp.o: ${OBJS} ${DPADD}
|
|
|
|
${_MKTARGET_LINK}
|
|
|
|
${LD} -r -o tmp.o ${OBJS}
|
|
|
|
${LD} -r \
|
|
|
|
`${OBJDUMP} --syms --reloc tmp.o | \
|
|
|
|
${TOOL_AWK} -f ${ARCHDIR}/kmodwrap.awk` \
|
|
|
|
-o ${.TARGET} tmp.o
|
|
|
|
|
|
|
|
${KMOD}_tramp.S: ${KMOD}_tmp.o ${ARCHDIR}/kmodtramp.awk ${ASM_H}
|
|
|
|
${_MKTARGET_CREATE}
|
|
|
|
${OBJDUMP} --syms --reloc ${KMOD}_tmp.o | \
|
|
|
|
${TOOL_AWK} -f ${ARCHDIR}/kmodtramp.awk \
|
|
|
|
> tmp.S && \
|
2019-01-22 00:11:54 +03:00
|
|
|
${MV} tmp.S ${.TARGET}
|
2013-08-07 21:36:11 +04:00
|
|
|
|
|
|
|
${PROG}: ${KMOD}_tmp.o ${KMOD}_tramp.o
|
|
|
|
${_MKTARGET_LINK}
|
|
|
|
.if exists(${ARCHDIR}/kmodhide.awk)
|
2014-11-06 15:05:44 +03:00
|
|
|
${LD} -r -Map=${.TARGET}.map \
|
|
|
|
-o tmp.o ${KMOD}_tmp.o ${KMOD}_tramp.o
|
2013-08-07 21:36:11 +04:00
|
|
|
${OBJCOPY} \
|
|
|
|
`${NM} tmp.o | ${TOOL_AWK} -f ${ARCHDIR}/kmodhide.awk` \
|
|
|
|
tmp.o ${.TARGET} && \
|
|
|
|
rm tmp.o
|
|
|
|
.else
|
2014-11-06 15:05:44 +03:00
|
|
|
${LD} -r -Map=${.TARGET}.map \
|
|
|
|
-o ${.TARGET} ${KMOD}_tmp.o ${KMOD}_tramp.o
|
2013-08-07 21:36:11 +04:00
|
|
|
.endif
|
|
|
|
.else
|
2014-11-13 05:31:24 +03:00
|
|
|
${PROG}: ${OBJS} ${DPADD} ${KMODSCRIPT}
|
2015-07-09 17:50:08 +03:00
|
|
|
${_MKTARGET_LINK}
|
2010-12-11 21:42:33 +03:00
|
|
|
${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
|
2014-11-06 15:05:44 +03:00
|
|
|
-Wl,-Map=${.TARGET}.map \
|
2009-12-14 04:00:46 +03:00
|
|
|
-o ${.TARGET} ${OBJS}
|
2012-02-20 03:19:37 +04:00
|
|
|
.endif
|
2016-02-02 21:38:10 +03:00
|
|
|
.if defined(CTFMERGE)
|
|
|
|
${CTFMERGE} ${CTFMFLAGS} -o ${.TARGET} ${OBJS}
|
|
|
|
.endif
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
##### Install rules
|
|
|
|
.if !target(kmodinstall)
|
2008-05-20 23:01:10 +04:00
|
|
|
.if !defined(KMODULEDIR)
|
2012-02-17 03:58:15 +04:00
|
|
|
_OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh -k
|
2008-05-21 23:56:30 +04:00
|
|
|
# Ensure these are recorded properly in METALOG on unprived installes:
|
2011-04-17 13:47:40 +04:00
|
|
|
KMODULEARCHDIR?= ${MACHINE}
|
|
|
|
_INST_DIRS= ${DESTDIR}/stand/${KMODULEARCHDIR}
|
|
|
|
_INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}
|
|
|
|
_INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules
|
|
|
|
KMODULEDIR= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
|
2008-05-31 23:58:35 +04:00
|
|
|
.endif
|
|
|
|
_PROG:= ${KMODULEDIR}/${PROG} # installed path
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
.if ${MKUPDATE} == "no"
|
|
|
|
${_PROG}! ${PROG} # install rule
|
|
|
|
.if !defined(BUILD) && !make(all) && !make(${PROG})
|
|
|
|
${_PROG}! .MADE # no build at install
|
|
|
|
.endif
|
|
|
|
.else
|
|
|
|
${_PROG}: ${PROG} # install rule
|
|
|
|
.if !defined(BUILD) && !make(all) && !make(${PROG})
|
|
|
|
${_PROG}: .MADE # no build at install
|
|
|
|
.endif
|
|
|
|
.endif
|
|
|
|
${_MKTARGET_INSTALL}
|
2008-12-01 01:05:56 +03:00
|
|
|
dirs=${_INST_DIRS:Q}; \
|
|
|
|
for d in $$dirs; do \
|
2008-05-21 23:56:30 +04:00
|
|
|
${INSTALL_DIR} $$d; \
|
|
|
|
done
|
2008-05-20 23:01:10 +04:00
|
|
|
${INSTALL_DIR} ${KMODULEDIR}
|
2008-11-12 15:35:50 +03:00
|
|
|
${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
|
2008-05-02 18:20:50 +04:00
|
|
|
${.ALLSRC} ${.TARGET}
|
|
|
|
|
|
|
|
kmodinstall:: ${_PROG}
|
|
|
|
.PHONY: kmodinstall
|
|
|
|
.PRECIOUS: ${_PROG} # keep if install fails
|
|
|
|
|
|
|
|
.undef _PROG
|
|
|
|
.endif # !target(kmodinstall)
|
|
|
|
|
|
|
|
##### Clean rules
|
2011-09-10 20:57:35 +04:00
|
|
|
CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS}
|
2014-11-06 15:05:44 +03:00
|
|
|
CLEANFILES+= ${PROG}.map
|
2014-11-12 05:19:28 +03:00
|
|
|
.if ${MKLDSCRIPT} == "yes"
|
|
|
|
CLEANFILES+= kldscript
|
|
|
|
.endif
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
##### Custom rules
|
|
|
|
lint: ${LOBJS}
|
|
|
|
.if defined(LOBJS) && !empty(LOBJS)
|
|
|
|
${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
|
|
|
|
.endif
|
|
|
|
|
|
|
|
##### Pull in related .mk logic
|
2009-04-10 20:16:12 +04:00
|
|
|
LINKSOWN?= ${KMODULEOWN}
|
|
|
|
LINKSGRP?= ${KMODULEGRP}
|
|
|
|
LINKSMODE?= ${KMODULEMODE}
|
2008-05-02 18:20:50 +04:00
|
|
|
.include <bsd.man.mk>
|
|
|
|
.include <bsd.links.mk>
|
|
|
|
.include <bsd.dep.mk>
|
2011-09-10 20:57:35 +04:00
|
|
|
.include <bsd.clean.mk>
|
2008-05-02 18:20:50 +04:00
|
|
|
|
|
|
|
.-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
|
|
|
|
.-include "$S/arch/${MACHINE}/include/Makefile.inc"
|