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