kmod.mk revision 2765
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.prog.mk,v 1.5 1994/09/11 21:28:30 rgrimes Exp $
3
4.if exists(${.CURDIR}/../Makefile.inc)
5.include "${.CURDIR}/../Makefile.inc"
6.endif
7
8.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
9
10#
11# Assume that we are in /usr/src/foo/bar, so /sys is
12# ${.CURDIR}/../../sys.  We don't bother adding a .PATH since nothing
13# actually lives in /sys directly.
14#
15CFLAGS+=${COPTS} -DKERNEL -I${.CURDIR}/../../sys -W -Wcomment -Wredundant-decls
16
17KMODGRP?=	bin
18KMODOWN?=	bin
19KMODMODE?=	555
20
21INSTALL?=	install
22
23DPSRCS+= ${SRCS:M*.h}
24OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
25
26.if !defined(PROG)
27PROG=	${KMOD}.o
28.endif
29
30${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 
31	${LD} -r ${LDFLAGS} -o ${.TARGET} ${OBJS}
32
33MKDEP=	-p
34
35.if	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
36	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
37	!defined(MAN7) && !defined(MAN8) && !defined(NOMAN)
38MAN1=	${KMOD}.4
39.endif
40
41_PROGSUBDIR: .USE
42.if defined(SUBDIR) && !empty(SUBDIR)
43	@for entry in ${SUBDIR}; do \
44		(${ECHODIR} "===> $$entry"; \
45		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
46			cd ${.CURDIR}/$${entry}.${MACHINE}; \
47		else \
48			cd ${.CURDIR}/$${entry}; \
49		fi; \
50		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}); \
51	done
52.endif
53
54.MAIN: all
55all: ${PROG} _PROGSUBDIR
56
57.if !target(clean)
58clean: _PROGSUBDIR
59	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES} 
60.endif
61
62.if !target(cleandir)
63cleandir: _PROGSUBDIR
64	rm -f a.out [Ee]rrs mklog ${PROG} ${OBJS} ${CLEANFILES}
65	rm -f ${.CURDIR}/tags .depend
66	cd ${.CURDIR}; rm -rf obj;
67.endif
68
69.if !target(install)
70.if !target(beforeinstall)
71beforeinstall:
72.endif
73.if !target(afterinstall)
74afterinstall:
75.endif
76
77realinstall: _PROGSUBDIR
78	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
79	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
80.if defined(LINKS) && !empty(LINKS)
81	@set ${LINKS}; \
82	while test $$# -ge 2; do \
83		l=${DESTDIR}$$1; \
84		shift; \
85		t=${DESTDIR}$$1; \
86		shift; \
87		${ECHO} $$t -\> $$l; \
88		rm -f $$t; \
89		ln $$l $$t; \
90	done; true
91.endif
92
93install: afterinstall
94.if !defined(NOMAN)
95afterinstall: realinstall maninstall
96.else
97afterinstall: realinstall
98.endif
99realinstall: beforeinstall
100.endif
101
102.if !target(obj)
103.if defined(NOOBJ)
104obj: _PROGSUBDIR
105.else
106obj: _PROGSUBDIR
107	@cd ${.CURDIR}; rm -rf obj; \
108	here=`pwd`; dest=/usr/obj`echo $$here | sed 's,^/usr/src,,'`; \
109	${ECHO} "$$here -> $$dest"; ln -s $$dest obj; \
110	if test -d /usr/obj -a ! -d $$dest; then \
111		mkdir -p $$dest; \
112	else \
113		true; \
114	fi;
115.endif
116.endif
117
118.if !target(tags)
119tags: ${SRCS} _PROGSUBDIR
120.if defined(PROG)
121	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
122	    sed "s;\${.CURDIR}/;;" > tags
123.endif
124.endif
125
126.if !defined(NOMAN)
127.include <bsd.man.mk>
128.elif !target(maninstall)
129maninstall:
130.endif
131
132.if !target(load)
133load:	${PROG}
134	/sbin/modload -o ${KMOD} -e${KMOD} ${PROG}
135.endif
136
137.if !target(unload)
138unload:	${PROG}
139	/sbin/modunload -n ${KMOD}
140.endif
141
142.include <bsd.dep.mk>
143