1# $OpenBSD: Makefile.loongson,v 1.30 2011/04/15 02:41:28 guenther Exp $ 2 3# For instructions on building kernels consult the config(8) and options(4) 4# manual pages. 5# 6# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE 7# IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING 8# DEBUG is set to -g by config if debugging is requested (config -g). 9# PROF is set to -pg by config if profiling is requested (config -p). 10 11.include <bsd.own.mk> 12 13MKDEP?= mkdep 14SIZE?= size 15STRIP?= strip 16AS?= as 17CC?= cc 18LD?= ld ${ENDIAN} 19 20AS+=${ENDIAN} 21CC+=${ENDIAN} 22LD+=${ENDIAN} 23 24# source tree is located via $S relative to the compilation directory 25.ifndef S 26S!= cd ../../../..; pwd 27.endif 28 29_machdir?= $S/arch/${_mach} 30_archdir?= $S/arch/${_arch} 31 32INCLUDES= -nostdinc -I. -I$S -I$S/arch 33CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP 34CWARNFLAGS= -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes \ 35 -Wno-main -Wno-uninitialized -Wno-format \ 36 -Wstack-larger-than-2047 37 38CMACHFLAGS= -mno-abicalls ${ABI} -msoft-float -Wa,-mfix-loongson2f-btb 39CMACHFLAGS+= -fno-builtin-printf -fno-builtin-snprintf \ 40 -fno-builtin-vsnprintf -fno-builtin-log \ 41 -fno-builtin-log2 -fno-builtin-malloc 42.if ${IDENT:M-DNO_PROPOLICE} 43CMACHFLAGS+= -fno-stack-protector 44.endif 45 46COPTS?= -O2 47CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE} 48AFLAGS= -D_LOCORE -x assembler-with-cpp ${CMACHFLAGS} 49LINKFLAGS= -e start -T ${_machdir}/conf/ld.script -Ttext=${LINK_ADDRESS} -warn-common 50 51.if ${IDENT:M-DDDB_STRUCT} 52DB_STRUCTINFO= db_structinfo.h 53.else 54DB_STRUCTINFO= 55.endif 56 57HOSTCC?= ${CC} 58HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//} 59HOSTED_CFLAGS= ${CFLAGS} 60HOSTED_C= ${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $< 61 62NORMAL_C_NOP= ${CC} ${CFLAGS} ${CPPFLAGS} -c $< 63NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< 64NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} -c $< 65 66%OBJS 67 68%CFILES 69 70%SFILES 71 72# load lines for config "xxx" will be emitted as: 73# xxx: ${SYSTEM_DEP} swapxxx.o 74# ${SYSTEM_LD_HEAD} 75# ${SYSTEM_LD} swapxxx.o 76# ${SYSTEM_LD_TAIL} 77SYSTEM_HEAD= locore.o param.o ioconf.o 78SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS} 79SYSTEM_DEP= Makefile ${SYSTEM_OBJ} 80SYSTEM_LD_HEAD= @rm -f $@ 81SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \ 82 ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} vers.o ${OBJS} 83SYSTEM_LD_TAIL= @${SIZE} $@; chmod 755 $@ 84 85DEBUG?= 86.if ${DEBUG} == "-g" 87LINKFLAGS+= -X 88STRIPFLAGS= -g -x 89SYSTEM_LD_TAIL+=; \ 90 echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \ 91 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \ 92 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb 93.else 94LINKFLAGS+= -x 95.endif 96 97%LOAD 98 99# cc's -MD puts the source and output paths in the dependency file; 100# since those are temp files here we need to fix it up. It also 101# puts the file in /tmp, so we use -MF to put it in the current 102# directory as assym.P and then generate assym.d from it with a 103# good target name 104assym.h: $S/kern/genassym.sh Makefile \ 105 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf 106 cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \ 107 sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp 108 sed '1s/.*/assym.h: \\/' assym.P > assym.d 109 sort -u assym.h.tmp > assym.h 110 111param.c: $S/conf/param.c 112 rm -f param.c 113 cp $S/conf/param.c . 114 115param.o: param.c Makefile 116 ${NORMAL_C} 117 118mcount.o: $S/lib/libkern/mcount.c Makefile 119 ${NORMAL_C_NOP} 120 121ioconf.o: ioconf.c 122 ${NORMAL_C} 123 124vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} 125 sh $S/conf/newvers.sh 126 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c 127 128clean:: 129 rm -f eddep *bsd *bsd.gdb tags *.[io] [a-z]*.s \ 130 [Ee]rrs linterrs assym.h ${DB_STRUCTINFO} 131 132lint: 133 @lint -hbxncez -Dvolatile= ${CPPFLAGS} -UKGDB \ 134 ${CFILES} ioconf.c param.c | \ 135 grep -v 'static function .* unused' 136 137symbols.sort: ${_machdir}/${_mach}/symbols.raw 138 grep -v '^#' ${_machdir}/${_mach}/symbols.raw \ 139 | sed 's/^ //' | sort -u > symbols.sort 140 141depend: 142 @touch $@ 143 144tags: 145 @echo "see $S/kern/Makefile for tags" 146 147db_structinfo.h: $S/ddb/db_structinfo.c $S/ddb/parse_structinfo.awk 148 ${CC} ${CFLAGS} ${CPPFLAGS} -MT $@ -gstabs -c $S/ddb/db_structinfo.c 149 objdump -g db_structinfo.o | awk -f $S/ddb/parse_structinfo.awk > $@ 150 rm -f db_structinfo.o 151 152locore.o: ${_machdir}/${_mach}/locore.S assym.h 153cache_loongson2.o context.o cp0access.o exception.o: assym.h 154fp.o lcore_access.o lcore_float.o tlbhandler.o lcore_ddb.o pmon32.o: assym.h 155 156# The install target can be redefined by putting a 157# install-kernel-${MACHINE_NAME} target into /etc/mk.conf 158MACHINE_NAME!= uname -n 159install: install-kernel-${MACHINE_NAME} 160.if !target(install-kernel-${MACHINE_NAME}}) 161install-kernel-${MACHINE_NAME}: 162 rm -f /obsd 163 ln /bsd /obsd 164 cp bsd /nbsd 165 mv /nbsd /bsd 166.endif 167 168# pull in the dependency information 169.if !empty(DB_STRUCTINFO) && !exists(${DB_STRUCTINFO}) 170 ${SYSTEM_OBJ}: ${DB_STRUCTINFO} 171.endif 172.ifnmake clean 173. for o in ${SYSTEM_OBJ:.o=.d} assym.d ${DB_STRUCTINFO:.h=.d} 174. if exists($o) 175. include "$o" 176. endif 177. endfor 178.endif 179 180%RULES 181