2003-11-14 23:09:38 +00:00
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
# Part of a unified Makefile for building kernels. This part includes all
|
|
|
|
# the definitions that need to be after all the % directives except %RULES
|
|
|
|
# and ones that act like they are part of %RULES.
|
2001-11-02 21:34:20 +00:00
|
|
|
#
|
2002-01-05 06:21:06 +00:00
|
|
|
# Most make variables should not be defined in this file. Instead, they
|
|
|
|
# should be defined in the kern.pre.mk so that port makefiles can
|
2002-01-06 20:33:55 +00:00
|
|
|
# override or augment them.
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2003-05-31 21:16:12 +00:00
|
|
|
# In case the config had a makeoptions DESTDIR...
|
|
|
|
.if defined(DESTDIR)
|
|
|
|
MKMODULESENV+= DESTDIR="${DESTDIR}"
|
|
|
|
.endif
|
2009-05-04 20:25:56 +00:00
|
|
|
SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;}
|
|
|
|
MKMODULESENV+= KERNBUILDDIR="${.CURDIR}" SYSDIR="${SYSDIR}"
|
2003-05-31 21:16:12 +00:00
|
|
|
|
2010-03-25 13:47:21 +00:00
|
|
|
.if defined(CONF_CFLAGS)
|
|
|
|
MKMODULESENV+= CONF_CFLAGS="${CONF_CFLAGS}"
|
|
|
|
.endif
|
|
|
|
|
2010-04-02 06:55:31 +00:00
|
|
|
.if defined(WITH_CTF)
|
|
|
|
MKMODULESENV+= WITH_CTF="${WITH_CTF}"
|
|
|
|
.endif
|
|
|
|
|
2003-02-21 11:02:49 +00:00
|
|
|
.MAIN: all
|
|
|
|
|
2003-03-03 09:35:44 +00:00
|
|
|
.for target in all clean cleandepend cleandir clobber depend install \
|
|
|
|
obj reinstall tags
|
2003-02-21 11:02:49 +00:00
|
|
|
${target}: kernel-${target}
|
|
|
|
.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
|
|
|
|
${target}: modules-${target}
|
|
|
|
modules-${target}:
|
2003-03-03 09:35:44 +00:00
|
|
|
cd $S/modules; ${MKMODULESENV} ${MAKE} \
|
|
|
|
${target:S/^reinstall$/install/:S/^clobber$/cleandir/}
|
2003-02-21 11:02:49 +00:00
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
|
2004-11-11 23:58:14 +00:00
|
|
|
# Handle out of tree ports
|
2005-06-09 05:38:18 +00:00
|
|
|
.if !defined(NO_MODULES) && defined(PORTS_MODULES)
|
2005-02-25 05:34:45 +00:00
|
|
|
PORTSMODULESENV=SYSDIR=${SYSDIR}
|
2005-06-05 18:34:16 +00:00
|
|
|
.for __target in all install reinstall clean
|
2005-02-25 05:34:45 +00:00
|
|
|
${__target}: ports-${__target}
|
2005-02-25 02:25:38 +00:00
|
|
|
ports-${__target}:
|
2004-11-11 23:58:14 +00:00
|
|
|
.for __i in ${PORTS_MODULES}
|
2005-06-05 18:34:16 +00:00
|
|
|
cd $${PORTSDIR:-/usr/ports}/${__i}; ${PORTSMODULESENV} ${MAKE} -B ${__target:C/install/deinstall reinstall/:C/reinstall/deinstall reinstall/}
|
2004-11-11 23:58:14 +00:00
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
.endif
|
|
|
|
|
2003-02-21 11:02:49 +00:00
|
|
|
.ORDER: kernel-install modules-install
|
|
|
|
|
2007-03-23 21:55:59 +00:00
|
|
|
kernel-all: ${KERNEL_KO} ${KERNEL_EXTRA}
|
2003-02-21 11:02:49 +00:00
|
|
|
|
2006-02-07 13:37:26 +00:00
|
|
|
kernel-cleandir: kernel-clean kernel-cleandepend
|
2003-03-03 09:35:44 +00:00
|
|
|
|
|
|
|
kernel-clobber:
|
2003-03-02 21:25:00 +00:00
|
|
|
find . -maxdepth 1 ! -type d ! -name version -delete
|
|
|
|
|
|
|
|
kernel-obj:
|
2003-02-21 11:02:49 +00:00
|
|
|
|
|
|
|
.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
|
|
|
|
modules: modules-all
|
|
|
|
|
|
|
|
.if !defined(NO_MODULES_OBJ)
|
|
|
|
modules-all modules-depend: modules-obj
|
|
|
|
.endif
|
|
|
|
.endif
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2005-10-24 23:54:39 +00:00
|
|
|
.if !defined(DEBUG)
|
|
|
|
FULLKERNEL= ${KERNEL_KO}
|
|
|
|
.else
|
|
|
|
FULLKERNEL= ${KERNEL_KO}.debug
|
2005-10-27 17:39:03 +00:00
|
|
|
${KERNEL_KO}: ${FULLKERNEL} ${KERNEL_KO}.symbols
|
|
|
|
${OBJCOPY} --strip-debug --add-gnu-debuglink=${KERNEL_KO}.symbols\
|
2005-10-27 14:24:45 +00:00
|
|
|
${FULLKERNEL} ${.TARGET}
|
2005-10-27 17:39:03 +00:00
|
|
|
${KERNEL_KO}.symbols: ${FULLKERNEL}
|
2005-10-27 14:24:45 +00:00
|
|
|
${OBJCOPY} --only-keep-debug ${FULLKERNEL} ${.TARGET}
|
2005-10-25 09:05:07 +00:00
|
|
|
install.debug reinstall.debug: gdbinit
|
|
|
|
cd ${.CURDIR}; ${MAKE} ${.TARGET:R}
|
2003-06-12 08:09:48 +00:00
|
|
|
|
2003-12-29 11:28:21 +00:00
|
|
|
# Install gdbinit files for kernel debugging.
|
2003-06-12 08:09:48 +00:00
|
|
|
gdbinit:
|
2003-12-29 11:28:21 +00:00
|
|
|
grep -v '# XXX' ${S}/../tools/debugscripts/dot.gdbinit | \
|
|
|
|
sed "s:MODPATH:${.OBJDIR}/modules:" > .gdbinit
|
2004-09-23 08:34:50 +00:00
|
|
|
cp ${S}/../tools/debugscripts/gdbinit.kernel ${.CURDIR}
|
2010-08-23 22:24:11 +00:00
|
|
|
.if exists(${S}/../tools/debugscripts/gdbinit.${MACHINE_CPUARCH})
|
|
|
|
cp ${S}/../tools/debugscripts/gdbinit.${MACHINE_CPUARCH} \
|
2003-12-29 11:28:21 +00:00
|
|
|
${.CURDIR}/gdbinit.machine
|
2001-11-02 21:34:20 +00:00
|
|
|
.endif
|
2004-01-21 08:23:46 +00:00
|
|
|
.endif
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2005-10-24 23:54:39 +00:00
|
|
|
${FULLKERNEL}: ${SYSTEM_DEP} vers.o
|
2001-11-02 21:34:20 +00:00
|
|
|
@rm -f ${.TARGET}
|
|
|
|
@echo linking ${.TARGET}
|
|
|
|
${SYSTEM_LD}
|
2011-11-29 16:34:44 +00:00
|
|
|
.if defined(WITH_CTF)
|
2011-11-29 08:38:47 +00:00
|
|
|
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
|
|
|
|
.endif
|
2004-02-13 13:21:41 +00:00
|
|
|
.if !defined(DEBUG)
|
|
|
|
${OBJCOPY} --strip-debug ${.TARGET}
|
|
|
|
.endif
|
2001-11-02 21:34:20 +00:00
|
|
|
${SYSTEM_LD_TAIL}
|
2006-06-13 00:57:10 +00:00
|
|
|
.if defined(MFS_IMAGE)
|
2008-02-05 10:46:30 +00:00
|
|
|
@sh ${S}/tools/embed_mfs.sh ${FULLKERNEL} ${MFS_IMAGE}
|
2006-06-13 00:57:10 +00:00
|
|
|
.endif
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2003-06-22 17:57:56 +00:00
|
|
|
.if !exists(${.OBJDIR}/.depend)
|
2004-06-26 06:02:06 +00:00
|
|
|
${SYSTEM_OBJS}: assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/}
|
2001-11-02 21:34:20 +00:00
|
|
|
.endif
|
|
|
|
|
2003-06-14 17:28:13 +00:00
|
|
|
LNFILES= ${CFILES:T:S/.c$/.ln/}
|
|
|
|
|
2001-11-02 21:34:20 +00:00
|
|
|
.for mfile in ${MFILES}
|
2002-08-19 01:00:37 +00:00
|
|
|
# XXX the low quality .m.o rules gnerated by config are normally used
|
|
|
|
# instead of the .m.c rules here.
|
|
|
|
${mfile:T:S/.m$/.c/}: ${mfile}
|
|
|
|
${AWK} -f $S/tools/makeobjops.awk ${mfile} -c
|
2001-11-02 21:34:20 +00:00
|
|
|
${mfile:T:S/.m$/.h/}: ${mfile}
|
2002-05-01 03:28:14 +00:00
|
|
|
${AWK} -f $S/tools/makeobjops.awk ${mfile} -h
|
2001-11-02 21:34:20 +00:00
|
|
|
.endfor
|
|
|
|
|
|
|
|
kernel-clean:
|
|
|
|
rm -f *.o *.so *.So *.ko *.s eddep errs \
|
2005-10-27 17:39:03 +00:00
|
|
|
${FULLKERNEL} ${KERNEL_KO} ${KERNEL_KO}.symbols \
|
2005-10-27 14:24:45 +00:00
|
|
|
linterrs makelinks tags vers.c \
|
2005-04-22 19:58:22 +00:00
|
|
|
vnode_if.c vnode_if.h vnode_if_newproto.h vnode_if_typedef.h \
|
2003-12-29 11:28:21 +00:00
|
|
|
${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
|
2006-10-13 22:28:14 +00:00
|
|
|
${CLEAN}
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2003-06-14 17:28:13 +00:00
|
|
|
lint: ${LNFILES}
|
2003-12-29 11:28:21 +00:00
|
|
|
${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \
|
|
|
|
tee -a linterrs
|
2002-03-17 10:05:57 +00:00
|
|
|
|
2001-11-02 21:34:20 +00:00
|
|
|
# This is a hack. BFD "optimizes" away dynamic mode if there are no
|
|
|
|
# dynamic references. We could probably do a '-Bforcedynamic' mode like
|
|
|
|
# in the a.out ld. For now, this works.
|
|
|
|
HACK_EXTRA_FLAGS?= -shared
|
|
|
|
hack.So: Makefile
|
2006-08-14 13:28:53 +00:00
|
|
|
:> hack.c
|
2003-12-29 11:34:33 +00:00
|
|
|
${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So
|
2001-11-02 21:34:20 +00:00
|
|
|
rm -f hack.c
|
|
|
|
|
2003-12-29 11:28:21 +00:00
|
|
|
# This rule stops ./assym.s in .depend from causing problems.
|
2001-11-02 21:34:20 +00:00
|
|
|
./assym.s: assym.s
|
|
|
|
|
|
|
|
assym.s: $S/kern/genassym.sh genassym.o
|
2004-03-22 15:45:17 +00:00
|
|
|
NM='${NM}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
|
2001-11-02 21:34:20 +00:00
|
|
|
|
|
|
|
genassym.o: $S/$M/$M/genassym.c
|
2003-12-30 07:54:39 +00:00
|
|
|
${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c
|
2001-11-02 21:34:20 +00:00
|
|
|
|
|
|
|
${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
|
|
|
|
|
2005-04-22 17:36:25 +00:00
|
|
|
kernel-depend: .depend
|
2002-08-18 20:41:19 +00:00
|
|
|
# The argument list can be very long, so use make -V and xargs to
|
2002-02-23 01:49:13 +00:00
|
|
|
# pass it to mkdep.
|
2005-11-30 18:15:06 +00:00
|
|
|
SRCS= assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \
|
|
|
|
${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
|
|
|
|
${MFILES:T:S/.m$/.h/}
|
2006-10-13 22:28:14 +00:00
|
|
|
.depend: .PRECIOUS ${SRCS}
|
2001-11-02 21:34:20 +00:00
|
|
|
rm -f .newdep
|
2004-06-27 23:03:43 +00:00
|
|
|
${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | \
|
2002-08-18 20:41:19 +00:00
|
|
|
MKDEP_CPP="${CC} -E" CC="${CC}" xargs mkdep -a -f .newdep ${CFLAGS}
|
2003-02-28 21:59:14 +00:00
|
|
|
${MAKE} -V SFILES | \
|
2002-08-18 20:41:19 +00:00
|
|
|
MKDEP_CPP="${CC} -E" xargs mkdep -a -f .newdep ${ASM_CFLAGS}
|
2001-11-02 21:34:20 +00:00
|
|
|
rm -f .depend
|
|
|
|
mv .newdep .depend
|
|
|
|
|
2005-11-30 18:15:06 +00:00
|
|
|
_ILINKS= machine
|
2010-07-13 13:11:18 +00:00
|
|
|
.if ${MACHINE} != ${MACHINE_CPUARCH}
|
|
|
|
_ILINKS+= ${MACHINE_CPUARCH}
|
2005-11-30 18:15:06 +00:00
|
|
|
.endif
|
2010-11-01 17:34:04 +00:00
|
|
|
.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
|
|
|
|
_ILINKS+= x86
|
|
|
|
.endif
|
2005-11-30 18:15:06 +00:00
|
|
|
|
|
|
|
# Ensure that the link exists without depending on it when it exists.
|
|
|
|
.for _link in ${_ILINKS}
|
|
|
|
.if !exists(${.OBJDIR}/${_link})
|
|
|
|
${SRCS}: ${_link}
|
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
|
|
|
|
${_ILINKS}:
|
|
|
|
@case ${.TARGET} in \
|
|
|
|
machine) \
|
|
|
|
path=${S}/${MACHINE}/include ;; \
|
2010-11-01 17:34:04 +00:00
|
|
|
*) \
|
|
|
|
path=${S}/${.TARGET}/include ;; \
|
2005-11-30 18:15:06 +00:00
|
|
|
esac ; \
|
|
|
|
${ECHO} ${.TARGET} "->" $$path ; \
|
|
|
|
ln -s $$path ${.TARGET}
|
|
|
|
|
2006-10-13 22:28:14 +00:00
|
|
|
# .depend needs include links so we remove them only together.
|
2001-11-02 21:34:20 +00:00
|
|
|
kernel-cleandepend:
|
2006-10-13 22:28:14 +00:00
|
|
|
rm -f .depend ${_ILINKS}
|
2001-11-02 21:34:20 +00:00
|
|
|
|
|
|
|
links:
|
|
|
|
egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
|
2003-12-29 11:28:21 +00:00
|
|
|
sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
|
2002-02-22 04:44:28 +00:00
|
|
|
${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
|
2003-12-29 11:28:21 +00:00
|
|
|
sort -u | comm -23 - dontlink | \
|
|
|
|
sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
|
2001-11-02 21:34:20 +00:00
|
|
|
sh makelinks; rm -f dontlink
|
|
|
|
|
|
|
|
kernel-tags:
|
|
|
|
@[ -f .depend ] || { echo "you must make depend first"; exit 1; }
|
|
|
|
sh $S/conf/systags.sh
|
|
|
|
|
2004-03-20 22:47:30 +00:00
|
|
|
kernel-install:
|
2005-10-27 14:24:45 +00:00
|
|
|
@if [ ! -f ${KERNEL_KO} ] ; then \
|
2001-11-02 21:34:20 +00:00
|
|
|
echo "You must build a kernel first." ; \
|
|
|
|
exit 1 ; \
|
|
|
|
fi
|
|
|
|
.if exists(${DESTDIR}${KODIR})
|
|
|
|
-thiskernel=`sysctl -n kern.bootfile` ; \
|
2005-04-28 14:45:57 +00:00
|
|
|
if [ ! "`dirname "$$thiskernel"`" -ef ${DESTDIR}${KODIR} ] ; then \
|
2001-11-02 21:34:20 +00:00
|
|
|
chflags -R noschg ${DESTDIR}${KODIR} ; \
|
|
|
|
rm -rf ${DESTDIR}${KODIR} ; \
|
|
|
|
else \
|
|
|
|
if [ -d ${DESTDIR}${KODIR}.old ] ; then \
|
|
|
|
chflags -R noschg ${DESTDIR}${KODIR}.old ; \
|
|
|
|
rm -rf ${DESTDIR}${KODIR}.old ; \
|
|
|
|
fi ; \
|
|
|
|
mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
|
2003-08-07 19:12:06 +00:00
|
|
|
sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \
|
2001-11-02 21:34:20 +00:00
|
|
|
fi
|
|
|
|
.endif
|
|
|
|
mkdir -p ${DESTDIR}${KODIR}
|
2009-01-07 09:56:54 +00:00
|
|
|
${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO} ${DESTDIR}${KODIR}
|
2011-05-22 18:09:51 +00:00
|
|
|
.if defined(DEBUG) && !defined(INSTALL_NODEBUG) && \
|
2011-05-23 21:32:45 +00:00
|
|
|
(defined(MK_KERNEL_SYMBOLS) && ${MK_KERNEL_SYMBOLS} != "no")
|
2009-01-07 09:56:54 +00:00
|
|
|
${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO}.symbols ${DESTDIR}${KODIR}
|
2005-10-24 23:54:39 +00:00
|
|
|
.endif
|
2007-03-23 21:55:59 +00:00
|
|
|
.if defined(KERNEL_EXTRA_INSTALL)
|
2009-01-07 09:56:54 +00:00
|
|
|
${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_EXTRA_INSTALL} ${DESTDIR}${KODIR}
|
2007-03-23 21:55:59 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2002-04-24 11:26:19 +00:00
|
|
|
kernel-reinstall:
|
2001-11-02 21:34:20 +00:00
|
|
|
@-chflags -R noschg ${DESTDIR}${KODIR}
|
2009-01-07 09:56:54 +00:00
|
|
|
${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO} ${DESTDIR}${KODIR}
|
2011-05-22 18:09:51 +00:00
|
|
|
.if defined(DEBUG) && !defined(INSTALL_NODEBUG) && \
|
2011-05-23 21:32:45 +00:00
|
|
|
(defined(MK_KERNEL_SYMBOLS) && ${MK_KERNEL_SYMBOLS} != "no")
|
2009-01-07 09:56:54 +00:00
|
|
|
${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO}.symbols ${DESTDIR}${KODIR}
|
2005-10-24 23:54:39 +00:00
|
|
|
.endif
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2005-03-29 11:23:25 +00:00
|
|
|
config.o env.o hints.o vers.o vnode_if.o:
|
2001-11-02 21:34:20 +00:00
|
|
|
${NORMAL_C}
|
2011-11-29 16:34:44 +00:00
|
|
|
@${NORMAL_CTFCONVERT}
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2005-03-29 11:23:25 +00:00
|
|
|
config.ln env.ln hints.ln vers.ln vnode_if.ln:
|
2003-06-14 17:28:13 +00:00
|
|
|
${NORMAL_LINT}
|
|
|
|
|
2001-11-02 21:34:20 +00:00
|
|
|
vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
|
2004-09-17 09:17:33 +00:00
|
|
|
MAKE=${MAKE} sh $S/conf/newvers.sh ${KERN_IDENT}
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2002-03-01 01:21:29 +00:00
|
|
|
vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
|
|
|
|
${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2006-10-26 19:04:20 +00:00
|
|
|
vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: $S/tools/vnode_if.awk \
|
|
|
|
$S/kern/vnode_if.src
|
|
|
|
vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
|
2002-03-01 01:21:29 +00:00
|
|
|
${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
|
2006-10-26 19:04:20 +00:00
|
|
|
vnode_if_newproto.h:
|
2004-12-01 23:16:38 +00:00
|
|
|
${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p
|
2006-10-26 19:04:20 +00:00
|
|
|
vnode_if_typedef.h:
|
2004-12-01 23:16:38 +00:00
|
|
|
${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q
|
2001-11-02 21:34:20 +00:00
|
|
|
|
2003-06-22 17:57:56 +00:00
|
|
|
# XXX strictly, everything depends on Makefile because changes to ${PROF}
|
|
|
|
# only appear there, but we don't handle that.
|
2003-06-14 17:28:13 +00:00
|
|
|
|
2003-02-28 22:12:17 +00:00
|
|
|
.include "kern.mk"
|