Home | History | Annotate | Line # | Download | only in mk
bsd.kmodule.mk revision 1.29.2.1
      1 #	$NetBSD: bsd.kmodule.mk,v 1.29.2.1 2011/06/23 14:18:46 cherry 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 clean:		cleankmod
     12 realinstall:	kmodinstall
     13 
     14 KERN=		$S/kern
     15 
     16 CFLAGS+=	-ffreestanding ${COPTS}
     17 CPPFLAGS+=	-nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
     18 CPPFLAGS+=	-isystem ${S}/../common/include
     19 CPPFLAGS+=	-D_KERNEL -D_LKM -D_MODULE
     20 
     21 # XXX until the kernel is fixed again...
     22 .if defined(HAVE_GCC) || defined(HAVE_PCC)
     23 CFLAGS+=	-fno-strict-aliasing -Wno-pointer-sign
     24 .endif
     25 
     26 # XXX This is a workaround for platforms that have relative relocations
     27 # that, when relocated by the module loader, result in addresses that
     28 # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc).
     29 # The real solution to this involves generating trampolines for those
     30 # relocations inside the loader and removing this workaround, as the
     31 # resulting code would be much faster.
     32 .if ${MACHINE_CPU} == "arm"
     33 CFLAGS+=	-mlong-calls
     34 .elif ${MACHINE_CPU} == "powerpc"
     35 CFLAGS+=	-mlongcall
     36 .endif
     37 
     38 # evbppc needs some special help
     39 .if ${MACHINE} == "evbppc"
     40 
     41 . ifndef PPC_INTR_IMPL
     42 PPC_INTR_IMPL=\"powerpc/intr.h\"
     43 . endif
     44 . ifndef PPC_PCI_MACHDEP_IMPL
     45 PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\"
     46 . endif
     47 CPPFLAGS+=      -DPPC_INTR_IMPL=${PPC_INTR_IMPL}
     48 CPPFLAGS+=      -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL}
     49 
     50 . ifdef PPC_IBM4XX
     51 CPPFLAGS+=      -DPPC_IBM4XX
     52 . elifdef PPC_BOOKE
     53 CPPFLAGS+=      -DPPC_BOOKE
     54 . else
     55 CPPFLAGS+=      -DPPC_OEA
     56 . endif
     57 
     58 .endif
     59 
     60 
     61 _YKMSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
     62 DPSRCS+=	${_YKMSRCS}
     63 CLEANFILES+=	${_YKMSRCS}
     64 
     65 .if exists($S/../sys/modules/xldscripts/kmodule)
     66 KMODSCRIPT=	$S/../sys/modules/xldscripts/kmodule
     67 .else
     68 KMODSCRIPT=	${DESTDIR}/usr/libdata/ldscripts/kmodule
     69 .endif
     70 
     71 OBJS+=		${SRCS:N*.h:N*.sh:R:S/$/.o/g}
     72 PROG?=		${KMOD}.kmod
     73 
     74 ##### Build rules
     75 realall:	${PROG}
     76 
     77 ${OBJS} ${LOBJS}: ${DPSRCS}
     78 
     79 ${PROG}: ${OBJS} ${DPADD}
     80 	${_MKTARGET_LINK}
     81 	${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \
     82 		-o ${.TARGET} ${OBJS}
     83 
     84 ##### Install rules
     85 .if !target(kmodinstall)
     86 .if !defined(KMODULEDIR)
     87 _OSRELEASE!=	${HOST_SH} $S/conf/osrelease.sh
     88 # Ensure these are recorded properly in METALOG on unprived installes:
     89 KMODULEARCHDIR?= ${MACHINE}
     90 _INST_DIRS=	${DESTDIR}/stand/${KMODULEARCHDIR}
     91 _INST_DIRS+=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}
     92 _INST_DIRS+=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules
     93 KMODULEDIR=	${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
     94 .endif
     95 _PROG:=		${KMODULEDIR}/${PROG} # installed path
     96 
     97 .if ${MKUPDATE} == "no"
     98 ${_PROG}! ${PROG}					# install rule
     99 .if !defined(BUILD) && !make(all) && !make(${PROG})
    100 ${_PROG}!	.MADE					# no build at install
    101 .endif
    102 .else
    103 ${_PROG}: ${PROG}					# install rule
    104 .if !defined(BUILD) && !make(all) && !make(${PROG})
    105 ${_PROG}:	.MADE					# no build at install
    106 .endif
    107 .endif
    108 	${_MKTARGET_INSTALL}
    109 	dirs=${_INST_DIRS:Q}; \
    110 	for d in $$dirs; do \
    111 		${INSTALL_DIR} $$d; \
    112 	done
    113 	${INSTALL_DIR} ${KMODULEDIR}
    114 	${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \
    115 		${.ALLSRC} ${.TARGET}
    116 
    117 kmodinstall::	${_PROG}
    118 .PHONY:		kmodinstall
    119 .PRECIOUS:	${_PROG}				# keep if install fails
    120 
    121 .undef _PROG
    122 .endif # !target(kmodinstall)
    123 
    124 ##### Clean rules
    125 cleankmod: .PHONY
    126 	rm -f a.out [Ee]rrs mklog core *.core \
    127 		${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
    128 
    129 ##### Custom rules
    130 lint: ${LOBJS}
    131 .if defined(LOBJS) && !empty(LOBJS)
    132 	${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[  ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD}
    133 .endif
    134 
    135 ##### Pull in related .mk logic
    136 LINKSOWN?= ${KMODULEOWN}
    137 LINKSGRP?= ${KMODULEGRP}
    138 LINKSMODE?= ${KMODULEMODE}
    139 .include <bsd.man.mk>
    140 .include <bsd.links.mk>
    141 .include <bsd.dep.mk>
    142 
    143 .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
    144 .-include "$S/arch/${MACHINE}/include/Makefile.inc"
    145