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