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# 540b3178a4SMike Smith# EXPORT_SYMS A list of symbols that should be exported from the module, 550b3178a4SMike Smith# or the name of a file containing a list of symbols, or NO 560b3178a4SMike Smith# to export no symbols. If missing, all global symbols are 570b3178a4SMike Smith# exported. 580b3178a4SMike Smith# 5953996fadSWolfram Schneider# +++ targets +++ 6053996fadSWolfram Schneider# 6153996fadSWolfram Schneider# distribute: 6253996fadSWolfram Schneider# This is a variant of install, which will 6353996fadSWolfram Schneider# put the stuff into the right "distribution". 6453996fadSWolfram Schneider# 6553996fadSWolfram Schneider# install: 6653996fadSWolfram Schneider# install the program and its manual pages; if the Makefile 6753996fadSWolfram Schneider# does not itself define the target install, the targets 6853996fadSWolfram Schneider# beforeinstall and afterinstall may also be used to cause 6953996fadSWolfram Schneider# actions immediately before and after the install target 7053996fadSWolfram Schneider# is executed. 7153996fadSWolfram Schneider# 7253996fadSWolfram Schneider# load: 73fe3cac87SNick Hibma# Load KLD. 7453996fadSWolfram Schneider# 7553996fadSWolfram Schneider# unload: 76fe3cac87SNick Hibma# Unload KLD. 7753996fadSWolfram Schneider# 7853996fadSWolfram Schneider# bsd.obj.mk: clean, cleandir and obj 79161e8999SBruce Evans# bsd.dep.mk: cleandepend, depend and tags 8053996fadSWolfram Schneider# bsd.man.mk: maninstall 8153996fadSWolfram Schneider# 82639a2e50SGarrett Wollman 83fe3cac87SNick HibmaKMODLOAD?= /sbin/kldload 84fe3cac87SNick HibmaKMODUNLOAD?= /sbin/kldunload 85f6611608SSheldon HearnOBJCOPY?= objcopy 867bc830bbSWolfram Schneider 870d2e2e23SDavid E. O'BrienTARGET_ARCH?= ${MACHINE_ARCH} 880d2e2e23SDavid E. O'Brien 89e0301e5dSPeter Wemm.if !target(__initialized__) 90e0301e5dSPeter Wemm__initialized__: 91639a2e50SGarrett Wollman.if exists(${.CURDIR}/../Makefile.inc) 92639a2e50SGarrett Wollman.include "${.CURDIR}/../Makefile.inc" 93639a2e50SGarrett Wollman.endif 94e0301e5dSPeter Wemm.endif 95639a2e50SGarrett Wollman 96639a2e50SGarrett Wollman.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 97639a2e50SGarrett Wollman 98c4473420SPeter WemmCFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 998fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 1004a2d2630SBruce Evans 101021886ffSBruce Evans# Don't use any standard or source-relative include directories. 102021886ffSBruce Evans# Since -nostdinc will annull any previous -I paths, we repeat all 103021886ffSBruce Evans# such paths after -nostdinc. It doesn't seem to be possible to 104021886ffSBruce Evans# add to the front of `make' variable. 105021886ffSBruce Evans_ICFLAGS:= ${CFLAGS:M-I*} 10626dac111SPoul-Henning KampCFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 107021886ffSBruce Evans 108fe3cac87SNick Hibma# Add -I paths for system headers. Individual KLD makefiles don't 109021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 110021886ffSBruce Evans# set because there are no standard paths for non-headers. 1117e820aaaSMike SmithCFLAGS+= -I. -I@ -I@/dev 1124a2d2630SBruce Evans 113a0b845feSBruce Evans# Add a -I path to standard headers like <stddef.h>. Use a relative 114a0b845feSBruce Evans# path to src/include if possible. If the @ symlink hasn't been built 115a0b845feSBruce Evans# yet, then we can't tell if the relative path exists. Add both the 116a0b845feSBruce Evans# potential relative path and an absolute path in that case. 117a0b845feSBruce Evans.if exists(@) 118a0b845feSBruce Evans.if exists(@/../include) 119a0b845feSBruce EvansCFLAGS+= -I@/../include 120a0b845feSBruce Evans.else 121b3e17ba2SSatoshi AsamiCFLAGS+= -I${DESTDIR}/usr/include 122b3e17ba2SSatoshi Asami.endif 123a0b845feSBruce Evans.else # !@ 124a0b845feSBruce EvansCFLAGS+= -I@/../include -I${DESTDIR}/usr/include 125a0b845feSBruce Evans.endif # @ 12656bac51bSPoul-Henning Kamp 1270b3178a4SMike Smith# Disallow common variables, and if we end up with commons from 1280b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself. 1290b3178a4SMike SmithCFLAGS+= -fno-common 1300b3178a4SMike SmithLDFLAGS+= -d -warn-common 1310b3178a4SMike Smith 1329e4be63dSBruce EvansCFLAGS+= ${DEBUG_FLAGS} 1339e4be63dSBruce Evans 13471395925SPeter Wemm.if ${OBJFORMAT} == elf 135fdbdd3a0SPeter WemmCLEANFILES+= setdef0.c setdef1.c setdefs.h 136fdbdd3a0SPeter WemmCLEANFILES+= setdef0.o setdef1.o 137fdbdd3a0SPeter Wemm.endif 138fdbdd3a0SPeter Wemm 139639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 140639a2e50SGarrett Wollman 141639a2e50SGarrett Wollman.if !defined(PROG) 14290f60fc9SMike SmithPROG= ${KMOD}.ko 14390f60fc9SMike Smith.endif 144639a2e50SGarrett Wollman 145f6611608SSheldon Hearn.if !defined(DEBUG) 146f6611608SSheldon HearnFULLPROG= ${PROG} 147f6611608SSheldon Hearn.else 148f6611608SSheldon HearnFULLPROG= ${PROG}.debug 149f6611608SSheldon Hearn${PROG}: ${FULLPROG} 150f6611608SSheldon Hearn ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 151f6611608SSheldon Hearn.endif 152f6611608SSheldon Hearn 153f6611608SSheldon Hearn${FULLPROG}: ${KMOD}.kld 15409be11baSPeter Wemm ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 15509be11baSPeter Wemm 1560b3178a4SMike Smith.if defined(EXPORT_SYMS) 1570b3178a4SMike SmithCLEANFILES+= ${.OBJDIR}/export_syms 1580b3178a4SMike Smith.endif 1590b3178a4SMike Smith 16009be11baSPeter Wemm${KMOD}.kld: ${OBJS} 1610b3178a4SMike Smith ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 1620b3178a4SMike Smith.if defined(EXPORT_SYMS) 1630b3178a4SMike Smith.if ${EXPORT_SYMS} == NO 1640b3178a4SMike Smith touch ${.OBJDIR}/export_syms 1650b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 1660b3178a4SMike Smith echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 1670b3178a4SMike Smith.else 1680b3178a4SMike Smith grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 1690b3178a4SMike Smith.endif 1700b3178a4SMike Smith awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 1710b3178a4SMike Smith ${.OBJDIR}/export_syms | \ 1720b3178a4SMike Smith xargs -t -J% ${OBJCOPY} % ${.TARGET} 1730b3178a4SMike Smith.endif 1740b3178a4SMike Smith 175fdbdd3a0SPeter Wemm 1765ce6c3cfSWolfram Schneider.if !defined(NOMAN) 1777da4bd3bSRuslan Ermilov.if 0 1787da4bd3bSRuslan ErmilovMAN?= ${KMOD}.4 179639a2e50SGarrett Wollman.endif 1807da4bd3bSRuslan Ermilov.include <bsd.man.mk> 1817da4bd3bSRuslan Ermilov.else 1827da4bd3bSRuslan Ermilov.if !target(all-man) 1837da4bd3bSRuslan Ermilovall-man: _SUBDIR 1847da4bd3bSRuslan Ermilov.endif 1857da4bd3bSRuslan Ermilov.if !target(maninstall) 186cd9a2f5cSJordan K. Hubbardmaninstall: _SUBDIR 1877da4bd3bSRuslan Ermilov.endif 1885ce6c3cfSWolfram Schneider.endif 1895ce6c3cfSWolfram Schneider 1904a2d2630SBruce Evans_ILINKS=@ machine 191639a2e50SGarrett Wollman 1924a2d2630SBruce Evans.MAIN: all 19347da63c3SBruce Evansall: objwarn ${PROG} all-man _SUBDIR 1944a2d2630SBruce Evans 195985f41afSWarner Loshbeforedepend: ${_ILINKS} 196985f41afSWarner Losh @rm -f .depend 197985f41afSWarner Losh 198f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which 199f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 200f3cc9575SWarner Losh.for _link in ${_ILINKS} 201f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link}) 202f3cc9575SWarner Losh${OBJS}: ${_link} 203f3cc9575SWarner Losh.endif 204f3cc9575SWarner Losh.endfor 2054a2d2630SBruce Evans 2069a8631b3SWarner Losh# Search for kernel source tree in standard places. 2079a8631b3SWarner Losh.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 2089a8631b3SWarner Losh.if !defined(SYSDIR) && exists(${_dir}/kern/) 2099a8631b3SWarner LoshSYSDIR= ${_dir} 2109a8631b3SWarner Losh.endif 2119a8631b3SWarner Losh.endfor 212aabafca0SJason Evans.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 2139a8631b3SWarner Losh.error "can't find kernel source tree" 2149a8631b3SWarner Losh.endif 2159a8631b3SWarner Losh 2164a2d2630SBruce Evans${_ILINKS}: 2179a8631b3SWarner Losh @case ${.TARGET} in \ 21808a04a89SPeter Wemm machine) \ 2199a8631b3SWarner Losh path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 22008a04a89SPeter Wemm @) \ 2219a8631b3SWarner Losh path=${SYSDIR} ;; \ 22208a04a89SPeter Wemm esac ; \ 22308a04a89SPeter Wemm path=`(cd $$path && /bin/pwd)` ; \ 22408a04a89SPeter Wemm ${ECHO} ${.TARGET} "->" $$path ; \ 22508a04a89SPeter Wemm ln -s $$path ${.TARGET} 2264a2d2630SBruce Evans 227f6611608SSheldon HearnCLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 228639a2e50SGarrett Wollman 229639a2e50SGarrett Wollman.if !target(install) 230639a2e50SGarrett Wollman.if !target(beforeinstall) 231639a2e50SGarrett Wollmanbeforeinstall: 232639a2e50SGarrett Wollman.endif 233639a2e50SGarrett Wollman.if !target(afterinstall) 234639a2e50SGarrett Wollmanafterinstall: 235639a2e50SGarrett Wollman.endif 236639a2e50SGarrett Wollman 237ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:= ${INSTALLFLAGS} 238e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 239e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 240e902c1bbSTim Vanderhoek.endfor 241e902c1bbSTim Vanderhoek 242a4c00586SDag-Erling Smørgravinstall.debug: _SUBDIR 243a4c00586SDag-Erling Smørgrav ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 244a4c00586SDag-Erling Smørgrav ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/ 245a4c00586SDag-Erling Smørgrav 246cd9a2f5cSJordan K. Hubbardrealinstall: _SUBDIR 2475ce6c3cfSWolfram Schneider ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 2482f7538d6SPeter Pentchev ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 249639a2e50SGarrett Wollman.if defined(LINKS) && !empty(LINKS) 250639a2e50SGarrett Wollman @set ${LINKS}; \ 251639a2e50SGarrett Wollman while test $$# -ge 2; do \ 252639a2e50SGarrett Wollman l=${DESTDIR}$$1; \ 253639a2e50SGarrett Wollman shift; \ 254639a2e50SGarrett Wollman t=${DESTDIR}$$1; \ 255639a2e50SGarrett Wollman shift; \ 256639a2e50SGarrett Wollman ${ECHO} $$t -\> $$l; \ 2572336a7eaSBruce Evans ln -f $$l $$t; \ 2582336a7eaSBruce Evans done; true 2592336a7eaSBruce Evans.endif 2602336a7eaSBruce Evans.if defined(SYMLINKS) && !empty(SYMLINKS) 2612336a7eaSBruce Evans @set ${SYMLINKS}; \ 2622336a7eaSBruce Evans while test $$# -ge 2; do \ 2632336a7eaSBruce Evans l=$$1; \ 2642336a7eaSBruce Evans shift; \ 2652336a7eaSBruce Evans t=${DESTDIR}$$1; \ 2662336a7eaSBruce Evans shift; \ 2672336a7eaSBruce Evans ${ECHO} $$t -\> $$l; \ 2682336a7eaSBruce Evans ln -fs $$l $$t; \ 269639a2e50SGarrett Wollman done; true 270639a2e50SGarrett Wollman.endif 271505222d3SPeter Wemm.if !defined(NO_XREF) 272ad7da9b4SPeter Wemm -kldxref ${DESTDIR}${KMODDIR} 273505222d3SPeter Wemm.endif 274639a2e50SGarrett Wollman 275cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR 276639a2e50SGarrett Wollman.if !defined(NOMAN) 277639a2e50SGarrett Wollmanafterinstall: realinstall maninstall 278639a2e50SGarrett Wollman.else 279639a2e50SGarrett Wollmanafterinstall: realinstall 280639a2e50SGarrett Wollman.endif 281639a2e50SGarrett Wollmanrealinstall: beforeinstall 282639a2e50SGarrett Wollman.endif 283639a2e50SGarrett Wollman 284d9584d76SJordan K. HubbardDISTRIBUTION?= bin 28555ff8fb1SPoul-Henning Kamp.if !target(distribute) 286cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR 287398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION} 288398ac038SJordan K. Hubbard cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 289398ac038SJordan K. Hubbard.endfor 29055ff8fb1SPoul-Henning Kamp.endif 29155ff8fb1SPoul-Henning Kamp 292639a2e50SGarrett Wollman.if !target(load) 2939a8631b3SWarner Loshload: ${PROG} 29446877fb2SBrian Feldman ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko 295639a2e50SGarrett Wollman.endif 296639a2e50SGarrett Wollman 297639a2e50SGarrett Wollman.if !target(unload) 298fe3cac87SNick Hibmaunload: 2999a8631b3SWarner Losh ${KMODUNLOAD} -v ${KMOD} 30008a04a89SPeter Wemm.endif 3011aa57be3SGarrett Wollman 3024fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h} 3034fea6704SBruce EvansCLEANFILES+= ${_src} 3044fea6704SBruce Evans.if !target(${_src}) 3054fea6704SBruce Evans${_src}: 3064fea6704SBruce Evans touch ${.TARGET} 3074fea6704SBruce Evans.endif 3084fea6704SBruce Evans.endfor 3094fea6704SBruce Evans 3107fecffecSDoug RabsonMFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 3116f2d8adbSBoris Popov dev/iicbus/iicbus_if.m isa/isa_if.m \ 3126f2d8adbSBoris Popov libkern/iconv_converter_if.m \ 3136f2d8adbSBoris Popov dev/mii/miibus_if.m \ 3147e820aaaSMike Smith dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 3157e820aaaSMike Smith dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 3160f55ac6cSCameron Grant dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 317ed277dc9SPeter Wemm dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m 3187fecffecSDoug Rabson 3197fecffecSDoug Rabson.for _srcsrc in ${MFILES} 3204fea6704SBruce Evans.for _ext in c h 3214fea6704SBruce Evans.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 3224fea6704SBruce EvansCLEANFILES+= ${_src} 3234fea6704SBruce Evans.if !target(${_src}) 324f3cc9575SWarner Losh.if !exists(@) 3254fea6704SBruce Evans${_src}: @ 326f3cc9575SWarner Losh.endif 3274fea6704SBruce Evans.if exists(@) 328c0de5879SDoug Rabson${_src}: @/kern/makeobjops.pl @/${_srcsrc} 3294fea6704SBruce Evans.endif 330c0de5879SDoug Rabson perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc} 3314fea6704SBruce Evans.endif 3324fea6704SBruce Evans.endfor # _src 3334fea6704SBruce Evans.endfor # _ext 3344fea6704SBruce Evans.endfor # _srcsrc 3354fea6704SBruce Evans 3369029b644SPeter Wemm.for _ext in c h 3379029b644SPeter Wemm.if ${SRCS:Mvnode_if.${_ext}} != "" 3389029b644SPeter WemmCLEANFILES+= vnode_if.${_ext} 339f3cc9575SWarner Losh.if !exists(@) 3409029b644SPeter Wemmvnode_if.${_ext}: @ 341f3cc9575SWarner Losh.endif 3424fea6704SBruce Evans.if exists(@) 3433b073b53SPeter Wemmvnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src 3444fea6704SBruce Evans.endif 3453b073b53SPeter Wemm perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src 3464fea6704SBruce Evans.endif 3479029b644SPeter Wemm.endfor 3481aa57be3SGarrett Wollman 34971395925SPeter Wemmregress: 35069b87d3eSEivind Eklund 35168e00b92SJordan K. Hubbard.include <bsd.dep.mk> 35247da63c3SBruce Evans 35347da63c3SBruce Evans.if !exists(${DEPENDFILE}) 354589d9341SBruce Evans${OBJS}: ${SRCS:M*.h} 35547da63c3SBruce Evans.endif 35647da63c3SBruce Evans 357afba897fSBruce Evans.include <bsd.obj.mk> 358afba897fSBruce Evans 3599e72552fSBruce Evans.include <bsd.kern.mk> 360