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