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