Home | History | Annotate | Line # | Download | only in conf
Makefile.kern.inc revision 1.3.2.2
      1 #	$NetBSD: Makefile.kern.inc,v 1.3.2.2 2002/01/08 00:29:12 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 MKDEP?=		mkdep
     26 STRIP?=		strip
     27 OBJCOPY?=	objcopy
     28 OBJDUMP?=	objdump
     29 
     30 ##
     31 ## (1) port independent source tree identification
     32 ##
     33 # source tree is located via $S relative to the compilation directory
     34 .ifndef S
     35 S!=	cd ../../../..; pwd
     36 .endif
     37 
     38 ##
     39 ## (2) compile settings
     40 ##
     41 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
     42 ##
     43 INCLUDES?=	-I. ${EXTRA_INCLUDES} -I$S/arch -I$S -nostdinc
     44 CPPFLAGS+=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
     45 DEFCOPTS?=	-O2
     46 COPTS?=		${DEFCOPTS}
     47 DBG=		# might contain unwanted -Ofoo
     48 DEFWARNINGS?=	yes
     49 .if (${DEFWARNINGS} == "yes")
     50 CWARNFLAGS+=	-Werror -Wall -Wno-main
     51 WEAK_POINTERS?=	no
     52 .if !(${WEAK_POINTERS} == "yes")
     53 CWARNFLAGS+=	-Wpointer-arith
     54 .endif
     55 LOOSE_PROTOTYPES?= no
     56 .if !(${LOOSE_PROTOTYPES} == "yes")
     57 CWARNFLAGS+=	-Wmissing-prototypes -Wstrict-prototypes
     58 .endif
     59 # XXX Delete -Wuninitialized for now, since the compiler doesn't
     60 # XXX always get it right.  --thorpej
     61 CWARNFLAGS+=	-Wno-uninitialized
     62 .endif
     63 CFLAGS+=	-ffreestanding ${DEBUG} ${COPTS} ${CWARNFLAGS}
     64 AFLAGS+=	-D_LOCORE
     65 
     66 # Define a set of xxx_G variables that will add -g to just those
     67 # files that match the shell patterns given in ${DEBUGLIST}
     68 #
     69 .for i in ${DEBUGLIST}
     70 .for j in ${CFILES:T:M$i.c}
     71 ${j:R}_G?= -g
     72 .endfor
     73 .endfor
     74 
     75 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
     76 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
     77 NORMAL_C?=	${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} ${PROF} -c $<
     78 NOPROF_C?=	${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} -c $<
     79 NORMAL_S?=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<
     80 
     81 ##
     82 ## (3) libkern and compat
     83 ##
     84 ## Set KERN_AS in the port Makefile to "obj" or "library".  The
     85 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
     86 ##
     87 
     88 ### find out what to use for libkern
     89 .include "$S/lib/libkern/Makefile.inc"
     90 .ifndef PROF
     91 LIBKERN?=	${KERNLIB}
     92 .else
     93 LIBKERN?=	${KERNLIB_PROF}
     94 .endif
     95 
     96 ### find out what to use for libcompat
     97 .include "$S/compat/common/Makefile.inc"
     98 .ifndef PROF
     99 LIBCOMPAT?=	${COMPATLIB}
    100 .else
    101 LIBCOMPAT?=	${COMPATLIB_PROF}
    102 .endif
    103 
    104 ##
    105 ## (4) local objects, compile rules, and dependencies
    106 ##
    107 ## Each port should have a corresponding section with settings for
    108 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
    109 ##
    110 MI_CFILES=ioconf.c param.c
    111 # the need for a MI_SFILES variable is dubitable at best
    112 MI_OBJS=${MI_CFILES:S/.c/.o/}
    113 
    114 param.c: $S/conf/param.c
    115 	rm -f param.c
    116 	cp $S/conf/param.c .
    117 
    118 param.o: Makefile
    119 
    120 .for _cfile in ${MI_CFILES}
    121 ${_cfile:T:R}.o: ${_cfile}
    122 	${NORMAL_C}
    123 .endfor
    124 
    125 ##
    126 ## (5) link settings
    127 ##
    128 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
    129 ## be set in the port's Makefile.  The port specific definitions for
    130 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
    131 ## depending on the value of DEBUG.
    132 ##
    133 # load lines for config "xxx" will be emitted as:
    134 # xxx: ${SYSTEM_DEP} swapxxx.o
    135 #	${SYSTEM_LD_HEAD}
    136 #	${SYSTEM_LD} swapxxx.o
    137 #	${SYSTEM_LD_TAIL}
    138 SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
    139 SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ}
    140 SYSTEM_LD_HEAD?=	@rm -f $@
    141 SYSTEM_LD?=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
    142 		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
    143 SYSTEM_LD_TAIL?=	@${SIZE} $@; chmod 755 $@
    144 
    145 TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
    146 LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
    147 LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
    148 ENTRYPOINT?=	start
    149 LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
    150 LINKFLAGS?=	${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
    151 		${EXTRA_LINKFLAGS}
    152 
    153 LINKFLAGS_DEBUG?=	-X
    154 SYSTEM_LD_TAIL_DEBUG?=; \
    155 		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
    156 		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
    157 		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
    158 LINKFLAGS_NORMAL?=	-S
    159 STRIPFLAGS?=	-g
    160 
    161 DEBUG?=
    162 .if ${DEBUG} == "-g"
    163 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
    164 LINKFLAGS+=	${LINKFLAGS_DEBUG}
    165 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
    166 .elifndef PROF
    167 LINKFLAGS+=	${LINKFLAGS_NORMAL}
    168 .endif
    169 
    170 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
    171 
    172 ##
    173 ## (6) port independent targets and dependencies: assym.h, vers.o
    174 ##
    175 .if !target(assym.h)
    176 assym.h: $S/kern/genassym.sh ${GENASSYM} ${GENASSYM_EXTRAS}
    177 	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
    178 	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
    179 	    > assym.h.tmp && \
    180 	mv -f assym.h.tmp assym.h
    181 .endif
    182 
    183 .if !target(vers.o)
    184 newvers: vers.o
    185 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
    186 	sh $S/conf/newvers.sh
    187 	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
    188 .endif
    189 
    190 # depend on root or device configuration
    191 autoconf.o conf.o: Makefile
    192 
    193 # depend on network or filesystem configuration
    194 uipc_proto.o vfs_conf.o: Makefile
    195 
    196 # depend on maxusers and CPU configuration
    197 assym.h machdep.o: Makefile
    198 
    199 ##
    200 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags
    201 ##
    202 ## Any ports that have other stuff to be cleaned up should fill in
    203 ## EXTRA_CLEAN.  Some ports may want different settings for
    204 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
    205 ##
    206 .if !target(__CLEANKERNEL)
    207 __CLEANKERNEL: .USE
    208 	@echo "${.TARGET}ing the kernel objects"
    209 	rm -f ${KERNELS} eddep tags *.[io] [a-z]*.s vers.c \
    210 	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
    211 	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
    212 .endif
    213 
    214 .if !target(kernelnames)
    215 kernelnames:
    216 	@echo "${KERNELS} ${EXTRA_KERNELS}"
    217 .endif
    218 
    219 .if !target(__CLEANDEPEND)
    220 __CLEANDEPEND: .USE
    221 	rm -f .depend
    222 .endif
    223 
    224 # do not !target these, the kern and compat Makefiles augment them
    225 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
    226 clean: __CLEANKERNEL
    227 depend: .depend
    228 
    229 .if !target(.depend)
    230 SRCS?=		${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
    231 MKDEP_AFLAGS?=	${AFLAGS}
    232 MKDEP_CFLAGS?=	${CFLAGS}
    233 .depend: ${SRCS} assym.h
    234 	${MKDEP} ${MKDEP_AFLAGS} ${CPPFLAGS} ${MD_SFILES} ${SFILES}
    235 	${MKDEP} -a ${MKDEP_CFLAGS} ${CPPFLAGS} ${MD_CFILES} ${MI_CFILES} \
    236 	    ${CFILES}
    237 	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
    238 	    sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
    239 	@sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
    240 	@rm -f assym.dep
    241 .endif
    242 
    243 .if !target(dependall)
    244 dependall: depend all
    245 .endif
    246 
    247 .if !target(lint)
    248 ALLSFILES?=	${MD_SFILES} ${SFILES}
    249 LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
    250 KERNLINTFLAGS?=	-hbxncez -Dvolatile=
    251 .for _sfile in ${ALLSFILES}
    252 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
    253 	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
    254 	      awk -f $S/kern/genlintstub.awk >${.TARGET}
    255 .endfor
    256 lint: ${CFILES} ${KERNLINTSTUBS} ${MI_CFILES} ${MD_CFILES}
    257 	@${LINT} ${KERNLINTFLAGS} ${CPPFLAGS} -UKGDB \
    258 	    ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES} | \
    259 	    grep -v 'static function .* unused'
    260 .endif
    261 
    262 .if !target(install)
    263 # The install target can be redefined by putting a
    264 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
    265 MACHINE_NAME!=  uname -n
    266 install: install-kernel-${MACHINE_NAME}
    267 .if !target(install-kernel-${MACHINE_NAME}})
    268 install-kernel-${MACHINE_NAME}:
    269 	rm -f ${DESTDIR}/onetbsd
    270 	ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
    271 	cp netbsd ${DESTDIR}/nnetbsd
    272 	mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
    273 .endif
    274 .endif
    275 
    276 .if !target(tags)
    277 tags:
    278 	@echo "see $S/kern/Makefile for tags"
    279 .endif
    280 
    281 ##
    282 ## the end
    283 ##
    284