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