Home | History | Annotate | Line # | Download | only in mk
bsd.kmodule.mk revision 1.59.12.1
      1  1.59.12.1  pgoyette #	$NetBSD: bsd.kmodule.mk,v 1.59.12.1 2019/01/26 21:59:58 pgoyette Exp $
      2       1.14      elad 
      3       1.14      elad # We are not building this with PIE
      4       1.14      elad MKPIE=no
      5        1.1        ad 
      6        1.1        ad .include <bsd.init.mk>
      7        1.1        ad .include <bsd.klinks.mk>
      8       1.57  christos 
      9       1.57  christos .if ${MKCTF:Uno} == "yes"
     10       1.57  christos CFLAGS+=	-g
     11       1.57  christos # Only need symbols for ctf, strip them after converting to CTF
     12       1.57  christos CTFFLAGS=	-L VERSION
     13       1.58  christos CTFMFLAGS=	-t -L VERSION
     14       1.57  christos .endif
     15       1.57  christos 
     16        1.7        ad .include <bsd.sys.mk>
     17        1.1        ad 
     18        1.1        ad ##### Basic targets
     19        1.1        ad realinstall:	kmodinstall
     20        1.1        ad 
     21        1.1        ad KERN=		$S/kern
     22       1.47  christos MKLDSCRIPT?=	no
     23        1.1        ad 
     24        1.6        ad CFLAGS+=	-ffreestanding ${COPTS}
     25        1.1        ad CPPFLAGS+=	-nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
     26        1.1        ad CPPFLAGS+=	-isystem ${S}/../common/include
     27       1.33   mbalmer CPPFLAGS+=	-D_KERNEL -D_LKM -D_MODULE -DSYSCTL_INCLUDE_DESCR
     28        1.1        ad 
     29       1.59     joerg CWARNFLAGS.clang+=	-Wno-error=address-of-packed-member -Wno-error=constant-conversion
     30       1.59     joerg 
     31        1.1        ad # XXX until the kernel is fixed again...
     32        1.1        ad CFLAGS+=	-fno-strict-aliasing -Wno-pointer-sign
     33        1.1        ad 
     34       1.24      jmmv # XXX This is a workaround for platforms that have relative relocations
     35       1.24      jmmv # that, when relocated by the module loader, result in addresses that
     36       1.24      jmmv # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
     37       1.24      jmmv # The real solution to this involves generating trampolines for those
     38       1.24      jmmv # relocations inside the loader and removing this workaround, as the
     39       1.24      jmmv # resulting code would be much faster.
     40       1.24      jmmv .if ${MACHINE_CPU} == "arm"
     41       1.41  jmcneill CFLAGS+=	-fno-common -fno-unwind-tables
     42       1.38     skrll .elif ${MACHINE_CPU} == "hppa"
     43       1.38     skrll CFLAGS+=	-mlong-calls
     44       1.24      jmmv .elif ${MACHINE_CPU} == "powerpc"
     45       1.44     joerg CFLAGS+=	${${ACTIVE_CC} == "gcc":? -mlongcall :}
     46       1.31      matt .elif ${MACHINE_CPU} == "vax"
     47       1.31      matt CFLAGS+=	-fno-pic
     48       1.45      matt .elif ${MACHINE_CPU} == "riscv"
     49       1.45      matt CFLAGS+=	-fPIC -Wa,-fno-pic
     50       1.54      matt .elif ${MACHINE_ARCH} == "mips64eb" && !defined(BSD_MK_COMPAT_FILE)
     51       1.53      matt CFLAGS+=	-mabi=64
     52       1.53      matt LDFLAGS+=	-Wl,-m,elf64btsmip
     53       1.54      matt .elif ${MACHINE_ARCH} == "mips64el" && !defined(BSD_MK_COMPAT_FILE)
     54       1.53      matt CFLAGS+=	-mabi=64
     55       1.53      matt LDFLAGS+=	-Wl,-m,elf64ltsmip
     56       1.24      jmmv .endif
     57       1.24      jmmv 
     58       1.43  nakayama .if ${MACHINE_CPU} == "sparc64"
     59       1.40    martin # force same memory model as rest of the kernel
     60       1.42     joerg CFLAGS+=	${${ACTIVE_CC} == "gcc":? -mcmodel=medlow :}
     61       1.42     joerg CFLAGS+=	${${ACTIVE_CC} == "clang":? -mcmodel=small :}
     62       1.40    martin .endif
     63       1.40    martin 
     64       1.28       mrg # evbppc needs some special help
     65       1.28       mrg .if ${MACHINE} == "evbppc"
     66       1.28       mrg 
     67       1.28       mrg . ifndef PPC_INTR_IMPL
     68       1.28       mrg PPC_INTR_IMPL=\"powerpc/intr.h\"
     69       1.28       mrg . endif
     70       1.28       mrg . ifndef PPC_PCI_MACHDEP_IMPL
     71       1.28       mrg PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\"
     72       1.28       mrg . endif
     73       1.28       mrg CPPFLAGS+=      -DPPC_INTR_IMPL=${PPC_INTR_IMPL}
     74       1.28       mrg CPPFLAGS+=      -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL}
     75       1.28       mrg 
     76       1.28       mrg . ifdef PPC_IBM4XX
     77       1.28       mrg CPPFLAGS+=      -DPPC_IBM4XX
     78       1.28       mrg . elifdef PPC_BOOKE
     79       1.28       mrg CPPFLAGS+=      -DPPC_BOOKE
     80       1.28       mrg . else
     81       1.28       mrg CPPFLAGS+=      -DPPC_OEA
     82       1.28       mrg . endif
     83       1.28       mrg 
     84       1.28       mrg .endif
     85       1.28       mrg 
     86       1.28       mrg 
     87        1.1        ad _YKMSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
     88        1.1        ad DPSRCS+=	${_YKMSRCS}
     89        1.1        ad CLEANFILES+=	${_YKMSRCS}
     90        1.7        ad 
     91       1.21     skrll .if exists($S/../sys/modules/xldscripts/kmodule)
     92       1.47  christos KMODSCRIPTSRC=	$S/../sys/modules/xldscripts/kmodule
     93        1.7        ad .else
     94       1.47  christos KMODSCRIPTSRC=	${DESTDIR}/usr/libdata/ldscripts/kmodule
     95       1.47  christos .endif
     96       1.47  christos .if ${MKLDSCRIPT} == "yes"
     97       1.47  christos KMODSCRIPT=	kldscript
     98       1.52  christos MKLDSCRIPTSH=	
     99       1.47  christos .else
    100       1.47  christos KMODSCRIPT=	${KMODSCRIPTSRC}
    101        1.7        ad .endif
    102        1.1        ad 
    103        1.1        ad PROG?=		${KMOD}.kmod
    104        1.1        ad 
    105        1.1        ad ##### Build rules
    106        1.1        ad realall:	${PROG}
    107        1.1        ad 
    108       1.35      matt .if (defined(USE_COMBINE) && ${USE_COMBINE} != "no" && !commands(${_P}) \
    109       1.35      matt    && !defined(NOCOMBINE.${_P}) && !defined(NOCOMBINE))
    110       1.35      matt .for f in ${SRCS:N*.h:N*.sh:N*.fth:C/\.[yl]$/.c/g}
    111       1.35      matt .if (${CPPFLAGS.$f:D1} == "1" || ${CPUFLAGS.$f:D2} == "2" \
    112       1.35      matt      || ${COPTS.$f:D3} == "3" || ${OBJCOPTS.$f:D4} == "4" \
    113       1.35      matt      || ${CXXFLAGS.$f:D5} == "5") \
    114       1.35      matt     || ("${f:M*.[cyl]}" == "" || commands(${f:R:S/$/.o/}))
    115       1.35      matt XOBJS+=		${f:R:S/$/.o/}
    116       1.35      matt .else
    117       1.35      matt XSRCS+=		${f}
    118       1.35      matt NODPSRCS+=	${f}
    119       1.35      matt .endif
    120       1.35      matt .endfor
    121       1.35      matt 
    122       1.35      matt .if !empty(XOBJS)
    123       1.35      matt ${XOBJS}:	${DPSRCS}
    124       1.35      matt .endif
    125       1.35      matt 
    126       1.47  christos .if ${MKLDSCRIPT} == "yes"
    127       1.52  christos ${KMODSCRIPT}: ${KMODSCRIPTSRC} ${XOBJS} $S/conf/mkldscript.sh
    128       1.52  christos 	@rm -f ${.TARGET}
    129       1.50  christos 	@OBJDUMP=${OBJDUMP} ${HOST_SH} $S/conf/mkldscript.sh \
    130       1.52  christos 	    -t ${KMODSCRIPTSRC} ${XOBJS} > ${.TARGET}
    131       1.47  christos .endif
    132       1.52  christos 
    133       1.52  christos ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD} ${KMODSCRIPT}
    134       1.35      matt 	${CC} ${LDFLAGS} -nostdlib -MD -combine -r -Wl,-T,${KMODSCRIPT},-d \
    135       1.46  uebayasi 		-Wl,-Map=${.TARGET}.map \
    136       1.35      matt 		-o ${.TARGET} ${CFLAGS} ${CPPFLAGS} ${XOBJS} \
    137       1.35      matt 		${XSRCS:@.SRC.@${.ALLSRC:M*.c:M*${.SRC.}}@:O:u} && \
    138       1.35      matt 	echo '.-include "${KMOD}.d"' > .depend
    139       1.35      matt 
    140       1.35      matt .else
    141       1.35      matt OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    142       1.35      matt 
    143        1.1        ad ${OBJS} ${LOBJS}: ${DPSRCS}
    144        1.1        ad 
    145       1.52  christos .if ${MKLDSCRIPT} == "yes"
    146       1.52  christos ${KMODSCRIPT}: ${KMODSCRIPTSRC} ${OBJS} $S/conf/mkldscript.sh
    147       1.52  christos 	@rm -f ${.TARGET}
    148       1.52  christos 	@OBJDUMP=${OBJDUMP} ${HOST_SH} $S/conf/mkldscript.sh \
    149       1.52  christos 	    -t ${KMODSCRIPTSRC} ${OBJS} > ${.TARGET}
    150       1.52  christos .endif
    151       1.52  christos 
    152       1.39      matt .if ${MACHINE_CPU} == "arm"
    153       1.39      matt # The solution to limited branch space involves generating trampolines for
    154       1.39      matt # those relocations while creating the module, as the resulting code will
    155       1.39      matt # be much faster and simplifies the loader.
    156       1.39      matt ARCHDIR=	$S/modules/arch/${MACHINE_CPU}
    157       1.39      matt ASM_H=		$S/arch/${MACHINE_CPU}/include/asm.h
    158       1.39      matt CLEANFILES+=	tmp.o tmp.S ${KMOD}_tmp.o ${KMOD}_tramp.o ${KMOD}_tramp.S
    159       1.39      matt ${KMOD}_tmp.o: ${OBJS} ${DPADD}
    160       1.39      matt 	${_MKTARGET_LINK}
    161       1.39      matt 	${LD} -r -o tmp.o ${OBJS}
    162       1.39      matt 	${LD} -r \
    163       1.39      matt 		`${OBJDUMP} --syms --reloc tmp.o | \
    164       1.39      matt 			${TOOL_AWK} -f ${ARCHDIR}/kmodwrap.awk` \
    165       1.39      matt 		 -o ${.TARGET} tmp.o
    166       1.39      matt 
    167       1.39      matt ${KMOD}_tramp.S: ${KMOD}_tmp.o ${ARCHDIR}/kmodtramp.awk ${ASM_H}
    168       1.39      matt 	${_MKTARGET_CREATE}
    169       1.39      matt 	${OBJDUMP} --syms --reloc ${KMOD}_tmp.o | \
    170       1.39      matt 		 ${TOOL_AWK} -f ${ARCHDIR}/kmodtramp.awk \
    171       1.39      matt 		 > tmp.S && \
    172  1.59.12.1  pgoyette 	${MV} tmp.S ${.TARGET}
    173       1.39      matt 
    174       1.39      matt ${PROG}: ${KMOD}_tmp.o ${KMOD}_tramp.o
    175       1.39      matt 	${_MKTARGET_LINK}
    176       1.39      matt .if exists(${ARCHDIR}/kmodhide.awk)
    177       1.46  uebayasi 	${LD} -r -Map=${.TARGET}.map \
    178       1.46  uebayasi 	    -o tmp.o ${KMOD}_tmp.o ${KMOD}_tramp.o
    179       1.39      matt 	${OBJCOPY} \
    180       1.39      matt 		`${NM} tmp.o | ${TOOL_AWK} -f ${ARCHDIR}/kmodhide.awk` \
    181       1.39      matt 		tmp.o ${.TARGET} && \
    182       1.39      matt 	rm tmp.o
    183       1.39      matt .else
    184       1.46  uebayasi 	${LD} -r -Map=${.TARGET}.map \
    185       1.46  uebayasi 	    -o ${.TARGET} ${KMOD}_tmp.o ${KMOD}_tramp.o
    186       1.39      matt .endif
    187       1.39      matt .else
    188       1.52  christos ${PROG}: ${OBJS} ${DPADD} ${KMODSCRIPT}
    189       1.55      matt 	${_MKTARGET_LINK}
    190       1.26    martin 	${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
    191       1.46  uebayasi 		-Wl,-Map=${.TARGET}.map \
    192       1.22      matt 		-o ${.TARGET} ${OBJS}
    193       1.35      matt .endif
    194       1.39      matt .endif
    195       1.58  christos .if defined(CTFMERGE)
    196       1.58  christos 	${CTFMERGE} ${CTFMFLAGS} -o ${.TARGET} ${OBJS}
    197       1.58  christos .endif
    198        1.1        ad 
    199        1.1        ad ##### Install rules
    200        1.1        ad .if !target(kmodinstall)
    201        1.7        ad .if !defined(KMODULEDIR)
    202       1.34  christos _OSRELEASE!=	${HOST_SH} $S/conf/osrelease.sh -k
    203        1.9        he # Ensure these are recorded properly in METALOG on unprived installes:
    204       1.28       mrg KMODULEARCHDIR?= ${MACHINE}
    205       1.28       mrg _INST_DIRS=	${DESTDIR}/stand/${KMODULEARCHDIR}
    206       1.28       mrg _INST_DIRS+=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}
    207       1.28       mrg _INST_DIRS+=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules
    208       1.28       mrg KMODULEDIR=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
    209       1.10    dyoung .endif
    210       1.10    dyoung _PROG:=		${KMODULEDIR}/${PROG} # installed path
    211        1.1        ad 
    212        1.1        ad .if ${MKUPDATE} == "no"
    213        1.1        ad ${_PROG}! ${PROG}					# install rule
    214        1.1        ad .if !defined(BUILD) && !make(all) && !make(${PROG})
    215        1.1        ad ${_PROG}!	.MADE					# no build at install
    216        1.1        ad .endif
    217        1.1        ad .else
    218        1.1        ad ${_PROG}: ${PROG}					# install rule
    219        1.1        ad .if !defined(BUILD) && !make(all) && !make(${PROG})
    220        1.1        ad ${_PROG}:	.MADE					# no build at install
    221        1.1        ad .endif
    222        1.1        ad .endif
    223        1.1        ad 	${_MKTARGET_INSTALL}
    224       1.16   hubertf 	dirs=${_INST_DIRS:Q}; \
    225       1.16   hubertf 	for d in $$dirs; do \
    226        1.9        he 		${INSTALL_DIR} $$d; \
    227        1.9        he 	done
    228        1.7        ad 	${INSTALL_DIR} ${KMODULEDIR}
    229       1.15        ad 	${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
    230        1.1        ad 		${.ALLSRC} ${.TARGET}
    231        1.1        ad 
    232        1.1        ad kmodinstall::	${_PROG}
    233        1.1        ad .PHONY:		kmodinstall
    234        1.1        ad .PRECIOUS:	${_PROG}				# keep if install fails
    235        1.1        ad 
    236        1.1        ad .undef _PROG
    237        1.1        ad .endif # !target(kmodinstall)
    238        1.1        ad 
    239        1.1        ad ##### Clean rules
    240       1.32       apb CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS}
    241       1.46  uebayasi CLEANFILES+= ${PROG}.map
    242       1.47  christos .if ${MKLDSCRIPT} == "yes"
    243       1.47  christos CLEANFILES+= kldscript
    244       1.47  christos .endif
    245        1.1        ad 
    246        1.1        ad ##### Custom rules
    247        1.1        ad lint: ${LOBJS}
    248        1.1        ad .if defined(LOBJS) && !empty(LOBJS)
    249        1.1        ad 	${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[  ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
    250        1.1        ad .endif
    251        1.1        ad 
    252        1.1        ad ##### Pull in related .mk logic
    253       1.19       apb LINKSOWN?= ${KMODULEOWN}
    254       1.19       apb LINKSGRP?= ${KMODULEGRP}
    255       1.19       apb LINKSMODE?= ${KMODULEMODE}
    256        1.1        ad .include <bsd.man.mk>
    257        1.1        ad .include <bsd.links.mk>
    258        1.1        ad .include <bsd.dep.mk>
    259       1.32       apb .include <bsd.clean.mk>
    260        1.1        ad 
    261        1.1        ad .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
    262        1.1        ad .-include "$S/arch/${MACHINE}/include/Makefile.inc"
    263