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