Home | History | Annotate | Line # | Download | only in conf
Makefile.kern.inc revision 1.236
      1 #	$NetBSD: Makefile.kern.inc,v 1.236 2015/09/03 14:23:52 uebayasi Exp $
      2 #
      3 # This file contains common `MI' targets and definitions and it is included
      4 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
      5 #
      6 # Each target in this file should be protected with `if !target(target)'
      7 # or `if !commands(target)' and each variable should only be conditionally
      8 # assigned `VAR ?= VALUE', so that everything can be overriden.
      9 #
     10 # DEBUG is set to -g if debugging.
     11 # PROF is set to -pg if profiling.
     12 #
     13 # To specify debugging, add the config line: makeoptions DEBUG="-g"
     14 # A better way is to specify -g only for a few files.
     15 #
     16 #	makeoptions DEBUGLIST="uvm* trap if_*"
     17 #
     18 # all ports are expected to include bsd.own.mk for toolchain settings
     19 
     20 # Default DEBUG to -g if kernel debug info is requested by MKKDEBUG=yes
     21 .if defined(MKKDEBUG) && ${MKKDEBUG} == "yes"
     22 DEBUG?=-g
     23 .endif
     24 
     25 ##
     26 ## (0) toolchain settings for things that aren't part of the standard
     27 ## toolchain
     28 ##
     29 HOST_SH?=	sh
     30 DBSYM?=		dbsym
     31 MKDEP?=		mkdep
     32 STRIP?=		strip
     33 OBJCOPY?=	objcopy
     34 OBJDUMP?=	objdump
     35 CSCOPE?=	cscope
     36 MKID?=		mkid
     37 UUDECODE?=	${TOOL_UUDECODE:Uuudecode}
     38 HEXDUMP?=	${TOOL_HEXDUMP:Uhexdump}
     39 GENASSYM?=	${TOOL_GENASSYM:Ugenassym}
     40 .MAKEOVERRIDES+=USETOOLS	# make sure proper value is propagated
     41 
     42 _MKMSG?=		@\#
     43 _MKSHMSG?=		echo
     44 _MKSHECHO?=		echo
     45 _MKSHNOECHO=		:
     46 _MKMSG_CREATE?=		:
     47 _MKTARGET_COMPILE?=	:
     48 _MKTARGET_CREATE?=	:
     49 
     50 ##
     51 ## (1) port independent source tree identification
     52 ##
     53 # source tree is located via $S relative to the compilation directory
     54 .ifndef S
     55 S!=	cd ../../../..; pwd
     56 .endif
     57 
     58 ##
     59 ## (2) compile settings
     60 ##
     61 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
     62 ##
     63 INCLUDES?=	-I. ${EXTRA_INCLUDES} -I${S}/../common/include -I$S/arch \
     64 		-I$S -nostdinc
     65 CPPFLAGS+=	${INCLUDES} ${IDENT} -D_KERNEL -D_KERNEL_OPT
     66 CPPFLAGS+=	-std=gnu99
     67 DEFCOPTS?=	-O2
     68 COPTS?=		${DEFCOPTS}
     69 DBG=		# might contain unwanted -Ofoo
     70 CWARNFLAGS+=	-Wall -Wno-main -Wno-format-zero-length -Wpointer-arith
     71 CWARNFLAGS+=	-Wmissing-prototypes -Wstrict-prototypes
     72 CWARNFLAGS+=	-Wold-style-definition
     73 CWARNFLAGS+=	-Wswitch -Wshadow
     74 CWARNFLAGS+=	-Wcast-qual -Wwrite-strings
     75 CWARNFLAGS+=	-Wno-unreachable-code
     76 #CWARNFLAGS+=	-Wc++-compat -Wno-error=c++-compat
     77 CWARNFLAGS+=	-Wno-pointer-sign -Wno-attributes
     78 .  if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "x86_64" || \
     79 	${MACHINE_ARCH} == "sparc64" || ${MACHINE} == "prep"
     80 CWARNFLAGS+=	-Wextra -Wno-unused-parameter
     81 .  endif
     82 .  if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "x86_64"
     83 CWARNFLAGS+=	-Wold-style-definition
     84 .  endif
     85 # Add -Wno-sign-compare.  -Wsign-compare is included in -Wall as of GCC 3.3,
     86 # but our sources aren't up for it yet.
     87 CWARNFLAGS+=	-Wno-sign-compare
     88 
     89 CWARNFLAGS.clang+=	-Wno-unknown-pragmas -Wno-conversion \
     90 			-Wno-self-assign
     91 
     92 CWARNFLAGS.ah_regdomain.c= ${${ACTIVE_CC} == "clang":? \
     93     -Wno-shift-count-negative -Wno-shift-count-overflow:}
     94 
     95 CWARNFLAGS.ioconf.c= ${${ACTIVE_CC} == "clang":? -Wno-unused-const-variable :}
     96 
     97 CFLAGS+=	-ffreestanding -fno-zero-initialized-in-bss
     98 CFLAGS+=	${DEBUG} ${COPTS}
     99 AFLAGS+=	-D_LOCORE -Wa,--fatal-warnings
    100 
    101 # XXX
    102 .if defined(HAVE_GCC) || defined(HAVE_LLVM)
    103 CFLAGS+=	-fno-strict-aliasing
    104 CFLAGS+=	-fno-common
    105 .endif
    106 
    107 .if ${USE_SSP:Uno} == "yes"
    108 COPTS.kern_ssp.c+=	-fno-stack-protector -D__SSP__
    109 .endif
    110 
    111 # for multi-cpu machines, cpu_hatch() straddles the init of
    112 # __stack_chk_guard, so ensure stack protection is disabled
    113 .if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "x86_64"
    114 COPTS.cpu.c+=		-fno-stack-protector
    115 .endif
    116 
    117 # Use the per-source COPTS variables to add -g to just those
    118 # files that match the shell patterns given in ${DEBUGLIST}
    119 #
    120 .for i in ${DEBUGLIST}
    121 . for j in ${CFILES:T:M$i.c}
    122 COPTS.${j}+=-g
    123 . endfor
    124 .endfor
    125 
    126 # Always compile debugsyms.c with debug information.
    127 # This allows gdb to use type informations.
    128 #
    129 COPTS.debugsyms.c+=	-g
    130 
    131 # Add CTF sections for DTrace
    132 .if defined(CTFCONVERT)
    133 COMPILE_CTFCONVERT=	${_MKSHECHO}\
    134 			${CTFCONVERT} ${CTFFLAGS} ${.TARGET} && \
    135 			${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
    136 .else
    137 COMPILE_CTFCONVERT=	${_MKSHNOECHO}
    138 .endif
    139 
    140 KCOMPILE.c=	${CC} ${COPTS.${<:T}} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
    141 KCOMPILE.s=	${CC} ${AFLAGS} ${AFLAGS.${<:T}} ${CPPFLAGS} -c $< -o $@
    142 KLINK.o=	${LD} -r ${LINKFORMAT} -Map=${.TARGET}.map -o ${.TARGET} ${.ALLSRC}
    143 
    144 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
    145 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
    146 NORMAL_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}" && \
    147 		${_MKSHECHO} ${KCOMPILE.c} ${PROF} && \
    148 		${KCOMPILE.c} ${PROF} && \
    149 		${COMPILE_CTFCONVERT}
    150 NOPROF_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}" && \
    151 		${_MKSHECHO} ${KCOMPILE.c} && \
    152 		${KCOMPILE.c} && \
    153 		${COMPILE_CTFCONVERT}
    154 NORMAL_S?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}" && \
    155 		${_MKSHECHO} ${KCOMPILE.s} && \
    156 		${KCOMPILE.s}
    157 
    158 # link rules:
    159 LINK_O?=	@${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}" && \
    160 		${_MKSHECHO} ${KLINK.o} && \
    161 		${KLINK.o}
    162 
    163 ##
    164 ## (3) libkern and compat
    165 ##
    166 ## Set KERN_AS in the port Makefile to "obj" or "library".  The
    167 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
    168 ##
    169 
    170 ### find out what to use for libkern
    171 .include "$S/lib/libkern/Makefile.inc"
    172 .ifndef PROF
    173 LIBKERN?=	${KERNLIB}
    174 .else
    175 LIBKERN?=	${KERNLIB_PROF}
    176 .endif
    177 
    178 LIBKERNLN?=	${KERNLIBLN}
    179 
    180 ### find out what to use for libcompat
    181 .include "$S/compat/common/Makefile.inc"
    182 .ifndef PROF
    183 SYSLIBCOMPAT?=	${COMPATLIB}
    184 .else
    185 SYSLIBCOMPAT?=	${COMPATLIB_PROF}
    186 .endif
    187 
    188 SYSLIBCOMPATLN?=	${COMPATLIBLN}
    189 
    190 ##
    191 ## (4) local objects, compile rules, and dependencies
    192 ##
    193 ## Each port should have a corresponding section with settings for
    194 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
    195 ##
    196 
    197 .if !defined(___USE_SUFFIX_RULES___)
    198 _MD_OBJS=	${MD_OBJS:T}
    199 .else
    200 _MD_OBJS=	${MD_OBJS}
    201 .endif
    202 
    203 ##
    204 ## (5) link settings
    205 ##
    206 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, LINKSCRIPT, and any EXTRA_LINKFLAGS
    207 ## must be set in the port's Makefile.  The port specific definitions for
    208 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
    209 ## depending on the value of DEBUG.
    210 ##
    211 # load lines for config "xxx" will be emitted as:
    212 # xxx: ${SYSTEM_DEP} swapxxxx.o vers.o build_kernel
    213 
    214 SYSTEM_OBJ?=	${_MD_OBJS} ${OBJS} ${SYSLIBCOMPAT} ${LIBKERN}
    215 SYSTEM_DEP+=	Makefile ${SYSTEM_OBJ}
    216 .if defined(CTFMERGE)
    217 SYSTEM_CTFMERGE= ${CTFMERGE} ${CTFMFLAGS} -o ${.TARGET} ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
    218 .else
    219 SYSTEM_CTFMERGE= ${_MKSHECHO}
    220 .endif
    221 SYSTEM_LD_HEAD?=@rm -f $@
    222 SYSTEM_LD?=	${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
    223 		${_MKSHECHO}\
    224 		${LD} -Map ${.TARGET}.map --cref ${LINKFLAGS} -o ${.TARGET} \
    225 		'$${SYSTEM_OBJ:N*swap*netbsd*}' '$${EXTRA_OBJ}' vers.o \
    226 		${OBJS:M*swap${.TARGET}.o}; \
    227 		${LD} -Map ${.TARGET}.map --cref ${LINKFLAGS} -o ${.TARGET} \
    228 		${SYSTEM_OBJ:N*swap*netbsd*} ${EXTRA_OBJ} vers.o \
    229 		${OBJS:M*swap${.TARGET}.o}
    230 
    231 # Give MD generated ldscript dependency on ${SYSTEM_OBJ}
    232 .if defined(KERNLDSCRIPT)
    233 .if target(${KERNLDSCRIPT})
    234 ${KERNLDSCRIPT}: ${SYSTEM_OBJ}
    235 .endif
    236 .endif
    237 
    238 .if defined(KERNLDSCRIPT)
    239 .for k in ${KERNELS}
    240 EXTRA_CLEAN+=	${k}.ldscript
    241 ${k}: ${k}.ldscript
    242 ${k}.ldscript: ${KERNLDSCRIPT} assym.h
    243 	${_MKTARGET_CREATE}
    244 	${CPP} -I. ${KERNLDSCRIPT} | grep -v '^#' | grep -v '^$$' >$@
    245 .endfor
    246 LINKSCRIPT=	-T ${.TARGET}.ldscript
    247 .endif
    248 
    249 TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
    250 LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
    251 LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
    252 ENTRYPOINT?=	start
    253 LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
    254 LINKFLAGS?=	${LINKFORMAT} ${LINKSCRIPT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
    255 		${EXTRA_LINKFLAGS}
    256 
    257 LINKFLAGS_DEBUG?=	-X
    258 
    259 SYSTEM_LD_TAIL?=@${TOOL_SED} '/const char sccs/!d;s/.*@(.)//;s/" "//;s/\\.*//' vers.c; \
    260 		${SIZE} $@; chmod 755 $@; \
    261 		${SYSTEM_CTFMERGE}
    262 SYSTEM_LD_TAIL_DEBUG?=; \
    263 		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
    264 		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
    265 		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
    266 LINKFLAGS_NORMAL?=	-S
    267 STRIPFLAGS?=	-g
    268 
    269 DEBUG?=
    270 .if !empty(DEBUG:M-g*)
    271 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
    272 LINKFLAGS+=	${LINKFLAGS_DEBUG}
    273 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
    274 CTFFLAGS+=	-g
    275 TARGETSFX=	.gdb
    276 .elifndef PROF
    277 LINKFLAGS+=	${LINKFLAGS_NORMAL}
    278 .endif
    279 
    280 SYSTEM_LD_HEAD+=${SYSTEM_LD_HEAD_EXTRA}
    281 SYSTEM_LD_TAIL_STAGE1=	${SYSTEM_LD_TAIL}
    282 SYSTEM_LD_TAIL_STAGE2=	${SYSTEM_LD_TAIL}
    283 .if defined(COPY_SYMTAB)
    284 SYSTEM_LD_TAIL_STAGE2+=	; echo ${DBSYM} $@; ${DBSYM} $@
    285 .if !empty(DEBUG:M-g)
    286 SYSTEM_LD_TAIL_STAGE2+=	; echo ${DBSYM} $@.gdb; ${DBSYM} $@.gdb
    287 .endif
    288 .endif
    289 SYSTEM_LD_TAIL_STAGE2+=	${SYSTEM_LD_TAIL_EXTRA}
    290 
    291 ##
    292 ## (6) port independent targets and dependencies: assym.h, vers.o
    293 ##
    294 
    295 .if !defined(___USE_SUFFIX_RULES___)
    296 OBJS.c=	${CFILES:T:R:C|$|.o|}
    297 OBJS.s=	${SFILES:T:R:C|$|.o|}
    298 OBJS.o=	${OFILES}
    299 # absolute, generated (build directory), relative (under $S)
    300 _CFILES=${CFILES:M/*} ${CFILES:N/*:N*/*} ${CFILES:N/*:M*/*:C|^|$S/|}
    301 _SFILES=${SFILES:M/*} ${SFILES:N/*:N*/*} ${SFILES:N/*:M*/*:C|^|$S/|}
    302 _MD_CFILES=${MD_CFILES}
    303 _MD_SFILES=${MD_SFILES}
    304 .else
    305 OBJS.c=	${CFILES:R:C|$|.o|}
    306 OBJS.s=	${SFILES:R:C|$|.o|}
    307 OBJS.o=	${OFILES}
    308 _CFILES=${CFILES}
    309 _SFILES=${SFILES}
    310 _MD_CFILES=${MD_CFILES:C|^$S/||}
    311 _MD_SFILES=${MD_SFILES:C|^$S/||}
    312 .endif # ___USE_SUFFIX_RULES___
    313 OBJS=	${OBJS.c} ${OBJS.s} ${OBJS.o}
    314 
    315 .if !defined(___USE_SUFFIX_RULES___)
    316 .for _s in ${_CFILES}
    317 .if !commands(${_s:T:R}.o)
    318 ${_s:T:R}.o: ${_s}
    319 	${NORMAL_C}
    320 .endif
    321 .endfor
    322 
    323 .for _s in ${_SFILES}
    324 .if !commands(${_s:T:R}.o)
    325 ${_s:T:R}.o: ${_s}
    326 	${NORMAL_S}
    327 .endif
    328 .endfor
    329 .endif # !___USE_SUFFIX_RULES___
    330 
    331 assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS} $S/conf/genassym.cf
    332 	${_MKTARGET_CREATE}
    333 	cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} $S/conf/genassym.cf | \
    334 	    ${GENASSYM} -- ${CC} ${CFLAGS:N-Wa,*} ${CPPFLAGS} ${PROF} \
    335 	    ${GENASSYM_CPPFLAGS} > assym.h.tmp && \
    336 	mv -f assym.h.tmp assym.h
    337 ${_MD_SFILES:C/\.[Ss]/.o/} ${_SFILES:C/\.[Ss]/.o/}: assym.h
    338 
    339 MKREPRO?=no
    340 
    341 .if ${MKREPRO} == "yes"
    342 _NVFLAGS=${NVFLAGS} -r
    343 .else
    344 _NVFLAGS=${NVFLAGS}
    345 .endif
    346 
    347 .if !target(vers.o)
    348 newvers: vers.o
    349 vers.o: ${SYSTEM_OBJ:O} Makefile $S/conf/newvers.sh \
    350 		$S/conf/osrelease.sh ${_NETBSD_VERSION_DEPENDS}
    351 	${_MKMSG_CREATE} vers.c
    352 	${HOST_SH} $S/conf/newvers.sh ${_NVFLAGS}
    353 	${_MKTARGET_COMPILE}
    354 	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
    355 	${COMPILE_CTFCONVERT}
    356 .endif
    357 
    358 ##
    359 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
    360 ##                   cscope, mkid
    361 ##
    362 ## Any ports that have other stuff to be cleaned up should fill in
    363 ## EXTRA_CLEAN.  Some ports may want different settings for
    364 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
    365 ##
    366 
    367 ##
    368 ## clean
    369 ##
    370 
    371 .if !target(__CLEANKERNEL)
    372 __CLEANKERNEL: .USE
    373 	${_MKMSG} "${.TARGET}ing the kernel objects"
    374 	rm -f ${KERNELS} *.map eddep tags *.[io] *.ko *.ln [a-z]*.s vers.c \
    375 	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
    376 	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
    377 .endif
    378 
    379 .if !target(kernelnames)
    380 kernelnames:
    381 	@echo "${KERNELS} ${EXTRA_KERNELS}"
    382 .endif
    383 
    384 .if !target(__CLEANDEPEND)
    385 __CLEANDEPEND: .USE
    386 	echo .depend ${DEPS} | xargs rm -f --
    387 .endif
    388 
    389 # do not !target these, the kern and compat Makefiles augment them
    390 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
    391 clean: __CLEANKERNEL
    392 depend: .depend
    393 dependall: depend .WAIT all
    394 
    395 ##
    396 ## depend
    397 ##
    398 
    399 .if !target(.depend)
    400 MKDEP_AFLAGS?=	${AFLAGS}
    401 MKDEP_CFLAGS?=	${CFLAGS}
    402 SSRCS=${_MD_SFILES} ${_SFILES}
    403 CSRCS=${_MD_CFILES} ${_CFILES}
    404 SRCS=${SSRCS} ${CSRCS}
    405 .if !defined(___USE_SUFFIX_RULES___)
    406 DEPS=	${SRCS:T:u:R:S/$/.d/g}
    407 .else
    408 DEPS=	${SRCS:u:R:S/$/.d/g}
    409 .endif
    410 
    411 .if !defined(___USE_SUFFIX_RULES___)
    412 .for _s in ${SSRCS}
    413 .if !target(${_s:T:R}.d)
    414 ${_s:T:R}.d: ${_s} assym.h
    415 	${_MKTARGET_CREATE}
    416 	${MKDEP} -f ${.TARGET}.tmp -- ${MKDEP_AFLAGS} \
    417 	    ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
    418 	mv -f ${.TARGET}.tmp ${.TARGET}
    419 .endif
    420 .endfor
    421 
    422 .for _s in ${CSRCS}
    423 .if !target(${_s:T:R}.d)
    424 ${_s:T:R}.d: ${_s}
    425 	${_MKTARGET_CREATE}
    426 	${MKDEP} -f ${.TARGET}.tmp -- ${MKDEP_CFLAGS} \
    427 	    ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
    428 	mv -f ${.TARGET}.tmp ${.TARGET}
    429 .endif
    430 .endfor
    431 .endif # !___USE_SUFFIX_RULES___
    432 
    433 assym.d: assym.h
    434 	${_MKTARGET_CREATE}
    435 	cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
    436 	    ${GENASSYM} -- ${MKDEP} -f assym.dep -- \
    437 	    ${CFLAGS:N-Wa,*} ${CPPFLAGS} ${GENASSYM_CPPFLAGS}
    438 	${TOOL_SED} -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >${.TARGET}
    439 	rm -f assym.dep
    440 
    441 DEPS+=	assym.d
    442 
    443 .depend: ${DEPS}
    444 	${_MKTARGET_CREATE}
    445 	echo "${.ALLSRC}" | ${MKDEP} -D
    446 .endif
    447 
    448 ##
    449 ## install
    450 ##
    451 
    452 # List of kernel images that will be installed into the root file system.
    453 # Some platforms may need to install more than one (e.g. a netbsd.aout file
    454 # to be loaded directly by the firmware), so this can be overriden by them.
    455 KERNIMAGES?=	netbsd
    456 
    457 .if !target(install)
    458 # The install target can be redefined by putting a
    459 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
    460 MACHINE_NAME!=  uname -n
    461 install: install-kernel-${MACHINE_NAME}
    462 .if !target(install-kernel-${MACHINE_NAME})
    463 install-kernel-${MACHINE_NAME}:
    464 .for _K in ${KERNIMAGES}
    465 	rm -f ${DESTDIR}/o${_K}
    466 	ln ${DESTDIR}/${_K} ${DESTDIR}/o${_K}
    467 	cp ${_K} ${DESTDIR}/n${_K}
    468 	mv ${DESTDIR}/n${_K} ${DESTDIR}/${_K}
    469 .endfor
    470 .endif
    471 .endif
    472 
    473 .include "${S}/conf/splash.mk"
    474 .include "${S}/conf/mdroot.mk"
    475 .include "${S}/conf/lint.mk"
    476 .include "${S}/conf/cscope.mk"
    477 .include "${S}/conf/gdbinit.mk"
    478 
    479 ##
    480 ## the kernel
    481 ##
    482 
    483 # The following files use alloca(3) or variable array allocations.
    484 # Their full name is noted as documentation.
    485 VARSTACK=kern/uipc_socket.c miscfs/genfs/genfs_vnops.c \
    486     nfs/nfs_bio.c uvm/uvm_bio.c \
    487     uvm/uvm_pager.c dev/ic/aic7xxx.c dev/ic/aic79xx.c arch/xen/i386/gdt.c \
    488     dev/ofw/ofw_subr.c
    489 
    490 .for __varstack in ${VARSTACK}
    491 COPTS.${__varstack:T} += -Wno-stack-protector
    492 .endfor
    493 
    494 AFLAGS+=	${AOPTS.${.IMPSRC:T}}
    495 CFLAGS+=	${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}}
    496 CPPFLAGS+=	${CPPFLAGS.${.IMPSRC:T}}
    497 CWARNFLAGS+=	${CWARNFLAGS.${.IMPSRC:T}}
    498 
    499 .MAIN: all
    500 all: .gdbinit
    501 .for k in ${KERNELS}
    502 all: .WAIT ${k}
    503 ${k}: ${SYSTEM_DEP:O} swap${k}.o vers.o build_kernel
    504 .endfor
    505 
    506 .if !defined(COPY_SYMTAB)
    507 build_kernel: .USE
    508 	${SYSTEM_LD_HEAD}
    509 	${SYSTEM_LD}
    510 	${SYSTEM_LD_TAIL_STAGE2}
    511 .else
    512 .for k in ${KERNELS}
    513 ${k}: $S/kern/kern_ksyms_buf.c
    514 .endfor
    515 build_kernel: .USE
    516 	${CC} ${CFLAGS} ${CPPFLAGS} -DCOPY_SYMTAB \
    517 	    -c $S/kern/kern_ksyms_buf.c -o kern_ksyms_buf.o
    518 	${SYSTEM_LD_HEAD}
    519 	${SYSTEM_LD} kern_ksyms_buf.o
    520 	${SYSTEM_LD_TAIL_STAGE1}
    521 	${CC} ${CFLAGS} ${CPPFLAGS} -DCOPY_SYMTAB \
    522 	    -DSYMTAB_SPACE=$$(${DBSYM} -P ${.TARGET}${TARGETSFX}) \
    523 	    -c $S/kern/kern_ksyms_buf.c -o kern_ksyms_buf_real.o
    524 	${SYSTEM_LD_HEAD}
    525 	${SYSTEM_LD} kern_ksyms_buf_real.o
    526 	${SYSTEM_LD_TAIL_STAGE2}
    527 .endif
    528 
    529 .include <bsd.files.mk>
    530 .include <bsd.clang-analyze.mk>
    531 
    532 ##
    533 ## suffix rules
    534 ##
    535 
    536 .if defined(___USE_SUFFIX_RULES___)
    537 .SUFFIXES: .genassym .assym.h
    538 .genassym.assym.h:
    539 	${_MKTARGET_CREATE}
    540 	${GENASSYM} -- ${CC} ${CFLAGS:N-Wa,*} ${CPPFLAGS} ${PROF} \
    541 	    ${GENASSYM_CPPFLAGS} < $< > $@
    542 	mv -f $@.tmp $@
    543 
    544 .SUFFIXES: .s .d
    545 .s.d:
    546 	${_MKTARGET_CREATE}
    547 	${MKDEP} -f $@.tmp -- ${MKDEP_AFLAGS} ${CPPFLAGS} ${CPPFLAGS.${<:T}} $<
    548 	mv -f $@.tmp $@
    549 
    550 .SUFFIXES: .S .d
    551 .S.d:
    552 	${_MKTARGET_CREATE}
    553 	${MKDEP} -f $@.tmp -- ${MKDEP_AFLAGS} ${CPPFLAGS} ${CPPFLAGS.${<:T}} $<
    554 	mv -f $@.tmp $@
    555 
    556 .SUFFIXES: .c .d
    557 .c.d:
    558 	${_MKTARGET_CREATE}
    559 	${MKDEP} -f $@.tmp -- ${MKDEP_CFLAGS} ${CPPFLAGS} ${CPPFLAGS.${<:T}} $<
    560 	mv -f $@.tmp $@
    561 
    562 .SUFFIXES: .c .o .go .po
    563 .c.o:
    564 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    565 	@${_MKSHECHO} ${KCOMPILE.c}
    566 	@${KCOMPILE.c}
    567 	@${COMPILE_CTFCONVERT}
    568 .c.go:
    569 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    570 	@${_MKSHECHO} ${KCOMPILE.c} -g
    571 	@${KCOMPILE.c} -g
    572 	@${COMPILE_CTFCONVERT}
    573 .c.po:
    574 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    575 	@${_MKSHECHO} ${KCOMPILE.c} -pg
    576 	@${KCOMPILE.c} -pg
    577 	@${COMPILE_CTFCONVERT}
    578 
    579 .SUFFIXES: .s .o .go .po
    580 .s.o:
    581 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    582 	@${_MKSHECHO} ${KCOMPILE.s}
    583 	@${KCOMPILE.s}
    584 .s.go:
    585 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    586 	@${_MKSHECHO} ${KCOMPILE.s} -g
    587 	@${KCOMPILE.s} -g
    588 .s.po:
    589 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    590 	@${_MKSHECHO} ${KCOMPILE.s} -pg
    591 	@${KCOMPILE.s} -pg
    592 
    593 .S.o:
    594 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    595 	@${_MKSHECHO} ${KCOMPILE.s}
    596 	@${KCOMPILE.s}
    597 .S.go:
    598 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    599 	@${_MKSHECHO} ${KCOMPILE.s} -g
    600 	@${KCOMPILE.s} -g
    601 .S.po:
    602 	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"
    603 	@${_MKSHECHO} ${KCOMPILE.s} -pg
    604 	@${KCOMPILE.s} -pg
    605 .endif # ___USE_SUFFIX_RULES___
    606 
    607 ##
    608 ## the end
    609 ##
    610