Home | History | Annotate | Line # | Download | only in conf
Makefile.kern.inc revision 1.68.2.4
      1 #	$NetBSD: Makefile.kern.inc,v 1.68.2.4 2007/09/03 14:33:04 yamt 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 ##
     21 ## (0) toolchain settings for things that aren't part of the standard
     22 ## toolchain
     23 ##
     24 HOST_SH?=	sh
     25 DBSYM?=		dbsym
     26 MKDEP?=		mkdep
     27 STRIP?=		strip
     28 OBJCOPY?=	objcopy
     29 OBJDUMP?=	objdump
     30 CSCOPE?=	cscope
     31 MKID?=		mkid
     32 UUDECODE?=	${TOOL_UUDECODE:Uuudecode}
     33 HEXDUMP?=	${TOOL_HEXDUMP:Uhexdump}
     34 GENASSYM?=	${TOOL_GENASSYM:Ugenassym}
     35 .MAKEOVERRIDES+=USETOOLS	# make sure proper value is propagated
     36 
     37 _MKMSG?=		@\#
     38 _MKSHMSG?=		echo
     39 _MKSHECHO?=		echo
     40 _MKMSG_CREATE?=		:
     41 _MKTARGET_COMPILE?=	:
     42 _MKTARGET_CREATE?=	:
     43 
     44 ##
     45 ## (1) port independent source tree identification
     46 ##
     47 # source tree is located via $S relative to the compilation directory
     48 .ifndef S
     49 S!=	cd ../../../..; pwd
     50 .endif
     51 
     52 ##
     53 ## (2) compile settings
     54 ##
     55 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
     56 ##
     57 INCLUDES?=	-I. ${EXTRA_INCLUDES} -I${S}/../common/include -I$S/arch \
     58 		-I$S -nostdinc
     59 CPPFLAGS+=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
     60 DEFCOPTS?=	-O2
     61 COPTS?=		${DEFCOPTS}
     62 DBG=		# might contain unwanted -Ofoo
     63 DEFWARNINGS?=	yes
     64 .if (${DEFWARNINGS} == "yes")
     65 . if !defined(NOGCCERROR)
     66 CWARNFLAGS+=	-Werror
     67 . endif
     68 CWARNFLAGS+=	-Wall -Wno-main -Wno-format-zero-length -Wpointer-arith
     69 CWARNFLAGS+=	-Wmissing-prototypes -Wstrict-prototypes
     70 CWARNFLAGS+=	-Wswitch -Wshadow
     71 CWARNFLAGS+=	-Wcast-qual -Wwrite-strings
     72 # Add -Wno-sign-compare.  -Wsign-compare is included in -Wall as of GCC 3.3,
     73 # but our sources aren't up for it yet.
     74 CWARNFLAGS+=	-Wno-sign-compare
     75 . if ${HAVE_GCC} > 3
     76 CWARNFLAGS+=	-Wno-pointer-sign -Wno-attributes
     77 .  if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "sparc64" || ${MACHINE} == "prep"
     78 CWARNFLAGS+=	-Wextra -Wno-unused-parameter
     79 .  endif
     80 . endif
     81 .endif
     82 
     83 CFLAGS+=	-ffreestanding -fno-zero-initialized-in-bss
     84 CFLAGS+=	${CPUFLAGS} ${DEBUG} ${COPTS} ${CWARNFLAGS}
     85 AFLAGS+=	${CPUFLAGS} -D_LOCORE -Wa,-fatal-warnings
     86 
     87 # XXX
     88 .if ${HAVE_GCC} > 3
     89 CFLAGS+=	-fno-strict-aliasing
     90 .endif
     91 
     92 .if ${USE_FORT:Uno} == "yes"
     93 CFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
     94 LDFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
     95 .endif
     96 
     97 # If we want the bpendtsleep: label in kern_synch.c, we need to use
     98 # -fno-reorder-blocks.  Don't make this a config(1) defflag without
     99 # making sure this fragment remains valid.
    100 .if ${HAVE_GCC} > 3 && !empty(${CFLAGS:M-DKERN_SYNCH_BPENDTSLEEP_LABEL})
    101 CFLAGS.kern_synch.c+=	-fno-reorder-blocks
    102 .endif
    103 
    104 # Use the per-source COPTS variables to add -g to just those
    105 # files that match the shell patterns given in ${DEBUGLIST}
    106 #
    107 .for i in ${DEBUGLIST}
    108 . for j in ${CFILES:T:M$i.c}
    109 COPTS.${j}+=-g
    110 . endfor
    111 .endfor
    112 
    113 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
    114 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
    115 NORMAL_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"; \
    116 		${_MKSHECHO}\
    117 		${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<; \
    118 		${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
    119 NOPROF_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"; \
    120 		${_MKSHECHO}\
    121 		${CC} ${CFLAGS} ${CPPFLAGS} -c $<; \
    122 		${CC} ${CFLAGS} ${CPPFLAGS} -c $<
    123 NORMAL_S?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"; \
    124 		${_MKSHECHO}\
    125 		${CC} ${AFLAGS} ${CPPFLAGS} -c $<; \
    126 		${CC} ${AFLAGS} ${CPPFLAGS} -c $<
    127 
    128 ##
    129 ## (3) libkern and compat
    130 ##
    131 ## Set KERN_AS in the port Makefile to "obj" or "library".  The
    132 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
    133 ##
    134 
    135 ### find out what to use for libkern
    136 .include "$S/lib/libkern/Makefile.inc"
    137 .ifndef PROF
    138 LIBKERN?=	${KERNLIB}
    139 .else
    140 LIBKERN?=	${KERNLIB_PROF}
    141 .endif
    142 
    143 LIBKERNLN?=	${KERNLIBLN}
    144 
    145 ### find out what to use for libcompat
    146 .include "$S/compat/common/Makefile.inc"
    147 .ifndef PROF
    148 SYSLIBCOMPAT?=	${COMPATLIB}
    149 .else
    150 SYSLIBCOMPAT?=	${COMPATLIB_PROF}
    151 .endif
    152 
    153 SYSLIBCOMPATLN?=	${COMPATLIBLN}
    154 
    155 ##
    156 ## (4) local objects, compile rules, and dependencies
    157 ##
    158 ## Each port should have a corresponding section with settings for
    159 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
    160 ##
    161 MI_CFILES=devsw.c ioconf.c param.c
    162 # the need for a MI_SFILES variable is dubitable at best
    163 MI_OBJS=${MI_CFILES:S/.c/.o/}
    164 
    165 param.c: $S/conf/param.c
    166 	${_MKTARGET_CREATE}
    167 	rm -f param.c
    168 	cp $S/conf/param.c .
    169 
    170 param.o: Makefile
    171 
    172 .for _cfile in ${MI_CFILES}
    173 ${_cfile:T:R}.o: ${_cfile}
    174 	${NORMAL_C}
    175 .endfor
    176 
    177 ##
    178 ## (5) link settings
    179 ##
    180 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
    181 ## be set in the port's Makefile.  The port specific definitions for
    182 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
    183 ## depending on the value of DEBUG.
    184 ##
    185 # load lines for config "xxx" will be emitted as:
    186 # xxx: ${SYSTEM_DEP} swapxxx.o
    187 #	${SYSTEM_LD_HEAD}
    188 #	${SYSTEM_LD} swapxxx.o
    189 #	${SYSTEM_LD_TAIL}
    190 SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${SYSLIBCOMPAT} ${LIBKERN}
    191 SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ:O} .gdbinit
    192 SYSTEM_LD_HEAD?=@rm -f $@
    193 SYSTEM_LD?=	@${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
    194 		${_MKSHECHO}\
    195 		${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o; \
    196 		${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
    197 SYSTEM_LD_TAIL?=@${SIZE} $@; chmod 755 $@
    198 
    199 TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
    200 LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
    201 LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
    202 ENTRYPOINT?=	start
    203 LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
    204 LINKFLAGS?=	${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
    205 		${EXTRA_LINKFLAGS}
    206 
    207 LINKFLAGS_DEBUG?=	-X
    208 SYSTEM_LD_TAIL_DEBUG?=; \
    209 		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
    210 		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
    211 		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
    212 LINKFLAGS_NORMAL?=	-S
    213 STRIPFLAGS?=	-g
    214 
    215 DEBUG?=
    216 .if !empty(DEBUG:M-g*)
    217 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
    218 LINKFLAGS+=	${LINKFLAGS_DEBUG}
    219 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
    220 .elifndef PROF
    221 LINKFLAGS+=	${LINKFLAGS_NORMAL}
    222 .endif
    223 
    224 SYSTEM_LD_TAIL+=; \
    225 	if grep -q '^\#define.*SYMTAB_SPACE' opt_ddbparam.h; then \
    226 		echo "${DBSYM} $@"; \
    227 		${DBSYM} $@; \
    228 	fi
    229 
    230 SYSTEM_LD_HEAD+=${SYSTEM_LD_HEAD_EXTRA}
    231 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
    232 
    233 ##
    234 ## (6) port independent targets and dependencies: assym.h, vers.o
    235 ##
    236 .if !target(assym.h)
    237 assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS}
    238 	${_MKTARGET_CREATE}
    239 	cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
    240 	    ${GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
    241 	    > assym.h.tmp && \
    242 	mv -f assym.h.tmp assym.h
    243 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
    244 .endif
    245 
    246 .if !target(vers.o)
    247 newvers: vers.o
    248 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
    249 	${_MKMSG_CREATE} vers.c
    250 	${HOST_SH} $S/conf/newvers.sh
    251 	${_MKTARGET_COMPILE}
    252 	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
    253 .endif
    254 
    255 .if !target(config_time.h)
    256 EXTRA_CLEAN+= config_time.h
    257 config_time.h: Makefile
    258 	${_MKTARGET_CREATE}
    259 	cp config_time.src config_time.h
    260 .endif
    261 
    262 .if defined(MEMORY_DISK_IMAGE)
    263 md_root_image.h: ${MEMORY_DISK_IMAGE}
    264 	${_MKTARGET_CREATE}
    265 	${TOOL_HEXDUMP} -v -e '"\t" 8/1 "0x%02x, " "\n"' ${.ALLSRC} > ${.TARGET}
    266 
    267 # XXX This is only needed when building md_root.o
    268 CPPFLAGS+=	-DMEMORY_DISK_IMAGE
    269 md_root.o: md_root_image.h
    270 .endif
    271 
    272 # depend on MEMORY_DISK_IMAGE configuration
    273 md_root.o: Makefile
    274 
    275 # depend on root or device configuration
    276 autoconf.o conf.o: Makefile
    277 
    278 # depend on network or filesystem configuration
    279 uipc_proto.o vfs_conf.o: Makefile
    280 
    281 # depend on maxusers and CPU configuration
    282 assym.h machdep.o: Makefile
    283 
    284 ##
    285 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
    286 ##                   cscope, mkid
    287 ##
    288 ## Any ports that have other stuff to be cleaned up should fill in
    289 ## EXTRA_CLEAN.  Some ports may want different settings for
    290 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
    291 ##
    292 .if !target(__CLEANKERNEL)
    293 __CLEANKERNEL: .USE
    294 	${_MKMSG} "${.TARGET}ing the kernel objects"
    295 	rm -f ${KERNELS} eddep tags *.[io] *.ln [a-z]*.s vers.c \
    296 	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
    297 	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
    298 .endif
    299 
    300 .if !target(kernelnames)
    301 kernelnames:
    302 	@echo "${KERNELS} ${EXTRA_KERNELS}"
    303 .endif
    304 
    305 .if !target(__CLEANDEPEND)
    306 __CLEANDEPEND: .USE
    307 	echo .depend ${DEPS} | xargs rm -f --
    308 .endif
    309 
    310 # do not !target these, the kern and compat Makefiles augment them
    311 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
    312 clean: __CLEANKERNEL
    313 depend: .depend
    314 dependall: depend .WAIT all
    315 
    316 .if !target(.depend)
    317 MKDEP_AFLAGS?=	${AFLAGS}
    318 MKDEP_CFLAGS?=	${CFLAGS}
    319 SSRCS=${MD_SFILES} ${SFILES}
    320 CSRCS=${MD_CFILES} ${MI_CFILES} ${CFILES}
    321 SRCS=${SSRCS} ${CSRCS}
    322 DEPS=	${SRCS:T:O:u:R:S/$/.d/g}
    323 
    324 .for _s in ${SSRCS}
    325 ${_s:T:R}.d: ${_s} assym.h config_time.h
    326 	${_MKTARGET_CREATE}
    327 	${MKDEP} -f ${.TARGET} -- ${MKDEP_AFLAGS} \
    328 	    ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
    329 .endfor
    330 .for _s in ${CSRCS}
    331 ${_s:T:R}.d: ${_s} config_time.h
    332 	${_MKTARGET_CREATE}
    333 	${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} \
    334 	    ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
    335 .endfor
    336 
    337 assym.d: assym.h config_time.h
    338 	${_MKTARGET_CREATE}
    339 	cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
    340 	    ${GENASSYM} -- ${MKDEP} -f assym.dep -- \
    341 	    ${CFLAGS} ${CPPFLAGS}
    342 	sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >${.TARGET}
    343 	rm -f assym.dep
    344 
    345 .depend: ${DEPS} assym.d
    346 	${_MKTARGET_CREATE}
    347 	echo "${.ALLSRC}" | ${MKDEP} -D
    348 .endif
    349 
    350 .if !target(lint)
    351 ALLSFILES?=	${MD_SFILES} ${SFILES}
    352 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
    353 KERNLINTFLAGS?=	-bcehnxzFS
    354 NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
    355 
    356 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    357 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${SYSLIBCOMPATLN}
    358 
    359 .for _sfile in ${ALLSFILES}
    360 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
    361 	${_MKTARGET_COMPILE}
    362 	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
    363 	      awk -f $S/kern/genlintstub.awk >${.TARGET}
    364 .endfor
    365 
    366 .for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    367 ${_cfile:T:R}.ln: ${_cfile}
    368 	${_MKTARGET_COMPILE}
    369 	${NORMAL_LN}
    370 .endfor
    371 
    372 lint: ${LOBJS}
    373 	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
    374 .endif
    375 
    376 # List of kernel images that will be installed into the root file system.
    377 # Some platforms may need to install more than one (e.g. a netbsd.aout file
    378 # to be loaded directly by the firmware), so this can be overriden by them.
    379 KERNIMAGES?=	netbsd
    380 
    381 .if !target(install)
    382 # The install target can be redefined by putting a
    383 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
    384 MACHINE_NAME!=  uname -n
    385 install: install-kernel-${MACHINE_NAME}
    386 .if !target(install-kernel-${MACHINE_NAME})
    387 install-kernel-${MACHINE_NAME}:
    388 .for _K in ${KERNIMAGES}
    389 	rm -f ${DESTDIR}/o${_K}
    390 	ln ${DESTDIR}/${_K} ${DESTDIR}/o${_K}
    391 	cp ${_K} ${DESTDIR}/n${_K}
    392 	mv ${DESTDIR}/n${_K} ${DESTDIR}/${_K}
    393 .endfor
    394 .endif
    395 .endif
    396 
    397 .if !target(tags)
    398 tags:
    399 	@echo "see $S/kern/Makefile for tags"
    400 .endif
    401 
    402 EXTRA_CLEAN+= cscope.out cscope.tmp
    403 .if !target(cscope.out)
    404 cscope.out: Makefile depend
    405 	${_MKTARGET_CREATE}
    406 	@sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/kern/.depend | \
    407 	tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/kern/\1|;s|^../../||;' > \
    408 	cscope.tmp
    409 	@sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/compat/.depend | \
    410 	tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/compat/\1|;s|^../../||;' >> \
    411 	cscope.tmp
    412 	@echo ${SRCS} | cat - cscope.tmp | tr -s ' ' '\n' | sort -u | \
    413 	${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
    414 #	cscope doesn't write cscope.out if it's uptodate, so ensure
    415 #	make doesn't keep calling cscope when not needed.
    416 	@rm -f cscope.tmp; touch cscope.out
    417 .endif
    418 
    419 .if !target(cscope)
    420 cscope: cscope.out
    421 	@${CSCOPE} -d
    422 .endif
    423 
    424 EXTRA_CLEAN+= ID
    425 .if !target(mkid)
    426 .PHONY: mkid
    427 mkid: ID
    428 
    429 ID: Makefile depend
    430 	${_MKTARGET_CREATE}
    431 	@${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
    432 	lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
    433 	`sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
    434 	| sort -u`
    435 
    436 .endif
    437 
    438 .include "${S}/gdbscripts/Makefile.inc"
    439 
    440 EXTRA_CLEAN+= .gdbinit
    441 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
    442 	${_MKTARGET_CREATE}
    443 	rm -f .gdbinit
    444 .for __gdbinit in ${SYS_GDBINIT}
    445 	echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
    446 .endfor
    447 .if defined(GDBINIT) && !empty(GDBINIT)
    448 .for __gdbinit in ${GDBINIT}
    449 	echo "source ${__gdbinit}" >> .gdbinit
    450 .endfor
    451 .endif
    452 
    453 # The following files use alloca(3) or variable array allocations.
    454 # Their full name is noted as documentation.
    455 VARSTACK=dev/cgd.c kern/uipc_socket.c miscfs/genfs/genfs_vnops.c \
    456     nfs/nfs_bio.c ufs/ufs/ufs_inode.c ufs/ufs/ufs_lookup.c uvm/uvm_bio.c \
    457     uvm/uvm_pager.c dev/ic/aic7xxx.c dev/ic/aic79xx.c arch/xen/i386/gdt.c
    458 
    459 . if ${HAVE_GCC} > 3
    460 .for __varstack in ${VARSTACK}
    461 COPTS.${__varstack:T} += -Wno-stack-protector
    462 .endfor
    463 .endif
    464 
    465 AFLAGS+=	${AOPTS.${.IMPSRC:T}}
    466 CFLAGS+=	${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}}
    467 CPPFLAGS+=	${CPPFLAGS.${.IMPSRC:T}}
    468 CWARNFLAGS+=	${CWARNFLAGS.${.IMPSRC:T}}
    469 
    470 ##
    471 ## the end
    472 ##
    473