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