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