xref: /freebsd/sys/conf/kmod.mk (revision 505222d35fea6a81779095049a6e87ddb6d78db4)
1639a2e50SGarrett Wollman#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
27f3dea24SPeter Wemm# $FreeBSD$
353996fadSWolfram Schneider#
4fe3cac87SNick Hibma# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
5fe3cac87SNick Hibma# drivers (KLD's).
653996fadSWolfram Schneider#
753996fadSWolfram Schneider#
853996fadSWolfram Schneider# +++ variables +++
953996fadSWolfram Schneider#
1053996fadSWolfram Schneider# CLEANFILES	Additional files to remove for the clean and cleandir targets.
1153996fadSWolfram Schneider#
1253996fadSWolfram Schneider# DISTRIBUTION  Name of distribution. [bin]
1353996fadSWolfram Schneider#
14fe3cac87SNick Hibma# KMOD          The name of the kernel module to build.
1553996fadSWolfram Schneider#
163bdfa9e5SDavid E. O'Brien# KMODDIR	Base path for kernel modules (see kld(4)). [/boot/kernel]
1753996fadSWolfram Schneider#
18fe3cac87SNick Hibma# KMODOWN	KLD owner. [${BINOWN}]
1953996fadSWolfram Schneider#
20fe3cac87SNick Hibma# KMODGRP	KLD group. [${BINGRP}]
2153996fadSWolfram Schneider#
22fe3cac87SNick Hibma# KMODMODE	KLD mode. [${BINMODE}]
2353996fadSWolfram Schneider#
24fe3cac87SNick Hibma# LINKS		The list of KLD links; should be full pathnames, the
2553996fadSWolfram Schneider#               linked-to file coming first, followed by the linked
2653996fadSWolfram Schneider#               file.  The files are hard-linked.  For example, to link
2771395925SPeter Wemm#               /modules/master and /modules/meister, use:
2853996fadSWolfram Schneider#
2971395925SPeter Wemm#			LINKS=  /modules/master /modules/meister
3053996fadSWolfram Schneider#
31fe3cac87SNick Hibma# KMODLOAD	Command to load a kernel module [/sbin/kldload]
327bc830bbSWolfram Schneider#
33fe3cac87SNick Hibma# KMODUNLOAD	Command to unload a kernel module [/sbin/kldunload]
347bc830bbSWolfram Schneider#
35fe3cac87SNick Hibma# NOMAN		KLD does not have a manual page if set.
3653996fadSWolfram Schneider#
37fe3cac87SNick Hibma# PROG          The name of the kernel module to build.
387bc830bbSWolfram Schneider#		If not supplied, ${KMOD}.o is used.
3953996fadSWolfram Schneider#
4053996fadSWolfram Schneider# SRCS          List of source files
4153996fadSWolfram Schneider#
4253996fadSWolfram Schneider# SUBDIR        A list of subdirectories that should be built as well.
4353996fadSWolfram Schneider#               Each of the targets will execute the same target in the
4453996fadSWolfram Schneider#               subdirectories.
4553996fadSWolfram Schneider#
462336a7eaSBruce Evans# SYMLINKS	Same as LINKS, except it creates symlinks and the
472336a7eaSBruce Evans#		linked-to pathname may be relative.
482336a7eaSBruce Evans#
4953996fadSWolfram Schneider# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
5053996fadSWolfram Schneider#
517fecffecSDoug Rabson# MFILES	Optionally a list of interfaces used by the module.
527fecffecSDoug Rabson#		This file contains a default list of interfaces.
5353996fadSWolfram Schneider#
5453996fadSWolfram Schneider# +++ targets +++
5553996fadSWolfram Schneider#
5653996fadSWolfram Schneider#       distribute:
5753996fadSWolfram Schneider#               This is a variant of install, which will
5853996fadSWolfram Schneider#               put the stuff into the right "distribution".
5953996fadSWolfram Schneider#
6053996fadSWolfram Schneider# 	install:
6153996fadSWolfram Schneider#               install the program and its manual pages; if the Makefile
6253996fadSWolfram Schneider#               does not itself define the target install, the targets
6353996fadSWolfram Schneider#               beforeinstall and afterinstall may also be used to cause
6453996fadSWolfram Schneider#               actions immediately before and after the install target
6553996fadSWolfram Schneider#		is executed.
6653996fadSWolfram Schneider#
6753996fadSWolfram Schneider# 	load:
68fe3cac87SNick Hibma#		Load KLD.
6953996fadSWolfram Schneider#
7053996fadSWolfram Schneider# 	unload:
71fe3cac87SNick Hibma#		Unload KLD.
7253996fadSWolfram Schneider#
7353996fadSWolfram Schneider# bsd.obj.mk: clean, cleandir and obj
74161e8999SBruce Evans# bsd.dep.mk: cleandepend, depend and tags
7553996fadSWolfram Schneider# bsd.man.mk: maninstall
7653996fadSWolfram Schneider#
77639a2e50SGarrett Wollman
78fe3cac87SNick HibmaKMODLOAD?=	/sbin/kldload
79fe3cac87SNick HibmaKMODUNLOAD?=	/sbin/kldunload
80f6611608SSheldon HearnOBJCOPY?=	objcopy
817bc830bbSWolfram Schneider
820d2e2e23SDavid E. O'BrienTARGET_ARCH?=	${MACHINE_ARCH}
830d2e2e23SDavid E. O'Brien
84e0301e5dSPeter Wemm.if !target(__initialized__)
85e0301e5dSPeter Wemm__initialized__:
86639a2e50SGarrett Wollman.if exists(${.CURDIR}/../Makefile.inc)
87639a2e50SGarrett Wollman.include "${.CURDIR}/../Makefile.inc"
88639a2e50SGarrett Wollman.endif
89e0301e5dSPeter Wemm.endif
90639a2e50SGarrett Wollman
91639a2e50SGarrett Wollman.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
92639a2e50SGarrett Wollman
93c4473420SPeter WemmCFLAGS+=	${COPTS} -D_KERNEL ${CWARNFLAGS}
948fe644b2SMike SmithCFLAGS+=	-DKLD_MODULE
954a2d2630SBruce Evans
96021886ffSBruce Evans# Don't use any standard or source-relative include directories.
97021886ffSBruce Evans# Since -nostdinc will annull any previous -I paths, we repeat all
98021886ffSBruce Evans# such paths after -nostdinc.  It doesn't seem to be possible to
99021886ffSBruce Evans# add to the front of `make' variable.
100021886ffSBruce Evans_ICFLAGS:=	${CFLAGS:M-I*}
10126dac111SPoul-Henning KampCFLAGS+=	-nostdinc -I- ${INCLMAGIC} ${_ICFLAGS}
102021886ffSBruce Evans
103fe3cac87SNick Hibma# Add -I paths for system headers.  Individual KLD makefiles don't
104021886ffSBruce Evans# need any -I paths for this.  Similar defaults for .PATH can't be
105021886ffSBruce Evans# set because there are no standard paths for non-headers.
1067e820aaaSMike SmithCFLAGS+=	-I. -I@ -I@/dev
1074a2d2630SBruce Evans
108a0b845feSBruce Evans# Add a -I path to standard headers like <stddef.h>.  Use a relative
109a0b845feSBruce Evans# path to src/include if possible.  If the @ symlink hasn't been built
110a0b845feSBruce Evans# yet, then we can't tell if the relative path exists.  Add both the
111a0b845feSBruce Evans# potential relative path and an absolute path in that case.
112a0b845feSBruce Evans.if exists(@)
113a0b845feSBruce Evans.if exists(@/../include)
114a0b845feSBruce EvansCFLAGS+=	-I@/../include
115a0b845feSBruce Evans.else
116b3e17ba2SSatoshi AsamiCFLAGS+=	-I${DESTDIR}/usr/include
117b3e17ba2SSatoshi Asami.endif
118a0b845feSBruce Evans.else # !@
119a0b845feSBruce EvansCFLAGS+=	-I@/../include -I${DESTDIR}/usr/include
120a0b845feSBruce Evans.endif # @
12156bac51bSPoul-Henning Kamp
1229e4be63dSBruce EvansCFLAGS+=	${DEBUG_FLAGS}
1239e4be63dSBruce Evans
12471395925SPeter Wemm.if ${OBJFORMAT} == elf
125fdbdd3a0SPeter WemmCLEANFILES+=	setdef0.c setdef1.c setdefs.h
126fdbdd3a0SPeter WemmCLEANFILES+=	setdef0.o setdef1.o
127fdbdd3a0SPeter Wemm.endif
128fdbdd3a0SPeter Wemm
129639a2e50SGarrett WollmanOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
130639a2e50SGarrett Wollman
131639a2e50SGarrett Wollman.if !defined(PROG)
13290f60fc9SMike SmithPROG=	${KMOD}.ko
13390f60fc9SMike Smith.endif
134639a2e50SGarrett Wollman
135f6611608SSheldon Hearn.if !defined(DEBUG)
136f6611608SSheldon HearnFULLPROG=	${PROG}
137f6611608SSheldon Hearn.else
138f6611608SSheldon HearnFULLPROG=	${PROG}.debug
139f6611608SSheldon Hearn${PROG}: ${FULLPROG}
140f6611608SSheldon Hearn	${OBJCOPY} --strip-debug ${FULLPROG} ${PROG}
141f6611608SSheldon Hearn.endif
142f6611608SSheldon Hearn
143f6611608SSheldon Hearn${FULLPROG}: ${KMOD}.kld
14409be11baSPeter Wemm	${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
14509be11baSPeter Wemm
14609be11baSPeter Wemm${KMOD}.kld: ${OBJS}
1479e0f2a9fSPeter Wemm	${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
148fdbdd3a0SPeter Wemm
1495ce6c3cfSWolfram Schneider.if !defined(NOMAN)
1507da4bd3bSRuslan Ermilov.if 0
1517da4bd3bSRuslan ErmilovMAN?=	${KMOD}.4
152639a2e50SGarrett Wollman.endif
1537da4bd3bSRuslan Ermilov.include <bsd.man.mk>
1547da4bd3bSRuslan Ermilov.else
1557da4bd3bSRuslan Ermilov.if !target(all-man)
1567da4bd3bSRuslan Ermilovall-man: _SUBDIR
1577da4bd3bSRuslan Ermilov.endif
1587da4bd3bSRuslan Ermilov.if !target(maninstall)
159cd9a2f5cSJordan K. Hubbardmaninstall: _SUBDIR
1607da4bd3bSRuslan Ermilov.endif
1615ce6c3cfSWolfram Schneider.endif
1625ce6c3cfSWolfram Schneider
1634a2d2630SBruce Evans_ILINKS=@ machine
164639a2e50SGarrett Wollman
1654a2d2630SBruce Evans.MAIN: all
16647da63c3SBruce Evansall: objwarn ${PROG} all-man _SUBDIR
1674a2d2630SBruce Evans
168985f41afSWarner Loshbeforedepend: ${_ILINKS}
169985f41afSWarner Losh	@rm -f .depend
170985f41afSWarner Losh
171f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which
172f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes.
173f3cc9575SWarner Losh.for _link in ${_ILINKS}
174f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link})
175f3cc9575SWarner Losh${OBJS}: ${_link}
176f3cc9575SWarner Losh.endif
177f3cc9575SWarner Losh.endfor
1784a2d2630SBruce Evans
1799a8631b3SWarner Losh# Search for kernel source tree in standard places.
1809a8631b3SWarner Losh.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
1819a8631b3SWarner Losh.if !defined(SYSDIR) && exists(${_dir}/kern/)
1829a8631b3SWarner LoshSYSDIR=	${_dir}
1839a8631b3SWarner Losh.endif
1849a8631b3SWarner Losh.endfor
185aabafca0SJason Evans.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
1869a8631b3SWarner Losh.error "can't find kernel source tree"
1879a8631b3SWarner Losh.endif
1889a8631b3SWarner Losh
1894a2d2630SBruce Evans${_ILINKS}:
1909a8631b3SWarner Losh	@case ${.TARGET} in \
19108a04a89SPeter Wemm	machine) \
1929a8631b3SWarner Losh		path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
19308a04a89SPeter Wemm	@) \
1949a8631b3SWarner Losh		path=${SYSDIR} ;; \
19508a04a89SPeter Wemm	esac ; \
19608a04a89SPeter Wemm	path=`(cd $$path && /bin/pwd)` ; \
19708a04a89SPeter Wemm	${ECHO} ${.TARGET} "->" $$path ; \
19808a04a89SPeter Wemm	ln -s $$path ${.TARGET}
1994a2d2630SBruce Evans
200f6611608SSheldon HearnCLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
201639a2e50SGarrett Wollman
202639a2e50SGarrett Wollman.if !target(install)
203639a2e50SGarrett Wollman.if !target(beforeinstall)
204639a2e50SGarrett Wollmanbeforeinstall:
205639a2e50SGarrett Wollman.endif
206639a2e50SGarrett Wollman.if !target(afterinstall)
207639a2e50SGarrett Wollmanafterinstall:
208639a2e50SGarrett Wollman.endif
209639a2e50SGarrett Wollman
210ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:=	${INSTALLFLAGS}
211e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
212e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
213e902c1bbSTim Vanderhoek.endfor
214e902c1bbSTim Vanderhoek
215cd9a2f5cSJordan K. Hubbardrealinstall: _SUBDIR
2165ce6c3cfSWolfram Schneider	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
2172f7538d6SPeter Pentchev	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
218639a2e50SGarrett Wollman.if defined(LINKS) && !empty(LINKS)
219639a2e50SGarrett Wollman	@set ${LINKS}; \
220639a2e50SGarrett Wollman	while test $$# -ge 2; do \
221639a2e50SGarrett Wollman		l=${DESTDIR}$$1; \
222639a2e50SGarrett Wollman		shift; \
223639a2e50SGarrett Wollman		t=${DESTDIR}$$1; \
224639a2e50SGarrett Wollman		shift; \
225639a2e50SGarrett Wollman		${ECHO} $$t -\> $$l; \
2262336a7eaSBruce Evans		ln -f $$l $$t; \
2272336a7eaSBruce Evans	done; true
2282336a7eaSBruce Evans.endif
2292336a7eaSBruce Evans.if defined(SYMLINKS) && !empty(SYMLINKS)
2302336a7eaSBruce Evans	@set ${SYMLINKS}; \
2312336a7eaSBruce Evans	while test $$# -ge 2; do \
2322336a7eaSBruce Evans		l=$$1; \
2332336a7eaSBruce Evans		shift; \
2342336a7eaSBruce Evans		t=${DESTDIR}$$1; \
2352336a7eaSBruce Evans		shift; \
2362336a7eaSBruce Evans		${ECHO} $$t -\> $$l; \
2372336a7eaSBruce Evans		ln -fs $$l $$t; \
238639a2e50SGarrett Wollman	done; true
239639a2e50SGarrett Wollman.endif
240505222d3SPeter Wemm.if !defined(NO_XREF)
241505222d3SPeter Wemm	kldxref ${DESTDIR}${KMODDIR}
242505222d3SPeter Wemm.endif
243639a2e50SGarrett Wollman
244cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR
245639a2e50SGarrett Wollman.if !defined(NOMAN)
246639a2e50SGarrett Wollmanafterinstall: realinstall maninstall
247639a2e50SGarrett Wollman.else
248639a2e50SGarrett Wollmanafterinstall: realinstall
249639a2e50SGarrett Wollman.endif
250639a2e50SGarrett Wollmanrealinstall: beforeinstall
251639a2e50SGarrett Wollman.endif
252639a2e50SGarrett Wollman
253d9584d76SJordan K. HubbardDISTRIBUTION?=	bin
25455ff8fb1SPoul-Henning Kamp.if !target(distribute)
255cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR
256398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION}
257398ac038SJordan K. Hubbard	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
258398ac038SJordan K. Hubbard.endfor
25955ff8fb1SPoul-Henning Kamp.endif
26055ff8fb1SPoul-Henning Kamp
261639a2e50SGarrett Wollman.if !target(load)
2629a8631b3SWarner Loshload:	${PROG}
26346877fb2SBrian Feldman	${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko
264639a2e50SGarrett Wollman.endif
265639a2e50SGarrett Wollman
266639a2e50SGarrett Wollman.if !target(unload)
267fe3cac87SNick Hibmaunload:
2689a8631b3SWarner Losh	${KMODUNLOAD} -v ${KMOD}
26908a04a89SPeter Wemm.endif
2701aa57be3SGarrett Wollman
2714fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h}
2724fea6704SBruce EvansCLEANFILES+=	${_src}
2734fea6704SBruce Evans.if !target(${_src})
2744fea6704SBruce Evans${_src}:
2754fea6704SBruce Evans	touch ${.TARGET}
2764fea6704SBruce Evans.endif
2774fea6704SBruce Evans.endfor
2784fea6704SBruce Evans
2797fecffecSDoug RabsonMFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
2806f2d8adbSBoris Popov    dev/iicbus/iicbus_if.m isa/isa_if.m \
2816f2d8adbSBoris Popov    libkern/iconv_converter_if.m \
2826f2d8adbSBoris Popov    dev/mii/miibus_if.m \
2837e820aaaSMike Smith    dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
2847e820aaaSMike Smith    dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \
2850f55ac6cSCameron Grant    dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
286ed277dc9SPeter Wemm    dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m
2877fecffecSDoug Rabson
2887fecffecSDoug Rabson.for _srcsrc in ${MFILES}
2894fea6704SBruce Evans.for _ext in c h
2904fea6704SBruce Evans.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
2914fea6704SBruce EvansCLEANFILES+=	${_src}
2924fea6704SBruce Evans.if !target(${_src})
293f3cc9575SWarner Losh.if !exists(@)
2944fea6704SBruce Evans${_src}: @
295f3cc9575SWarner Losh.endif
2964fea6704SBruce Evans.if exists(@)
297c0de5879SDoug Rabson${_src}: @/kern/makeobjops.pl @/${_srcsrc}
2984fea6704SBruce Evans.endif
299c0de5879SDoug Rabson	perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc}
3004fea6704SBruce Evans.endif
3014fea6704SBruce Evans.endfor # _src
3024fea6704SBruce Evans.endfor # _ext
3034fea6704SBruce Evans.endfor # _srcsrc
3044fea6704SBruce Evans
3059029b644SPeter Wemm.for _ext in c h
3069029b644SPeter Wemm.if ${SRCS:Mvnode_if.${_ext}} != ""
3079029b644SPeter WemmCLEANFILES+=	vnode_if.${_ext}
308f3cc9575SWarner Losh.if !exists(@)
3099029b644SPeter Wemmvnode_if.${_ext}: @
310f3cc9575SWarner Losh.endif
3114fea6704SBruce Evans.if exists(@)
3123b073b53SPeter Wemmvnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
3134fea6704SBruce Evans.endif
3143b073b53SPeter Wemm	perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
3154fea6704SBruce Evans.endif
3169029b644SPeter Wemm.endfor
3171aa57be3SGarrett Wollman
31871395925SPeter Wemmregress:
31969b87d3eSEivind Eklund
32068e00b92SJordan K. Hubbard.include <bsd.dep.mk>
32147da63c3SBruce Evans
32247da63c3SBruce Evans.if !exists(${DEPENDFILE})
323589d9341SBruce Evans${OBJS}: ${SRCS:M*.h}
32447da63c3SBruce Evans.endif
32547da63c3SBruce Evans
326afba897fSBruce Evans.include <bsd.obj.mk>
327afba897fSBruce Evans
3289e72552fSBruce Evans.include <bsd.kern.mk>
329