2003-11-04 17:52:22 +03:00
|
|
|
# $NetBSD: bsd.kmod.mk,v 1.71 2003/11/04 14:52:22 scw Exp $
|
1996-08-23 00:33:02 +04:00
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
.include <bsd.init.mk>
|
1997-10-11 12:16:24 +04:00
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
##### Basic targets
|
1997-05-07 19:53:28 +04:00
|
|
|
.PHONY: cleankmod kmodinstall load unload
|
2001-08-14 11:02:13 +04:00
|
|
|
clean: cleankmod
|
2001-11-02 08:21:47 +03:00
|
|
|
realinstall: kmodinstall
|
1997-05-07 00:54:31 +04:00
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
##### Default values
|
2003-10-11 11:15:59 +04:00
|
|
|
.if !defined(S)
|
|
|
|
.if defined(NETBSDSRCDIR)
|
|
|
|
S= ${NETBSDSRCDIR}/sys
|
|
|
|
.elif defined(BSDSRCDIR)
|
|
|
|
S= ${BSDSRCDIR}/sys
|
|
|
|
.else
|
|
|
|
S= /sys
|
|
|
|
.endif
|
|
|
|
.endif
|
1997-05-07 19:53:28 +04:00
|
|
|
KERN= $S/kern
|
1996-08-23 00:33:02 +04:00
|
|
|
|
2001-12-28 10:49:26 +03:00
|
|
|
CFLAGS+= -ffreestanding ${COPTS}
|
2001-11-15 01:01:40 +03:00
|
|
|
CPPFLAGS+= -nostdinc -I. -I${.CURDIR} -isystem $S -isystem $S/arch
|
2001-12-28 10:49:26 +03:00
|
|
|
CPPFLAGS+= -D_KERNEL -D_LKM
|
1996-08-23 00:33:02 +04:00
|
|
|
|
1997-05-09 17:40:34 +04:00
|
|
|
DPSRCS+= ${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
|
2003-08-01 21:03:41 +04:00
|
|
|
CLEANFILES+= ${SRCS:M*.l:.l=.c} ${SRCS:M*.y:.y=.c}
|
|
|
|
CLEANFILES+= ${YHEADER:D${SRCS:M*.y:.y=.h}}
|
2003-09-04 12:27:08 +04:00
|
|
|
CLEANFILES+= machine ${MACHINE_CPU} tmp.o
|
1996-08-28 03:31:47 +04:00
|
|
|
|
2003-09-04 12:27:08 +04:00
|
|
|
# see below why this is necessary
|
2002-07-29 11:42:52 +04:00
|
|
|
.if ${MACHINE} == "sun2" || ${MACHINE} == "sun3"
|
2003-09-04 12:27:08 +04:00
|
|
|
CLEANFILES+= sun68k
|
2002-07-29 11:42:52 +04:00
|
|
|
.elif ${MACHINE} == "sparc64"
|
2003-09-04 12:27:08 +04:00
|
|
|
CLEANFILES+= sparc
|
|
|
|
.elif ${MACHINE} == "i386"
|
|
|
|
CLEANFILES+= x86
|
|
|
|
.elif ${MACHINE} == "amd64"
|
|
|
|
CLEANFILES+= x86
|
2003-05-08 02:36:06 +04:00
|
|
|
CFLAGS+= -mcmodel=kernel
|
2003-11-04 17:52:22 +03:00
|
|
|
.elif ${MACHINE_CPU} == "powerpc" || \
|
|
|
|
${MACHINE_CPU} == "arm"
|
2003-02-19 22:03:41 +03:00
|
|
|
CLEANFILES+= ${KMOD}_tramp.o ${KMOD}_tramp.S tmp.S ${KMOD}_tmp.o
|
2002-07-29 11:42:52 +04:00
|
|
|
.endif
|
|
|
|
|
1997-05-09 17:25:46 +04:00
|
|
|
OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/g}
|
2001-11-02 08:21:47 +03:00
|
|
|
PROG?= ${KMOD}.o
|
|
|
|
MAN?= ${KMOD}.4
|
1996-08-23 00:33:02 +04:00
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
##### Build rules
|
2002-03-21 15:54:21 +03:00
|
|
|
realall: ${PROG}
|
1996-08-23 00:33:02 +04:00
|
|
|
|
2003-08-01 21:03:41 +04:00
|
|
|
${OBJS} ${LOBJS}: ${DPSRCS}
|
2002-03-21 15:54:21 +03:00
|
|
|
|
2003-11-04 17:52:22 +03:00
|
|
|
.if ${MACHINE_CPU} == "powerpc" || \
|
|
|
|
${MACHINE_CPU} == "arm"
|
2003-02-19 22:03:41 +03:00
|
|
|
${KMOD}_tmp.o: ${OBJS} ${DPADD}
|
|
|
|
${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
|
|
|
|
mv tmp.o ${.TARGET}
|
|
|
|
|
2003-11-04 17:52:22 +03:00
|
|
|
${KMOD}_tramp.S: ${KMOD}_tmp.o $S/lkm/arch/${MACHINE_CPU}/lkmtramp.awk
|
2003-02-19 22:03:41 +03:00
|
|
|
${OBJDUMP} --reloc ${KMOD}_tmp.o | \
|
2003-11-04 17:52:22 +03:00
|
|
|
awk -f $S/lkm/arch/${MACHINE_CPU}/lkmtramp.awk > tmp.S
|
2003-02-19 22:03:41 +03:00
|
|
|
mv tmp.S ${.TARGET}
|
|
|
|
|
|
|
|
${PROG}: ${KMOD}_tmp.o ${KMOD}_tramp.o
|
|
|
|
${LD} -r ${LDFLAGS} \
|
|
|
|
`${OBJDUMP} --reloc ${KMOD}_tmp.o | \
|
2003-11-04 17:52:22 +03:00
|
|
|
awk -f $S/lkm/arch/${MACHINE_CPU}/lkmwrap.awk` \
|
2003-02-19 22:03:41 +03:00
|
|
|
-o tmp.o ${KMOD}_tmp.o ${KMOD}_tramp.o
|
2003-11-04 17:52:22 +03:00
|
|
|
.if exists($S/lkm/arch/${MACHINE_CPU}/lkmhide.awk)
|
2003-04-23 22:34:20 +04:00
|
|
|
${OBJCOPY} \
|
2003-11-04 17:52:22 +03:00
|
|
|
`${NM} tmp.o | awk -f $S/lkm/arch/${MACHINE_CPU}/lkmhide.awk` \
|
2003-07-18 08:04:03 +04:00
|
|
|
tmp.o tmp1.o
|
2003-04-23 22:34:20 +04:00
|
|
|
mv tmp1.o tmp.o
|
|
|
|
.endif
|
2003-02-19 22:03:41 +03:00
|
|
|
mv tmp.o ${.TARGET}
|
|
|
|
.else
|
2002-03-21 15:54:21 +03:00
|
|
|
${PROG}: ${OBJS} ${DPADD}
|
1996-08-23 00:33:02 +04:00
|
|
|
${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
|
|
|
|
mv tmp.o ${.TARGET}
|
2003-02-19 22:03:41 +03:00
|
|
|
.endif
|
1996-08-23 00:33:02 +04:00
|
|
|
|
2003-09-04 12:27:08 +04:00
|
|
|
# XXX. This should be done a better way. It's @'d to reduce visual spew.
|
|
|
|
# XXX .BEGIN is used to make sure the links are done before anything else.
|
|
|
|
.if make(depend) || make(all) || make(dependall)
|
|
|
|
.BEGIN:
|
|
|
|
@rm -f machine && \
|
|
|
|
ln -s $S/arch/${MACHINE}/include machine
|
|
|
|
@rm -f ${MACHINE_CPU} && \
|
|
|
|
ln -s $S/arch/${MACHINE_CPU}/include ${MACHINE_CPU}
|
|
|
|
# XXX. it gets worse..
|
|
|
|
.if ${MACHINE} == "sun2" || ${MACHINE} == "sun3"
|
|
|
|
@rm -f sun68k && \
|
|
|
|
ln -s $S/arch/sun68k/include sun68k
|
|
|
|
.endif
|
|
|
|
.if ${MACHINE} == "sparc64"
|
|
|
|
@rm -f sparc && \
|
|
|
|
ln -s $S/arch/sparc/include sparc
|
|
|
|
.endif
|
|
|
|
.if ${MACHINE} == "amd64"
|
|
|
|
@rm -f x86 && \
|
|
|
|
ln -s $S/arch/x86/include x86
|
|
|
|
.endif
|
|
|
|
.if ${MACHINE_CPU} == "i386"
|
|
|
|
@rm -f x86 && \
|
|
|
|
ln -s $S/arch/x86/include x86
|
|
|
|
.endif
|
|
|
|
.endif
|
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
##### Install rules
|
1997-05-07 21:17:20 +04:00
|
|
|
.if !target(kmodinstall)
|
2001-11-02 08:21:47 +03:00
|
|
|
_PROG:= ${DESTDIR}${KMODDIR}/${PROG} # installed path
|
2000-06-06 13:22:00 +04:00
|
|
|
|
2003-07-18 12:26:01 +04:00
|
|
|
.if ${MKUPDATE} == "no"
|
2002-02-12 00:14:58 +03:00
|
|
|
${_PROG}! ${PROG} # install rule
|
|
|
|
.if !defined(BUILD) && !make(all) && !make(${PROG})
|
|
|
|
${_PROG}! .MADE # no build at install
|
|
|
|
.endif
|
|
|
|
.else
|
2001-11-02 08:21:47 +03:00
|
|
|
${_PROG}: ${PROG} # install rule
|
2002-02-12 00:14:58 +03:00
|
|
|
.if !defined(BUILD) && !make(all) && !make(${PROG})
|
|
|
|
${_PROG}: .MADE # no build at install
|
|
|
|
.endif
|
|
|
|
.endif
|
2001-11-02 08:21:47 +03:00
|
|
|
${INSTALL_FILE} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
|
2002-10-22 22:48:27 +04:00
|
|
|
${SYSPKGTAG} ${.ALLSRC} ${.TARGET}
|
2000-06-06 13:53:29 +04:00
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
kmodinstall:: ${_PROG}
|
|
|
|
.PRECIOUS: ${_PROG} # keep if install fails
|
1997-03-25 00:54:12 +03:00
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
.undef _PROG
|
|
|
|
.endif # !target(kmodinstall)
|
|
|
|
|
|
|
|
##### Clean rules
|
|
|
|
cleankmod:
|
|
|
|
rm -f a.out [Ee]rrs mklog core *.core \
|
|
|
|
${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
|
|
|
|
|
|
|
|
##### Custom rules
|
1996-08-23 00:33:02 +04:00
|
|
|
lint: ${LOBJS}
|
|
|
|
.if defined(LOBJS) && !empty(LOBJS)
|
1997-11-04 01:51:23 +03:00
|
|
|
${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
|
1996-08-23 00:33:02 +04:00
|
|
|
.endif
|
|
|
|
|
|
|
|
.if !target(load)
|
2001-11-02 08:21:47 +03:00
|
|
|
load: ${PROG}
|
2001-09-30 00:10:07 +04:00
|
|
|
/sbin/modload ${KMOD_LOADFLAGS} -o ${KMOD} ${PROG}
|
1996-08-23 00:33:02 +04:00
|
|
|
.endif
|
|
|
|
|
|
|
|
.if !target(unload)
|
1999-11-03 01:42:51 +03:00
|
|
|
unload:
|
1996-08-23 00:33:02 +04:00
|
|
|
/sbin/modunload -n ${KMOD}
|
|
|
|
.endif
|
|
|
|
|
2001-11-02 08:21:47 +03:00
|
|
|
##### Pull in related .mk logic
|
1996-08-23 00:33:02 +04:00
|
|
|
.include <bsd.man.mk>
|
1997-03-25 00:54:12 +03:00
|
|
|
.include <bsd.links.mk>
|
1996-08-23 00:33:02 +04:00
|
|
|
.include <bsd.sys.mk>
|
2003-07-31 17:47:32 +04:00
|
|
|
.include <bsd.dep.mk>
|
1999-03-10 09:34:19 +03:00
|
|
|
|
2001-10-05 19:30:06 +04:00
|
|
|
.-include "$S/arch/${MACHINE_CPU}/include/Makefile.inc"
|
|
|
|
.-include "$S/arch/${MACHINE}/include/Makefile.inc"
|