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