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
|
# $OpenBSD: bsd.syspatch.mk,v 1.24 2018/11/18 15:30:04 ajacoutot Exp $
#
# Copyright (c) 2016-2017 Robert Nagy <robert@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.include <bsd.own.mk>
ERRATA?=
ECURR=${ERRATA:C/_.*//}
EPREV!=echo ${ECURR} | awk '{printf "%03d\n", $$1 - 1;}'
EPREV_PATH!=echo ${FAKEROOT}/syspatch/${OSrev}-${EPREV}*
# use the base and xenocara build user
BUILDUSER?= build
# binaries used by this makefile
FETCH= /usr/bin/ftp -Vm
# make sure to only use the original OpenBSD mirror
MIRROR= https://ftp.openbsd.org/pub/OpenBSD/patches/${OSREV}/common
# build type defaults to src
BUILD?= src
SYSPATCH_BASE= syspatch${OSrev}-${ERRATA}
SYSPATCH_SHRT= ${OSrev}-${ERRATA}
# the final name of the syspatch tarball
SYSPATCH= ${SYSPATCH_BASE}.tgz
# arguments used by different tools
MTREE_FILES= /etc/mtree/4.4BSD.dist
MTREE_ARGS= -qdep ${FAKE} -U
SIGNIFY_KEY= /etc/signify/openbsd-${OSrev}-base.pub
PATCH_STRIP?= -p0
PATCH_ARGS= -d ${SRCDIR} -z .orig --forward --quiet -E ${PATCH_STRIP}
# miscellaneous variables
SYSPATCH_DIR= ${FAKE}/var/syspatch/${SYSPATCH_SHRT}
FAKE= ${FAKEROOT}/syspatch/${SYSPATCH_SHRT}
KERNEL= $$(sysctl -n kern.osversion | cut -d '\#' -f 1)
_PATCH_COOKIE= ${ERRATA}/.patch_done
_BUILD_COOKIE= ${ERRATA}/.build_done
_FAKE_COOKIE= ${ERRATA}/.fake_done
.if ${BUILD:L:Msrc} || ${BUILD:L:Mkernel}
SRCDIR= ${BSDSRCDIR}
.elif ${BUILD:L:Mxenocara}
XSRCDIR?= /usr/xenocara
SRCDIR= ${XSRCDIR}
MTREE_FILES+= /etc/mtree/BSD.x11.dist
.endif
.MAIN: all
all: ${_BUILD_COOKIE}
.if !target(clean)
clean:
rm -rf ${ERRATA} ${SYSPATCH}
.endif
depend:
cleandir: clean
${_FAKE_COOKIE}:
.ifndef FAKEROOT
@{ echo "***> setenv FAKEROOT before doing that!"; \
exit 1; };
.else
@if [[ `id -u` -ne 0 ]]; then \
{ echo "***> $@ must be called by root"; \
exit 1; }; \
fi
@destmp=`df -P ${FAKEROOT} | awk 'END { print $$6 }'`; \
if ! mount | grep -q " $${destmp} .*noperm"; then \
echo ${FAKEROOT} must be on a noperm filesystem >&2; \
false; \
fi; \
if [[ `stat -f '%Su %Lp' $${destmp}` != '${BUILDUSER} 700' ]]; then \
echo $${destmp} must have owner BUILDUSER and mode 700 >&2; \
false; \
fi
@test -f ${EPREV_PATH}/usr/lib/crt0.o || \
{ echo "***> previous (${EPREV}) syspatch build is missing"; \
exit 1; }; \
echo '>> Copying previous syspatch fakeroot to ${FAKE}'; \
${INSTALL} -d -m 755 ${SYSPATCH_DIR}; \
cd ${EPREV_PATH} && tar cf - . | \
(cd ${FAKE} && tar xpf - )
@${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} \
${ERRATA}/${ERRATA}.patch.sig ${SYSPATCH_DIR}
.for _m in ${MTREE_FILES}
@su ${BUILDUSER} -c '/usr/sbin/mtree ${MTREE_ARGS} -f ${_m}' >/dev/null
.endfor
@su ${BUILDUSER} -c 'touch $@'
.endif
${ERRATA}/${ERRATA}.patch.sig:
@su ${BUILDUSER} -c '${INSTALL} -d -m 755 ${ERRATA}' && \
echo '>> Fetching & Verifying ${MIRROR}/${.TARGET:T}'; \
su ${BUILDUSER} -c '${FETCH} -o ${ERRATA}/${.TARGET:T} \
${MIRROR}/${.TARGET:T}'
${ERRATA}/${ERRATA}.patch: ${ERRATA}/${ERRATA}.patch.sig
@su ${BUILDUSER} -c '/usr/bin/signify -Vep ${SIGNIFY_KEY} -x \
${ERRATA}/${.TARGET:T}.sig -m ${.TARGET}'
${_PATCH_COOKIE}: ${ERRATA}/${ERRATA}.patch
@echo '>> Applying ${ERRATA}.patch'; \
/usr/bin/patch ${PATCH_ARGS} < ${ERRATA}/${ERRATA}.patch || \
{ echo "***> ${ERRATA}.patch did not apply cleanly"; \
exit 1; };
@su ${BUILDUSER} -c 'touch $@'
.ifdef DESTDIR
${_BUILD_COOKIE}: ${_PATCH_COOKIE} ${_FAKE_COOKIE}
@{ echo "***> cannot set DESTDIR here!"; \
exit 1; };
.elif !defined(FAKEROOT)
${_BUILD_COOKIE}: ${_PATCH_COOKIE} ${_FAKE_COOKIE}
@{ echo "***> setenv FAKEROOT before doing that!"; \
exit 1; };
.else
${_BUILD_COOKIE}: ${_PATCH_COOKIE} ${_FAKE_COOKIE}
@echo '>> Building syspatch for ${ERRATA}'
.if ${BUILD:L:Msrc}
. for _t in clean obj build
@cd ${SRCDIR} && /usr/bin/make SYSPATCH_PATH=${EPREV_PATH} ${_t}
. endfor
@su ${BUILDUSER} -c "cd ${SRCDIR} && make SYSPATCH_PATH=${EPREV_PATH} DESTDIR=${FAKE} install"
.elif ${BUILD:L:Mxenocara}
. for _t in clean bootstrap obj build
@cd ${SRCDIR} && /usr/bin/make SYSPATCH_PATH=${EPREV_PATH} ${_t}
. endfor
@su ${BUILDUSER} -c "cd ${SRCDIR} && make SYSPATCH_PATH=${EPREV_PATH} DESTDIR=${FAKE} install"
.elif ${BUILD:L:Mkernel}
. for _t in clean obj
@cd ${SRCDIR} && /usr/bin/make SYSPATCH_PATH=${EPREV_PATH} ${_t}
. endfor
@cd ${SRCDIR} && make SYSPATCH_PATH=${EPREV_PATH} DESTDIR=${FAKE} includes
. for _kern in GENERIC GENERIC.MP
@if cd ${SRCDIR}/sys/arch/${MACHINE}/conf; then \
if config ${_kern}; then \
if cd ../compile/${_kern} && make clean && make ; then \
exit 0; \
fi; exit 1; \
fi; exit 1; \
fi;
@if [ ${_kern} = "GENERIC" ]; then \
su ${BUILDUSER} -c 'umask ${WOBJUMASK} && \
cd ${SRCDIR}/sys/arch/${MACHINE}/compile/GENERIC/obj && \
cp -p *.o Makefile ld.script makegap.sh \
${FAKE}/usr/share/relink/kernel/GENERIC/' || \
{ echo "***> failed to install ${_kern} object files"; \
exit 1; }; \
elif [ ${_kern} = "GENERIC.MP" ]; then \
su ${BUILDUSER} -c 'umask ${WOBJUMASK} && \
cd ${SRCDIR}/sys/arch/${MACHINE}/compile/GENERIC.MP/obj && \
cp -p *.o Makefile ld.script makegap.sh \
${FAKE}/usr/share/relink/kernel/GENERIC.MP/' || \
{ echo "***> failed to install ${_kern} object files"; \
exit 1; }; \
fi; exit 0
. endfor
# install newly built kernel on the build machine
@cd ${SRCDIR}/sys/arch/${MACHINE}/compile/${KERNEL} && \
make install
.endif
@su ${BUILDUSER} -c 'touch $@'
.endif
syspatch: ${SYSPATCH}
${SYSPATCH}: ${ERRATA}/.plist
.for _m in ${MTREE_FILES}
@su ${BUILDUSER} -c '/usr/sbin/mtree ${MTREE_ARGS} -f ${_m}' >/dev/null
.endfor
@su ${BUILDUSER} -c 'tar -Pczf ${.TARGET} -C ${FAKE} -I ${ERRATA}/.plist' || \
{ echo "***> unable to create ${.TARGET}"; \
exit 1; };
@echo ">> Created ${SYSPATCH}";
${ERRATA}/.plist: ${_BUILD_COOKIE}
@echo ">> Creating the list of files to be included in ${SYSPATCH}"
@su ${BUILDUSER} -c \
'${.CURDIR}/diff.sh ${EPREV_PATH} ${FAKE} \
done > ${.TARGET}' || \
{ echo "***> unable to create list of files"; \
exit 1; };
@su ${BUILDUSER} -c 'sed -i "s,^${FAKEROOT}/syspatch/${OSrev}-[^/]*/,,g" ${.TARGET}'
.include <bsd.obj.mk>
|