1# $OpenBSD: Makefile.landisk,v 1.82 2021/01/28 17:39:03 deraadt 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 15 16# source tree is located via $S relative to the compilation directory 17.ifndef S 18S!= cd ../../../..; pwd 19.endif 20 21_machdir?= $S/arch/${_mach} 22_archdir?= $S/arch/${_arch} 23 24INCLUDES= -nostdinc -I$S -I${.OBJDIR} -I$S/arch 25CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP 26CWARNFLAGS= -Werror -Wall -Wimplicit-function-declaration \ 27 -Wno-main -Wno-uninitialized -Wno-pointer-sign \ 28 -Wframe-larger-than=2047 29 30CMACHFLAGS= -m4-nofpu 31CMACHFLAGS+= -fno-builtin-printf -fno-builtin-snprintf \ 32 -fno-builtin-vsnprintf -fno-builtin-log \ 33 -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS} 34SORTR= sort -R 35.if ${IDENT:M-DNO_PROPOLICE} 36CMACHFLAGS+= -fno-stack-protector 37.endif 38.if ${IDENT:M-DSMALL_KERNEL} 39SORTR= cat 40#COPTIMIZE?=-Oz # locks up during boot 41.endif 42 43DEBUG?= -g 44COPTIMIZE?= -O2 45CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTIMIZE} ${COPTS} ${PIPE} 46AFLAGS= -D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS} 47LINKFLAGS= -N -Ttext 0x8c002000 -e start --warn-common -nopie 48 49HOSTCC?= ${CC} 50HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//} 51HOSTED_CFLAGS= ${CFLAGS} 52HOSTED_C= ${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $< 53 54NORMAL_C_NOP= ${CC} ${CFLAGS} ${CPPFLAGS} -c $< 55NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< 56NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} ${PROF} -c $< 57 58%OBJS 59 60%CFILES 61 62%SFILES 63 64# load lines for config "xxx" will be emitted as: 65# xxx: ${SYSTEM_DEP} swapxxx.o 66# ${SYSTEM_LD_HEAD} 67# ${SYSTEM_LD} swapxxx.o 68# ${SYSTEM_LD_TAIL} 69SYSTEM_HEAD= locore0.o gap.o 70SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS} param.o ioconf.o 71SYSTEM_DEP= Makefile ${SYSTEM_OBJ} ld.script 72SYSTEM_LD_HEAD= @rm -f $@ 73SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \ 74 umask 007; \ 75 echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \ 76 ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder` 77SYSTEM_LD_TAIL= @${SIZE} $@ 78 79.if ${DEBUG} == "-g" 80STRIPFLAGS= -S 81SYSTEM_LD_TAIL+=; umask 007; \ 82 echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \ 83 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \ 84 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb 85.else 86LINKFLAGS+= -S 87.endif 88 89%LOAD 90 91# cc's -MD puts the source and output paths in the dependency file; 92# since those are temp files here we need to fix it up. It also 93# puts the file in /tmp, so we use -MF to put it in the current 94# directory as assym.P and then generate assym.d from it with a 95# good target name 96assym.h: $S/kern/genassym.sh Makefile \ 97 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf 98 cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \ 99 sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp 100 sed '1s/.*/assym.h: \\/' assym.P > assym.d 101 sort -u assym.h.tmp > assym.h 102 103param.c: $S/conf/param.c 104 rm -f param.c 105 cp $S/conf/param.c . 106 107param.o: param.c Makefile 108 ${NORMAL_C} 109 110mcount.o: $S/lib/libkern/mcount.c Makefile 111 ${NORMAL_C_NOP} 112 113ioconf.o: ioconf.c 114 ${NORMAL_C} 115 116ld.script: ${_machdir}/conf/ld.script 117 cp ${_machdir}/conf/ld.script $@ 118 119makegap.sh: 120 cp $S/conf/makegap.sh $@ 121 122MAKE_GAP = LD="${LD}" sh makegap.sh 0xc3c3c3c3 123 124gap.o: Makefile makegap.sh vers.o 125 ${MAKE_GAP} 126 127vers.o: ${SYSTEM_DEP:Ngap.o} 128 sh $S/conf/newvers.sh 129 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c 130 131clean: 132 rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \ 133 gap.link ld.script lorder makegap.sh param.c 134 135cleandir: clean 136 rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c 137 138depend obj: 139 140locore.o: ${_machdir}/${_mach}/locore.S assym.h 141locore0.o: ${_machdir}/${_mach}/locore0.S assym.h 142locore_subr.o vectors.o in_cksum.o: assym.h 143 144hardlink-obsd: 145 [[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd 146 147newinstall: 148 install -F -m 700 bsd /bsd && sha256 -h /var/db/kernel.SHA256 /bsd 149 150install: update-link hardlink-obsd newinstall 151 152# pull in the dependency information 153.ifnmake clean 154. for o in ${SYSTEM_OBJ:Ngap.o} assym.h 155. if exists(${o:R}.d) 156. include "${o:R}.d" 157. elif exists($o) 158 .PHONY: $o 159. endif 160. endfor 161.endif 162 163%RULES 164