1# $NetBSD: bsd.kmodule.mk,v 1.38 2013/08/06 06:08:39 skrll Exp $ 2 3# We are not building this with PIE 4MKPIE=no 5 6.include <bsd.init.mk> 7.include <bsd.klinks.mk> 8.include <bsd.sys.mk> 9 10##### Basic targets 11realinstall: kmodinstall 12 13KERN= $S/kern 14 15CFLAGS+= -ffreestanding ${COPTS} 16CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch 17CPPFLAGS+= -isystem ${S}/../common/include 18CPPFLAGS+= -D_KERNEL -D_LKM -D_MODULE -DSYSCTL_INCLUDE_DESCR 19 20# XXX until the kernel is fixed again... 21CFLAGS+= -fno-strict-aliasing -Wno-pointer-sign 22 23# XXX This is a workaround for platforms that have relative relocations 24# that, when relocated by the module loader, result in addresses that 25# overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc). 26# The real solution to this involves generating trampolines for those 27# relocations inside the loader and removing this workaround, as the 28# resulting code would be much faster. 29.if ${MACHINE_CPU} == "arm" 30CFLAGS+= -mlong-calls 31.elif ${MACHINE_CPU} == "hppa" 32CFLAGS+= -mlong-calls 33.elif ${MACHINE_CPU} == "powerpc" 34CFLAGS+= -mlongcall 35.elif ${MACHINE_CPU} == "vax" 36CFLAGS+= -fno-pic 37.endif 38 39# evbppc needs some special help 40.if ${MACHINE} == "evbppc" 41 42. ifndef PPC_INTR_IMPL 43PPC_INTR_IMPL=\"powerpc/intr.h\" 44. endif 45. ifndef PPC_PCI_MACHDEP_IMPL 46PPC_PCI_MACHDEP_IMPL=\"powerpc/pci_machdep.h\" 47. endif 48CPPFLAGS+= -DPPC_INTR_IMPL=${PPC_INTR_IMPL} 49CPPFLAGS+= -DPPC_PCI_MACHDEP_IMPL=${DPPC_PCI_MACHDEP_IMPL} 50 51. ifdef PPC_IBM4XX 52CPPFLAGS+= -DPPC_IBM4XX 53. elifdef PPC_BOOKE 54CPPFLAGS+= -DPPC_BOOKE 55. else 56CPPFLAGS+= -DPPC_OEA 57. endif 58 59.endif 60 61 62_YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 63DPSRCS+= ${_YKMSRCS} 64CLEANFILES+= ${_YKMSRCS} 65 66.if exists($S/../sys/modules/xldscripts/kmodule) 67KMODSCRIPT= $S/../sys/modules/xldscripts/kmodule 68.else 69KMODSCRIPT= ${DESTDIR}/usr/libdata/ldscripts/kmodule 70.endif 71 72PROG?= ${KMOD}.kmod 73 74##### Build rules 75realall: ${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/})) 84XOBJS+= ${f:R:S/$/.o/} 85.else 86XSRCS+= ${f} 87NODPSRCS+= ${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 103OBJS+= ${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: 118KMODULEARCHDIR?= ${MACHINE} 119_INST_DIRS= ${DESTDIR}/stand/${KMODULEARCHDIR} 120_INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE} 121_INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules 122KMODULEDIR= ${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 146kmodinstall:: ${_PROG} 147.PHONY: kmodinstall 148.PRECIOUS: ${_PROG} # keep if install fails 149 150.undef _PROG 151.endif # !target(kmodinstall) 152 153##### Clean rules 154CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS} 155 156##### Custom rules 157lint: ${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 163LINKSOWN?= ${KMODULEOWN} 164LINKSGRP?= ${KMODULEGRP} 165LINKSMODE?= ${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