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