Home | History | Annotate | Line # | Download | only in mk
bsd.kmodule.mk revision 1.35
      1 #	$NetBSD: bsd.kmodule.mk,v 1.35 2012/02/19 23:19:37 matt Exp $
      2 
      3 # We are not building this with PIE
      4 MKPIE=no
      5 
      6 .include <bsd.init.mk>
      7 .include <bsd.klinks.mk>
      8 .include <bsd.sys.mk>
      9 
     10 ##### Basic targets
     11 realinstall:	kmodinstall
     12 
     13 KERN=		$S/kern
     14 
     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
     19 
     20 # XXX until the kernel is fixed again...
     21 .if defined(HAVE_GCC) || defined(HAVE_PCC)
     22 CFLAGS+=	-fno-strict-aliasing -Wno-pointer-sign
     23 .endif
     24 
     25 # XXX This is a workaround for platforms that have relative relocations
     26 # that, when relocated by the module loader, result in addresses that
     27 # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
     28 # The real solution to this involves generating trampolines for those
     29 # relocations inside the loader and removing this workaround, as the
     30 # resulting code would be much faster.
     31 .if ${MACHINE_CPU} == "arm"
     32 CFLAGS+=	-mlong-calls
     33 .elif ${MACHINE_CPU} == "powerpc"
     34 CFLAGS+=	-mlongcall
     35 .elif ${MACHINE_CPU} == "vax"
     36 CFLAGS+=	-fno-pic
     37 .endif
     38 
     39 # evbppc needs some special help
     40 .if ${MACHINE} == "evbppc"
     41 
     42 . ifndef PPC_INTR_IMPL
     43 PPC_INTR_IMPL=\"powerpc/intr.h\"
     44 . endif
     45 . ifndef PPC_PCI_MACHDEP_IMPL
     46 PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\"
     47 . endif
     48 CPPFLAGS+=      -DPPC_INTR_IMPL=${PPC_INTR_IMPL}
     49 CPPFLAGS+=      -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL}
     50 
     51 . ifdef PPC_IBM4XX
     52 CPPFLAGS+=      -DPPC_IBM4XX
     53 . elifdef PPC_BOOKE
     54 CPPFLAGS+=      -DPPC_BOOKE
     55 . else
     56 CPPFLAGS+=      -DPPC_OEA
     57 . endif
     58 
     59 .endif
     60 
     61 
     62 _YKMSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
     63 DPSRCS+=	${_YKMSRCS}
     64 CLEANFILES+=	${_YKMSRCS}
     65 
     66 .if exists($S/../sys/modules/xldscripts/kmodule)
     67 KMODSCRIPT=	$S/../sys/modules/xldscripts/kmodule
     68 .else
     69 KMODSCRIPT=	${DESTDIR}/usr/libdata/ldscripts/kmodule
     70 .endif
     71 
     72 PROG?=		${KMOD}.kmod
     73 
     74 ##### Build rules
     75 realall:	${PROG}
     76 
     77 .if (defined(USE_COMBINE) && ${USE_COMBINE} != "no" && !commands(${_P}) \
     78    && !defined(NOCOMBINE.${_P}) && !defined(NOCOMBINE))
     79 .for f in ${SRCS:N*.h:N*.sh:N*.fth:C/\.[yl]$/.c/g}
     80 .if (${CPPFLAGS.$f:D1} == "1" || ${CPUFLAGS.$f:D2} == "2" \
     81      || ${COPTS.$f:D3} == "3" || ${OBJCOPTS.$f:D4} == "4" \
     82      || ${CXXFLAGS.$f:D5} == "5") \
     83     || ("${f:M*.[cyl]}" == "" || commands(${f:R:S/$/.o/}))
     84 XOBJS+=		${f:R:S/$/.o/}
     85 .else
     86 XSRCS+=		${f}
     87 NODPSRCS+=	${f}
     88 .endif
     89 .endfor
     90 
     91 .if !empty(XOBJS)
     92 ${XOBJS}:	${DPSRCS}
     93 .endif
     94 
     95 ${PROG}: ${XOBJS} ${XSRCS} ${DPSRCS} ${DPADD}
     96 	${_MKTARGET_LINK}
     97 	${CC} ${LDFLAGS} -nostdlib -MD -combine -r -Wl,-T,${KMODSCRIPT},-d \
     98 		-o ${.TARGET} ${CFLAGS} ${CPPFLAGS} ${XOBJS} \
     99 		${XSRCS:@.SRC.@${.ALLSRC:M*.c:M*${.SRC.}}@:O:u} && \
    100 	echo '.-include "${KMOD}.d"' > .depend
    101 
    102 .else
    103 OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
    104 
    105 ${OBJS} ${LOBJS}: ${DPSRCS}
    106 
    107 ${PROG}: ${OBJS} ${DPADD}
    108 	${_MKTARGET_LINK}
    109 	${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
    110 		-o ${.TARGET} ${OBJS}
    111 .endif
    112 
    113 ##### Install rules
    114 .if !target(kmodinstall)
    115 .if !defined(KMODULEDIR)
    116 _OSRELEASE!=	${HOST_SH} $S/conf/osrelease.sh -k
    117 # Ensure these are recorded properly in METALOG on unprived installes:
    118 KMODULEARCHDIR?= ${MACHINE}
    119 _INST_DIRS=	${DESTDIR}/stand/${KMODULEARCHDIR}
    120 _INST_DIRS+=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}
    121 _INST_DIRS+=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules
    122 KMODULEDIR=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
    123 .endif
    124 _PROG:=		${KMODULEDIR}/${PROG} # installed path
    125 
    126 .if ${MKUPDATE} == "no"
    127 ${_PROG}! ${PROG}					# install rule
    128 .if !defined(BUILD) && !make(all) && !make(${PROG})
    129 ${_PROG}!	.MADE					# no build at install
    130 .endif
    131 .else
    132 ${_PROG}: ${PROG}					# install rule
    133 .if !defined(BUILD) && !make(all) && !make(${PROG})
    134 ${_PROG}:	.MADE					# no build at install
    135 .endif
    136 .endif
    137 	${_MKTARGET_INSTALL}
    138 	dirs=${_INST_DIRS:Q}; \
    139 	for d in $$dirs; do \
    140 		${INSTALL_DIR} $$d; \
    141 	done
    142 	${INSTALL_DIR} ${KMODULEDIR}
    143 	${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
    144 		${.ALLSRC} ${.TARGET}
    145 
    146 kmodinstall::	${_PROG}
    147 .PHONY:		kmodinstall
    148 .PRECIOUS:	${_PROG}				# keep if install fails
    149 
    150 .undef _PROG
    151 .endif # !target(kmodinstall)
    152 
    153 ##### Clean rules
    154 CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS}
    155 
    156 ##### Custom rules
    157 lint: ${LOBJS}
    158 .if defined(LOBJS) && !empty(LOBJS)
    159 	${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[  ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
    160 .endif
    161 
    162 ##### Pull in related .mk logic
    163 LINKSOWN?= ${KMODULEOWN}
    164 LINKSGRP?= ${KMODULEGRP}
    165 LINKSMODE?= ${KMODULEMODE}
    166 .include <bsd.man.mk>
    167 .include <bsd.links.mk>
    168 .include <bsd.dep.mk>
    169 .include <bsd.clean.mk>
    170 
    171 .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
    172 .-include "$S/arch/${MACHINE}/include/Makefile.inc"
    173