1# $NetBSD$ 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... 21.if defined(HAVE_GCC) || defined(HAVE_PCC) 22CFLAGS+= -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" 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 72OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g} 73PROG?= ${KMOD}.kmod 74 75##### Build rules 76realall: ${PROG} 77 78${OBJS} ${LOBJS}: ${DPSRCS} 79 80${PROG}: ${OBJS} ${DPADD} 81 ${_MKTARGET_LINK} 82 ${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \ 83 -o ${.TARGET} ${OBJS} 84 85##### Install rules 86.if !target(kmodinstall) 87.if !defined(KMODULEDIR) 88_OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh -k 89# Ensure these are recorded properly in METALOG on unprived installes: 90KMODULEARCHDIR?= ${MACHINE} 91_INST_DIRS= ${DESTDIR}/stand/${KMODULEARCHDIR} 92_INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE} 93_INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules 94KMODULEDIR= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD} 95.endif 96_PROG:= ${KMODULEDIR}/${PROG} # installed path 97 98.if ${MKUPDATE} == "no" 99${_PROG}! ${PROG} # install rule 100.if !defined(BUILD) && !make(all) && !make(${PROG}) 101${_PROG}! .MADE # no build at install 102.endif 103.else 104${_PROG}: ${PROG} # install rule 105.if !defined(BUILD) && !make(all) && !make(${PROG}) 106${_PROG}: .MADE # no build at install 107.endif 108.endif 109 ${_MKTARGET_INSTALL} 110 dirs=${_INST_DIRS:Q}; \ 111 for d in $$dirs; do \ 112 ${INSTALL_DIR} $$d; \ 113 done 114 ${INSTALL_DIR} ${KMODULEDIR} 115 ${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \ 116 ${.ALLSRC} ${.TARGET} 117 118kmodinstall:: ${_PROG} 119.PHONY: kmodinstall 120.PRECIOUS: ${_PROG} # keep if install fails 121 122.undef _PROG 123.endif # !target(kmodinstall) 124 125##### Clean rules 126CLEANFILES+= a.out [Ee]rrs mklog core *.core ${PROG} ${OBJS} ${LOBJS} 127 128##### Custom rules 129lint: ${LOBJS} 130.if defined(LOBJS) && !empty(LOBJS) 131 ${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD} 132.endif 133 134##### Pull in related .mk logic 135LINKSOWN?= ${KMODULEOWN} 136LINKSGRP?= ${KMODULEGRP} 137LINKSMODE?= ${KMODULEMODE} 138.include <bsd.man.mk> 139.include <bsd.links.mk> 140.include <bsd.dep.mk> 141.include <bsd.clean.mk> 142 143.-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc" 144.-include "$S/arch/${MACHINE}/include/Makefile.inc" 145