1# $OpenBSD: Makefile.loongson,v 1.84 2023/09/06 01:47:37 jsg 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 13SIZE?= size 14STRIP?= ctfstrip 15AS?= as 16CC?= cc 17LD?= ld ${ENDIAN} 18 19AS+=${ENDIAN} 20CC+=${ENDIAN} 21LD+=${ENDIAN} 22 23# source tree is located via $S relative to the compilation directory 24.ifndef S 25S!= cd ../../../..; pwd 26.endif 27 28_machdir?= $S/arch/${_mach} 29_archdir?= $S/arch/${_arch} 30 31INCLUDES= -nostdinc -I$S -I${.OBJDIR} -I$S/arch \ 32 -I$S/dev/pci/drm/include \ 33 -I$S/dev/pci/drm/include/uapi 34CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP 35CWARNFLAGS= -Werror -Wall -Wimplicit-function-declaration \ 36 -Wno-pointer-sign \ 37 -Wframe-larger-than=2047 38 39CMACHFLAGS= -mno-abicalls ${ABI} -msoft-float -Wa,-mfix-loongson2f-btb -G 0 40CMACHFLAGS+= -ffreestanding ${NOPIE_FLAGS} 41SORTR= sort -R 42.if ${IDENT:M-DNO_PROPOLICE} 43CMACHFLAGS+= -fno-stack-protector 44.endif 45.if ${IDENT:M-DSMALL_KERNEL} 46SORTR= cat 47COPTIMIZE?= -Oz 48.endif 49.if ${COMPILER_VERSION:Mclang} 50NO_INTEGR_AS= -no-integrated-as 51CMACHFLAGS+= -fomit-frame-pointer 52CWARNFLAGS+= -Wno-address-of-packed-member -Wno-constant-conversion \ 53 -Wno-unused-but-set-variable -Wno-gnu-folding-constant 54.endif 55 56DEBUG?= -g 57COPTIMIZE?= -O2 58CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTIMIZE} ${COPTS} ${PIPE} 59AFLAGS= -D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS} 60LINKFLAGS= -e start -T ld.script -Ttext=${LINK_ADDRESS} -warn-common -nopie 61 62HOSTCC?= ${CC} 63HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//} 64HOSTED_CFLAGS= ${CFLAGS} 65HOSTED_C= ${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $< 66 67NORMAL_C_NOP= ${CC} ${CFLAGS} ${CPPFLAGS} -fno-ret-protector -c $< 68NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< 69NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} ${PROF} -c $< 70 71%OBJS 72 73%CFILES 74 75%SFILES 76 77# load lines for config "xxx" will be emitted as: 78# xxx: ${SYSTEM_DEP} swapxxx.o 79# ${SYSTEM_LD_HEAD} 80# ${SYSTEM_LD} swapxxx.o 81# ${SYSTEM_LD_TAIL} 82SYSTEM_HEAD= locore0.o gap.o 83SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS} param.o ioconf.o 84SYSTEM_DEP= Makefile ${SYSTEM_OBJ} ld.script 85SYSTEM_LD_HEAD= @rm -f $@ 86SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \ 87 umask 007; \ 88 echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \ 89 ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder` 90SYSTEM_LD_TAIL= @${SIZE} $@ 91 92.if ${DEBUG} == "-g" 93STRIPFLAGS= -S 94SYSTEM_LD_TAIL+=; umask 007; \ 95 echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \ 96 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \ 97 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb 98.else 99LINKFLAGS+= -S 100.endif 101 102%LOAD 103 104# cc's -MD puts the source and output paths in the dependency file; 105# since those are temp files here we need to fix it up. It also 106# puts the file in /tmp, so we use -MF to put it in the current 107# directory as assym.P and then generate assym.d from it with a 108# good target name 109assym.h: $S/kern/genassym.sh Makefile \ 110 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf 111 cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \ 112 sh $S/kern/genassym.sh ${CC} ${NO_INTEGR_AS} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp 113 sed '1s/.*/assym.h: \\/' assym.P > assym.d 114 sort -u assym.h.tmp > assym.h 115 116param.c: $S/conf/param.c 117 rm -f param.c 118 cp $S/conf/param.c . 119 120param.o: param.c Makefile 121 ${NORMAL_C} 122 123mcount.o: $S/lib/libkern/mcount.c Makefile 124 ${NORMAL_C_NOP} 125 126ioconf.o: ioconf.c 127 ${NORMAL_C} 128 129ld.script: ${_machdir}/conf/ld.script 130 cp ${_machdir}/conf/ld.script $@ 131 132gapdummy.o: 133 echo '__asm(".section .rodata,\"a\"");' > gapdummy.c 134 ${CC} -c ${CFLAGS} ${CPPFLAGS} gapdummy.c -o $@ 135 136makegap.sh: 137 cp $S/conf/makegap.sh $@ 138 139MAKE_GAP = LD="${LD}" sh makegap.sh 0xefefefef gapdummy.o 140 141gap.o: Makefile makegap.sh gapdummy.o vers.o 142 ${MAKE_GAP} 143 144vers.o: ${SYSTEM_DEP:Ngap.o} 145 sh $S/conf/newvers.sh 146 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c 147 148clean: 149 rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \ 150 gap.link gapdummy.c ld.script lorder makegap.sh param.c 151 152cleandir: clean 153 rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c 154 155depend obj: 156 157locore0.o: ${_machdir}/${_mach}/locore0.S assym.h 158context.o cp0access.o exception.o locore.o: assym.h 159lcore_access.o lcore_ddb.o lcore_float.o tlbhandler.o: assym.h 160pmon32.o: assym.h 161 162hardlink-obsd: 163 [[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd 164 165newinstall: 166 install -F -m 700 bsd /bsd && sha256 -h /var/db/kernel.SHA256 /bsd 167 168install: update-link hardlink-obsd newinstall 169 170# pull in the dependency information 171.ifnmake clean 172. for o in ${SYSTEM_OBJ:Ngap.o} assym.h 173. if exists(${o:R}.d) 174. include "${o:R}.d" 175. elif exists($o) 176 .PHONY: $o 177. endif 178. endfor 179.endif 180 181%RULES 182