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# 5553996fadSWolfram Schneider# 5653996fadSWolfram Schneider# +++ targets +++ 5753996fadSWolfram Schneider# 5853996fadSWolfram Schneider# distribute: 5953996fadSWolfram Schneider# This is a variant of install, which will 6053996fadSWolfram Schneider# put the stuff into the right "distribution". 6153996fadSWolfram Schneider# 6253996fadSWolfram Schneider# install: 6353996fadSWolfram Schneider# install the program and its manual pages; if the Makefile 6453996fadSWolfram Schneider# does not itself define the target install, the targets 6553996fadSWolfram Schneider# beforeinstall and afterinstall may also be used to cause 6653996fadSWolfram Schneider# actions immediately before and after the install target 6753996fadSWolfram Schneider# is executed. 6853996fadSWolfram Schneider# 6953996fadSWolfram Schneider# load: 70fe3cac87SNick Hibma# Load KLD. 7153996fadSWolfram Schneider# 7253996fadSWolfram Schneider# unload: 73fe3cac87SNick Hibma# Unload KLD. 7453996fadSWolfram Schneider# 7553996fadSWolfram Schneider# bsd.obj.mk: clean, cleandir and obj 76161e8999SBruce Evans# bsd.dep.mk: cleandepend, depend and tags 7753996fadSWolfram Schneider# bsd.man.mk: maninstall 7853996fadSWolfram Schneider# 79639a2e50SGarrett Wollman 80fe3cac87SNick HibmaKMODLOAD?= /sbin/kldload 81fe3cac87SNick HibmaKMODUNLOAD?= /sbin/kldunload 827bc830bbSWolfram Schneider 83e0301e5dSPeter Wemm.if !target(__initialized__) 84e0301e5dSPeter Wemm__initialized__: 85639a2e50SGarrett Wollman.if exists(${.CURDIR}/../Makefile.inc) 86639a2e50SGarrett Wollman.include "${.CURDIR}/../Makefile.inc" 87639a2e50SGarrett Wollman.endif 88e0301e5dSPeter Wemm.endif 89639a2e50SGarrett Wollman 90639a2e50SGarrett Wollman.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 91639a2e50SGarrett Wollman 92fdbdd3a0SPeter WemmCFLAGS+= ${COPTS} -DKERNEL ${CWARNFLAGS} 938fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 944a2d2630SBruce Evans 95021886ffSBruce Evans# Don't use any standard or source-relative include directories. 96021886ffSBruce Evans# Since -nostdinc will annull any previous -I paths, we repeat all 97021886ffSBruce Evans# such paths after -nostdinc. It doesn't seem to be possible to 98021886ffSBruce Evans# add to the front of `make' variable. 99021886ffSBruce Evans_ICFLAGS:= ${CFLAGS:M-I*} 100021886ffSBruce EvansCFLAGS+= -nostdinc -I- ${_ICFLAGS} 101021886ffSBruce Evans 102fe3cac87SNick Hibma# Add -I paths for system headers. Individual KLD makefiles don't 103021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 104021886ffSBruce Evans# set because there are no standard paths for non-headers. 1054a2d2630SBruce EvansCFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 1064a2d2630SBruce Evans 107021886ffSBruce Evans# XXX this is now dubious. 108b3e17ba2SSatoshi Asami.if defined(DESTDIR) 109b3e17ba2SSatoshi AsamiCFLAGS+= -I${DESTDIR}/usr/include 110b3e17ba2SSatoshi Asami.endif 11156bac51bSPoul-Henning Kamp 11208a04a89SPeter Wemm.if defined(VFS_KLD) 11308a04a89SPeter WemmSRCS+= vnode_if.h 11408a04a89SPeter WemmCLEANFILES+= vnode_if.h vnode_if.c 11508a04a89SPeter Wemm.endif 11608a04a89SPeter Wemm 11771395925SPeter Wemm.if ${OBJFORMAT} == elf 118fdbdd3a0SPeter WemmCLEANFILES+= setdef0.c setdef1.c setdefs.h 119fdbdd3a0SPeter WemmCLEANFILES+= setdef0.o setdef1.o 120fdbdd3a0SPeter Wemm.endif 121fdbdd3a0SPeter Wemm 122639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 123639a2e50SGarrett Wollman 124639a2e50SGarrett Wollman.if !defined(PROG) 12590f60fc9SMike SmithPROG= ${KMOD}.ko 12690f60fc9SMike Smith.endif 127639a2e50SGarrett Wollman 128fdbdd3a0SPeter Wemm${PROG}: ${OBJS} ${DPADD} ${KMODDEPS} 129fdbdd3a0SPeter Wemm.if ${OBJFORMAT} == elf 130fdbdd3a0SPeter Wemm gensetdefs ${OBJS} 131fdbdd3a0SPeter Wemm ${CC} ${CFLAGS} -c setdef0.c 132fdbdd3a0SPeter Wemm ${CC} ${CFLAGS} -c setdef1.c 133fdbdd3a0SPeter Wemm ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${OBJS} setdef1.o ${KMODDEPS} 134fdbdd3a0SPeter Wemm.else 13590f60fc9SMike Smith ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 136fdbdd3a0SPeter Wemm.endif 137639a2e50SGarrett Wollman 138fdbdd3a0SPeter Wemm.if defined(KMODDEPS) 139fdbdd3a0SPeter Wemm.for dep in ${KMODDEPS} 1401e216ab5SPeter WemmCLEANFILES+= ${dep} __${dep}_hack_dep.c 141fdbdd3a0SPeter Wemm 142fdbdd3a0SPeter Wemm${dep}: 1431e216ab5SPeter Wemm touch __${dep}_hack_dep.c 1441e216ab5SPeter Wemm ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c 145fdbdd3a0SPeter Wemm.endfor 146fdbdd3a0SPeter Wemm.endif 147fdbdd3a0SPeter Wemm 1485ce6c3cfSWolfram Schneider.if !defined(NOMAN) 1495ce6c3cfSWolfram Schneider.include <bsd.man.mk> 1505ce6c3cfSWolfram Schneider.if !defined(_MANPAGES) || empty(_MANPAGES) 151639a2e50SGarrett WollmanMAN1= ${KMOD}.4 152639a2e50SGarrett Wollman.endif 153639a2e50SGarrett Wollman 1545ce6c3cfSWolfram Schneider.elif !target(maninstall) 155cd9a2f5cSJordan K. Hubbardmaninstall: _SUBDIR 1565ce6c3cfSWolfram Schneiderall-man: 1575ce6c3cfSWolfram Schneider.endif 1585ce6c3cfSWolfram Schneider 1594a2d2630SBruce Evans_ILINKS=@ machine 160639a2e50SGarrett Wollman 1614a2d2630SBruce Evans.MAIN: all 16247da63c3SBruce Evansall: objwarn ${PROG} all-man _SUBDIR 1634a2d2630SBruce Evans 16447da63c3SBruce Evansbeforedepend ${OBJS}: ${_ILINKS} 1654a2d2630SBruce Evans 1664a2d2630SBruce Evans# The search for the link targets works best if we are in a normal src 16771395925SPeter Wemm# tree, and not too deeply below src/sys/modules. If we are near "/", then 1684a2d2630SBruce Evans# we may find /sys - this is harmless. Other abnormal "sys" directories 1694a2d2630SBruce Evans# found in the search are likely to cause problems. If nothing is found, 1704a2d2630SBruce Evans# then the links default to /usr/include and /usr/include/machine. 1714a2d2630SBruce Evans${_ILINKS}: 17208a04a89SPeter Wemm @set +x; for up in ../.. ../../.. ; do \ 17308a04a89SPeter Wemm case ${.TARGET} in \ 17408a04a89SPeter Wemm machine) \ 17508a04a89SPeter Wemm testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 17608a04a89SPeter Wemm path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 17708a04a89SPeter Wemm defaultpath=/usr/include/machine ;; \ 17808a04a89SPeter Wemm @) \ 17908a04a89SPeter Wemm testpath=${.CURDIR}/$$up/sys ; \ 18008a04a89SPeter Wemm path=${.CURDIR}/$$up ; \ 18108a04a89SPeter Wemm defaultpath=/usr/include ;; \ 18208a04a89SPeter Wemm esac ; \ 18308a04a89SPeter Wemm if [ -d $$testpath ] ; then break ; fi ; \ 18408a04a89SPeter Wemm path=$$defaultpath ; \ 18508a04a89SPeter Wemm done ; \ 18608a04a89SPeter Wemm path=`(cd $$path && /bin/pwd)` ; \ 18708a04a89SPeter Wemm ${ECHO} ${.TARGET} "->" $$path ; \ 18808a04a89SPeter Wemm ln -s $$path ${.TARGET} 1894a2d2630SBruce Evans 19071395925SPeter WemmCLEANFILES+= ${PROG} ${OBJS} ${_ILINKS} symb.tmp tmp.o 191639a2e50SGarrett Wollman 192639a2e50SGarrett Wollman.if !target(install) 193639a2e50SGarrett Wollman.if !target(beforeinstall) 194639a2e50SGarrett Wollmanbeforeinstall: 195639a2e50SGarrett Wollman.endif 196639a2e50SGarrett Wollman.if !target(afterinstall) 197639a2e50SGarrett Wollmanafterinstall: 198639a2e50SGarrett Wollman.endif 199639a2e50SGarrett Wollman 200e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${INSTALLFLAGS} 201e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 202e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 203e902c1bbSTim Vanderhoek.endfor 204e902c1bbSTim Vanderhoek 205cd9a2f5cSJordan K. Hubbardrealinstall: _SUBDIR 2065ce6c3cfSWolfram Schneider ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 207e902c1bbSTim Vanderhoek ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 208639a2e50SGarrett Wollman.if defined(LINKS) && !empty(LINKS) 209639a2e50SGarrett Wollman @set ${LINKS}; \ 210639a2e50SGarrett Wollman while test $$# -ge 2; do \ 211639a2e50SGarrett Wollman l=${DESTDIR}$$1; \ 212639a2e50SGarrett Wollman shift; \ 213639a2e50SGarrett Wollman t=${DESTDIR}$$1; \ 214639a2e50SGarrett Wollman shift; \ 215639a2e50SGarrett Wollman ${ECHO} $$t -\> $$l; \ 2162336a7eaSBruce Evans ln -f $$l $$t; \ 2172336a7eaSBruce Evans done; true 2182336a7eaSBruce Evans.endif 2192336a7eaSBruce Evans.if defined(SYMLINKS) && !empty(SYMLINKS) 2202336a7eaSBruce Evans @set ${SYMLINKS}; \ 2212336a7eaSBruce Evans while test $$# -ge 2; do \ 2222336a7eaSBruce Evans l=$$1; \ 2232336a7eaSBruce Evans shift; \ 2242336a7eaSBruce Evans t=${DESTDIR}$$1; \ 2252336a7eaSBruce Evans shift; \ 2262336a7eaSBruce Evans ${ECHO} $$t -\> $$l; \ 2272336a7eaSBruce Evans ln -fs $$l $$t; \ 228639a2e50SGarrett Wollman done; true 229639a2e50SGarrett Wollman.endif 230639a2e50SGarrett Wollman 231cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR 232639a2e50SGarrett Wollman.if !defined(NOMAN) 233639a2e50SGarrett Wollmanafterinstall: realinstall maninstall 234639a2e50SGarrett Wollman.else 235639a2e50SGarrett Wollmanafterinstall: realinstall 236639a2e50SGarrett Wollman.endif 237639a2e50SGarrett Wollmanrealinstall: beforeinstall 238639a2e50SGarrett Wollman.endif 239639a2e50SGarrett Wollman 240d9584d76SJordan K. HubbardDISTRIBUTION?= bin 24155ff8fb1SPoul-Henning Kamp.if !target(distribute) 242cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR 243398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION} 244398ac038SJordan K. Hubbard cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 245398ac038SJordan K. Hubbard.endfor 24655ff8fb1SPoul-Henning Kamp.endif 24755ff8fb1SPoul-Henning Kamp 248639a2e50SGarrett Wollman.if !target(load) 249fe3cac87SNick Hibmaload: ${PROG} install 250fe3cac87SNick Hibma ${KMODLOAD} ${KMOD} 251639a2e50SGarrett Wollman.endif 252639a2e50SGarrett Wollman 253639a2e50SGarrett Wollman.if !target(unload) 254fe3cac87SNick Hibmaunload: 255fe3cac87SNick Hibma ${KMODUNLOAD} ${KMOD} 256639a2e50SGarrett Wollman.endif 257639a2e50SGarrett Wollman 25808a04a89SPeter Wemm.if exists(${.CURDIR}/../../kern) 25908a04a89SPeter WemmKERN= ${.CURDIR}/../../kern 26008a04a89SPeter Wemm.else 2611aa57be3SGarrett WollmanKERN= ${.CURDIR}/../../sys/kern 26208a04a89SPeter Wemm.endif 2631aa57be3SGarrett Wollman 2641aa57be3SGarrett Wollmanvnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 2651aa57be3SGarrett Wollman sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 2661aa57be3SGarrett Wollman 26771395925SPeter Wemmregress: 26869b87d3eSEivind Eklund 26968e00b92SJordan K. Hubbard.include <bsd.dep.mk> 27047da63c3SBruce Evans 27147da63c3SBruce Evans.if !exists(${DEPENDFILE}) 272589d9341SBruce Evans${OBJS}: ${SRCS:M*.h} 27347da63c3SBruce Evans.endif 27447da63c3SBruce Evans 275afba897fSBruce Evans.include <bsd.obj.mk> 276afba897fSBruce Evans 2779e72552fSBruce Evans.include <bsd.kern.mk> 278