kmod.mk revision 78161
1186681Sed# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2186681Sed# $FreeBSD: head/sys/conf/kmod.mk 78161 2001-06-13 10:58:39Z peter $ 3186681Sed# 4186681Sed# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 5186681Sed# drivers (KLD's). 6186681Sed# 7186681Sed# 8186681Sed# +++ variables +++ 9186681Sed# 10186681Sed# CLEANFILES Additional files to remove for the clean and cleandir targets. 11186681Sed# 12186681Sed# DISTRIBUTION Name of distribution. [bin] 13186681Sed# 14186681Sed# KMOD The name of the kernel module to build. 15186681Sed# 16186681Sed# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 17186681Sed# 18186681Sed# KMODOWN KLD owner. [${BINOWN}] 19186681Sed# 20186681Sed# KMODGRP KLD group. [${BINGRP}] 21186681Sed# 22186681Sed# KMODMODE KLD mode. [${BINMODE}] 23186681Sed# 24186681Sed# LINKS The list of KLD links; should be full pathnames, the 25186681Sed# linked-to file coming first, followed by the linked 26186681Sed# file. The files are hard-linked. For example, to link 27186681Sed# /modules/master and /modules/meister, use: 28186681Sed# 29186681Sed# LINKS= /modules/master /modules/meister 30186681Sed# 31186681Sed# KMODLOAD Command to load a kernel module [/sbin/kldload] 32186681Sed# 33186681Sed# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 34186681Sed# 35186681Sed# NOMAN KLD does not have a manual page if set. 36186681Sed# 37186681Sed# PROG The name of the kernel module to build. 38186681Sed# If not supplied, ${KMOD}.o is used. 39186681Sed# 40186681Sed# SRCS List of source files 41186681Sed# 42186681Sed# SUBDIR A list of subdirectories that should be built as well. 43186681Sed# Each of the targets will execute the same target in the 44186681Sed# subdirectories. 45186681Sed# 46186681Sed# SYMLINKS Same as LINKS, except it creates symlinks and the 47186681Sed# linked-to pathname may be relative. 48186681Sed# 49186681Sed# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 50186681Sed# 51186681Sed# MFILES Optionally a list of interfaces used by the module. 52188391Sed# This file contains a default list of interfaces. 53186681Sed# 54186681Sed# +++ targets +++ 55186681Sed# 56186681Sed# distribute: 57186681Sed# This is a variant of install, which will 58186681Sed# put the stuff into the right "distribution". 59186681Sed# 60186681Sed# install: 61186681Sed# install the program and its manual pages; if the Makefile 62186681Sed# does not itself define the target install, the targets 63186681Sed# beforeinstall and afterinstall may also be used to cause 64186681Sed# actions immediately before and after the install target 65186681Sed# is executed. 66186681Sed# 67186681Sed# load: 68186681Sed# Load KLD. 69186681Sed# 70186681Sed# unload: 71186681Sed# Unload KLD. 72186681Sed# 73186681Sed# bsd.obj.mk: clean, cleandir and obj 74186681Sed# bsd.dep.mk: cleandepend, depend and tags 75186681Sed# bsd.man.mk: maninstall 76186681Sed# 77186681Sed 78186681SedKMODLOAD?= /sbin/kldload 79186681SedKMODUNLOAD?= /sbin/kldunload 80186681Sed 81186681SedTARGET_ARCH?= ${MACHINE_ARCH} 82186681Sed 83186681Sed.if !target(__initialized__) 84186681Sed__initialized__: 85186681Sed.if exists(${.CURDIR}/../Makefile.inc) 86186681Sed.include "${.CURDIR}/../Makefile.inc" 87186681Sed.endif 88186681Sed.endif 89186681Sed 90186681Sed.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 91186681Sed 92186681SedCFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 93186681SedCFLAGS+= -DKLD_MODULE 94186681Sed 95186681Sed# Don't use any standard or source-relative include directories. 96186681Sed# Since -nostdinc will annull any previous -I paths, we repeat all 97186681Sed# such paths after -nostdinc. It doesn't seem to be possible to 98186681Sed# add to the front of `make' variable. 99186681Sed_ICFLAGS:= ${CFLAGS:M-I*} 100186681SedCFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 101186681Sed 102186681Sed# Add -I paths for system headers. Individual KLD makefiles don't 103186681Sed# need any -I paths for this. Similar defaults for .PATH can't be 104186681Sed# set because there are no standard paths for non-headers. 105186681SedCFLAGS+= -I. -I@ -I@/dev 106186681Sed 107186681Sed# Add a -I path to standard headers like <stddef.h>. Use a relative 108186681Sed# path to src/include if possible. If the @ symlink hasn't been built 109186681Sed# yet, then we can't tell if the relative path exists. Add both the 110186681Sed# potential relative path and an absolute path in that case. 111189064Sed.if exists(@) 112186681Sed.if exists(@/../include) 113186681SedCFLAGS+= -I@/../include 114186681Sed.else 115186681SedCFLAGS+= -I${DESTDIR}/usr/include 116186681Sed.endif 117186681Sed.else # !@ 118186681SedCFLAGS+= -I@/../include -I${DESTDIR}/usr/include 119186681Sed.endif # @ 120186681Sed 121186681SedCFLAGS+= ${DEBUG_FLAGS} 122186681Sed 123186681Sed.if ${OBJFORMAT} == elf 124186681SedCLEANFILES+= setdef0.c setdef1.c setdefs.h 125186681SedCLEANFILES+= setdef0.o setdef1.o 126186681Sed.endif 127186681Sed 128186681SedOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 129186681Sed 130186681Sed.if !defined(PROG) 131186681SedPROG= ${KMOD}.ko 132186681Sed.endif 133186681Sed 134186681Sed${PROG}: ${KMOD}.kld 135186681Sed ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 136186681Sed 137186681Sed${KMOD}.kld: ${OBJS} 138186681Sed ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS} 139186681Sed 140186681Sed.if !defined(NOMAN) 141186681Sed.if 0 142186681SedMAN?= ${KMOD}.4 143186681Sed.endif 144186681Sed.include <bsd.man.mk> 145186681Sed.else 146186681Sed.if !target(all-man) 147186681Sedall-man: _SUBDIR 148186681Sed.endif 149186681Sed.if !target(maninstall) 150186681Sedmaninstall: _SUBDIR 151186681Sed.endif 152186681Sed.endif 153186681Sed 154186681Sed_ILINKS=@ machine 155186681Sed 156189617Sed.MAIN: all 157186681Sedall: objwarn ${PROG} all-man _SUBDIR 158186681Sed 159189617Sedbeforedepend: ${_ILINKS} 160186681Sed @rm -f .depend 161186681Sed 162189617Sed# Ensure that the links exist without depending on it when it exists which 163189617Sed# causes all the modules to be rebuilt when the directory pointed to changes. 164189617Sed.for _link in ${_ILINKS} 165189617Sed.if !exists(${.OBJDIR}/${_link}) 166189617Sed${OBJS}: ${_link} 167189617Sed.endif 168189617Sed.endfor 169189617Sed 170189617Sed# Search for kernel source tree in standard places. 171189617Sed.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 172189617Sed.if !defined(SYSDIR) && exists(${_dir}/kern/) 173186681SedSYSDIR= ${_dir} 174186681Sed.endif 175186681Sed.endfor 176186681Sed.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 177186681Sed.error "can't find kernel source tree" 178186681Sed.endif 179186681Sed 180188391Sed${_ILINKS}: 181186681Sed @case ${.TARGET} in \ 182188391Sed machine) \ 183186681Sed path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 184186681Sed @) \ 185186681Sed path=${SYSDIR} ;; \ 186188391Sed esac ; \ 187188391Sed path=`(cd $$path && /bin/pwd)` ; \ 188186681Sed ${ECHO} ${.TARGET} "->" $$path ; \ 189186681Sed ln -s $$path ${.TARGET} 190186681Sed 191186681SedCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 192186681Sed 193188391Sed.if !target(install) 194188391Sed.if !target(beforeinstall) 195188391Sedbeforeinstall: 196188391Sed.endif 197188391Sed.if !target(afterinstall) 198188391Sedafterinstall: 199186681Sed.endif 200186681Sed 201186681Sed_INSTALLFLAGS:= ${INSTALLFLAGS} 202186681Sed.for ie in ${INSTALLFLAGS_EDIT} 203186681Sed_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 204186681Sed.endfor 205186681Sed 206186681Sedrealinstall: _SUBDIR 207186681Sed ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 208186681Sed ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 209186681Sed.if defined(LINKS) && !empty(LINKS) 210186681Sed @set ${LINKS}; \ 211186681Sed while test $$# -ge 2; do \ 212186681Sed l=${DESTDIR}$$1; \ 213186681Sed shift; \ 214186681Sed t=${DESTDIR}$$1; \ 215186681Sed shift; \ 216186681Sed ${ECHO} $$t -\> $$l; \ 217186681Sed ln -f $$l $$t; \ 218186681Sed done; true 219186681Sed.endif 220186681Sed.if defined(SYMLINKS) && !empty(SYMLINKS) 221186681Sed @set ${SYMLINKS}; \ 222186681Sed while test $$# -ge 2; do \ 223186681Sed l=$$1; \ 224186681Sed shift; \ 225186681Sed t=${DESTDIR}$$1; \ 226186681Sed shift; \ 227186681Sed ${ECHO} $$t -\> $$l; \ 228186681Sed ln -fs $$l $$t; \ 229186681Sed done; true 230186681Sed.endif 231186681Sed 232186681Sedinstall: afterinstall _SUBDIR 233186681Sed.if !defined(NOMAN) 234186681Sedafterinstall: realinstall maninstall 235186681Sed.else 236186681Sedafterinstall: realinstall 237186681Sed.endif 238186681Sedrealinstall: beforeinstall 239186681Sed.endif 240186681Sed 241186681SedDISTRIBUTION?= bin 242186681Sed.if !target(distribute) 243186681Seddistribute: _SUBDIR 244186681Sed.for dist in ${DISTRIBUTION} 245186681Sed cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 246186681Sed.endfor 247186681Sed.endif 248186681Sed 249186681Sed.if !target(load) 250186681Sedload: ${PROG} 251186681Sed ${KMODLOAD} -v ./${KMOD}.ko 252186681Sed.endif 253186681Sed 254186681Sed.if !target(unload) 255186681Sedunload: 256186681Sed ${KMODUNLOAD} -v ${KMOD} 257186681Sed.endif 258186681Sed 259186681Sed.for _src in ${SRCS:Mopt_*.h} 260186681SedCLEANFILES+= ${_src} 261186681Sed.if !target(${_src}) 262186681Sed${_src}: 263186681Sed touch ${.TARGET} 264186681Sed.endif 265186681Sed.endfor 266186681Sed 267186681SedMFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 268186681Sed dev/iicbus/iicbus_if.m isa/isa_if.m \ 269186681Sed libkern/iconv_converter_if.m \ 270186681Sed dev/mii/miibus_if.m \ 271186681Sed dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 272186681Sed dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 273186681Sed dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 274186681Sed dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m 275186681Sed 276186681Sed.for _srcsrc in ${MFILES} 277186681Sed.for _ext in c h 278186681Sed.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 279186681SedCLEANFILES+= ${_src} 280186681Sed.if !target(${_src}) 281186681Sed.if !exists(@) 282186681Sed${_src}: @ 283186681Sed.endif 284186681Sed.if exists(@) 285186681Sed${_src}: @/kern/makeobjops.pl @/${_srcsrc} 286186681Sed.endif 287186681Sed perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc} 288186681Sed.endif 289186681Sed.endfor # _src 290186681Sed.endfor # _ext 291186681Sed.endfor # _srcsrc 292186681Sed 293186681Sed.for _ext in c h 294186681Sed.if ${SRCS:Mvnode_if.${_ext}} != "" 295186681SedCLEANFILES+= vnode_if.${_ext} 296186681Sed.if !exists(@) 297186681Sedvnode_if.${_ext}: @ 298186681Sed.endif 299188391Sed.if exists(@) 300186681Sedvnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src 301186681Sed.endif 302186681Sed perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src 303186681Sed.endif 304186681Sed.endfor 305186681Sed 306186681Sedregress: 307186681Sed 308186681Sed.include <bsd.dep.mk> 309186681Sed 310186681Sed.if !exists(${DEPENDFILE}) 311186681Sed${OBJS}: ${SRCS:M*.h} 312186681Sed.endif 313186681Sed 314186681Sed.include <bsd.obj.mk> 315186681Sed 316186681Sed.include <bsd.kern.mk> 317186681Sed