Makefile.kern.inc revision 1.91       1 #	$NetBSD: Makefile.kern.inc,v 1.91 2006/10/30 17:56:30 garbled 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 we want the bpendtsleep: label in kern_synch.c, we need to use
     93 # -fno-reorder-blocks.  Don't make this a config(1) defflag without
     94 # making sure this fragment remains valid.
     95 .if ${HAVE_GCC} > 3 && !empty(${CFLAGS:M-DKERN_SYNCH_BPENDTSLEEP_LABEL})
     96 CFLAGS.kern_synch.c+=	-fno-reorder-blocks
     97 .endif
     98 
     99 # Use the per-source COPTS variables to add -g to just those
    100 # files that match the shell patterns given in ${DEBUGLIST}
    101 #
    102 .for i in ${DEBUGLIST}
    103 . for j in ${CFILES:T:M$i.c}
    104 COPTS.${j}+=-g
    105 . endfor
    106 .endfor
    107 
    108 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
    109 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
    110 NORMAL_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"; \
    111 		${_MKSHECHO}\
    112 		${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<; \
    113 		${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
    114 NOPROF_C?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"; \
    115 		${_MKSHECHO}\
    116 		${CC} ${CFLAGS} ${CPPFLAGS} -c $<; \
    117 		${CC} ${CFLAGS} ${CPPFLAGS} -c $<
    118 NORMAL_S?=	@${_MKSHMSG} "compile  ${.CURDIR:T}/${.TARGET}"; \
    119 		${_MKSHECHO}\
    120 		${CC} ${AFLAGS} ${CPPFLAGS} -c $<; \
    121 		${CC} ${AFLAGS} ${CPPFLAGS} -c $<
    122 
    123 ##
    124 ## (3) libkern and compat
    125 ##
    126 ## Set KERN_AS in the port Makefile to "obj" or "library".  The
    127 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
    128 ##
    129 
    130 ### find out what to use for libkern
    131 .include "$S/lib/libkern/Makefile.inc"
    132 .ifndef PROF
    133 LIBKERN?=	${KERNLIB}
    134 .else
    135 LIBKERN?=	${KERNLIB_PROF}
    136 .endif
    137 
    138 LIBKERNLN?=	${KERNLIBLN}
    139 
    140 ### find out what to use for libcompat
    141 .include "$S/compat/common/Makefile.inc"
    142 .ifndef PROF
    143 SYSLIBCOMPAT?=	${COMPATLIB}
    144 .else
    145 SYSLIBCOMPAT?=	${COMPATLIB_PROF}
    146 .endif
    147 
    148 SYSLIBCOMPATLN?=	${COMPATLIBLN}
    149 
    150 ##
    151 ## (4) local objects, compile rules, and dependencies
    152 ##
    153 ## Each port should have a corresponding section with settings for
    154 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
    155 ##
    156 MI_CFILES=devsw.c ioconf.c param.c
    157 # the need for a MI_SFILES variable is dubitable at best
    158 MI_OBJS=${MI_CFILES:S/.c/.o/}
    159 
    160 param.c: $S/conf/param.c
    161 	${_MKTARGET_CREATE}
    162 	rm -f param.c
    163 	cp $S/conf/param.c .
    164 
    165 param.o: Makefile
    166 
    167 .for _cfile in ${MI_CFILES}
    168 ${_cfile:T:R}.o: ${_cfile}
    169 	${NORMAL_C}
    170 .endfor
    171 
    172 ##
    173 ## (5) link settings
    174 ##
    175 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
    176 ## be set in the port's Makefile.  The port specific definitions for
    177 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
    178 ## depending on the value of DEBUG.
    179 ##
    180 # load lines for config "xxx" will be emitted as:
    181 # xxx: ${SYSTEM_DEP} swapxxx.o
    182 #	${SYSTEM_LD_HEAD}
    183 #	${SYSTEM_LD} swapxxx.o
    184 #	${SYSTEM_LD_TAIL}
    185 SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${SYSLIBCOMPAT} ${LIBKERN}
    186 SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ:O} .gdbinit
    187 SYSTEM_LD_HEAD?=@rm -f $@
    188 SYSTEM_LD?=	@${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
    189 		${_MKSHECHO}\
    190 		${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o; \
    191 		${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
    192 SYSTEM_LD_TAIL?=@${SIZE} $@; chmod 755 $@
    193 
    194 TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
    195 LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
    196 LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
    197 ENTRYPOINT?=	start
    198 LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
    199 LINKFLAGS?=	${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
    200 		${EXTRA_LINKFLAGS}
    201 
    202 LINKFLAGS_DEBUG?=	-X
    203 SYSTEM_LD_TAIL_DEBUG?=; \
    204 		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
    205 		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
    206 		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
    207 LINKFLAGS_NORMAL?=	-S
    208 STRIPFLAGS?=	-g
    209 
    210 DEBUG?=
    211 .if !empty(DEBUG:M-g*)
    212 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
    213 LINKFLAGS+=	${LINKFLAGS_DEBUG}
    214 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
    215 .elifndef PROF
    216 LINKFLAGS+=	${LINKFLAGS_NORMAL}
    217 .endif
    218 
    219 SYSTEM_LD_TAIL+=; \
    220 	if grep -q '^\#define.*SYMTAB_SPACE' opt_ddbparam.h; then \
    221 		echo "${DBSYM} $@"; \
    222 		${DBSYM} $@; \
    223 	fi
    224 
    225 SYSTEM_LD_HEAD+=${SYSTEM_LD_HEAD_EXTRA}
    226 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
    227 
    228 ##
    229 ## (6) port independent targets and dependencies: assym.h, vers.o
    230 ##
    231 .if !target(assym.h)
    232 assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS}
    233 	${_MKTARGET_CREATE}
    234 	cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
    235 	    ${GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
    236 	    > assym.h.tmp && \
    237 	mv -f assym.h.tmp assym.h
    238 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
    239 .endif
    240 
    241 .if !target(vers.o)
    242 newvers: vers.o
    243 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
    244 	${_MKMSG_CREATE} vers.c
    245 	${HOST_SH} $S/conf/newvers.sh
    246 	${_MKTARGET_COMPILE}
    247 	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
    248 .endif
    249 
    250 .if !target(config_time.h)
    251 EXTRA_CLEAN+= config_time.h
    252 config_time.h: Makefile
    253 	${_MKTARGET_CREATE}
    254 	cp config_time.src config_time.h
    255 .endif
    256 
    257 .if defined(MEMORY_DISK_IMAGE)
    258 md_root_image.h: ${MEMORY_DISK_IMAGE}
    259 	${_MKTARGET_CREATE}
    260 	${TOOL_HEXDUMP} -v -e '"\t" 8/1 "0x%02x, " "\n"' ${.ALLSRC} > ${.TARGET}
    261 
    262 # XXX This is only needed when building md_root.o
    263 CPPFLAGS+=	-DMEMORY_DISK_IMAGE
    264 md_root.o: md_root_image.h
    265 .endif
    266 
    267 # depend on MEMORY_DISK_IMAGE configuration
    268 md_root.o: Makefile
    269 
    270 # depend on root or device configuration
    271 autoconf.o conf.o: Makefile
    272 
    273 # depend on network or filesystem configuration
    274 uipc_proto.o vfs_conf.o: Makefile
    275 
    276 # depend on maxusers and CPU configuration
    277 assym.h machdep.o: Makefile
    278 
    279 ##
    280 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
    281 ##                   cscope, mkid
    282 ##
    283 ## Any ports that have other stuff to be cleaned up should fill in
    284 ## EXTRA_CLEAN.  Some ports may want different settings for
    285 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
    286 ##
    287 .if !target(__CLEANKERNEL)
    288 __CLEANKERNEL: .USE
    289 	${_MKMSG} "${.TARGET}ing the kernel objects"
    290 	rm -f ${KERNELS} eddep tags *.[io] *.ln [a-z]*.s vers.c \
    291 	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
    292 	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
    293 .endif
    294 
    295 .if !target(kernelnames)
    296 kernelnames:
    297 	@echo "${KERNELS} ${EXTRA_KERNELS}"
    298 .endif
    299 
    300 .if !target(__CLEANDEPEND)
    301 __CLEANDEPEND: .USE
    302 	echo .depend ${DEPS} | xargs rm -f --
    303 .endif
    304 
    305 # do not !target these, the kern and compat Makefiles augment them
    306 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
    307 clean: __CLEANKERNEL
    308 depend: .depend
    309 dependall: depend .WAIT all
    310 
    311 .if !target(.depend)
    312 MKDEP_AFLAGS?=	${AFLAGS}
    313 MKDEP_CFLAGS?=	${CFLAGS}
    314 SSRCS=${MD_SFILES} ${SFILES}
    315 CSRCS=${MD_CFILES} ${MI_CFILES} ${CFILES}
    316 SRCS=${SSRCS} ${CSRCS}
    317 DEPS=	${SRCS:T:O:u:R:S/$/.d/g}
    318 
    319 .for _s in ${SSRCS}
    320 ${_s:T:R}.d: ${_s} assym.h config_time.h
    321 	${_MKTARGET_CREATE}
    322 	${MKDEP} -f ${.TARGET} -- ${MKDEP_AFLAGS} \
    323 	    ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
    324 .endfor
    325 .for _s in ${CSRCS}
    326 ${_s:T:R}.d: ${_s} config_time.h
    327 	${_MKTARGET_CREATE}
    328 	${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} \
    329 	    ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
    330 .endfor
    331 
    332 assym.d: assym.h config_time.h
    333 	${_MKTARGET_CREATE}
    334 	cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
    335 	    ${GENASSYM} -- ${MKDEP} -f assym.dep -- \
    336 	    ${CFLAGS} ${CPPFLAGS}
    337 	sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >${.TARGET}
    338 	rm -f assym.dep
    339 
    340 .depend: ${DEPS} assym.d
    341 	${_MKTARGET_CREATE}
    342 	echo "${.ALLSRC}" | ${MKDEP} -D
    343 .endif
    344 
    345 .if !target(lint)
    346 ALLSFILES?=	${MD_SFILES} ${SFILES}
    347 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
    348 KERNLINTFLAGS?=	-bcehnxzFS
    349 NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
    350 
    351 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    352 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${SYSLIBCOMPATLN}
    353 
    354 .for _sfile in ${ALLSFILES}
    355 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
    356 	${_MKTARGET_COMPILE}
    357 	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
    358 	      awk -f $S/kern/genlintstub.awk >${.TARGET}
    359 .endfor
    360 
    361 .for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    362 ${_cfile:T:R}.ln: ${_cfile}
    363 	${_MKTARGET_COMPILE}
    364 	${NORMAL_LN}
    365 .endfor
    366 
    367 lint: ${LOBJS}
    368 	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
    369 .endif
    370 
    371 .if !target(install)
    372 # The install target can be redefined by putting a
    373 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
    374 MACHINE_NAME!=  uname -n
    375 install: install-kernel-${MACHINE_NAME}
    376 .if !target(install-kernel-${MACHINE_NAME})
    377 install-kernel-${MACHINE_NAME}:
    378 	rm -f ${DESTDIR}/onetbsd
    379 	ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
    380 	cp netbsd ${DESTDIR}/nnetbsd
    381 	mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
    382 .endif
    383 .endif
    384 
    385 .if !target(tags)
    386 tags:
    387 	@echo "see $S/kern/Makefile for tags"
    388 .endif
    389 
    390 EXTRA_CLEAN+= cscope.out cscope.tmp
    391 .if !target(cscope.out)
    392 cscope.out: Makefile depend
    393 	${_MKTARGET_CREATE}
    394 	@sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/kern/.depend | \
    395 	tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/kern/\1|;s|^../../||;' > \
    396 	cscope.tmp
    397 	@sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/compat/.depend | \
    398 	tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/compat/\1|;s|^../../||;' >> \
    399 	cscope.tmp
    400 	@echo ${SRCS} | cat - cscope.tmp | tr -s ' ' '\n' | sort -u | \
    401 	${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
    402 #	cscope doesn't write cscope.out if it's uptodate, so ensure
    403 #	make doesn't keep calling cscope when not needed.
    404 	@rm -f cscope.tmp; touch cscope.out
    405 .endif
    406 
    407 .if !target(cscope)
    408 cscope: cscope.out
    409 	@${CSCOPE} -d
    410 .endif
    411 
    412 EXTRA_CLEAN+= ID
    413 .if !target(mkid)
    414 .PHONY: mkid
    415 mkid: ID
    416 
    417 ID: Makefile depend
    418 	${_MKTARGET_CREATE}
    419 	@${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
    420 	lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
    421 	`sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
    422 	| sort -u`
    423 
    424 .endif
    425 
    426 .include "${S}/gdbscripts/Makefile.inc"
    427 
    428 EXTRA_CLEAN+= .gdbinit
    429 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
    430 	${_MKTARGET_CREATE}
    431 	rm -f .gdbinit
    432 .for __gdbinit in ${SYS_GDBINIT}
    433 	echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
    434 .endfor
    435 .if defined(GDBINIT) && !empty(GDBINIT)
    436 .for __gdbinit in ${GDBINIT}
    437 	echo "source ${__gdbinit}" >> .gdbinit
    438 .endfor
    439 .endif
    440 
    441 AFLAGS+=	${AOPTS.${.IMPSRC:T}}
    442 CFLAGS+=	${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}}
    443 CPPFLAGS+=	${CPPFLAGS.${.IMPSRC:T}}
    444 CWARNFLAGS+=	${CWARNFLAGS.${.IMPSRC:T}}
    445 
    446 ##
    447 ## the end
    448 ##
    449