1 1.24 jmmv # $NetBSD: bsd.kmodule.mk,v 1.24 2010/01/18 23:39:07 jmmv 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.1 ad 21 1.1 ad # XXX until the kernel is fixed again... 22 1.11 gmcgarry .if (defined(HAVE_GCC) && ${HAVE_GCC} == 4) || defined(HAVE_PCC) 23 1.1 ad CFLAGS+= -fno-strict-aliasing -Wno-pointer-sign 24 1.1 ad .endif 25 1.1 ad 26 1.24 jmmv # XXX This is a workaround for platforms that have relative relocations 27 1.24 jmmv # that, when relocated by the module loader, result in addresses that 28 1.24 jmmv # overflow the size of the relocation (e.g. R_PPC_REL24 in powerpc). 29 1.24 jmmv # The real solution to this involves generating trampolines for those 30 1.24 jmmv # relocations inside the loader and removing this workaround, as the 31 1.24 jmmv # resulting code would be much faster. 32 1.24 jmmv .if ${MACHINE_CPU} == "arm" 33 1.24 jmmv CFLAGS+= -mlong-calls 34 1.24 jmmv .elif ${MACHINE_CPU} == "powerpc" 35 1.24 jmmv CFLAGS+= -mlongcall 36 1.24 jmmv .endif 37 1.24 jmmv 38 1.1 ad _YKMSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} 39 1.1 ad DPSRCS+= ${_YKMSRCS} 40 1.1 ad CLEANFILES+= ${_YKMSRCS} 41 1.7 ad 42 1.21 skrll .if exists($S/../sys/modules/xldscripts/kmodule) 43 1.21 skrll KMODSCRIPT= $S/../sys/modules/xldscripts/kmodule 44 1.7 ad .else 45 1.12 mrg KMODSCRIPT= ${DESTDIR}/usr/libdata/ldscripts/kmodule 46 1.7 ad .endif 47 1.1 ad 48 1.1 ad OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g} 49 1.1 ad PROG?= ${KMOD}.kmod 50 1.1 ad 51 1.1 ad ##### Build rules 52 1.1 ad realall: ${PROG} 53 1.1 ad 54 1.1 ad ${OBJS} ${LOBJS}: ${DPSRCS} 55 1.1 ad 56 1.1 ad ${PROG}: ${OBJS} ${DPADD} 57 1.1 ad ${_MKTARGET_LINK} 58 1.23 mrg ${CC} ${LDFLAGS} -nostdlib -r -Wl,-T,${KMODSCRIPT},-d \ 59 1.22 matt -o ${.TARGET} ${OBJS} 60 1.1 ad 61 1.1 ad ##### Install rules 62 1.1 ad .if !target(kmodinstall) 63 1.7 ad .if !defined(KMODULEDIR) 64 1.7 ad _OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh 65 1.9 he # Ensure these are recorded properly in METALOG on unprived installes: 66 1.18 rmind _INST_DIRS= ${DESTDIR}/stand/${MACHINE} 67 1.18 rmind _INST_DIRS+= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE} 68 1.18 rmind _INST_DIRS+= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}/modules 69 1.18 rmind KMODULEDIR= ${DESTDIR}/stand/${MACHINE}/${_OSRELEASE}/modules/${KMOD} 70 1.10 dyoung .endif 71 1.10 dyoung _PROG:= ${KMODULEDIR}/${PROG} # installed path 72 1.1 ad 73 1.1 ad .if ${MKUPDATE} == "no" 74 1.1 ad ${_PROG}! ${PROG} # install rule 75 1.1 ad .if !defined(BUILD) && !make(all) && !make(${PROG}) 76 1.1 ad ${_PROG}! .MADE # no build at install 77 1.1 ad .endif 78 1.1 ad .else 79 1.1 ad ${_PROG}: ${PROG} # install rule 80 1.1 ad .if !defined(BUILD) && !make(all) && !make(${PROG}) 81 1.1 ad ${_PROG}: .MADE # no build at install 82 1.1 ad .endif 83 1.1 ad .endif 84 1.1 ad ${_MKTARGET_INSTALL} 85 1.16 hubertf dirs=${_INST_DIRS:Q}; \ 86 1.16 hubertf for d in $$dirs; do \ 87 1.9 he ${INSTALL_DIR} $$d; \ 88 1.9 he done 89 1.7 ad ${INSTALL_DIR} ${KMODULEDIR} 90 1.15 ad ${INSTALL_FILE} -o ${KMODULEOWN} -g ${KMODULEGRP} -m ${KMODULEMODE} \ 91 1.1 ad ${.ALLSRC} ${.TARGET} 92 1.1 ad 93 1.1 ad kmodinstall:: ${_PROG} 94 1.1 ad .PHONY: kmodinstall 95 1.1 ad .PRECIOUS: ${_PROG} # keep if install fails 96 1.1 ad 97 1.1 ad .undef _PROG 98 1.1 ad .endif # !target(kmodinstall) 99 1.1 ad 100 1.1 ad ##### Clean rules 101 1.1 ad cleankmod: .PHONY 102 1.1 ad rm -f a.out [Ee]rrs mklog core *.core \ 103 1.1 ad ${PROG} ${OBJS} ${LOBJS} ${CLEANFILES} 104 1.1 ad 105 1.1 ad ##### Custom rules 106 1.1 ad lint: ${LOBJS} 107 1.1 ad .if defined(LOBJS) && !empty(LOBJS) 108 1.1 ad ${LINT} ${LINTFLAGS} ${LDFLAGS:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS} ${LDADD} 109 1.1 ad .endif 110 1.1 ad 111 1.1 ad ##### Pull in related .mk logic 112 1.19 apb LINKSOWN?= ${KMODULEOWN} 113 1.19 apb LINKSGRP?= ${KMODULEGRP} 114 1.19 apb LINKSMODE?= ${KMODULEMODE} 115 1.1 ad .include <bsd.man.mk> 116 1.1 ad .include <bsd.links.mk> 117 1.1 ad .include <bsd.dep.mk> 118 1.1 ad 119 1.1 ad .-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc" 120 1.1 ad .-include "$S/arch/${MACHINE}/include/Makefile.inc" 121