Home | History | Annotate | Line # | Download | only in conf
Makefile.kern.inc revision 1.27
      1 #	$NetBSD: Makefile.kern.inc,v 1.27 2002/11/02 07:57:05 perry 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 # depend on root or device configuration
    193 autoconf.o conf.o: Makefile
    194 
    195 # depend on network or filesystem configuration
    196 uipc_proto.o vfs_conf.o: Makefile
    197 
    198 # depend on maxusers and CPU configuration
    199 assym.h machdep.o: Makefile
    200 
    201 ##
    202 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
    203 ##                   cscope, mkid
    204 ##
    205 ## Any ports that have other stuff to be cleaned up should fill in
    206 ## EXTRA_CLEAN.  Some ports may want different settings for
    207 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
    208 ##
    209 .if !target(__CLEANKERNEL)
    210 __CLEANKERNEL: .USE
    211 	@echo "${.TARGET}ing the kernel objects"
    212 	rm -f ${KERNELS} eddep tags *.[io] *.ln [a-z]*.s vers.c \
    213 	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
    214 	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
    215 .endif
    216 
    217 .if !target(kernelnames)
    218 kernelnames:
    219 	@echo "${KERNELS} ${EXTRA_KERNELS}"
    220 .endif
    221 
    222 .if !target(__CLEANDEPEND)
    223 __CLEANDEPEND: .USE
    224 	rm -f .depend
    225 .endif
    226 
    227 # do not !target these, the kern and compat Makefiles augment them
    228 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
    229 clean: __CLEANKERNEL
    230 depend: .depend
    231 
    232 .if !target(.depend)
    233 SRCS?=		${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
    234 MKDEP_AFLAGS?=	${AFLAGS}
    235 MKDEP_CFLAGS?=	${CFLAGS}
    236 .depend: ${SRCS} assym.h
    237 	${MKDEP} ${MKDEP_AFLAGS} ${CPPFLAGS} ${MD_SFILES} ${SFILES}
    238 	${MKDEP} -a ${MKDEP_CFLAGS} ${CPPFLAGS} ${MD_CFILES} ${MI_CFILES} \
    239 	    ${CFILES}
    240 	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
    241 	    sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
    242 	@sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
    243 	@rm -f assym.dep
    244 .endif
    245 
    246 .if !target(dependall)
    247 dependall: depend all
    248 .endif
    249 
    250 .if !target(lint)
    251 ALLSFILES?=	${MD_SFILES} ${SFILES}
    252 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
    253 KERNLINTFLAGS?=	-bcehnxzFS
    254 NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
    255 
    256 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    257 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${LIBCOMPATLN}
    258 
    259 .for _sfile in ${ALLSFILES}
    260 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
    261 	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
    262 	      awk -f $S/kern/genlintstub.awk >${.TARGET}
    263 .endfor
    264 
    265 .for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    266 ${_cfile:T:R}.ln: ${_cfile}
    267 	${NORMAL_LN}
    268 .endfor
    269 
    270 lint: ${LOBJS}
    271 	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
    272 .endif
    273 
    274 .if !target(install)
    275 # The install target can be redefined by putting a
    276 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
    277 MACHINE_NAME!=  uname -n
    278 install: install-kernel-${MACHINE_NAME}
    279 .if !target(install-kernel-${MACHINE_NAME}})
    280 install-kernel-${MACHINE_NAME}:
    281 	rm -f ${DESTDIR}/onetbsd
    282 	ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
    283 	cp netbsd ${DESTDIR}/nnetbsd
    284 	mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
    285 .endif
    286 .endif
    287 
    288 .if !target(tags)
    289 tags:
    290 	@echo "see $S/kern/Makefile for tags"
    291 .endif
    292 
    293 EXTRA_CLEAN+= cscope.out
    294 .if !target(cscope.out)
    295 cscope.out: Makefile depend
    296 	@echo Building cscope.out source database
    297 	@echo ${SRCS} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' \
    298 	lib/kern/.depend lib/compat/.depend | tr ' ' '\n' | \
    299 	sed "s|^../../||" | sort -u` \
    300 	| ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
    301 #	cscope doesn't write cscope.out if it's uptodate, so ensure
    302 #	make doesn't keep calling cscope when not needed.
    303 	@touch cscope.out
    304 .endif
    305 
    306 .if !target(cscope)
    307 cscope: cscope.out
    308 	@${CSCOPE} -d
    309 .endif
    310 
    311 EXTRA_CLEAN+= ID
    312 .if !target(mkid)
    313 .PHONY: mkid
    314 mkid: ID
    315 
    316 ID: Makefile depend
    317 	@echo Building mkid database
    318 	@${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
    319 	lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
    320 	`sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
    321 	| sort -u`
    322 
    323 .endif
    324 
    325 .include "${S}/gdbscripts/Makefile.inc"
    326 
    327 EXTRA_CLEAN+= .gdbinit
    328 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
    329 	@echo building GDB initialization file
    330 	rm -f .gdbinit
    331 .for __gdbinit in ${SYS_GDBINIT}
    332 	echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
    333 .endfor
    334 .if defined(GDBINIT) && !empty(GDBINIT)
    335 .for __gdbinit in ${GDBINIT}
    336 	echo "source ${__gdbinit}" >> .gdbinit
    337 .endfor
    338 .endif
    339 
    340 ##
    341 ## the end
    342 ##
    343