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