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