Makefile revision 1.203
1#	$NetBSD: Makefile,v 1.203 2002/03/01 06:22:09 chs Exp $
2#	from: @(#)Makefile	8.7 (Berkeley) 5/25/95
3
4# Environment variables without default values:
5#   DESTDIR must be set before anything in this file will work.
6#   RELEASEDIR is where the tarred up stuff for a snapshot or
7#	release will be placed.
8#
9# Environment variables with default values:
10#   LOCALTIME will set the default local time for the system you
11#	build; it determines what /etc/localtime is symlink'd to.
12#   KERNSRCDIR points to kernel source; it is set by default to ../sys,
13#	but can be overridden.
14#   KERNOBJDIR is the kernel build directory, it defaults to
15#	${KERNSRCDIR}/arch/${MACHINE}/compile, but can be overridden.
16#   KERNCONFDIR is where the configuration files for kernels are found;
17#	default is ${KERNSRCDIR}/arch/${MACHINE}/conf but can be overridden.
18#   UPDATE is normally undefined; if defined, don't do a 'make clean'
19#	before kernel compile
20#   NO_SENDMAIL is normally undefined; if defined, it will not do a
21#	`make distribution' in the sendmail config file source directory.
22#
23# Targets:
24#    distribution: makes a full NetBSD distribution in DESTDIR. If
25#	INSTALL_DONE is set, it will not do a `make install.'
26#	if DISTRIBUTION_DONE is set, it will not do anything.
27#    distrib-dirs: creates an empty NetBSD directory tree in DESTDIR.
28#	Called by distribution.
29#    snapshot: calls distribution, above, and then tars up the files
30#	into a release(7) format in RELEASEDIR. Any port-dependent
31#	stuff for this target is found in etc.${MACHINE}/Makefile.inc.
32#    release: a synonym for `snapshot'
33
34# setting NOOBJ prevents "make obj" from doing anything;
35# an objdir would break the installation stuff below
36NOOBJ=		# defined
37
38# do this before bsd.own.mk so we get correct KERNSRCDIR
39.include "../Makefile.inc"
40
41# For NO_SENDMAIL, INSTPRIV, MKCRYPTO
42.include <bsd.own.mk>
43
44.MAKEOVERRIDES+=	USETOOLS
45
46TZDIR=		/usr/share/zoneinfo
47LOCALTIME?=	UTC
48PWD_MKDB?=	pwd_mkdb
49
50# Flags for creating ISO CDROM image
51# mkisofs is expected to be in $PATH, install via pkgsrc/sysutils/cdrecord
52MKISOFS?=	mkisofs
53MKISOFS_FLAGS+= -J -l \
54		-r -T -v \
55		-P "The NetBSD Project" \
56		-m "${RELEASEDIR}/installation/cdrom"
57
58# MD Makefile.inc may append MD targets to BIN[123].  Make sure all
59# are empty, to preserve the old semantics of setting them below with "=".
60BIN1=
61BIN2=
62BIN3=
63
64# Directories to build in ${RELEASEDIR}.   MD Makefile.inc files can
65# add to this.
66# NOTE: Parent directories must be listed before subdirectories.
67INSTALLATION_DIRS= \
68	binary binary/sets binary/kernel installation
69
70.if exists(etc.${MACHINE}/Makefile.inc)
71.include "etc.${MACHINE}/Makefile.inc"
72.endif
73
74# Use multiple jobs for kernel builds, if NBUILDJOBS set.
75# (Taken from src/Makefile.)
76.if defined(NBUILDJOBS)
77_J= -j${NBUILDJOBS}
78.endif
79
80# -rw-r--r--
81BINOWN= root
82BINGRP= wheel
83BIN1+=	bootptab changelist csh.cshrc csh.login csh.logout daily \
84	daily.conf dm.conf floppytab ftpchroot ftpusers ftpwelcome \
85	gettytab group hosts hosts.lpd inetd.conf lkm.conf \
86	mailer.conf man.conf monthly monthly.conf mrouted.conf \
87	netconfig networks newsyslog.conf nsswitch.conf ntp.conf \
88	phones printcap profile protocols rbootd.conf rc rc.conf \
89	rc.lkm rc.local rc.subr rc.shutdown remote rpc \
90	security security.conf services shells sysctl.conf syslog.conf \
91	weekly weekly.conf wscons.conf \
92	etc.${MACHINE}/ttys etc.${MACHINE}/disktab
93
94.if	(${MACHINE_ARCH} == "m68k") || \
95	(${MACHINE_ARCH} == "ns32k") || \
96	(${MACHINE_ARCH} == "vax") || \
97	(${MACHINE_ARCH} == "arm32")
98BIN1+=	ld.so.conf
99.elif exists(etc.${MACHINE_ARCH}/ld.so.conf)
100BIN1+=	etc.${MACHINE_ARCH}/ld.so.conf
101.endif
102
103.if exists(etc.${MACHINE_ARCH}/ttyaction)
104BIN1+=	etc.${MACHINE_ARCH}/ttyaction
105.endif
106
107# -rw-rw-r--
108BIN2+=	motd
109
110# -rw-------
111BIN3+=	hosts.equiv
112
113NAMEDB=	127 root.cache named.conf localhost loopback.v6
114PCS=	pcs750.bin
115
116.if make(release) || make(snapshot) || make(distribution)		# {
117# find out endianness of target and set proper flag for pwd_mkdb so that
118# it creates database in same endianness
119.if exists(${DESTDIR}/usr/include/sys/endian.h)
120TARGET_ENDIANNESS!= \
121	printf '\#include <sys/endian.h>\n_BYTE_ORDER\n' | \
122	${CC} -I${DESTDIR}/usr/include -E - | tail -1 | awk '{print $$1}'
123.else
124TARGET_ENDIANNESS=
125.endif
126
127.if ${TARGET_ENDIANNESS} == "1234"
128TARGET_ENDIANNESS= -L
129.elif ${TARGET_ENDIANNESS} == "4321"
130TARGET_ENDIANNESS= -B
131.else
132TARGET_ENDIANNESS=
133.endif
134.endif	# release || snapshot || distribution				# }
135
136.include <bsd.kernobj.mk>
137
138obj:
139	mkdir -p ${KERNOBJDIR}
140
141check_destdir: .PHONY
142.if !defined(DESTDIR)
143	@echo "setenv DESTDIR before doing that!"
144	@false
145.else
146	@true
147.endif
148
149check_releasedir: .PHONY
150.if !defined(RELEASEDIR)
151	@echo "setenv RELEASEDIR before doing that!"
152	@false
153.else
154	@true
155.endif
156
157distribution: check_destdir .WAIT distrib-dirs
158.if !defined(DISTRIBUTION_DONE)
159.if !defined(INSTALL_DONE)
160	(cd ..; ${MAKE} _DISTRIB= includes)
161	(cd ..; ${MAKE} _DISTRIB= install)
162.endif	# !INSTALL_DONE
163	${MAKE} install-etc-files
164.endif	# !DISTRIBUTION_DONE
165
166install-etc-files: check_destdir
167	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 ${BIN1} ${DESTDIR}/etc
168	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 664 ${BIN2} ${DESTDIR}/etc
169	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 ${BIN3} ${DESTDIR}/etc
170	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 aliases \
171	    ${DESTDIR}/etc/mail
172	${INSTALL_FILE} -o root -g wheel -m 600 crontab \
173	    ${DESTDIR}/var/cron/tabs/root
174	${INSTALL_FILE} -o root -g wheel -m 600 master.passwd ${DESTDIR}/etc
175	${PWD_MKDB} -p ${TARGET_ENDIANNESS} -d ${DESTDIR}/ \
176		${DESTDIR}/etc/master.passwd
177.if defined(UNPRIVED)
178	echo "${DESTDIR}/etc/passwd type=file mode=0644 uname=root gname=wheel" \
179		| sed -e 's|^/|./|g' -e 's|//|/|g' >>${METALOG}
180	echo "${DESTDIR}/etc/pwd.db type=file mode=0644 uname=root gname=wheel" \
181		| sed -e 's|^/|./|g' -e 's|//|/|g' >>${METALOG}
182	echo "${DESTDIR}/etc/spwd.db type=file mode=0600 uname=root gname=wheel" \
183		| sed -e 's|^/|./|g' -e 's|//|/|g' >>${METALOG}
184.endif	# UNPRIVED
185	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
186	     MAKEDEV.local etc.${MACHINE}/MAKEDEV ${DESTDIR}/dev
187	${INSTALL_FILE} -o root -g wheel -m 600 minfree ${DESTDIR}/var/crash
188	(cd root; \
189		${INSTALL_FILE} -o root -g wheel -m 644 dot.cshrc \
190		    ${DESTDIR}/root/.cshrc; \
191		${INSTALL_FILE} -o root -g wheel -m 600 dot.klogin \
192		    ${DESTDIR}/root/.klogin; \
193		${INSTALL_FILE} -o root -g wheel -m 644 dot.login \
194		    ${DESTDIR}/root/.login; \
195		${INSTALL_FILE} -o root -g wheel -m 644 dot.profile \
196		    ${DESTDIR}/root/.profile; \
197		${INSTALL_FILE} -o root -g wheel -m 644 dot.shrc \
198		    ${DESTDIR}/root/.shrc; \
199		rm -f ${DESTDIR}/.cshrc ${DESTDIR}/.profile; \
200		${INSTALL_LINK} ${DESTDIR}/root/.cshrc ${DESTDIR}/.cshrc; \
201		${INSTALL_LINK} ${DESTDIR}/root/.profile ${DESTDIR}/.profile)
202	(cd defaults; ${MAKE} install)
203	(cd mtree; ${MAKE} install)
204	(cd namedb; \
205		${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
206		    ${NAMEDB} ${DESTDIR}/etc/namedb)
207	(cd rc.d; ${MAKE} install)
208	${INSTALL_SYMLINK} -o root -g wheel -m 755 \
209		${TZDIR}/${LOCALTIME} ${DESTDIR}/etc/localtime
210	${INSTALL_SYMLINK} -o root -g wheel -m 755 \
211		/usr/sbin/rmt ${DESTDIR}/etc/rmt
212	${INSTALL_FILE} -o ${BINOWN} -g operator -m 664 /dev/null \
213		${DESTDIR}/etc/dumpdates
214	${INSTALL_FILE} -o ${BINOWN} -g operator -m 600 /dev/null \
215		${DESTDIR}/etc/skeykeys
216	${INSTALL_FILE} -o root -g wheel -m 600 /dev/null \
217		${DESTDIR}/var/at/at.deny
218	${INSTALL_FILE} -o root -g wheel -m 600 /dev/null \
219		${DESTDIR}/var/cron/log
220	${INSTALL_FILE} -o nobody -g ${BINGRP} -m 664 /dev/null \
221		${DESTDIR}/var/db/locate.database
222	${INSTALL_FILE} -o uucp -g dialer -m 640 /dev/null \
223		${DESTDIR}/var/log/aculog
224	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 /dev/null \
225		${DESTDIR}/var/log/authlog
226	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 664 /dev/null \
227		${DESTDIR}/var/log/lastlog
228	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 640 /dev/null \
229		${DESTDIR}/var/log/lpd-errs
230	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 /dev/null \
231		${DESTDIR}/var/log/maillog
232	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 /dev/null \
233		${DESTDIR}/var/log/messages
234	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 /dev/null \
235		${DESTDIR}/var/log/secure
236	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 /dev/null \
237		${DESTDIR}/var/log/sendmail.st
238	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 /dev/null \
239		${DESTDIR}/var/log/wtmp
240	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 600 /dev/null \
241		${DESTDIR}/var/log/xferlog
242	${INSTALL_FILE} -o daemon -g staff -m 664 /dev/null \
243		${DESTDIR}/var/msgs/bounds
244	${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m 664 /dev/null \
245		${DESTDIR}/var/run/utmp
246	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
247		${DESTDIR}/var/games/atc_scores
248	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
249		${DESTDIR}/var/games/battlestar.log
250	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
251		${DESTDIR}/var/games/cfscores
252	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
253		${DESTDIR}/var/games/criblog
254	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
255		${DESTDIR}/var/games/robots_roll
256	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
257		${DESTDIR}/var/games/rogue.scores
258	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
259		${DESTDIR}/var/games/saillog
260	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
261		${DESTDIR}/var/games/snakerawscores
262	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
263		${DESTDIR}/var/games/snake.log
264	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
265		${DESTDIR}/var/games/tetris.scores
266	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
267		${DESTDIR}/var/games/larn/llog12.0
268	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
269		${DESTDIR}/var/games/larn/lscore12.0
270	${INSTALL_FILE} -o games -g games -m 664 /dev/null \
271		${DESTDIR}/var/games/larn/playerids
272	(cd etc.${MACHINE}; ${INSTALL_FILE} -o ${BINOWN} \
273	    -g ${BINGRP} -m 444 fstab.* ${DESTDIR}/etc)
274	(cd skel; ${MAKE} distribution)
275	(cd ../usr.bin/mail; ${MAKE} distribution)
276	(cd ../gnu/usr.sbin/postfix/; ${MAKE} distribution)
277.if (${MKCRYPTO} != "no")
278	(cd ../usr.bin/ssh; ${MAKE} distribution)
279.endif
280.if !defined(NO_SENDMAIL)
281	(cd ../gnu/usr.sbin/sendmail/cf/cf; ${MAKE} distribution)
282.endif
283
284distrib-dirs: check_destdir
285	${INSTALL_DIR} -o root -g wheel -m 755 ${DESTDIR}
286	${MTREE} -def mtree/NetBSD.dist -p ${DESTDIR}/ -U ${UNPRIVED:D-W}
287	rm -f ${DESTDIR}/sys
288	${INSTALL_SYMLINK} -o root -g wheel -m 755 usr/src/sys ${DESTDIR}/sys
289
290release snapshot: check_destdir check_releasedir .WAIT \
291    distribution snap_pre snap_md_pre snap_kern snap_md_post
292	(cd ../distrib/sets; ${MAKE} sets)
293	sh ../distrib/sets/makesums -t ${RELEASEDIR}/binary/kernel '*.gz'
294
295# Standalone target to create a CDROM image after the release
296# was composed. Should be run after "make build" in both src and xsrc
297iso-image: check_destdir check_releasedir .WAIT iso-image_md_post
298
299iso-image_mi: check_destdir check_releasedir .WAIT iso-image_md_pre
300	@if ${MKISOFS} --version; then \
301		mkdir -p ${RELEASEDIR}/installation/cdrom ; \
302		${MKISOFS} ${MKISOFS_FLAGS} \
303			-o ${RELEASEDIR}/installation/cdrom/netbsd-${MACHINE}.iso \
304			${RELEASEDIR} ; \
305		sh ../distrib/sets/makesums -t ${RELEASEDIR}/installation/cdrom '*.iso' ; \
306	else \
307		echo "install pkgsrc/sysutils/cdrecord and type 'make iso-image'." ; \
308	fi
309
310# Setup the $RELEASEDIR to produce a bootable CD image:
311iso-image_md_pre: check_destdir check_releasedir
312# nothing here -- look in the machine-dependent Makefile.inc
313
314# Fixup the  CD-image to be bootable
315iso-image_md_post: check_destdir check_releasedir .WAIT iso-image_mi
316# nothing here -- look in the machine-dependent Makefile.inc
317
318snap_pre: check_destdir check_releasedir
319# Could be a mount point, ignore the errors
320	-/bin/rm -rf ${RELEASEDIR}
321	${INSTALL} -d -m 755 ${RELEASEDIR}
322.for dir in ${INSTALLATION_DIRS}
323	${INSTALL} -d -m 755 ${RELEASEDIR}/${dir}
324.endfor
325
326# This target builds the kernels specified by each port.  A port may
327# specify the following kernels:
328#
329#	KERNEL_SETS		The list of kernels that will be
330#				packaged into sets, named
331#				kern-${kernel}.tgz.  These kernels
332#				are also placed in the binary/kernel
333#				area of the release package as
334#				netbsd-${kernel}.gz.
335#
336#	EXTRA_KERNELS		Additional kernels to place in the
337#				binary/kernel area of the release
338#				package as netbsd-${kernel}.gz, but
339#				which are not placed into sets. This
340#				allows a port to provide e.g. a netbootable
341#				installation kernel containing a ramdisk.
342#
343#	BUILD_KERNELS		Additional kernels to build which are
344#				not placed into sets nor into the
345#				binary/kernel area of the release
346#				package.  These are typically kernels
347#				that are built for inclusion only in
348#				installation disk/CD-ROM/tape images.
349#
350# A port may also specify KERNEL_SUFFIXES, which is an optional list
351# of filename suffixes for kernels to include in the kernel sets and
352# in the binary/kernel area of the release package (e.g. "netbsd" vs.
353# "netbsd.ecoff" and "netbsd.srec").  It is not an error if kernels
354# with these suffixes do not exist in the kernel build directory.
355#
356GETKERNELAWK=	awk '/^config/ {print $$2; found=1} \
357		END{ if (found == 0) print "netbsd"; }'
358#
359.if !target(snap_kern)
360snap_kern: check_destdir check_releasedir
361.if !defined(KERNELS_DONE)						# {
362.for configfile in ${KERNEL_SETS} ${EXTRA_KERNELS} ${BUILD_KERNELS}
363	cd ${KERNCONFDIR} && ${CONFIG} \
364		-b ${KERNOBJDIR}/${configfile:C/.*\///} -s ${KERNSRCDIR} ${configfile}
365.if !defined(UPDATE)
366	cd ${KERNOBJDIR}/${configfile:C/.*\///} && ${MAKE} distclean
367.endif
368	cd ${KERNOBJDIR}/${configfile:C/.*\///} && ${MAKE} depend && ${MAKE} ${_J}
369.endfor # build kernels
370.endif # KERNELS_DONE							# }
371.for configfile in ${KERNEL_SETS}
372	kernlist=`${GETKERNELAWK} ${KERNCONFDIR}/${configfile}`; \
373	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
374	cd $${kerndir} && \
375		tarlist=`for kernel in $${kernlist}; do \
376			echo "$${kernel}"; \
377			for s in ${KERNEL_SUFFIXES}; do \
378				if [ -f $${kernel}.$${s} ]; then \
379					echo "$${kernel}.$${s}"; \
380				fi; \
381			done; \
382		done`; \
383		GZIP=-9 ${PAX} -zwf \
384		    ${RELEASEDIR}/binary/sets/kern-${configfile}.tgz $${tarlist}
385.endfor # make kernel sets
386.for configfile in ${KERNEL_SETS} ${EXTRA_KERNELS}
387	kernlist=`${GETKERNELAWK} ${KERNCONFDIR}/${configfile:C/.*\///}`; \
388	kerndir=${KERNOBJDIR}/${configfile:C/.*\///}; \
389	cd $${kerndir} &&	\
390		gziplist=`for kernel in $${kernlist}; do \
391			echo "$${kernel}"; \
392			for s in ${KERNEL_SUFFIXES}; do \
393				if [ -f $${kernel}.$${s} ]; then \
394					echo "$${kernel}.$${s}"; \
395				fi; \
396			done; \
397		done`; \
398		for kernel in $${gziplist} ; do \
399		gzip -c -9 < $${kernel} > \
400		    ${RELEASEDIR}/binary/kernel/$${kernel}-${configfile:C/.*\///}.gz ; done
401.endfor # place KERNEL_SETS kernels + EXTRA_KERNELS in binary/kernel/...
402.endif # no target(snap_kern)
403
404snap_md_pre: check_destdir check_releasedir
405# nothing here -- look in the machine-dependent Makefile.inc
406
407snap_md_post: check_destdir check_releasedir
408# nothing here -- look in the machine-dependent Makefile.inc
409
410.include <bsd.prog.mk>
411