summaryrefslogtreecommitdiffstats
path: root/sys/conf/kern.post.mk
blob: 4775f1fe7fe5400a3040918bd75800253642a6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# kern.post.mk
#
# Unified Makefile for building kenrels.  This includes all the definitions
# that need to be included after all the % directives, except %RULES and
# things that act like they are part of %RULES
#
# Most make variables should not be defined in this file.  Instead, they
# should be defined in the kern.pre.mk so that port makefiles can
# override or augment them.
#
# $FreeBSD$
#

.PHONY:	all modules

depend: kernel-depend
clean:  kernel-clean
cleandepend:  kernel-cleandepend
clobber: kernel-clobber
tags:  kernel-tags
install: kernel-install
install.debug: kernel-install.debug
reinstall: kernel-reinstall
reinstall.debug: kernel-reinstall.debug

.if !defined(DEBUG)
FULLKERNEL=	${KERNEL_KO}
.else
FULLKERNEL=	${KERNEL_KO}.debug
${KERNEL_KO}: ${FULLKERNEL}
	${OBJCOPY} --strip-debug ${FULLKERNEL} ${KERNEL_KO}
.endif

${FULLKERNEL}: ${SYSTEM_DEP} vers.o
	@rm -f ${.TARGET}
	@echo linking ${.TARGET}
	${SYSTEM_LD}
	${SYSTEM_LD_TAIL}

.if !exists(.depend)
${SYSTEM_OBJS}: vnode_if.h ${BEFORE_DEPEND:M*.h} ${MFILES:T:S/.m$/.h/}
.endif

.for mfile in ${MFILES}
${mfile:T:S/.m$/.h/}: ${mfile}
	perl5 $S/kern/makeobjops.pl -h ${mfile}
.endfor

kernel-clean:
	rm -f *.o *.so *.So *.ko *.s eddep errs \
	      ${FULLKERNEL} ${KERNEL_KO} linterrs makelinks \
	      setdef[01].c setdefs.h tags \
	      vers.c vnode_if.c vnode_if.h \
	      ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
	      ${CLEAN}

kernel-clobber:
	find . -type f ! -name version -delete

lint: ${CFILES}
	${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC}

locore.o: $S/$M/$M/locore.s assym.s
	${NORMAL_S}

# This is a hack.  BFD "optimizes" away dynamic mode if there are no
# dynamic references.  We could probably do a '-Bforcedynamic' mode like
# in the a.out ld.  For now, this works.
HACK_EXTRA_FLAGS?= -shared
hack.So: Makefile
	touch hack.c
	${CC} ${FMT} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.So
	rm -f hack.c

# this rule stops ./assym.s in .depend from causing problems
./assym.s: assym.s

assym.s: $S/kern/genassym.sh genassym.o
	NM=${NM} OBJFORMAT=elf sh $S/kern/genassym.sh genassym.o > ${.TARGET}

