Makefile.kern.inc revision 1.3.2.8       1 #	$NetBSD: Makefile.kern.inc,v 1.3.2.8 2002/09/17 21:19:09 nathanw 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}. There are
      5 # many `MI' definitions that should end up in here, but they are not yet.
      6 #
      7 # Each target in this file should be protected with `if !target(target)'
      8 # or `if !commands(target)' and each variable should only be conditionally
      9 # assigned `VAR ?= VALUE', so that everything can be overriden.
     10 #
     11 # DEBUG is set to -g if debugging.
     12 # PROF is set to -pg if profiling.
     13 #
     14 # To specify debugging, add the config line: makeoptions DEBUG="-g"
     15 # A better way is to specify -g only for a few files.
     16 #
     17 #	makeoptions DEBUGLIST="uvm* trap if_*"
     18 #
     19 # all ports are expected to include bsd.own.mk for toolchain settings
     20 
     21 ##
     22 ## (0) toolchain settings for things that aren't part of the standard
     23 ## toolchain
     24 ##
     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 CWARNFLAGS+=	-Werror -Wall -Wno-main -Wno-format-zero-length
     55 WEAK_POINTERS?=	no
     56 .if !(${WEAK_POINTERS} == "yes")
     57 CWARNFLAGS+=	-Wpointer-arith
     58 .endif
     59 LOOSE_PROTOTYPES?= no
     60 .if !(${LOOSE_PROTOTYPES} == "yes")
     61 CWARNFLAGS+=	-Wmissing-prototypes -Wstrict-prototypes
     62 .endif
     63 # XXX Delete -Wuninitialized for now, since the compiler doesn't
     64 # XXX always get it right.  --thorpej
     65 CWARNFLAGS+=	-Wno-uninitialized
     66 .endif
     67 CFLAGS+=	-ffreestanding ${DEBUG} ${COPTS} ${CWARNFLAGS}
     68 AFLAGS+=	-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 ### 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 ##
    109 ## (4) local objects, compile rules, and dependencies
    110 ##
    111 ## Each port should have a corresponding section with settings for
    112 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
    113 ##
    114 MI_CFILES=devsw.c ioconf.c param.c
    115 # the need for a MI_SFILES variable is dubitable at best
    116 MI_OBJS=${MI_CFILES:S/.c/.o/}
    117 
    118 param.c: $S/conf/param.c
    119 	rm -f param.c
    120 	cp $S/conf/param.c .
    121 
    122 param.o: Makefile
    123 
    124 .for _cfile in ${MI_CFILES}
    125 ${_cfile:T:R}.o: ${_cfile}
    126 	${NORMAL_C}
    127 .endfor
    128 
    129 ##
    130 ## (5) link settings
    131 ##
    132 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
    133 ## be set in the port's Makefile.  The port specific definitions for
    134 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
    135 ## depending on the value of DEBUG.
    136 ##
    137 # load lines for config "xxx" will be emitted as:
    138 # xxx: ${SYSTEM_DEP} swapxxx.o
    139 #	${SYSTEM_LD_HEAD}
    140 #	${SYSTEM_LD} swapxxx.o
    141 #	${SYSTEM_LD_TAIL}
    142 SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
    143 SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ} .gdbinit
    144 SYSTEM_LD_HEAD?=	@rm -f $@
    145 SYSTEM_LD?=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
    146 		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
    147 SYSTEM_LD_TAIL?=	@${SIZE} $@; chmod 755 $@
    148 
    149 TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
    150 LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
    151 LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
    152 ENTRYPOINT?=	start
    153 LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
    154 LINKFLAGS?=	${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
    155 		${EXTRA_LINKFLAGS}
    156 
    157 LINKFLAGS_DEBUG?=	-X
    158 SYSTEM_LD_TAIL_DEBUG?=; \
    159 		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
    160 		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
    161 		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
    162 LINKFLAGS_NORMAL?=	-S
    163 STRIPFLAGS?=	-g
    164 
    165 DEBUG?=
    166 .if ${DEBUG} == "-g"
    167 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
    168 LINKFLAGS+=	${LINKFLAGS_DEBUG}
    169 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
    170 .elifndef PROF
    171 LINKFLAGS+=	${LINKFLAGS_NORMAL}
    172 .endif
    173 
    174 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
    175 
    176 ##
    177 ## (6) port independent targets and dependencies: assym.h, vers.o
    178 ##
    179 .if !target(assym.h)
    180 assym.h: $S/kern/genassym.sh ${GENASSYM} ${GENASSYM_EXTRAS}
    181 	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
    182 	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
    183 	    > assym.h.tmp && \
    184 	mv -f assym.h.tmp assym.h
    185 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
    186 .endif
    187 
    188 .if !target(vers.o)
    189 newvers: vers.o
    190 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
    191 	sh $S/conf/newvers.sh
    192 	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
    193 .endif
    194 
    195 # depend on root or device configuration
    196 autoconf.o conf.o: Makefile
    197 
    198 # depend on network or filesystem configuration
    199 uipc_proto.o vfs_conf.o: Makefile
    200 
    201 # depend on maxusers and CPU configuration
    202 assym.h machdep.o: Makefile
    203 
    204 ##
    205 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
    206 ##                   cscope, mkid
    207 ##
    208 ## Any ports that have other stuff to be cleaned up should fill in
    209 ## EXTRA_CLEAN.  Some ports may want different settings for
    210 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
    211 ##
    212 .if !target(__CLEANKERNEL)
    213 __CLEANKERNEL: .USE
    214 	@echo "${.TARGET}ing the kernel objects"
    215 	rm -f ${KERNELS} eddep tags *.[io] [a-z]*.s vers.c \
    216 	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
    217 	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
    218 .endif
    219 
    220 .if !target(kernelnames)
    221 kernelnames:
    222 	@echo "${KERNELS} ${EXTRA_KERNELS}"
    223 .endif
    224 
    225 .if !target(__CLEANDEPEND)
    226 __CLEANDEPEND: .USE
    227 	rm -f .depend
    228 .endif
    229 
    230 # do not !target these, the kern and compat Makefiles augment them
    231 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
    232 clean: __CLEANKERNEL
    233 depend: .depend
    234 
    235 .if !target(.depend)
    236 SRCS?=		${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
    237 MKDEP_AFLAGS?=	${AFLAGS}
    238 MKDEP_CFLAGS?=	${CFLAGS}
    239 .depend: ${SRCS} assym.h
    240 	${MKDEP} ${MKDEP_AFLAGS} ${CPPFLAGS} ${MD_SFILES} ${SFILES}
    241 	${MKDEP} -a ${MKDEP_CFLAGS} ${CPPFLAGS} ${MD_CFILES} ${MI_CFILES} \
    242 	    ${CFILES}
    243 	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
    244 	    sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
    245 	@sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
    246 	@rm -f assym.dep
    247 .endif
    248 
    249 .if !target(dependall)
    250 dependall: depend all
    251 .endif
    252 
    253 .if !target(lint)
    254 ALLSFILES?=	${MD_SFILES} ${SFILES}
    255 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
    256 KERNLINTFLAGS?=	-hbxncez -Dvolatile=
    257 .for _sfile in ${ALLSFILES}
    258 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
    259 	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
    260 	      awk -f $S/kern/genlintstub.awk >${.TARGET}
    261 .endfor
    262 lint: ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    263 	@${LINT} ${KERNLINTFLAGS} ${CPPFLAGS} -UKGDB \
    264 	    ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES} | \
    265 	    grep -v 'static function .* unused'
    266 .endif
    267 
    268 .if !target(install)
    269 # The install target can be redefined by putting a
    270 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
    271 MACHINE_NAME!=  uname -n
    272 install: install-kernel-${MACHINE_NAME}
    273 .if !target(install-kernel-${MACHINE_NAME}})
    274 install-kernel-${MACHINE_NAME}:
    275 	rm -f ${DESTDIR}/onetbsd
    276 	ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
    277 	cp netbsd ${DESTDIR}/nnetbsd
    278 	mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
    279 .endif
    280 .endif
    281 
    282 .if !target(tags)
    283 tags:
    284 	@echo "see $S/kern/Makefile for tags"
    285 .endif
    286 
    287 EXTRA_CLEAN+= cscope.out
    288 .if !target(cscope.out)
    289 cscope.out: Makefile depend
    290 	@echo Building cscope.out source database
    291 	@echo ${SRCS} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' \
    292 	lib/kern/.depend lib/compat/.depend | tr ' ' '\n' | \
    293 	sed "s|^../../||" | sort -u` \
    294 	| ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
    295 #	cscope doesn't write cscope.out if it's uptodate, so ensure
    296 #	make doesn't keep calling cscope when not needed.
    297 	@touch cscope.out
    298 .endif
    299 
    300 .if !target(cscope)
    301 cscope: cscope.out
    302 	@${CSCOPE} -d
    303 .endif
    304 
    305 EXTRA_CLEAN+= ID
    306 .if !target(mkid)
    307 .PHONY: mkid
    308 mkid: ID
    309 
    310 ID: Makefile depend
    311 	@echo Building mkid database
    312 	@${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
    313 	lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
    314 	`sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
    315 	| sort -u`
    316 
    317 .endif
    318 
    319 .include "${S}/gdbscripts/Makefile.inc"
    320 
    321 EXTRA_CLEAN+= .gdbinit
    322 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
    323 	@echo building GDB initialization file
    324 	rm -f .gdbinit
    325 .for __gdbinit in ${SYS_GDBINIT}
    326 	echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
    327 .endfor
    328 .if defined(GDBINIT) && !empty(GDBINIT)
    329 .for __gdbinit in ${GDBINIT}
    330 	echo "source ${__gdbinit}" >> .gdbinit
    331 .endfor
    332 .endif
    333 
    334 ##
    335 ## the end
    336 ##
    337