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# 1453996fadSWolfram Schneider# KERN Main Kernel source directory. [${.CURDIR}/../../sys/kern] 1553996fadSWolfram Schneider# 16fe3cac87SNick Hibma# KMOD The name of the kernel module to build. 1753996fadSWolfram Schneider# 18fe3cac87SNick Hibma# KMODDIR Base path for kernel modules (see kld(4)). [/modules] 1953996fadSWolfram Schneider# 20fe3cac87SNick Hibma# KMODOWN KLD owner. [${BINOWN}] 2153996fadSWolfram Schneider# 22fe3cac87SNick Hibma# KMODGRP KLD group. [${BINGRP}] 2353996fadSWolfram Schneider# 24fe3cac87SNick Hibma# KMODMODE KLD mode. [${BINMODE}] 2553996fadSWolfram Schneider# 26fe3cac87SNick Hibma# LINKS The list of KLD links; should be full pathnames, the 2753996fadSWolfram Schneider# linked-to file coming first, followed by the linked 2853996fadSWolfram Schneider# file. The files are hard-linked. For example, to link 2971395925SPeter Wemm# /modules/master and /modules/meister, use: 3053996fadSWolfram Schneider# 3171395925SPeter Wemm# LINKS= /modules/master /modules/meister 3253996fadSWolfram Schneider# 33fe3cac87SNick Hibma# KMODLOAD Command to load a kernel module [/sbin/kldload] 347bc830bbSWolfram Schneider# 35fe3cac87SNick Hibma# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 367bc830bbSWolfram Schneider# 37fe3cac87SNick Hibma# NOMAN KLD does not have a manual page if set. 3853996fadSWolfram Schneider# 39fe3cac87SNick Hibma# PROG The name of the kernel module to build. 407bc830bbSWolfram Schneider# If not supplied, ${KMOD}.o is used. 4153996fadSWolfram Schneider# 4253996fadSWolfram Schneider# SRCS List of source files 4353996fadSWolfram Schneider# 4490f60fc9SMike Smith# KMODDEPS List of modules which this one is dependant on 4590f60fc9SMike Smith# 4653996fadSWolfram Schneider# SUBDIR A list of subdirectories that should be built as well. 4753996fadSWolfram Schneider# Each of the targets will execute the same target in the 4853996fadSWolfram Schneider# subdirectories. 4953996fadSWolfram Schneider# 502336a7eaSBruce Evans# SYMLINKS Same as LINKS, except it creates symlinks and the 512336a7eaSBruce Evans# linked-to pathname may be relative. 522336a7eaSBruce Evans# 5353996fadSWolfram Schneider# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 5453996fadSWolfram Schneider# 557fecffecSDoug Rabson# MFILES Optionally a list of interfaces used by the module. 567fecffecSDoug Rabson# This file contains a default list of interfaces. 5753996fadSWolfram Schneider# 5853996fadSWolfram Schneider# +++ targets +++ 5953996fadSWolfram Schneider# 6053996fadSWolfram Schneider# distribute: 6153996fadSWolfram Schneider# This is a variant of install, which will 6253996fadSWolfram Schneider# put the stuff into the right "distribution". 6353996fadSWolfram Schneider# 6453996fadSWolfram Schneider# install: 6553996fadSWolfram Schneider# install the program and its manual pages; if the Makefile 6653996fadSWolfram Schneider# does not itself define the target install, the targets 6753996fadSWolfram Schneider# beforeinstall and afterinstall may also be used to cause 6853996fadSWolfram Schneider# actions immediately before and after the install target 6953996fadSWolfram Schneider# is executed. 7053996fadSWolfram Schneider# 7153996fadSWolfram Schneider# load: 72fe3cac87SNick Hibma# Load KLD. 7353996fadSWolfram Schneider# 7453996fadSWolfram Schneider# unload: 75fe3cac87SNick Hibma# Unload KLD. 7653996fadSWolfram Schneider# 7753996fadSWolfram Schneider# bsd.obj.mk: clean, cleandir and obj 78161e8999SBruce Evans# bsd.dep.mk: cleandepend, depend and tags 7953996fadSWolfram Schneider# bsd.man.mk: maninstall 8053996fadSWolfram Schneider# 81639a2e50SGarrett Wollman 82fe3cac87SNick HibmaKMODLOAD?= /sbin/kldload 83fe3cac87SNick HibmaKMODUNLOAD?= /sbin/kldunload 847bc830bbSWolfram Schneider 85e0301e5dSPeter Wemm.if !target(__initialized__) 86e0301e5dSPeter Wemm__initialized__: 87639a2e50SGarrett Wollman.if exists(${.CURDIR}/../Makefile.inc) 88639a2e50SGarrett Wollman.include "${.CURDIR}/../Makefile.inc" 89639a2e50SGarrett Wollman.endif 90e0301e5dSPeter Wemm.endif 91639a2e50SGarrett Wollman 92639a2e50SGarrett Wollman.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 93639a2e50SGarrett Wollman 94c4473420SPeter WemmCFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 958fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 964a2d2630SBruce Evans 97021886ffSBruce Evans# Don't use any standard or source-relative include directories. 98021886ffSBruce Evans# Since -nostdinc will annull any previous -I paths, we repeat all 99021886ffSBruce Evans# such paths after -nostdinc. It doesn't seem to be possible to 100021886ffSBruce Evans# add to the front of `make' variable. 101021886ffSBruce Evans_ICFLAGS:= ${CFLAGS:M-I*} 102021886ffSBruce EvansCFLAGS+= -nostdinc -I- ${_ICFLAGS} 103021886ffSBruce Evans 104fe3cac87SNick Hibma# Add -I paths for system headers. Individual KLD makefiles don't 105021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 106021886ffSBruce Evans# set because there are no standard paths for non-headers. 107a0b845feSBruce EvansCFLAGS+= -I. -I@ 1084a2d2630SBruce Evans 109a0b845feSBruce Evans# Add a -I path to standard headers like <stddef.h>. Use a relative 110a0b845feSBruce Evans# path to src/include if possible. If the @ symlink hasn't been built 111a0b845feSBruce Evans# yet, then we can't tell if the relative path exists. Add both the 112a0b845feSBruce Evans# potential relative path and an absolute path in that case. 113a0b845feSBruce Evans.if exists(@) 114a0b845feSBruce Evans.if exists(@/../include) 115a0b845feSBruce EvansCFLAGS+= -I@/../include 116a0b845feSBruce Evans.else 117b3e17ba2SSatoshi AsamiCFLAGS+= -I${DESTDIR}/usr/include 118b3e17ba2SSatoshi Asami.endif 119a0b845feSBruce Evans.else # !@ 120a0b845feSBruce EvansCFLAGS+= -I@/../include -I${DESTDIR}/usr/include 121a0b845feSBruce Evans.endif # @ 12256bac51bSPoul-Henning Kamp 1239e4be63dSBruce EvansCFLAGS+= ${DEBUG_FLAGS} 1249e4be63dSBruce Evans 12571395925SPeter Wemm.if ${OBJFORMAT} == elf 126fdbdd3a0SPeter WemmCLEANFILES+= setdef0.c setdef1.c setdefs.h 127fdbdd3a0SPeter WemmCLEANFILES+= setdef0.o setdef1.o 128fdbdd3a0SPeter Wemm.endif 129fdbdd3a0SPeter Wemm 130639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 131639a2e50SGarrett Wollman 132639a2e50SGarrett Wollman.if !defined(PROG) 13390f60fc9SMike SmithPROG= ${KMOD}.ko 13490f60fc9SMike Smith.endif 135639a2e50SGarrett Wollman 1369e0f2a9fSPeter Wemm${PROG}: ${KMOD}.kld ${KMODDEPS} 1379e0f2a9fSPeter Wemm ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS} 1389e0f2a9fSPeter Wemm 1399e0f2a9fSPeter Wemm${KMOD}.kld: ${OBJS} 140fdbdd3a0SPeter Wemm.if ${OBJFORMAT} == elf 141fdbdd3a0SPeter Wemm gensetdefs ${OBJS} 142fdbdd3a0SPeter Wemm ${CC} ${CFLAGS} -c setdef0.c 143fdbdd3a0SPeter Wemm ${CC} ${CFLAGS} -c setdef1.c 1449e0f2a9fSPeter Wemm ${LD} ${LDFLAGS} -r -o ${.TARGET} setdef0.o ${OBJS} setdef1.o 145fdbdd3a0SPeter Wemm.else 1469e0f2a9fSPeter Wemm ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS} 147fdbdd3a0SPeter Wemm.endif 148639a2e50SGarrett Wollman 149fdbdd3a0SPeter Wemm.if defined(KMODDEPS) 150fdbdd3a0SPeter Wemm.for dep in ${KMODDEPS} 1511e216ab5SPeter WemmCLEANFILES+= ${dep} __${dep}_hack_dep.c 152fdbdd3a0SPeter Wemm 153fdbdd3a0SPeter Wemm${dep}: 1541e216ab5SPeter Wemm touch __${dep}_hack_dep.c 1551e216ab5SPeter Wemm ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c 156fdbdd3a0SPeter Wemm.endfor 157fdbdd3a0SPeter Wemm.endif 158fdbdd3a0SPeter Wemm 1595ce6c3cfSWolfram Schneider.if !defined(NOMAN) 1605ce6c3cfSWolfram Schneider.include <bsd.man.mk> 1615ce6c3cfSWolfram Schneider.if !defined(_MANPAGES) || empty(_MANPAGES) 162639a2e50SGarrett WollmanMAN1= ${KMOD}.4 163639a2e50SGarrett Wollman.endif 164639a2e50SGarrett Wollman 1655ce6c3cfSWolfram Schneider.elif !target(maninstall) 166cd9a2f5cSJordan K. Hubbardmaninstall: _SUBDIR 1675ce6c3cfSWolfram Schneiderall-man: 1685ce6c3cfSWolfram Schneider.endif 1695ce6c3cfSWolfram Schneider 1704a2d2630SBruce Evans_ILINKS=@ machine 171639a2e50SGarrett Wollman 1724a2d2630SBruce Evans.MAIN: all 17347da63c3SBruce Evansall: objwarn ${PROG} all-man _SUBDIR 1744a2d2630SBruce Evans 17547da63c3SBruce Evansbeforedepend ${OBJS}: ${_ILINKS} 1764a2d2630SBruce Evans 1774a2d2630SBruce Evans# The search for the link targets works best if we are in a normal src 17871395925SPeter Wemm# tree, and not too deeply below src/sys/modules. If we are near "/", then 1794a2d2630SBruce Evans# we may find /sys - this is harmless. Other abnormal "sys" directories 1804a2d2630SBruce Evans# found in the search are likely to cause problems. If nothing is found, 1814a2d2630SBruce Evans# then the links default to /usr/include and /usr/include/machine. 1824a2d2630SBruce Evans${_ILINKS}: 18308a04a89SPeter Wemm @set +x; for up in ../.. ../../.. ; do \ 18408a04a89SPeter Wemm case ${.TARGET} in \ 18508a04a89SPeter Wemm machine) \ 18608a04a89SPeter Wemm testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 18708a04a89SPeter Wemm path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 18808a04a89SPeter Wemm defaultpath=/usr/include/machine ;; \ 18908a04a89SPeter Wemm @) \ 19008a04a89SPeter Wemm testpath=${.CURDIR}/$$up/sys ; \ 19108a04a89SPeter Wemm path=${.CURDIR}/$$up ; \ 19208a04a89SPeter Wemm defaultpath=/usr/include ;; \ 19308a04a89SPeter Wemm esac ; \ 19408a04a89SPeter Wemm if [ -d $$testpath ] ; then break ; fi ; \ 19508a04a89SPeter Wemm path=$$defaultpath ; \ 19608a04a89SPeter Wemm done ; \ 19708a04a89SPeter Wemm path=`(cd $$path && /bin/pwd)` ; \ 19808a04a89SPeter Wemm ${ECHO} ${.TARGET} "->" $$path ; \ 19908a04a89SPeter Wemm ln -s $$path ${.TARGET} 2004a2d2630SBruce Evans 2019e0f2a9fSPeter WemmCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 202639a2e50SGarrett Wollman 203639a2e50SGarrett Wollman.if !target(install) 204639a2e50SGarrett Wollman.if !target(beforeinstall) 205639a2e50SGarrett Wollmanbeforeinstall: 206639a2e50SGarrett Wollman.endif 207639a2e50SGarrett Wollman.if !target(afterinstall) 208639a2e50SGarrett Wollmanafterinstall: 209639a2e50SGarrett Wollman.endif 210639a2e50SGarrett Wollman 211e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${INSTALLFLAGS} 212e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 213e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 214e902c1bbSTim Vanderhoek.endfor 215e902c1bbSTim Vanderhoek 216cd9a2f5cSJordan K. Hubbardrealinstall: _SUBDIR 2175ce6c3cfSWolfram Schneider ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 218e902c1bbSTim Vanderhoek ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 219639a2e50SGarrett Wollman.if defined(LINKS) && !empty(LINKS) 220639a2e50SGarrett Wollman @set ${LINKS}; \ 221639a2e50SGarrett Wollman while test $$# -ge 2; do \ 222639a2e50SGarrett Wollman l=${DESTDIR}$$1; \ 223639a2e50SGarrett Wollman shift; \ 224639a2e50SGarrett Wollman t=${DESTDIR}$$1; \ 225639a2e50SGarrett Wollman shift; \ 226639a2e50SGarrett Wollman ${ECHO} $$t -\> $$l; \ 2272336a7eaSBruce Evans ln -f $$l $$t; \ 2282336a7eaSBruce Evans done; true 2292336a7eaSBruce Evans.endif 2302336a7eaSBruce Evans.if defined(SYMLINKS) && !empty(SYMLINKS) 2312336a7eaSBruce Evans @set ${SYMLINKS}; \ 2322336a7eaSBruce Evans while test $$# -ge 2; do \ 2332336a7eaSBruce Evans l=$$1; \ 2342336a7eaSBruce Evans shift; \ 2352336a7eaSBruce Evans t=${DESTDIR}$$1; \ 2362336a7eaSBruce Evans shift; \ 2372336a7eaSBruce Evans ${ECHO} $$t -\> $$l; \ 2382336a7eaSBruce Evans ln -fs $$l $$t; \ 239639a2e50SGarrett Wollman done; true 240639a2e50SGarrett Wollman.endif 241639a2e50SGarrett Wollman 242cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR 243639a2e50SGarrett Wollman.if !defined(NOMAN) 244639a2e50SGarrett Wollmanafterinstall: realinstall maninstall 245639a2e50SGarrett Wollman.else 246639a2e50SGarrett Wollmanafterinstall: realinstall 247639a2e50SGarrett Wollman.endif 248639a2e50SGarrett Wollmanrealinstall: beforeinstall 249639a2e50SGarrett Wollman.endif 250639a2e50SGarrett Wollman 251d9584d76SJordan K. HubbardDISTRIBUTION?= bin 25255ff8fb1SPoul-Henning Kamp.if !target(distribute) 253cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR 254398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION} 255398ac038SJordan K. Hubbard cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 256398ac038SJordan K. Hubbard.endfor 25755ff8fb1SPoul-Henning Kamp.endif 25855ff8fb1SPoul-Henning Kamp 259639a2e50SGarrett Wollman.if !target(load) 260fe3cac87SNick Hibmaload: ${PROG} install 261fe3cac87SNick Hibma ${KMODLOAD} ${KMOD} 262639a2e50SGarrett Wollman.endif 263639a2e50SGarrett Wollman 264639a2e50SGarrett Wollman.if !target(unload) 265fe3cac87SNick Hibmaunload: 266fe3cac87SNick Hibma ${KMODUNLOAD} ${KMOD} 267639a2e50SGarrett Wollman.endif 268639a2e50SGarrett Wollman 26908a04a89SPeter Wemm.if exists(${.CURDIR}/../../kern) 27008a04a89SPeter WemmKERN= ${.CURDIR}/../../kern 27108a04a89SPeter Wemm.else 2721aa57be3SGarrett WollmanKERN= ${.CURDIR}/../../sys/kern 27308a04a89SPeter Wemm.endif 2741aa57be3SGarrett Wollman 2754fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h} 2764fea6704SBruce EvansCLEANFILES+= ${_src} 2774fea6704SBruce Evans.if !target(${_src}) 2784fea6704SBruce Evans${_src}: 2794fea6704SBruce Evans touch ${.TARGET} 2804fea6704SBruce Evans.endif 2814fea6704SBruce Evans.endfor 2824fea6704SBruce Evans 2837fecffecSDoug RabsonMFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 284647b247cSPeter Wemm dev/iicbus/iicbus_if.m isa/isa_if.m dev/mii/miibus_if.m \ 285647b247cSPeter Wemm dev/pccard/card_if.m dev/pccard/power_if.m pci/pci_if.m \ 286647b247cSPeter Wemm dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m dev/usb/usb_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}) 2934fea6704SBruce Evans${_src}: @ 2944fea6704SBruce Evans.if exists(@) 2954fea6704SBruce Evans${_src}: @/kern/makedevops.pl @/${_srcsrc} 2964fea6704SBruce Evans.endif 2974fea6704SBruce Evans perl @/kern/makedevops.pl -${_ext} @/${_srcsrc} 2984fea6704SBruce Evans.endif 2994fea6704SBruce Evans.endfor # _src 3004fea6704SBruce Evans.endfor # _ext 3014fea6704SBruce Evans.endfor # _srcsrc 3024fea6704SBruce Evans 3039029b644SPeter Wemm.for _ext in c h 3049029b644SPeter Wemm.if ${SRCS:Mvnode_if.${_ext}} != "" 3059029b644SPeter WemmCLEANFILES+= vnode_if.${_ext} 3069029b644SPeter Wemmvnode_if.${_ext}: @ 3074fea6704SBruce Evans.if exists(@) 3083b073b53SPeter Wemmvnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src 3094fea6704SBruce Evans.endif 3103b073b53SPeter Wemm perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src 3114fea6704SBruce Evans.endif 3129029b644SPeter Wemm.endfor 3131aa57be3SGarrett Wollman 31471395925SPeter Wemmregress: 31569b87d3eSEivind Eklund 31668e00b92SJordan K. Hubbard.include <bsd.dep.mk> 31747da63c3SBruce Evans 31847da63c3SBruce Evans.if !exists(${DEPENDFILE}) 319589d9341SBruce Evans${OBJS}: ${SRCS:M*.h} 32047da63c3SBruce Evans.endif 32147da63c3SBruce Evans 322afba897fSBruce Evans.include <bsd.obj.mk> 323afba897fSBruce Evans 3249e72552fSBruce Evans.include <bsd.kern.mk> 325