-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbsd.binpatch.mk
More file actions
305 lines (262 loc) · 8.98 KB
/
bsd.binpatch.mk
File metadata and controls
305 lines (262 loc) · 8.98 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Copyright (c) 2002-2012, Gerardo Santana Gómez Garrido <gerardo.santana@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ================================================================ VARIABLES
# Architecture we are building on/for
ARCH=${MACHINE_ARCH}
# You'll need to copy your kernel configuration file into
# ${WRKDIR}/sys/arch/${ARCH}/conf/ if you want to compile it.
# Defaults to GENERIC kernel
KERNEL?=GENERIC
DISTNAME?=binpatch-${OSREV}
PKGNAME?=${DISTNAME}
FLAVOR_EXT:=-${ARCH}-${PATCH}
FULLPKGNAME?=${DISTNAME}${FLAVOR_EXT}
# The directory where the OpenBSD installation files
# and source are stored
DISTDIR?=${.CURDIR}/distfiles
# Where patches are stored
PATCHDIR?=${.CURDIR}/patches
# The OpenBSD installation files should be in a subdirectory.
# Defaults to $ARCH
DISTSUBDIR?=${ARCH}
# FETCH program
FETCH=ftp
# The OpenBSD Master Site
MASTER_SITE_OPENBSD?=ftp://ftp.openbsd.org/pub
MASTER_SITE_SUBDIR?=OpenBSD/patches/${OSREV}
# The working directories. All of them will be created, and removed.
WRKDIR?=${.CURDIR}/work-${DISTNAME}
WRKSRC?=${WRKDIR}/src
WRKOBJ?=${WRKDIR}/obj
WRKINST?=${WRKDIR}/fake
PACKAGEDIR?=${.CURDIR}/packages
PKGDIR?=${.CURDIR}/pkg
# Variables needed for making the sources (after patching)
DESTDIR:=${WRKINST}
BSDOBJDIR=${WRKOBJ}
BSDSRCDIR:=${WRKSRC}
MAKE_ENV:= env DESTDIR=${DESTDIR} BSDOBJDIR=${BSDOBJDIR} BSDSRCDIR=${BSDSRCDIR} INSTALL_COPY=-C
# Signing variables
SIGNKEY?=NO
.if defined(SIGNPASS) && exists(${SIGNPASS})
SIGNCMD := -f ${SIGNPASS} ${SIGNKEY}
.else
SIGNCMD := ${SIGNKEY}
.endif
# ============================================== SPECIAL TARGETS & SHORTCUTS
# Subroutine to include for building a kernel patch
_kernel: .USE
.for _kern in ${KERNEL}
cd ${WRKSRC}/sys/arch/${ARCH}/conf && \
config ./${_kern} && \
cd ../compile/${_kern} && \
${MAKE_ENV} make depend && \
${MAKE_ENV} make && \
if [ ${_kern} = "GENERIC" ]; then \
cp -p bsd ${WRKINST}; \
elif [ ${_kern} = "GENERIC.MP" ]; then \
cp -p bsd ${WRKINST}/bsd.mp; \
else \
cp -p bsd ${WRKINST}/bsd.${_kern}; \
fi
.endfor
# Shortcuts
_obj=${MAKE_ENV} make obj
_cleandir=${MAKE_ENV} make cleandir
_depend=${MAKE_ENV} make depend
_includes=${MAKE_ENV} make includes
_build=${MAKE_ENV} make && ${_install}
_install=${MAKE_ENV} make install
_obj_wrp=${MAKE_ENV} make -f Makefile.bsd-wrapper obj
_cleandir_wrp=${MAKE_ENV} make -f Makefile.bsd-wrapper cleandir
_depend_wrp=${MAKE_ENV} make -f Makefile.bsd-wrapper depend
_build_wrp=${MAKE_ENV} make -f Makefile.bsd-wrapper && ${_install_wrp}
_install_wrp=${MAKE_ENV} make -f Makefile.bsd-wrapper install
# ================================================================== COOKIES
COOKIE:=${WRKDIR}/.cookie
INIT_COOKIE:=${WRKINST}/.init-done
EXTRACT_COOKIE:=${WRKDIR}/.extract-done
PATCH_FILES=
PATCH_COOKIES=
BUILD_COOKIES=
# ============================================== PATCHING & BUILDING TARGETS
# Create targets and define variables only for our ${ARCH}
PATCH_LIST:=${PATCH_${ARCH:U}} ${PATCH_COMMON}
.for _patch in ${PATCH_LIST}
# _number holds the patch number, that's enough
# to identify a patch file
_number:=${_patch:C/_.*//}
dummy:=${PATCH_${ARCH:U}:M${_patch}*}
.if !empty(dummy)
_file :=${ARCH}/${_patch}.patch
.else
_file :=common/${_patch}.patch
.endif
# List of patch files
PATCH_FILE_${_number}:= ${PATCHDIR}/${_file}
PATCH_FILES:= ${PATCH_FILES} ${PATCH_FILE_${_number}}
# Fetches the patch file
${PATCH_FILE_${_number}}:
@echo ">> ${.TARGET:T} doesn't seem to exist on this system."
@mkdir -p ${.TARGET:H}
@cd ${.TARGET:H} && \
for site in ${MASTER_SITE_OPENBSD}; do \
echo ">> Attempting to fetch ${.TARGET} from $${site}/${MASTER_SITE_SUBDIR}/"; \
if ${FETCH} $${site}/${MASTER_SITE_SUBDIR}/${.TARGET:S@${PATCHDIR}/@@}; then \
exit 0; \
fi; \
done; exit 1
PATCH_COOKIE_${_number}:=${WRKDIR}/.${_patch}-applied
# Patches the source tree
${PATCH_COOKIE_${_number}}: ${PATCH_FILE_${_number}}
@cd ${WRKSRC} && \
patch -p0 < ${PATCH_FILE_${.TARGET:E:C/_.*//}}
@touch -f ${.TARGET}
COOKIE_${_number}:=${WRKDIR}/.${_patch}-build-start
BUILD_COOKIE_${_number}:=${WRKDIR}/.${_patch}-built
# Builds the patch applied
${BUILD_COOKIE_${_number}}:
@touch -f ${COOKIE_${.TARGET:E:C/_.*//}}
@env PATCH="${PATCH}" ${MAKE_ENV} make ${.TARGET:E:C/-built//}
@touch -f ${.TARGET}
.endfor
.for _p in ${PATCH}
PATCH_COOKIES += ${PATCH_COOKIE_${_p}}
BUILD_COOKIES += ${BUILD_COOKIE_${_p}}
.endfor
# ============================================================= MAIN TARGETS
# Extracts sources
extract: ${EXTRACT_COOKIE}
${EXTRACT_COOKIE}:
.if defined(CDSRC)
@if [ ! -f ${DISTDIR}/src.tar.gz ]; then \
echo "+------------------------";\
echo "|"; \
echo "| Error: copy src.tar.gz from CD3 to ${DISTDIR}"; \
echo "|"; \
echo "+------------------------";\
exit 1; \
fi
.else
@if [ ! -f ${DISTDIR}/src.tar.gz -o ! -f ${DISTDIR}/sys.tar.gz ]; then \
echo "+------------------------";\
echo "|"; \
echo "| Error: download src.tar.gz and sys.tar.gz from an FTP server and"; \
echo "| put them in ${DISTDIR}"; \
echo "|"; \
echo "+------------------------";\
exit 1; \
fi
.endif
@echo "===> Extracting sources"
rm -rf ${WRKOBJ} ${WRKSRC}
mkdir -p ${WRKOBJ}
mkdir -p ${WRKSRC}
tar xzpf ${DISTDIR}/src.tar.gz -C ${WRKSRC}
.if ! defined(CDSRC)
tar xzpf ${DISTDIR}/sys.tar.gz -C ${WRKSRC}
.endif
touch -f ${.TARGET}
# Extracts the OpenBSD installation files
init: ${INIT_COOKIE}
${INIT_COOKIE}:
@echo "===> Creating fake install tree"
rm -rf ${WRKINST}
mkdir -p ${WRKINST}
.for _pkg in base comp etc game man
tar xzpf ${DISTDIR}/${ARCH}/${_pkg}${OSrev}.tgz -C ${WRKINST}
.endfor
cp -p ${DISTDIR}/${ARCH}/bsd ${WRKINST} && \
touch -f ${.TARGET}
# Applies patches
patch: extract ${PATCH_COOKIES}
# The cookie for detecting a change in the timestamp
${COOKIE}!
@touch -f ${.TARGET}
# Builds the patch applied
build: init patch ${COOKIE} ${BUILD_COOKIES}
# Packages the modified files
plist: build
@echo "===> Finding changed binaries"
@mkdir -p ${PKGDIR}
@cd ${WRKINST} && \
find . -newer ${COOKIE_${PATCH}} -a ! -newer ${BUILD_COOKIE_${PATCH}} -type f > ${PKGDIR}/PLIST${FLAVOR_EXT}
package: build
@mkdir -p ${PACKAGEDIR}
@echo "===> Building package for ${FULLPKGNAME} in ${PACKAGEDIR}";
@cat ${PKGDIR}/PLIST-${ARCH}-$${PATCH} | \
(cd ${WRKINST} && xargs tar czpf ${PACKAGEDIR}/${FULLPKGNAME}.tgz)
@if [ "${SIGNKEY}" != "NO" ]; then \
if [ ! -f "${SIGNKEY}" ]; then \
echo "+-------------------------"; \
echo "|"; \
echo "| Key file (${SIGNKEY}) not found."; \
echo "| Package will not be signed."; \
echo "|"; \
echo "+-------------------------"; \
else \
echo "===> Signing package with ${SIGNKEY}"; \
gzsig sign ${SIGNCMD} ${PACKAGEDIR}/${FULLPKGNAME}.tgz; \
if [ -f "${SIGNKEY}.pub" ]; then \
echo "===> Verifying package with ${SIGNKEY}.pub"; \
gzsig verify ${SIGNKEY}.pub ${PACKAGEDIR}/${FULLPKGNAME}.tgz;\
fi; \
fi; \
fi
@echo "+-------------------------"
@echo "|"
@echo "| The binary patch has been created in"
@echo "| ${PACKAGEDIR}"
@echo "|"
@echo "| To install it run make install or:"
@echo "|"
@echo "| # cd ${PACKAGEDIR}"
@echo "| # tar xzpf ${FULLPKGNAME}.tgz -C /"
@echo "|"
@echo "+-------------------------"
# Installs the binary patch
install:
tar xzpf ${PACKAGEDIR}/${FULLPKGNAME}.tgz -C /
# Cleans the working directory
clean:
@echo "===> Cleaning working directory"
rm -rf ${WRKDIR}
# Removes the directories and cookie created by extract
clean-extract:
rm -rf ${WRKSRC} ${WRKOBJ} ${EXTRACT_COOKIE}
# Removes fake directory
clean-init:
rm -rf ${WRKINST}
.if defined(show)
.MAIN: show
show:
. for _s in ${show}
@echo ${${_s}:Q}
. endfor
.else
.MAIN: build
.endif
.include <bsd.own.mk>