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