NetBSD/share/mk/bsd.kmod.mk
cgd 1d20ab5d2e if 'clean' is not already defined, rather than simply defining it with
a bunch of rules, define a clean{kmod,lib,prog} target with the rules,
and have both clean and cleandir depend on that.  That eliminates a bug
where 'cleandir' in a directory which included e.g. bsd.prog.mk but which
also had subdirs would 'make clean' all the subdirs and then 'make cleandir'
all ofthe subdirs.  It also allows Makefiles to add more dependencies
to 'clean' after inclusion of the make template.

If 'clean' is already defined, the behaviour is the same as it used to be.
1997-01-22 01:34:11 +00:00

122 lines
2.1 KiB
Makefile

# $NetBSD: bsd.kmod.mk,v 1.7 1997/01/22 01:34:11 cgd Exp $
S!= cd ${.CURDIR}/..;pwd
KERN= $S/kern
.if exists(${.CURDIR}/../Makefile.inc)
.include "${.CURDIR}/../Makefile.inc"
.endif
.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
.include <bsd.own.mk>
CFLAGS+= ${COPTS} -D_KERNEL -D_LKM -I. -I${.CURDIR} -I$S -I$S/arch
CLEANFILES+= machine ${MACHINE}
DPSRCS+= ${SRCS:M*.h}
OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
.if !defined(PROG)
PROG= ${KMOD}.o
.endif
${PROG}: ${DPSRCS} ${OBJS} ${DPADD}
${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
mv tmp.o ${.TARGET}
.if !defined(MAN)
MAN= ${KMOD}.4
.endif
.MAIN: all
all: machine ${PROG} _SUBDIRUSE
machine:
ln -s $S/arch/${MACHINE}/include machine
ln -s machine ${MACHINE}
.if !target(clean)
cleankmod:
rm -f a.out [Ee]rrs mklog core *.core \
${PROG} ${OBJS} ${LOBJS} ${CLEANFILES}
clean: _SUBDIRUSE cleankmod
cleandir: _SUBDIRUSE cleankmod
.else
cleandir: _SUBDIRUSE clean
.endif
#
# if no beforedepend target is defined, generate an empty target here
#
.if !target(beforedepend)
beforedepend: machine
.endif
#
# define various install targets
#
.if !target(install)
.if !target(beforeinstall)
beforeinstall:
.endif
.if !target(afterinstall)
afterinstall:
.endif
.if !target(realinstall)
realinstall:
${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
${PROG} ${DESTDIR}${KMODDIR}
.endif
install: maninstall _SUBDIRUSE
.if defined(LINKS) && !empty(LINKS)
@set ${LINKS}; \
while test $$# -ge 2; do \
l=${DESTDIR}$$1; \
shift; \
t=${DESTDIR}$$1; \
shift; \
${ECHO} $$t -\> $$l; \
rm -f $$t; \
ln $$l $$t; \
done; true
.endif
maninstall: afterinstall
afterinstall: realinstall
realinstall: beforeinstall
.endif
.if !target(lint)
lint: ${LOBJS}
.if defined(LOBJS) && !empty(LOBJS)
@${LINT} ${LINTFLAGS} ${LDFLAGS:M-L*} ${LOBJS} ${LDADD}
.endif
.endif
.if !target(load)
load: ${PROG}
/sbin/modload -o ${KMOD} -e${KMOD}_lkmentry ${PROG}
.endif
.if !target(unload)
unload: ${PROG}
/sbin/modunload -n ${KMOD}
.endif
.include <bsd.dep.mk>
.if !defined(NOMAN)
.include <bsd.man.mk>
.endif
.include <bsd.obj.mk>
.include <bsd.dep.mk>
.include <bsd.subdir.mk>
.include <bsd.sys.mk>