Blob


1 # $OpenBSD$
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).
11 .include <bsd.own.mk>
13 SIZE?= size
14 STRIP?= ctfstrip
16 # source tree is located via $S relative to the compilation directory
17 .ifndef S
18 S!= cd ../../../..; pwd
19 .endif
21 _machdir?= $S/arch/${_mach}
22 _archdir?= $S/arch/${_arch}
24 INCLUDES= -nostdinc -I$S -I${.OBJDIR} -I$S/arch
25 CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP
26 CWARNFLAGS= -Werror -Wall -Wimplicit-function-declaration \
27 -Wno-main -Wno-uninitialized -Wno-pointer-sign \
28 -Wframe-larger-than=2047
30 CMACHFLAGS= -msoft-float -Wa,-many
31 CMACHFLAGS+= -fno-builtin-printf -fno-builtin-snprintf \
32 -fno-builtin-vsnprintf -fno-builtin-log \
33 -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS}
34 SORTR= sort -R
35 .if ${IDENT:M-DNO_PROPOLICE}
36 CMACHFLAGS+= -fno-stack-protector
37 .endif
38 .if ${IDENT:M-DSMALL_KERNEL}
39 SORTR= cat
40 .endif
42 DEBUG?= -g
43 COPTS?= -O2
44 CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
45 AFLAGS= -D_LOCORE ${CMACHFLAGS}
46 LINKFLAGS= -N -Ttext 100114 -e start --warn-common -nopie
48 HOSTCC?= ${CC}
49 HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
50 HOSTED_CFLAGS= ${CFLAGS}
51 HOSTED_C= ${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
53 NORMAL_C_NOP= ${CC} ${CFLAGS} ${CPPFLAGS} -c $<
54 NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
55 NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} -c $<
57 %OBJS
59 %CFILES
61 %SFILES
63 # load lines for config "xxx" will be emitted as:
64 # xxx: ${SYSTEM_DEP} swapxxx.o
65 # ${SYSTEM_LD_HEAD}
66 # ${SYSTEM_LD} swapxxx.o
67 # ${SYSTEM_LD_TAIL}
68 SYSTEM_HEAD= locore0.o gap.o
69 SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS} param.o ioconf.o
70 SYSTEM_DEP= Makefile ${SYSTEM_OBJ} ld.script
71 SYSTEM_LD_HEAD= @rm -f $@
72 SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
73 umask 007; \
74 echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \
75 ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder`
76 SYSTEM_LD_TAIL= @${SIZE} $@
78 .if ${DEBUG} == "-g"
79 STRIPFLAGS= -S
80 SYSTEM_LD_TAIL+=; umask 007; \
81 echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
82 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
83 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
84 .else
85 LINKFLAGS+= -S
86 .endif
88 %LOAD
90 # cc's -MD puts the source and output paths in the dependency file;
91 # since those are temp files here we need to fix it up. It also
92 # puts the file in /tmp, so we use -MF to put it in the current
93 # directory as assym.P and then generate assym.d from it with a
94 # good target name
95 assym.h: $S/kern/genassym.sh Makefile \
96 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
97 cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
98 sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -MF assym.P > assym.h.tmp
99 sed '1s/.*/assym.h: \\/' assym.P > assym.d
100 sort -u assym.h.tmp > assym.h
102 param.c: $S/conf/param.c
103 rm -f param.c
104 cp $S/conf/param.c .
106 param.o: param.c Makefile
107 ${NORMAL_C}
109 mcount.o: $S/lib/libkern/mcount.c Makefile
110 ${NORMAL_C_NOP}
112 ioconf.o: ioconf.c
113 ${NORMAL_C}
115 ld.script: ${_machdir}/conf/ld.script
116 cp ${_machdir}/conf/ld.script $@
118 makegap.sh:
119 cp $S/conf/makegap.sh $@
121 MAKE_GAP = LD="${LD}" sh makegap.sh 0x00000000 # guaranteed illegal
123 gap.o: Makefile makegap.sh vers.o
124 ${MAKE_GAP}
126 vers.o: ${SYSTEM_DEP:Ngap.o}
127 sh $S/conf/newvers.sh
128 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
130 clean:
131 rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \
132 gap.link ld.script lorder makegap.sh param.c
134 cleandir: clean
135 rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c
137 depend obj:
139 locore0.o: ${_machdir}/${_mach}/locore0.S assym.h
140 locore.o: ${_machdir}/${_mach}/locore.S assym.h
141 mutex.o: assym.h
143 hardlink-obsd:
144 [[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd
146 newinstall:
147 umask 077 && cp bsd /nbsd && mv /nbsd /bsd && \
148 sha256 -h /var/db/kernel.SHA256 /bsd
150 install: update-link hardlink-obsd newinstall
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
163 %RULES