xref: /openbsd-src/distrib/syspatch/bsd.syspatch.mk (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1#	$OpenBSD: bsd.syspatch.mk,v 1.3 2016/09/05 11:55:06 robert Exp $
2#
3# Copyright (c) 2016 Robert Nagy <robert@openbsd.org>
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17.include <bsd.own.mk>
18
19ERRATA?=
20
21# binaries used by this makefile
22FETCH=		/usr/bin/ftp -Vm
23
24# make sure to only use the original OpenBSD mirror
25MIRROR=		http://ftp.openbsd.org/pub/OpenBSD/patches/${OSREV}/common
26
27# the final name of the syspatch tarball
28SYSPATCH=	syspatch-${OSrev}-${ERRATA}.tgz
29
30# arguments used by different tools
31MTREE_FILES=	/etc/mtree/4.4BSD.dist
32MTREE_ARGS=	-qdep ${FAKE} -U
33SIGNIFY_KEY=	/etc/signify/openbsd-${OSrev}-base.pub
34PATCH_STRIP?=	-p0
35PATCH_ARGS=	-d ${SRCDIR} -z .orig --forward --quiet -E ${PATCH_STRIP}
36
37# build type defaults to src
38BUILD?=		src
39
40# miscellaneous variables
41SYSPATCH_DIR=	${FAKE}/var/syspatch/${OSREV}
42FAKE=		${ERRATA}/fake
43SRCDIR=		${BSDSRCDIR}
44SUBDIR?=
45
46_PATCH_COOKIE=	${ERRATA}/.patch_done
47_BUILD_COOKIE=	${ERRATA}/.build_done
48_FAKE_COOKIE=	${ERRATA}/.fake_done
49_INSTALL_COOKIE=${ERRATA}/.install_done
50
51.if ${BUILD:L:Msrc}
52SRCDIR=		${BSDSRCDIR}
53.elif ${BUILD:L:Mxenocara}
54SRCDIR=		${X11SRC}
55MTREE_FILES+=	/etc/mtree/BSD.x11.dist
56.endif
57
58.MAIN: all
59all: ${_BUILD_COOKIE}
60
61.if !target(clean)
62clean:
63	rm -rf .depend ${ERRATA} ${SYSPATCH}
64.endif
65
66cleandir: clean
67
68${_FAKE_COOKIE}: ${_BUILD_COOKIE}
69.for _m in ${MTREE_FILES}
70	@${SUDO} /usr/sbin/mtree ${MTREE_ARGS} -f ${_m} >/dev/null
71.endfor
72	@touch $@
73
74${ERRATA}/${ERRATA}.patch:
75	@${INSTALL} -d -m 755 ${SYSPATCH_DIR} && \
76	echo ">> Fetch ${MIRROR}/${.TARGET:T}.sig"; \
77	if ${FETCH} -o ${SYSPATCH_DIR}/${.TARGET:T}.sig \
78		${MIRROR}/${.TARGET:T}.sig; then \
79		if /usr/bin/signify -Vep ${SIGNIFY_KEY} -x \
80			${SYSPATCH_DIR}/${.TARGET:T}.sig -m ${.TARGET}; then \
81				exit 0; \
82		fi; \
83	fi; exit 1
84
85${_PATCH_COOKIE}: ${ERRATA}/${ERRATA}.patch
86	@/usr/bin/patch ${PATCH_ARGS} < ${ERRATA}/${ERRATA}.patch || \
87		{ echo "***>   ${ERRATA}.patch did not apply cleanly"; \
88		exit 1; };
89	@touch $@
90
91${_INSTALL_COOKIE}: ${_FAKE_COOKIE}
92.if ${BUILD:L:Msrc} || ${BUILD:L:Mxenocara}
93.  if defined(SUBDIR) && !empty(SUBDIR)
94.    for _s in ${SUBDIR}
95	@if [ -f ${_s}/Makefile.bsd-wrapper ]; then \
96		_mk_spec_="-f Makefile.bsd-wrapper"; \
97	fi; \
98	cd ${_s} && ${SUDO} /usr/bin/make $${_mk_spec_} \
99		DESTDIR=${.OBJDIR}/${FAKE} install
100.    endfor
101.  endif
102.elif ${BUILD:L:Mkernel}
103.  for _kern in GENERIC GENERIC.MP
104	@if [ ${_kern} = "GENERIC" ]; then \
105		${SUDO} \
106		cp -p ${SRCDIR}/sys/arch/${MACHINE_ARCH}/compile/${_kern}/bsd \
107		${.OBJDIR}/${FAKE}/bsd || \
108		{ echo "***>   failed to install ${_kern}"; \
109		exit 1; }; \
110	elif [ ${_kern} = "GENERIC.MP" ]; then \
111		${SUDO} \
112		cp -p ${SRCDIR}/sys/arch/${MACHINE_ARCH}/compile/${_kern}/bsd \
113		${.OBJDIR}/${FAKE}/bsd.mp || \
114		{ echo "***>   failed to install ${_kern}"; \
115		exit 1; }; \
116	fi; exit 0
117.  endfor
118.endif
119	@touch $@
120
121${_BUILD_COOKIE}: ${_PATCH_COOKIE}
122.if ${BUILD:L:Msrc} || ${BUILD:L:Mxenocara}
123.  if defined(SUBDIR) && !empty(SUBDIR)
124.    for _s in ${SUBDIR}
125	@if [ -f ${_s}/Makefile.bsd-wrapper ]; then \
126		_mk_spec_="-f Makefile.bsd-wrapper"; \
127	fi; \
128	for _t in obj depend all; do \
129		cd ${_s} && /usr/bin/make $${_mk_spec_} $${_t}; \
130	done;
131.    endfor
132.  endif
133.elif ${BUILD:L:Mkernel}
134.  for _kern in GENERIC GENERIC.MP
135	@if cd ${SRCDIR}/sys/arch/${MACHINE_ARCH}/conf; then \
136		if config ${_kern}; then \
137			if cd ../compile/${_kern} && make clean && make; then \
138				exit 0; \
139			fi; exit 1; \
140		fi; exit 1; \
141	fi; exit 1
142.  endfor
143.endif
144	@touch $@
145
146syspatch: ${SYSPATCH}
147
148${SYSPATCH}: ${ERRATA}/.plist
149.for _m in ${MTREE_FILES}
150	@${SUDO} /usr/sbin/mtree ${MTREE_ARGS} -f ${_m} >/dev/null
151	@${SUDO} chown -R root:wheel ${SYSPATCH_DIR}
152.endfor
153	@tar -Pczf ${.TARGET} -C ${FAKE} -I ${ERRATA}/.plist || \
154		{ echo "***>   unable to create ${.TARGET}"; \
155		exit 1; };
156	@echo ">> Created ${SYSPATCH}"; \
157
158${ERRATA}/.fplist: ${_INSTALL_COOKIE}
159	@${SUDO} find ${FAKE} \! -type d > ${.OBJDIR}/${ERRATA}/.fplist || \
160		{ echo "***>   unable to create list of files"; \
161		exit 1; };
162
163${ERRATA}/.plist: ${ERRATA}/.fplist
164	@for _l in $$(cat ${.OBJDIR}/${ERRATA}/.fplist); do \
165		_o=$$(echo $${_l} | sed "s,${FAKE},,g"); \
166		cmp -s $${_l} $${_o} || echo $${_o} | sed 's,^/,,g'; \
167	done > ${.OBJDIR}/${ERRATA}/.plist
168
169findstatic:
170.if defined(LIB) && !empty(LIB)
171	@cd ${SRCDIR} && for _m in $$(find {bin,sbin} \
172		\( -name Makefile -o -name Makefile.bsd-wrapper \) \
173		-exec grep -l '\-l${LIB}' {} \;); do \
174		echo "SUBDIR+= $$(dirname $${_m})"; \
175	done
176.endif
177
178.include <bsd.obj.mk>
179