1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD$ 3# 4# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 5# drivers (KLD's). 6# 7# 8# +++ variables +++ 9# 10# CLEANFILES Additional files to remove for the clean and cleandir targets. 11# 12# DISTRIBUTION Name of distribution. [bin] 13# 14# KMOD The name of the kernel module to build. 15# 16# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 17# 18# KMODOWN KLD owner. [${BINOWN}] 19# 20# KMODGRP KLD group. [${BINGRP}] 21# 22# KMODMODE KLD mode. [${BINMODE}] 23# 24# LINKS The list of KLD links; should be full pathnames, the 25# linked-to file coming first, followed by the linked 26# file. The files are hard-linked. For example, to link 27# /modules/master and /modules/meister, use: 28# 29# LINKS= /modules/master /modules/meister 30# 31# KMODLOAD Command to load a kernel module [/sbin/kldload] 32# 33# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 34# 35# PROG The name of the kernel module to build. 36# If not supplied, ${KMOD}.o is used. 37# 38# SRCS List of source files 39# 40# SUBDIR A list of subdirectories that should be built as well. 41# Each of the targets will execute the same target in the 42# subdirectories. 43# 44# SYMLINKS Same as LINKS, except it creates symlinks and the 45# linked-to pathname may be relative. 46# 47# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 48# 49# MFILES Optionally a list of interfaces used by the module. 50# This file contains a default list of interfaces. 51# 52# EXPORT_SYMS A list of symbols that should be exported from the module, 53# or the name of a file containing a list of symbols, or YES 54# to export all symbols. If not defined, no symbols are 55# exported. 56# 57# +++ targets +++ 58# 59# distribute: 60# This is a variant of install, which will 61# put the stuff into the right "distribution". 62# 63# install: 64# install the kernel module; if the Makefile 65# does not itself define the target install, the targets 66# beforeinstall and afterinstall may also be used to cause 67# actions immediately before and after the install target 68# is executed. 69# 70# load: 71# Load KLD. 72# 73# unload: 74# Unload KLD. 75# 76# bsd.obj.mk: clean, cleandir and obj 77# bsd.dep.mk: cleandepend, depend and tags 78# 79 80AWK?= awk 81KMODLOAD?= /sbin/kldload 82KMODUNLOAD?= /sbin/kldunload 83OBJCOPY?= objcopy 84 85.if defined(KMODDEPS) 86.error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND" 87.endif 88 89.include <bsd.init.mk> 90 91.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 92 93CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 94CFLAGS+= -DKLD_MODULE 95 96# Don't use any standard or source-relative include directories. 97# Since -nostdinc will annull any previous -I paths, we repeat all 98# such paths after -nostdinc. It doesn't seem to be possible to 99# add to the front of `make' variable. 100_ICFLAGS:= ${CFLAGS:M-I*} 101CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 102 103# Add -I paths for system headers. Individual KLD makefiles don't 104# need any -I paths for this. Similar defaults for .PATH can't be 105# set because there are no standard paths for non-headers. 106CFLAGS+= -I. -I@ -I@/dev 107 108# Add a -I path to standard headers like <stddef.h>. Use a relative 109# path to src/include if possible. If the @ symlink hasn't been built 110# yet, then we can't tell if the relative path exists. Add both the 111# potential relative path and an absolute path in that case. 112.if exists(@) 113.if exists(@/../include) 114CFLAGS+= -I@/../include 115.else 116CFLAGS+= -I${DESTDIR}/usr/include 117.endif 118.else # !@ 119CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 120.endif # @ 121 122# Disallow common variables, and if we end up with commons from 123# somewhere unexpected, allocate storage for them in the module itself. 124CFLAGS+= -fno-common 125LDFLAGS+= -d -warn-common 126 127CFLAGS+= ${DEBUG_FLAGS} 128 129.if ${OBJFORMAT} == elf 130CLEANFILES+= setdef0.c setdef1.c setdefs.h 131CLEANFILES+= setdef0.o setdef1.o 132.endif 133 134OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 135 136.if !defined(PROG) 137PROG= ${KMOD}.ko 138.endif 139 140.if !defined(DEBUG) 141FULLPROG= ${PROG} 142.else 143FULLPROG= ${PROG}.debug 144${PROG}: ${FULLPROG} 145 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 146.endif 147 148${FULLPROG}: ${KMOD}.kld 149 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 150 151EXPORT_SYMS?= NO 152.if ${EXPORT_SYMS} != YES 153CLEANFILES+= ${.OBJDIR}/export_syms 154.endif 155 156${KMOD}.kld: ${OBJS} 157 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 158.if defined(EXPORT_SYMS) 159.if ${EXPORT_SYMS} != YES 160.if ${EXPORT_SYMS} == NO 161 touch ${.OBJDIR}/export_syms 162.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 163 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 164.else 165 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 166.endif 167 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 168 ${.OBJDIR}/export_syms | \ 169 xargs -J% ${OBJCOPY} % ${.TARGET} 170.endif 171.endif 172 173_ILINKS=@ machine 174 175all: objwarn ${PROG} 176 177beforedepend: ${_ILINKS} 178 @rm -f .depend 179 180# Ensure that the links exist without depending on it when it exists which 181# causes all the modules to be rebuilt when the directory pointed to changes. 182.for _link in ${_ILINKS} 183.if !exists(${.OBJDIR}/${_link}) 184${OBJS}: ${_link} 185.endif 186.endfor 187 188# Search for kernel source tree in standard places. 189.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 190.if !defined(SYSDIR) && exists(${_dir}/kern/) 191SYSDIR= ${_dir} 192.endif 193.endfor 194.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 195.error "can't find kernel source tree" 196.endif 197 198${_ILINKS}: 199 @case ${.TARGET} in \ 200 machine) \ 201 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 202 @) \ 203 path=${SYSDIR} ;; \ 204 esac ; \ 205 path=`(cd $$path && /bin/pwd)` ; \ 206 ${ECHO} ${.TARGET} "->" $$path ; \ 207 ln -s $$path ${.TARGET} 208 209CLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 210 211.if !target(install) 212.if !target(beforeinstall) 213beforeinstall: 214.endif 215.if !target(afterinstall) 216afterinstall: 217.endif 218 219_INSTALLFLAGS:= ${INSTALLFLAGS} 220.for ie in ${INSTALLFLAGS_EDIT} 221_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 222.endfor 223 224.if defined(DEBUG) 225install.debug: 226 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 227.endif 228 229realinstall: 230.if defined(DEBUG) && defined(INSTALL_DEBUG) 231 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 232 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/ 233.else 234 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 235 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 236.if defined(LINKS) && !empty(LINKS) 237 @set ${LINKS}; \ 238 while test $$# -ge 2; do \ 239 l=${DESTDIR}$$1; \ 240 shift; \ 241 t=${DESTDIR}$$1; \ 242 shift; \ 243 ${ECHO} $$t -\> $$l; \ 244 ln -f $$l $$t; \ 245 done; true 246.endif 247.if defined(SYMLINKS) && !empty(SYMLINKS) 248 @set ${SYMLINKS}; \ 249 while test $$# -ge 2; do \ 250 l=$$1; \ 251 shift; \ 252 t=${DESTDIR}$$1; \ 253 shift; \ 254 ${ECHO} $$t -\> $$l; \ 255 ln -fs $$l $$t; \ 256 done; true 257.endif 258.if !defined(NO_XREF) 259 @if type kldxref >/dev/null 2>&1; then \ 260 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 261 kldxref ${DESTDIR}${KMODDIR}; \ 262 fi 263.endif 264.endif 265 266install: afterinstall 267afterinstall: realinstall 268realinstall: beforeinstall 269.endif 270 271DISTRIBUTION?= bin 272.if !target(distribute) 273distribute: 274.for dist in ${DISTRIBUTION} 275 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 276.endfor 277.endif 278 279.if !target(load) 280load: ${PROG} 281 ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko 282.endif 283 284.if !target(unload) 285unload: 286 ${KMODUNLOAD} -v ${KMOD} 287.endif 288 289.for _src in ${SRCS:Mopt_*.h} 290CLEANFILES+= ${_src} 291.if !target(${_src}) 292${_src}: 293 touch ${.TARGET} 294.endif 295.endfor 296 297MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 298 dev/iicbus/iicbus_if.m isa/isa_if.m \ 299 libkern/iconv_converter_if.m \ 300 dev/mii/miibus_if.m \ 301 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 302 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 303 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 304 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m 305 306.for _srcsrc in ${MFILES} 307.for _ext in c h 308.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 309CLEANFILES+= ${_src} 310.if !target(${_src}) 311.if !exists(@) 312${_src}: @ 313.endif 314.if exists(@) 315${_src}: @/tools/makeobjops.awk @/${_srcsrc} 316.endif 317 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 318.endif 319.endfor # _src 320.endfor # _ext 321.endfor # _srcsrc 322 323.for _ext in c h 324.if ${SRCS:Mvnode_if.${_ext}} != "" 325CLEANFILES+= vnode_if.${_ext} 326.if !exists(@) 327vnode_if.${_ext}: @ 328.endif 329.if exists(@) 330vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 331.endif 332 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 333.endif 334.endfor 335 336regress: 337 338lint: ${SRCS} 339 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 340 341.include <bsd.dep.mk> 342 343.if !exists(${DEPENDFILE}) 344${OBJS}: ${SRCS:M*.h} 345.endif 346 347.include <bsd.obj.mk> 348.include <bsd.kern.mk> 349