1#	$OpenBSD: Makefile,v 1.488 2024/02/29 22:21:21 bluhm Exp $
2
3.include <bsd.own.mk>
4
5TZDIR=		/usr/share/zoneinfo
6LOCALTIME=	Canada/Mountain
7MTREEDIR=	/etc/mtree
8
9NOOBJ=
10
11KERNELS = GENERIC bsd
12
13.if exists(etc.${MACHINE}/Makefile.inc)
14.include "etc.${MACHINE}/Makefile.inc"
15.endif
16
17.for CONF K in ${KERNELS}
18.  if !target($K)
19$K:
20	cd ../sys/arch/${MACHINE}/compile/${CONF} && \
21		{ [[ -n "${KEEPKERNELS}" ]] || ${MAKE} cleandir; } && \
22		${MAKE} config && ${MAKE} clean && exec ${MAKE};
23.  endif
24ALL_KERNELS += $K
25.endfor
26
27kernels: ${ALL_KERNELS}
28.for CONF K in ${KERNELS}
29	cp ../sys/arch/${MACHINE}/compile/${CONF}/obj/bsd ${RELEASEDIR}/$K
30	chmod a+r ${RELEASEDIR}/$K
31.endfor
32	cd ${.CURDIR}/../sys/arch/${MACHINE}/compile/ && \
33		tar -chzf ${DESTDIR}/usr/share/relink/kernel.tgz -s ',/obj/,/,' \
34		GENERIC*/obj/*.o GENERIC*/obj/Makefile \
35		GENERIC*/obj/ld.script GENERIC*/obj/makegap.sh
36	chown root:wheel ${DESTDIR}/usr/share/relink/kernel.tgz
37	chmod 644 ${DESTDIR}/usr/share/relink/kernel.tgz
38
39# -rw-r--r--
40BINOWN= root
41BINGRP= wheel
42MUTABLE=changelist daily etc.${MACHINE}/disktab \
43	etc.${MACHINE}/login.conf ftpusers gettytab group ksh.kshrc locate.rc \
44	mailer.conf moduli monthly netstart newsyslog.conf ntpd.conf \
45	pf.os protocols rc rc.conf rpc services shells syslog.conf weekly
46
47# -rw-r--r--
48EXAMPLES=acme-client.conf chio.conf dhclient.conf dhcpd.conf exports \
49	httpd.conf ifstated.conf inetd.conf man.conf mixerctl.conf \
50	mrouted.conf ntpd.conf printcap rad.conf rbootd.conf \
51	remote sensorsd.conf wsconsctl.conf
52
53# -rw-------
54EXAMPLES_600=bgpd.conf doas.conf dvmrpd.conf eigrpd.conf hostapd.conf \
55	iked.conf ipsec.conf ldapd.conf ldpd.conf login_ldap.conf \
56	ospf6d.conf ospfd.conf pf.conf radiusd.conf rc.local \
57	rc.securelevel rc.shutdown relayd.conf ripd.conf sasyncd.conf \
58	snmpd.conf vm.conf ypldap.conf
59
60# -r-xr-xr-x
61RCDAEMONS=amd apmd bgpd bgplgd bootparamd cron dhcpd dhcpleased dhcrelay \
62	dhcrelay6 dvmrpd eigrpd ftpd ftpproxy ftpproxy6 hostapd hotplugd \
63	httpd identd ifstated iked inetd isakmpd iscsid ldapd ldattach ldomd \
64	ldpd lockd lpd mopd mountd mrouted nfsd npppd nsd ntpd ospf6d ospfd \
65	pflogd portmap rad radiusd rarpd rbootd relayd resolvd ripd route6d \
66	sasyncd sensorsd slowcgi slaacd smtpd sndiod snmpd spamd \
67	spamlogd sshd statd syslogd tftpd tftpproxy unbound \
68	unwind vmd watchdogd wsmoused xenodm ypbind ypldap ypserv
69
70MISETS=	base${OSrev}.tgz comp${OSrev}.tgz man${OSrev}.tgz game${OSrev}.tgz
71
72all clean cleandir etc install:
73
74install-mtree:
75	${INSTALL} -c -o root -g wheel -m 600 mtree/special \
76	    ${DESTDIR}${MTREEDIR}
77	${INSTALL} -c -o root -g wheel -m 444 mtree/4.4BSD.dist \
78	    ${DESTDIR}${MTREEDIR}
79	${INSTALL} -c -o root -g wheel -m 444 mtree/BSD.x11.dist \
80	    ${DESTDIR}${MTREEDIR}
81
82.ifndef DESTDIR
83distribution-etc-root-var distribution distrib-dirs release:
84	@echo setenv DESTDIR before doing that!
85	@false
86.else
87distribution-etc-root-var: distrib-dirs
88	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 ${MUTABLE} ${DESTDIR}/etc
89	sh ttys.pty | cat etc.${MACHINE}/ttys - > ${DESTDIR}/etc/ttys && \
90	    chown ${BINOWN}:${BINGRP} ${DESTDIR}/etc/ttys && \
91	    chmod 644 ${DESTDIR}/etc/ttys
92	cat examples/sysctl.conf etc.${MACHINE}/sysctl.conf > \
93	    ${DESTDIR}/etc/examples/sysctl.conf && \
94	    chown ${BINOWN}:${BINGRP} ${DESTDIR}/etc/examples/sysctl.conf && \
95	    chmod 644 ${DESTDIR}/etc/examples/sysctl.conf
96	cat fbtab.head etc.${MACHINE}/fbtab fbtab.tail > ${DESTDIR}/etc/fbtab && \
97	    chown ${BINOWN}:${BINGRP} ${DESTDIR}/etc/fbtab && \
98	    chmod 644 ${DESTDIR}/etc/fbtab
99	${INSTALL} -c -o ${BINOWN} -g operator -m 664 motd ${DESTDIR}/etc
100	${INSTALL} -c -o root -g crontab -m 600 crontab ${DESTDIR}/var/cron/tabs/root
101	${INSTALL} -c -o root -g wheel -m 600 master.passwd ${DESTDIR}/etc
102	pwd_mkdb -p -d ${DESTDIR}/etc /etc/master.passwd
103	chown root:wheel ${DESTDIR}/etc/passwd ${DESTDIR}/etc/pwd.db
104	chown root:_shadow ${DESTDIR}/etc/spwd.db
105	${INSTALL} -c -o root -g wheel -m 600 pf.conf ${DESTDIR}/etc
106	${INSTALL} -c -o root -g _nsd -m 640 nsd.conf ${DESTDIR}/var/nsd/etc
107	${INSTALL} -c -o root -g wheel -m 644 unbound.conf ${DESTDIR}/var/unbound/etc
108	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 555 \
109	    etc.${MACHINE}/MAKEDEV ${DESTDIR}/dev
110	cd root; \
111		${INSTALL} -c -o root -g wheel -m 644 dot.cshrc \
112		    ${DESTDIR}/root/.cshrc; \
113		${INSTALL} -c -o root -g wheel -m 644 dot.login \
114		    ${DESTDIR}/root/.login; \
115		${INSTALL} -c -o root -g wheel -m 644 dot.profile \
116		    ${DESTDIR}/root/.profile; \
117		${INSTALL} -c -o root -g wheel -m 644 dot.Xdefaults \
118		    ${DESTDIR}/root/.Xdefaults; \
119		${INSTALL} -c -o root -g wheel -m 644 dot.cvsrc \
120		    ${DESTDIR}/root/.cvsrc; \
121		${INSTALL} -c -o root -g wheel -m 600 /dev/null \
122		    ${DESTDIR}/root/.ssh/authorized_keys; \
123		rm -f ${DESTDIR}/.cshrc ${DESTDIR}/.profile; \
124		${INSTALL} -c -o root -g wheel -m 644 dot.cshrc \
125		    ${DESTDIR}/.cshrc; \
126		${INSTALL} -c -o root -g wheel -m 644 dot.profile \
127		    ${DESTDIR}/.profile
128	cd skel; \
129		${INSTALL} -c -o root -g wheel -m 644 dot.cshrc \
130		    ${DESTDIR}/etc/skel/.cshrc; \
131		${INSTALL} -c -o root -g wheel -m 644 dot.login \
132		    ${DESTDIR}/etc/skel/.login; \
133		${INSTALL} -c -o root -g wheel -m 644 dot.mailrc \
134		    ${DESTDIR}/etc/skel/.mailrc; \
135		${INSTALL} -c -o root -g wheel -m 644 dot.profile \
136		    ${DESTDIR}/etc/skel/.profile; \
137		${INSTALL} -c -o root -g wheel -m 644 dot.Xdefaults \
138		    ${DESTDIR}/etc/skel/.Xdefaults; \
139		${INSTALL} -c -o root -g wheel -m 644 dot.cvsrc \
140		    ${DESTDIR}/etc/skel/.cvsrc; \
141		${INSTALL} -c -o root -g wheel -m 600 /dev/null \
142		    ${DESTDIR}/etc/skel/.ssh/authorized_keys
143	cd amd; \
144		${INSTALL} -c -o root -g wheel -m 644 master.sample \
145		    ${DESTDIR}/etc/amd
146	cd ppp; \
147		${INSTALL} -c -o root -g wheel -m 600 chap-secrets \
148		    ${DESTDIR}/etc/ppp; \
149		${INSTALL} -c -o root -g wheel -m 600 options \
150		    ${DESTDIR}/etc/ppp; \
151		${INSTALL} -c -o root -g wheel -m 600 options.sample \
152		    ${DESTDIR}/etc/ppp; \
153		${INSTALL} -c -o root -g wheel -m 600 chatscript.sample \
154		    ${DESTDIR}/etc/ppp; \
155		${INSTALL} -c -o root -g wheel -m 600 pap-secrets \
156		    ${DESTDIR}/etc/ppp
157	cd rpki; \
158		${INSTALL} -c -o root -g wheel -m 644 \
159		    afrinic.tal apnic.tal lacnic.tal ripe.tal \
160		    arin.constraints afrinic.constraints apnic.constraints \
161		    lacnic.constraints ripe.constraints \
162		    ${DESTDIR}/etc/rpki
163	cd examples; \
164		${INSTALL} -c -o root -g wheel -m 644 ${EXAMPLES} \
165		    ${DESTDIR}/etc/examples; \
166		${INSTALL} -c -o root -g wheel -m 600 ${EXAMPLES_600} \
167		    ${DESTDIR}/etc/examples; \
168		chgrp operator ${DESTDIR}/etc/examples/chio.conf
169		chgrp auth ${DESTDIR}/etc/examples/login_ldap.conf
170		chmod 0640 ${DESTDIR}/etc/examples/login_ldap.conf
171	cd signify; \
172		${INSTALL} -c -o root -g wheel -m 644 *.pub \
173		    ${DESTDIR}/etc/signify
174	ln -fs ${TZDIR}/${LOCALTIME} ${DESTDIR}/etc/localtime
175	chown -h root:wheel ${DESTDIR}/etc/localtime
176	ln -fs /usr/sbin/rmt ${DESTDIR}/etc/rmt
177	chown -h root:wheel ${DESTDIR}/etc/rmt
178	${INSTALL} -c -o root -g wheel -m 644 /dev/null \
179	    ${DESTDIR}/var/account/acct
180	${INSTALL} -c -o root -g wheel -m 644 minfree \
181	    ${DESTDIR}/var/crash
182	${INSTALL} -c -o ${BINOWN} -g operator -m 664 /dev/null \
183	    ${DESTDIR}/etc/dumpdates
184	${INSTALL} -c -o root -g crontab -m 660 /dev/null \
185	    ${DESTDIR}/var/cron/at.deny
186	${INSTALL} -c -o root -g crontab -m 660 /dev/null \
187	    ${DESTDIR}/var/cron/cron.deny
188	${INSTALL} -c -o root -g wheel -m 600 /dev/null \
189	    ${DESTDIR}/var/cron/log
190	${INSTALL} -c -o root -g wheel -m 444 /dev/null \
191	    ${DESTDIR}/var/db/locate.database
192	${INSTALL} -c -o _rpki-client -g wheel -m 644 /dev/null \
193	    ${DESTDIR}/var/db/rpki-client/openbgpd
194	${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
195	    ${DESTDIR}/var/log/authlog
196	${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
197	    ${DESTDIR}/var/log/daemon
198	${INSTALL} -c -o ${BINOWN} -g wheel -m 600 /dev/null \
199	    ${DESTDIR}/var/log/failedlogin
200	${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
201	    ${DESTDIR}/var/log/ftpd
202	${INSTALL} -c -o ${BINOWN} -g wheel -m 644 /dev/null \
203	    ${DESTDIR}/var/log/lastlog
204	${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
205	    ${DESTDIR}/var/log/lpd-errs
206	${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
207	    ${DESTDIR}/var/log/maillog
208	${INSTALL} -c -o ${BINOWN} -g wheel -m 644 /dev/null \
209	    ${DESTDIR}/var/log/messages
210	${INSTALL} -c -o ${BINOWN} -g wheel -m 600 /dev/null \
211	    ${DESTDIR}/var/log/secure
212	${INSTALL} -c -o ${BINOWN} -g wheel -m 644 /dev/null \
213	    ${DESTDIR}/var/log/wtmp
214	${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \
215	    ${DESTDIR}/var/log/xferlog
216	cd ../usr.sbin/ypserv/ypinit && exec ${MAKE} distribution
217	cd ../usr.bin/ssh && exec ${MAKE} distribution
218	cd ../lib/libcrypto && exec ${MAKE} distribution
219	cd ../usr.bin/bgplg && exec ${MAKE} distribution
220	cd ../usr.bin/mail && exec ${MAKE} distribution
221	cd ../usr.sbin/ikectl && exec ${MAKE} distribution
222	cd ../usr.sbin/ldapd && exec ${MAKE} distribution
223	cd ../usr.sbin/npppd && exec ${MAKE} distribution
224	cd mail && exec ${MAKE} distribution
225	${INSTALL} -c -o root -g wheel -m 600 root/root.mail \
226	    ${DESTDIR}/var/mail/root
227	cd rc.d; \
228		${INSTALL} -c -o root -g wheel -m 644 rc.subr \
229		    ${DESTDIR}/etc/rc.d && \
230		${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 555 ${RCDAEMONS} \
231		    ${DESTDIR}/etc/rc.d
232	cd ${DESTDIR}/var; ln -fs ../tmp
233	chown -h root:wheel ${DESTDIR}/var/tmp
234	touch ${DESTDIR}/var/sysmerge/etcsum
235	chown root:wheel ${DESTDIR}/var/sysmerge/etcsum
236	chmod 644 ${DESTDIR}/var/sysmerge/etcsum
237	cd ${DESTDIR}/ && \
238		sort ${.CURDIR}/../distrib/sets/lists/etc/{mi,md.${MACHINE}} | \
239		xargs sha256 -h ${DESTDIR}/var/sysmerge/etcsum || true
240	cd ${DESTDIR}/ && \
241		sort ${.CURDIR}/../distrib/sets/lists/etc/{mi,md.${MACHINE}} | \
242		pax -w -d | gzip -9 > ${DESTDIR}/var/sysmerge/etc.tgz
243	chown root:wheel ${DESTDIR}/var/sysmerge/etc.tgz
244	chmod 644 ${DESTDIR}/var/sysmerge/etc.tgz
245
246distribution:
247	exec ${MAKE} distribution-etc-root-var
248	cd .. && exec ${MAKE} install
249
250distrib-dirs:
251	if [ ! -d ${DESTDIR}/. ]; then \
252		${INSTALL} -d -o root -g wheel -m 755 ${DESTDIR}; \
253	fi
254	mtree -qdef mtree/4.4BSD.dist -p ${DESTDIR}/ -U
255	cd ${DESTDIR}/; ln -fhs usr/src/sys sys
256	chown -h root:wheel ${DESTDIR}/sys
257
258.ifndef RELEASEDIR
259release:
260	@echo setenv RELEASEDIR before building a release.
261	@false
262.else
263release:
264	umask ${WOBJUMASK}; exec ${MAKE} do-release
265
266do-release:
267	@if [[ `id -u` -ne 0 ]]; then \
268		echo $@ must be called by root >&2; \
269		false; \
270	fi
271	@destmp=`df -P ${DESTDIR} | awk 'END { print $$6 }'`; \
272	if ! mount | grep -q " $${destmp} .*noperm"; then \
273		echo ${DESTDIR} must be on a noperm filesystem >&2; \
274		false; \
275	fi; \
276	if [[ `stat -f '%Su %Lp' $${destmp}` != '${BUILDUSER} 700' ]]; then \
277		echo $${destmp} must have owner BUILDUSER and mode 700 >&2; \
278		false; \
279	fi
280	${MAKE} release-sets
281	${MAKE} distrib
282	su ${BUILDUSER} -c 'exec ${MAKE} sha'
283	-cd ${RELEASEDIR} && chmod g-w,a+rX *
284
285release-sets:
286	su ${BUILDUSER} -c 'exec ${MAKE} distribution'
287	su ${BUILDUSER} -c 'exec ${MAKE} kernels'
288	cp -p ${DESTDIR}/usr/share/relink/kernel.tgz /usr/share/relink/kernel.tgz
289	${MAKE} bootblocks
290	cd ${RELEASEDIR} && rm -f SHA256
291	cd ../distrib/sets && exec su ${BUILDUSER} -c 'exec sh maketars ${OSrev}'
292
293sha:
294	-cd ${RELEASEDIR}; \
295	    date -u "+Build date: %s - %+" > BUILDINFO; \
296	    cksum -a sha256 BUILDINFO INSTALL.`arch -ks` \
297	    ${ALL_KERNELS} ${MDEXT} ${MISETS} | sort > SHA256
298
299.endif
300
301.endif	# DESTDIR check
302
303distrib:
304	umask 022; cd ../distrib && \
305	    ${MAKE} && exec ${MAKE} install
306
307.PHONY: distribution-etc-root-var distribution distrib-dirs \
308	release allarchs kernels release-sets m4 install-mtree \
309	bootblocks do-release ${ALL_KERNELS}
310
311SUBDIR+= etc.alpha etc.amd64 etc.arm64 etc.armv7
312SUBDIR+= etc.hppa etc.i386 etc.landisk etc.loongson etc.luna88k
313SUBDIR+= etc.macppc etc.octeon etc.powerpc64 etc.riscv64
314SUBDIR+= etc.sparc64
315
316.include <bsd.subdir.mk>
317.include <bsd.prog.mk>
318