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