genassym.o: $S/$M/$M/genassym.c
	${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c

${SYSTEM_OBJS} genassym.o vers.o: opt_global.h

kernel-depend:
.if defined(EXTRA_KERNELDEP)
	${EXTRA_KERNELDEP}
.endif
	rm -f .olddep
	if [ -f .depend ]; then mv .depend .olddep; fi
	${MAKE} _kernel-depend

# The argument list can be very long, use make -V and xargs to
# pass it to mkdep.
_kernel-depend: assym.s vnode_if.h ${BEFORE_DEPEND} \
	    ${CFILES} ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
	    ${SYSTEM_SFILES} ${MFILES:T:S/.m$/.h/}
	if [ -f .olddep ]; then mv .olddep .depend; fi
	rm -f .newdep
	MKDEP_CPP="${CC} -E" CC="${CC}" \
	    ${MAKE} -V CFILES -V SYSTEM_CFILES -V GEN_CFILES | xargs \
	    mkdep -a -f .newdep ${CFLAGS}
	MKDEP_CPP="${CC} -E" \
	    ${MAKE} -V SFILES -V SYSTEM_SFILES | xargs \
	    mkdep -a -f .newdep ${ASM_CFLAGS}
	rm -f .depend
	mv .newdep .depend

kernel-cleandepend:
	rm -f .depend

links:
	egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
	  sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
	${MAKE} -V CFILES | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
	  sort -u | comm -23 - dontlink | \
	  sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
	sh makelinks; rm -f dontlink

kernel-tags:
	@[ -f .depend ] || { echo "you must make depend first"; exit 1; }
	sh $S/conf/systags.sh
	rm -f tags1
	sed -e 's,      ../,    ,' tags > tags1

kernel-install kernel-install.debug:
.if exists(${DESTDIR}/boot)
	@if [ ! -f ${DESTDIR}/boot/device.hints ] ; then \
		echo "You must set up a ${DESTDIR}/boot/device.hints file first." ; \
		exit 1 ; \
	fi
	@if [ x"`grep device.hints ${DESTDIR}/boot/defaults/loader.conf ${DESTDIR}/boot/loader.conf`" = "x" ]; then \
		echo "You must activate /boot/device.hints in loader.conf." ; \
		exit 1 ; \
	fi
.endif
	@if [ ! -f ${KERNEL_KO}${.TARGET:S/kernel-install//} ] ; then \
		echo "You must build a kernel first." ; \
		exit 1 ; \
	fi
.if exists(${DESTDIR}${KODIR})
	-thiskernel=`sysctl -n kern.bootfile` ; \
	if [ "$$thiskernel" = ${DESTDIR}${KODIR}.old/${KERNEL_KO} ] ; then \
		chflags -R noschg ${DESTDIR}${KODIR} ; \
		rm -rf ${DESTDIR}${KODIR} ; \
	else \
		if [ -d ${DESTDIR}${KODIR}.old ] ; then \
			chflags -R noschg ${DESTDIR}${KODIR}.old ; \
			rm -rf ${DESTDIR}${KODIR}.old ; \
		fi ; \
		mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
		if [ "$$thiskernel" = ${DESTDIR}${KODIR}/${KERNEL_KO} ] ; then \
			sysctl -w kern.bootfile=${DESTDIR}${KODIR}.old/${KERNEL_KO} ; \
		fi; \
	fi
.endif
	mkdir -p ${DESTDIR}${KODIR}
	install -c -m 555 -o root -g wheel \
		${KERNEL_KO}${.TARGET:S/kernel-install//} ${DESTDIR}${KODIR}

kernel-reinstall kernel-reinstall.debug:
	@-chflags -R noschg ${DESTDIR}${KODIR}
	install -c -m 555 -o root -g wheel \
		${KERNEL_KO}${.TARGET:S/kernel-reinstall//} ${DESTDIR}${KODIR}

.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
all:	modules
depend: modules-depend
clean:  modules-clean
cleandepend:  modules-cleandepend
cleandir:  modules-cleandir
clobber:  modules-clobber
tags:  modules-tags
install: modules-install
install.debug: modules-install.debug
reinstall: modules-reinstall
reinstall.debug: modules-reinstall.debug
.endif

modules:
	@mkdir -p ${.OBJDIR}/modules
	cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \
	    ${MKMODULESENV} ${MAKE} all

modules-depend:
	@mkdir -p ${.OBJDIR}/modules
	cd $S/modules ; ${MKMODULESENV} ${MAKE} obj ; \
	    ${MKMODULESENV} ${MAKE} depend

modules-clean:
	cd $S/modules ; ${MKMODULESENV} ${MAKE} clean

modules-cleandepend:
	cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandepend

modules-clobber:	modules-clean
	rm -rf ${MKMODULESENV}

modules-cleandir:
	cd $S/modules ; ${MKMODULESENV} ${MAKE} cleandir

modules-tags:
	cd $S/modules ; ${MKMODULESENV} ${MAKE} tags

modules-install modules-reinstall:
	cd $S/modules ; ${MKMODULESENV} ${MAKE} install

modules-install.debug modules-reinstall.debug:
	cd $S/modules ; ${MKMODULESENV} ${MAKE} install.debug

config.o:
	${NORMAL_C}

vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
	sh $S/conf/newvers.sh ${KERN_IDENT} ${IDENT}

# XXX strictly, everything depends on Makefile because changes to ${PROF}
# only appear there, but we don't handle that.
vers.o:
	${NORMAL_C}

hints.o:	hints.c
	${NORMAL_C}

env.o:	env.c
	${NORMAL_C}

vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c

vnode_if.h: $S/tools/vnode_if.awk $S/kern/vnode_if.src
	${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h

vnode_if.o:
	${NORMAL_C}

.include <bsd.kern.mk>
OpenPOWER on IntegriCloud