xref: /dragonfly/Makefile.inc1 (revision a361ab312536a661d74caf5630c7ae20bcd8e3e4)
1#
2# $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $
3#
4# This file defines the user-driven targets.
5#
6# Standard targets are documented in the makefiles in /usr/share/mk and include:
7#         obj depend all install clean cleandepend cleanobj
8#
9# Build-time options are documented in make.conf(5).
10#
11
12DFLYVERSION!=   awk '/^\#define[[:blank:]]__DragonFly_version/ {print $$3}' \
13                    < ${.CURDIR}/sys/sys/param.h
14
15OSREL!=             echo ${DFLYVERSION} | \
16                    awk '{a=int($$1/100000); b=int(($$1-(a*100000))/100); \
17                    print a "." b}'
18
19# Put initial settings here.
20SUBDIR=
21
22# /libexec/ld-elf.so.2 needs to be installed first
23# Otherwise, install(1) beeing a dynamically linked binary will fail
24# during the first upgrade from a static to a dynamic world
25SUBDIR+= libexec
26
27# We need to do include and lib early.
28#
29SUBDIR+= include
30SUBDIR+= lib
31
32SUBDIR+= bin
33.if !defined(NO_GAMES)
34SUBDIR+= games
35.endif
36SUBDIR+= gnu
37SUBDIR+= sbin
38.if !defined(NO_SHARE)
39SUBDIR+= share
40.endif
41SUBDIR+= stand
42SUBDIR+= sys
43SUBDIR+= usr.bin
44SUBDIR+= usr.sbin
45
46SUBDIR+= etc
47
48# These are last, since it is nice to at least get the base system
49# rebuilt before you do them.
50.if defined(LOCAL_DIRS)
51.for _DIR in ${LOCAL_DIRS}
52.if exists(${.CURDIR}/${_DIR}) & exists(${.CURDIR}/${_DIR}/Makefile)
53SUBDIR+= ${_DIR}
54.endif
55.endfor
56.endif
57
58.if defined(SUBDIR_OVERRIDE)
59SUBDIR=             ${SUBDIR_OVERRIDE}
60.endif
61
62.if defined(NOCLEANDIR)
63CLEANDIR= clean cleandepend
64.else
65CLEANDIR= cleandir
66.endif
67
68.if defined(NO_CLEAN)
69NOCLEAN=  # defined
70.endif
71
72# Base of the checked-out dports repo to use when WITH_DPORTS is enabled.
73# This will be null-mounted and merged with /usr/src/dports.base in the
74# chroot (buildportschroot) via build-all and install-all.
75#
76DPORTSBASE?=        /usr/dports
77
78# Object directory base in primary make.  Note that when we rerun make
79# from inside this file we change MAKEOBJDIRPREFIX to the appropriate
80# subdirectory because the rest of the build system needs it that way.
81# The original object directory base is saved in OBJTREE.
82#
83MAKEOBJDIRPREFIX?=  /usr/obj
84OBJTREE?=           ${MAKEOBJDIRPREFIX}
85
86# Used for stage installs and pathing
87#
88DESTDIRBASE:=                 ${OBJTREE}${.CURDIR}
89
90# Remove DESTDIR from MAKEFLAGS.  It is present in the environment
91# anyhow, and we need to be able to override it for stage installs
92.MAKEFLAGS:=        ${.MAKEFLAGS:NDESTDIR=*}
93
94# This section sets the tools used to build the world/kernel
95WORLD_CCVER?=                 gcc80
96WORLD_LDVER?=                 ld.bfd
97WORLD_BINUTILSVER?= binutils234
98
99.if !defined(NO_BACKUP)
100# Set the backup parameters if they are not already defined
101#
102WORLD_BACKUP?=                /var/backups/world_backup
103AUTO_BACKUP?=                 ${OBJTREE}/world_backup/${DESTDIR}
104.endif
105
106TARGET_ARCH?=       ${MACHINE_ARCH}
107.if ${TARGET_ARCH} == ${MACHINE_ARCH}
108TARGET?=  ${MACHINE}
109.else
110TARGET?=  ${TARGET_ARCH}
111.endif
112.if make(buildworld)
113BUILD_ARCH!=        sysctl -n hw.machine_arch
114
115# temporary until everybody has converted to x86_64
116.if ${BUILD_ARCH} == "amd64"
117BUILD_ARCH=         x86_64
118.endif
119
120.if ${MACHINE_ARCH} != ${BUILD_ARCH}
121.error To cross-build, set TARGET_ARCH.
122.endif
123.endif
124
125# XXX this is ugly and we need to come up with a nicer solution
126.if !defined(TARGET_PLATFORM)
127.if ${TARGET_ARCH} == "x86_64"
128TARGET_PLATFORM= pc64
129.else
130.error Unknown target architecture.
131.endif
132.endif
133
134THREAD_LIB?=        thread_xu
135
136# BTOOLS  (Natively built) All non-cross-development tools that the
137#                   main build needs.  This includes things like 'mkdir' and 'rm'.
138#                   We will not use the native system's exec path once we start
139#                   on WORLD.  (bootstrap-tools and build-tools or BTOOLS)
140#
141# CTOOLS  (Natively built) Cross development tools which are specific
142#                   to the target architecture.
143#
144# WORLD             (Cross built) Our ultimate buildworld, using only BTOOLS and
145#                   CTOOLS.
146#
147# MACHINE_PLATFORM  Platform Architecture we are building on
148# MACHINE           Machine Architecture (usually the same as MACHINE_ARCH)
149# MACHINE_ARCH                CPU Architecture we are building on
150#
151# TARGET_PLATFORM   Platform Architecture we are building for
152# TARGET            Machine Architecture we are building for
153# TARGET_ARCH                 CPU Architecture we are building for
154#
155BTOOLSDEST=         ${DESTDIRBASE}/btools_${MACHINE_ARCH}
156CTOOLSDEST=         ${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH}
157WORLDDEST=          ${DESTDIRBASE}/world_${TARGET_ARCH}
158
159# The bootstrap-tools path is used by the bootstrap-tools, build-tools, and
160# cross-tools stages to augment the existing command path to access newer
161# versions of certain utilities that the cross-tools stage might expect.
162#
163BTOOLSPATH= ${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/sbin:${BTOOLSDEST}/bin
164
165# The cross-tools path containing the cross-tools to cross build the
166# ultimate world.
167#
168CTOOLSPATH= ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/sbin:${CTOOLSDEST}/bin
169
170# The strict temporary command path contains all binaries required
171# by the buildworld system after the cross-tools stage.
172#
173# NOTE: Append '/usr/local/bin:/usr/local/sbin' to support external compilers.
174#       See compilers.conf(5) man page for more info.
175#
176STRICTTMPPATH= ${CTOOLSPATH}:${BTOOLSPATH}:/usr/local/bin:/usr/local/sbin
177
178TMPDIR?=  /tmp
179TMPPID!=  echo $$$$
180
181#
182# Building a world goes through the following stages
183#
184# 1. bootstrap-tool stage [BMAKE]
185#         This stage is responsible for creating programs that
186#         are needed for backward compatibility reasons. They
187#         are not built as cross-tools.
188# 2. build-tool stage [TMAKE]
189#         This stage is responsible for creating the object
190#         tree and building any tools that are needed during
191#         the build process.
192# 3. cross-tool stage [XMAKE]
193#         This stage is responsible for creating any tools that
194#         are needed for cross-builds. A cross-compiler is one
195#         of them.
196# 4. world stage [WMAKE]
197#         This stage actually builds the world.
198# 5. install stage (optional) [IMAKE]
199#         This stage installs a previously built world.
200#
201# In all cases we must carefully adjust the environment so the proper
202# tools and header files are used.
203#
204# NOTE: The M4 environment variable is used by the [f]lex binary to
205#         override the location of the 'm4' binary.  The override is
206#         needed for certain buildworld version transitions, specifically
207#         past a certain point in 3.3 because the older /usr/bin/m4 will
208#         generate output that will blow up the newer [f]lex/yacc/bison
209#         utilities.
210#
211
212# bootstrap-tool stage
213#
214BMAKEENV= MAKEOBJDIRPREFIX=${BTOOLSDEST} \
215                    OBJTREE=${OBJTREE} \
216                    DESTDIR=${BTOOLSDEST} \
217                    LC_ALL=C \
218                    _SHLIBDIRPREFIX=${BTOOLSDEST} \
219                    PATH=${BTOOLSPATH}:${PATH} \
220                    M4=${BTOOLSDEST}/usr/bin/m4 \
221                    INSTALL="sh ${.CURDIR}/tools/install.sh"
222
223BMAKE=              ${BMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
224                    -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
225                    -DNO_WERROR -DNO_NLS -DSYSBUILD
226
227# build-tool stage
228#
229TMAKEENV= MAKEOBJDIRPREFIX=${BTOOLSDEST} \
230                    OBJTREE=${OBJTREE} \
231                    DESTDIR= \
232                    LC_ALL=C \
233                    PATH=${BTOOLSPATH}:${PATH} \
234                    M4=${BTOOLSDEST}/usr/bin/m4 \
235                    INSTALL="sh ${.CURDIR}/tools/install.sh"
236
237TMAKE=              ${TMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
238                    -DNOSHARED -DSYSBUILD
239
240# cross-tool stage
241#
242# note: TOOLS_PREFIX points to the obj root holding the cross
243#         compiler binaries, while USRDATA_PREFIX points to the obj root
244#         holding the target environment (and also determines where cross-built
245#         libraries, crt*.o, and include files are installed).
246#
247XMAKEENV= MAKEOBJDIRPREFIX=${CTOOLSDEST} \
248                    OBJTREE=${OBJTREE} \
249                    DESTDIR=${CTOOLSDEST} \
250                    LC_ALL=C \
251                    _SHLIBDIRPREFIX=${CTOOLSDEST} \
252                    INSTALL="sh ${.CURDIR}/tools/install.sh" \
253                    TOOLS_PREFIX=${CTOOLSDEST} \
254                    USRDATA_PREFIX=${WORLDDEST} \
255                    SELECT_LINKER=${WORLD_LDVER} \
256                    M4=${BTOOLSDEST}/usr/bin/m4 \
257                    PATH=${BTOOLSPATH}:${PATH}
258
259XMAKE=              ${XMAKEENV} make -f Makefile.inc1 -DNO_GDB \
260                    -DBOOTSTRAPPING -DNOMAN -DNOSHARED -DSYSBUILD
261
262# world stage, note the strict path and note that TOOLS_PREFIX is left
263# unset and USRDATA_PREFIX (which defaults to TOOLS_PREFIX) is set to empty,
264# which is primarily for the compiler so it targets / (e.g. /usr/<blah>)
265# for both binary and library paths, even though it is being compiled to
266# WORLDDEST.  None of the programs in the world stage are ever actually
267# executed during the buildworld/installworld.
268#
269CROSSENV= MAKEOBJDIRPREFIX=${WORLDDEST} \
270                    OBJTREE=${OBJTREE} \
271                    MACHINE_ARCH=${TARGET_ARCH} \
272                    MACHINE=${TARGET} \
273                    MACHINE_PLATFORM=${TARGET_PLATFORM} \
274                    LC_ALL=C \
275                    OBJFORMAT_PATH=${CTOOLSDEST} \
276                    HOST_CCVER=${HOST_CCVER} \
277                    CCVER=${WORLD_CCVER} \
278                    LDVER=${WORLD_LDVER} \
279                    BINUTILSVER=${WORLD_BINUTILSVER}
280
281WMAKEENV= ${CROSSENV} \
282                    WORLDBUILD=1 \
283                    DESTDIR=${WORLDDEST} \
284                    _SHLIBDIRPREFIX=${WORLDDEST} \
285                    INSTALL="sh ${.CURDIR}/tools/install.sh" \
286                    M4=${BTOOLSDEST}/usr/bin/m4 \
287                    PATH=${STRICTTMPPATH}
288
289WMAKE=              ${WMAKEENV} make -f Makefile.inc1 -DSYSBUILD
290
291# install stage
292#
293IMAKEENV= ${CROSSENV} \
294                    PATH=${STRICTTMPPATH}
295IMAKE=              ${IMAKEENV} make -f Makefile.inc1 -DSYSBUILD
296
297# kernel stage
298#
299KMAKEENV= ${WMAKEENV}
300
301# buildworld
302#
303# Attempt to rebuild the entire system, with reasonable chance of
304# success, regardless of how old your existing system is.
305#
306_worldtmp: _cleantmp _mtreetmp
307.ORDER: _cleantmp _mtreetmp
308
309_cleantmp:
310.if !defined(NOCLEAN)
311          -chflags -R noschg ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
312          rm -rf ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
313.else
314          # XXX - These two can depend on any header file.
315          rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
316          rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
317.endif
318
319_mtreetmp:
320          @echo
321          @echo "--------------------------------------------------------------"
322          @echo ">>> Rebuilding the temporary build tree"
323          @echo "--------------------------------------------------------------"
324          mkdir -p ${DESTDIRBASE} ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
325.for _dir in ${WORLDDEST} ${BTOOLSDEST} ${CTOOLSDEST}
326          mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist  \
327                    -p ${_dir}/  > /dev/null
328          mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist             \
329                    -p ${_dir}/usr > /dev/null
330.endfor
331          mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist         \
332                    -p ${WORLDDEST}/usr/include > /dev/null
333          ${LN} -sf ${.CURDIR}/sys ${WORLDDEST}
334
335_bwcleanup: umountports
336          mkdir -p ${DESTDIRBASE}
337          chflags -R noschg ${DESTDIRBASE}
338          rm -rxf ${DESTDIRBASE}
339
340_bwinit:
341          @echo "--------------------------------------------------------------"
342          @echo ">>> starting buildworld target"
343          @echo "--------------------------------------------------------------"
344_bootstrap-tools:
345          @echo
346          @echo "--------------------------------------------------------------"
347          @echo ">>> stage 1: bootstrap tools"
348          @echo "--------------------------------------------------------------"
349          cd ${.CURDIR}; ${BMAKE} bootstrap-tools
350_cleanobj:
351          @echo
352          @echo "--------------------------------------------------------------"
353          @echo ">>> stage 2a: cleaning up the object tree"
354          @echo "--------------------------------------------------------------"
355          cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
356_obj:
357          @echo
358          @echo "--------------------------------------------------------------"
359          @echo ">>> stage 2b: rebuilding the object tree"
360          @echo "--------------------------------------------------------------"
361          cd ${.CURDIR}; ${WMAKE} par-obj
362_build-tools:
363          @echo
364          @echo "--------------------------------------------------------------"
365          @echo ">>> stage 2c: build tools"
366          @echo "--------------------------------------------------------------"
367          cd ${.CURDIR}; ${TMAKE} build-tools
368_cross-tools:
369          @echo
370          @echo "--------------------------------------------------------------"
371          @echo ">>> stage 3: cross tools"
372          @echo "--------------------------------------------------------------"
373          cd ${.CURDIR}; ${XMAKE} cross-tools
374_includes:
375          @echo
376          @echo "--------------------------------------------------------------"
377          @echo ">>> stage 4a: populating ${WORLDDEST}/usr/include"
378          @echo "--------------------------------------------------------------"
379          cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
380_libraries:
381          @echo
382          @echo "--------------------------------------------------------------"
383          @echo ">>> stage 4b: building libraries"
384          @echo "--------------------------------------------------------------"
385          cd ${.CURDIR}; ${WMAKE} -DNOHTML -DNOMAN -DNOFSCHG libraries
386_depend:
387          @echo
388          @echo "--------------------------------------------------------------"
389          @echo ">>> stage 4c: make dependencies"
390          @echo "--------------------------------------------------------------"
391          cd ${.CURDIR}; ${WMAKE} par-depend
392everything:
393          @echo
394          @echo "--------------------------------------------------------------"
395          @echo ">>> stage 4d: building everything"
396          @echo "--------------------------------------------------------------"
397          cd ${.CURDIR}; ${WMAKE} all
398_initrd:
399          @echo
400          @echo "--------------------------------------------------------------"
401          @echo ">>> stage 5: building rescue and initrd"
402          @echo "--------------------------------------------------------------"
403.if !defined(NO_INITRD)
404          cd ${.CURDIR}/initrd; ${WMAKEENV} make all
405.endif
406_bwdone:
407          @echo "--------------------------------------------------------------"
408          @echo ">>> buildworld target complete"
409          @echo "--------------------------------------------------------------"
410_qwinit:
411          @echo "--------------------------------------------------------------"
412          @echo ">>> starting quickworld target"
413          @echo "--------------------------------------------------------------"
414_qwdone:
415          @echo "--------------------------------------------------------------"
416          @echo ">>> quickworld target complete"
417          @echo "--------------------------------------------------------------"
418_iwinit:
419          @echo "--------------------------------------------------------------"
420          @echo ">>> starting installworld target"
421          @echo "--------------------------------------------------------------"
422
423# note: buildworld no longer depends on _cleanobj because we rm -rf the
424# entire object tree and built the bootstrap tools in a different location.
425#
426# buildworld        - build everything from scratch
427# quickworld        - skip the bootstrap, build, and cross-build steps
428# realquickworld - skip the bootstrap, build, crossbuild, and depend step.
429#
430# note: we include _obj in realquickworld to prevent accidental creation
431# of files in /usr/src.
432
433WMAKE_TGTS=
434.if !defined(SUBDIR_OVERRIDE)
435WMAKE_TGTS+=        _worldtmp _bootstrap-tools
436.endif
437WMAKE_TGTS+=        _obj _build-tools
438.if !defined(SUBDIR_OVERRIDE)
439WMAKE_TGTS+=        _cross-tools
440.endif
441WMAKE_TGTS+=        _includes _libraries _depend everything _initrd
442
443.if defined(WMAKE_TGTS_OVERRIDE)
444SUBDIR=
445WMAKE_TGTS=         ${WMAKE_TGTS_OVERRIDE}
446.endif
447
448QMAKE_TGTS=         _mtreetmp _obj _includes _libraries _depend everything _initrd
449
450buildworld: _bwinit ${WMAKE_TGTS} _bwdone
451
452quickworld: _qwinit ${QMAKE_TGTS} _qwdone
453
454realquickworld: _qwinit _mtreetmp _obj _includes _libraries everything _qwdone
455
456crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
457
458.ORDER: umountports mountports
459GENLOGDIR=          /usr/obj${.CURDIR}
460
461# Build a chroot environment for buildports
462#
463# The chroot environment is built by doing a fresh make installworld
464# and make distribution, mounting expected filesystems, doing the
465# initial ldconfig setup, and copying resolv.conf to hopefully get
466# a working network.  Without these elements, various parts of dsynth
467# and the pkg system will bail.
468#
469buildportschroot: umountports
470          mkdir -p ${WORLDDEST}/chroot
471          mkdir -p ${WORLDDEST}/chroot/usr/src
472          @echo "building chroot, logfile in: ${GENLOGDIR}/chroot.out"
473          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` installworld DESTDIR=${WORLDDEST}/chroot > ${GENLOGDIR}/chroot.out 2>&1)
474          @(cd ${.CURDIR}/etc; ${MAKE} -j `sysctl -n hw.ncpu` distribution DESTDIR=${WORLDDEST}/chroot >> ${GENLOGDIR}/chroot.out 2>&1)
475          @echo "mounting procfs, devfs, tmpfs in chroot"
476          @(cd ${.CURDIR}; ${MAKE} mountports >> ${GENLOGDIR}/chroot.out 2>&1)
477          chroot ${WORLDDEST}/chroot /bin/csh -c "cd /etc/rc.d; sh ldconfig start"
478          cp /etc/resolv.conf ${WORLDDEST}/chroot/etc/
479          @(cd ${.CURDIR}; ${MAKE} umountports >> ${GENLOGDIR}/chroot.out 2>&1)
480
481# Build dragonfly/base dports using the chroot environment setup by
482# buildportschroot.
483#
484# NOTE: The real system's /usr/distfiles.base is shared with the chroot and
485#         dsynth will fetch source dists as necessary.  If the real system
486#         is not yet fully up-to-date, it might not have its /usr/distfiles.base
487#         yet though so create it if necessary.
488#
489buildports: umountports mountports
490          mkdir -p ${WORLDDEST}/chroot
491          mkdir -p ${WORLDDEST}/chroot/build/synth
492          mkdir -p ${WORLDDEST}/chroot/build/synth/live_packages
493          mkdir -p ${WORLDDEST}/chroot/build/synth/logs
494          mkdir -p ${WORLDDEST}/chroot/build/synth/options
495          mkdir -p ${WORLDDEST}/chroot/build/synth/build
496          mkdir -p /usr/distfiles.base
497          cp ${.CURDIR}/dports.base/dsynth.ini ${WORLDDEST}/chroot/build/synth/
498          cp ${.CURDIR}/dports.base/pkg.conf ${WORLDDEST}/chroot/build/
499          @echo "dsynth logs will be stored in ${WORLDDEST}/chroot/build/synth/logs"
500          @echo "pkg file path: file:///${WORLDDEST}/chroot/build/synth/live_packages/"
501          chroot ${WORLDDEST}/chroot dsynth -SS -y -C /build/synth build dragonfly/base
502          @(cd ${.CURDIR}; ${MAKE} umountports)
503
504# Install base system ports (does not require the chroot but does require
505# the dports stuff that was built in the chroot)
506#
507# NOTE: At the moment, the pkg install command may require interactivity,
508#         do not redirect.  We have to adjust pkg.conf's paths because
509#         we are installing relative to the real root and not the chroot.
510#
511installports: umountports mountports
512          cd ${WORLDDEST} && tar xvzpf ${WORLDDEST}/chroot/build/synth/live_packages/All/pkg-*.pkg > /dev/null 2>&1
513          cat ${.CURDIR}/dports.base/pkg.conf | sed -e 's#/build#${WORLDDEST}/chroot/build#' > ${WORLDDEST}/chroot/build/pkg.conf
514          ${WORLDDEST}/usr/local/sbin/pkg-static --rootdir ${DESTDIR}/ -R ${WORLDDEST}/chroot/build install dragonfly-base
515          @(cd ${.CURDIR}; ${MAKE} umountports)
516
517.ORDER: build-all install-all
518
519mountports:
520          @echo "mounting for ports chroot"
521          mount_devfs dummy ${WORLDDEST}/chroot/dev
522          mount_procfs dummy ${WORLDDEST}/chroot/proc
523          mount_tmpfs dummy ${WORLDDEST}/chroot/tmp
524          mount_tmpfs dummy ${WORLDDEST}/chroot/var/tmp
525          mount_null ${.CURDIR} ${WORLDDEST}/chroot/usr/src
526          mount_null ${DPORTSBASE} ${WORLDDEST}/chroot/usr/src/dports.base
527          mkdir -p ${WORLDDEST}/chroot/usr/src/dports.base/dragonfly
528          mount_null ${.CURDIR}/dports.base/dragonfly ${WORLDDEST}/chroot/usr/src/dports.base/dragonfly
529          mount_null /usr/distfiles.base ${WORLDDEST}/chroot/usr/distfiles.base
530
531# Cleanup the chroot's mounts but otherwise leave it intact
532#
533# Strange make lines avoid junk reporting to stderr
534#
535umountports:
536          @echo "cleanup any old dsynth mounts (if any)"
537          -@chroot ${WORLDDEST}/chroot dsynth -SS -y -C /build/synth cleanup > /dev/null 2>&1 || true
538          @echo "unmount old chroot devfs, procfs, etc (if any)"
539          -@umount -f ${WORLDDEST}/chroot/usr/distfiles.base > /dev/null 2>&1 || true
540          -@umount -f ${WORLDDEST}/chroot/usr/src/dports.base/dragonfly > /dev/null 2>&1 || true
541          -@umount -f ${WORLDDEST}/chroot/usr/src/dports.base > /dev/null 2>&1 || true
542          -@umount -f ${WORLDDEST}/chroot/usr/src > /dev/null 2>&1 || true
543          -@umount -f ${WORLDDEST}/chroot/dev > /dev/null 2>&1 || true
544          -@umount -f ${WORLDDEST}/chroot/proc > /dev/null 2>&1 || true
545          -@umount -f ${WORLDDEST}/chroot/tmp > /dev/null 2>&1 || true
546          -@umount -f ${WORLDDEST}/chroot/var/tmp > /dev/null 2>&1 || true
547
548# build-all
549#
550# build
551build-all: _bwcleanup
552          @echo "Building world, log file in ${GENLOGDIR}/bw.out"
553          @mkdir -p ${GENLOGDIR}
554          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` buildworld > ${GENLOGDIR}/bw.out 2>&1)
555          @sync
556          @echo "Building kernel, log file in ${GENLOGDIR}/bk.out"
557          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` buildkernel > ${GENLOGDIR}/bk.out 2>&1)
558          @echo "build-all main buildworld and buildkernel completed ok"
559          @sync
560.if defined(WITH_DPORTS)
561          @echo "Building dragonfly/base dports, logs in ${GENLOGDIR}/bp.out"
562          @echo "IF YOU INTERRUPT THE MAKE, THEN RUN make umountports"
563          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` buildportschroot > ${GENLOGDIR}/bp.out 2>&1)
564          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` buildports > ${GENLOGDIR}/bp.out 2>&1)
565.endif
566
567install-all:
568          @echo "Installing kernel, log file in ${GENLOGDIR}/bk.out"
569          @mkdir -p ${GENLOGDIR}
570          @(cd ${.CURDIR}; ${MAKE} -j 1 installkernel >> ${GENLOGDIR}/bk.out 2>&1)
571          @sync
572          @echo "Installing world, log file in ${GENLOGDIR}/bw.out"
573          @(cd ${.CURDIR}; ${MAKE} -j 1 installworld >> ${GENLOGDIR}/bw.out 2>&1)
574          @sync
575          @echo "Upgrading world"
576          @(cd ${.CURDIR}; ${MAKE} -j 1 upgrade >> ${GENLOGDIR}/bw.out 2>&1)
577          @sync
578          @echo "install-all main world and kernel completed ok."
579.if defined(WITH_DPORTS)
580          @echo "Installing dragonfly/base dports, log file in ${GENLOGDIR}/bp.out"
581          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` installports)
582          @(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` umountports >> ${GENLOGDIR}/bp.out 2>&1)
583.endif
584          @echo "reboot recommended and after that, "
585          @echo "when doing a major upgrade, 'pkg upgrade -f' after rebooting"
586
587.ORDER: _bwinit ${WMAKE_TGTS} _bwdone
588.ORDER: _obj _includes
589.ORDER: _qwinit _mtreetmp _obj
590.ORDER: _bwcleanup _bwinit
591.ORDER: installcheck backupworld-auto
592.ORDER: everything _qwdone
593
594
595# installcheck
596#
597# Checks to be sure system is ready for installworld
598#
599installcheck: _iwinit
600.if !defined(OVERRIDE_CHECKS)
601.if !defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/"
602          @case `uname -r` in \
603              1.2*|1.3-*|1.3.*|1.4.*|1.5.0-*|1.5.1-*|1.5.2-*|1.5.3-*) \
604                    echo "You must upgrade your kernel to at least 1.5.4" \
605                         "and reboot before you can safely installworld," \
606                         "due to libc/system call ABI changes."; \
607                    /usr/bin/false; \
608          esac
609          @case `uname -r` in \
610              1.*|2.*|3.0*|3.1*|3.2*|3.3*|3.4*|3.5*|3.6*) \
611                    echo "The system is too old for a normal installworld," \
612                         "you need to use 'installworld-force'."; \
613                    /usr/bin/false; \
614          esac
615.endif
616.endif
617
618# installworld
619#
620# Backs up the current world if ${AUTO_BACKUP} is writable.
621# Installs everything compiled by a 'buildworld'.
622#
623installworld: installcheck
624.if !defined(NO_BACKUP)
625          -@mkdir -p ${AUTO_BACKUP} > /dev/null 2>&1
626          @cd ${.CURDIR}; \
627              (touch ${AUTO_BACKUP}/.updating > /dev/null 2>&1 && \
628               ${IMAKE} backupworld-auto) || \
629              echo "Cannot write to ${AUTO_BACKUP} - world not backed up"
630.endif
631          cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
632          ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc \
633              ${DESTDIR}/etc/upgrade/
634          cd ${.CURDIR}; ${IMAKE} -DWORLDINSTALL os-release
635.if !defined(NO_INITRD)
636          cd ${.CURDIR}; ${IMAKE} -DWORLDINSTALL initrd
637.endif
638          sync
639          @echo "--------------------------------------------------------------"
640          @echo ">>> installworld target complete"
641          @echo "--------------------------------------------------------------"
642
643os-release:
644          @echo "NAME=DragonFly" > ${DESTDIR}/etc/os-release
645          @echo "VERSION=${OSREL}-SYNTH" >> ${DESTDIR}/etc/os-release
646          @echo "VERSION_ID=${OSREL}" >> ${DESTDIR}/etc/os-release
647          @echo "ID=dragonfly" >> ${DESTDIR}/etc/os-release
648          @echo "ANSI_COLOR=\"0;32\"" >> ${DESTDIR}/etc/os-release
649          @echo "PRETTY_NAME=\"DragonFlyBSD ${OSREL}-SYNTH\"" >> ${DESTDIR}/etc/os-release
650          @echo "CPE_NAME=\"cpe:/o:dragonflybsd:dragonfly:${OSREL}\"" >> ${DESTDIR}/etc/os-release
651          @echo "SUPPORT_URL=\"http://chat.efnet.org:9090/?nick=dflynick&channels=%23dragonflybsd&Login=Login\"" >> ${DESTDIR}/etc/os-release
652          @echo "HOME_URL=\"https://www.dragonflybsd.org/\"" >> ${DESTDIR}/etc/os-release
653          @echo "BUG_REPORT_URL=\"https://bugs.dragonflybsd.org/\"" >> ${DESTDIR}/etc/os-release
654          @echo "MACHINE_ARCH=${MACHINE_ARCH}" >> ${DESTDIR}/etc/os-release
655          @echo "MACHINE=${MACHINE}" >> ${DESTDIR}/etc/os-release
656          @echo "DFLYVERSION=${DFLYVERSION}" >> ${DESTDIR}/etc/os-release
657
658installworld-force:
659          @echo "Doing a forced installworld.  This will install to a temporary directory,"
660          @echo "then copy the main binaries and libraries with a static cpdup to ${DESTDIR}/"
661          @echo "and finally will issue a normal installworld."
662          @echo
663          @echo "Starting in 5 seconds.  ^C to abort."
664          @echo
665          sleep 1
666          rm -rf /usr/obj/temp > /dev/null 2>&1 || chflags -R noschg /usr/obj/temp
667          rm -rf /usr/obj/temp
668          mkdir -p /usr/obj/temp/cpdup/bin
669          (cd ${.CURDIR}/bin/cpdup; \
670                    make clean && \
671                    make obj && \
672                    make clean && \
673                    make CFLAGS=-static all install DESTDIR=/usr/obj/temp/cpdup NOMAN=TRUE)
674          @echo "XXXXXXXXX Installing to temporary XXXXXXXXX"
675          @sleep 1
676          (cd ${.CURDIR}; ${MAKE} installworld DESTDIR=/usr/obj/temp > /dev/null 2>&1)
677          @echo "XXXXXXXXX Blasting binaries and libraries XXXXXXXXX"
678          @sleep 1
679          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/bin /bin
680          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/sbin /sbin
681          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/lib /lib
682          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/bin /usr/bin
683          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/sbin /usr/sbin
684          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/lib /usr/lib
685          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/libexec /libexec
686          /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/libexec /usr/libexec
687          @echo "XXXXXXXXX Doing final installworld XXXXXXXX"
688          sleep 5
689          (cd ${.CURDIR}; ${MAKE} installworld OVERRIDE_CHECKS=TRUE)
690          (cd ${.CURDIR}; ${MAKE} upgrade OVERRIDE_CHECKS=TRUE)
691.if !defined(NO_INITRD)
692          (cd ${.CURDIR}; ${MAKE} initrd)
693.endif
694
695# reinstall
696#
697# If you have a build server, you can NFS mount the source and obj directories
698# and do a 'make reinstall' on the *client* to install new binaries from the
699# most recent server build.
700#
701reinstall:
702          @echo "--------------------------------------------------------------"
703          @echo ">>> Making hierarchy"
704          @echo "--------------------------------------------------------------"
705          cd ${.CURDIR}; make -f Makefile.inc1 hierarchy
706          @echo
707          @echo "--------------------------------------------------------------"
708          @echo ">>> Installing everything"
709          @echo "--------------------------------------------------------------"
710          cd ${.CURDIR}; make -f Makefile.inc1 install
711
712# initrd
713#
714# Install the rescue tools and the initrd image built by 'buildworld'.
715#
716initrd: .PHONY
717          (cd ${.CURDIR}/initrd; ${IMAKEENV} make install)
718
719
720# buildkernel, nativekernel, quickkernel, realquickkernel, and installkernel
721#
722# Which kernels to build and/or install is specified by setting
723# KERNCONF. If not defined an X86_64_GENERIC kernel is built/installed.
724# Only the existing (depending TARGET) config files are used
725# for building kernels and only the first of these is designated
726# as the one being installed.
727#
728# You can specify INSTALLSTRIPPED=1 if you wish the installed
729# kernel and modules to be stripped of its debug info (required
730# symbols are left intact).  You can specify INSTALLSTRIPPEDMODULES
731# if you only want to strip the modules of their debug info.  These
732# only apply if you have DEBUG=-g in your kernel config or make line.
733#
734# Note that we have to use TARGET instead of TARGET_ARCH when
735# we're in kernel-land. Since only TARGET_ARCH is (expected) to
736# be set to cross-build, we have to make sure TARGET is set
737# properly.
738
739.if !defined(KERNCONF) && defined(KERNEL)
740KERNCONF= ${KERNEL}
741KERNWARN= yes
742.else
743# XXX makeshift fix to build the right kernel for the (target) architecture
744# We should configure this in the platform files somehow
745.if ${TARGET_ARCH} == "x86_64"
746KERNCONF?=          X86_64_GENERIC
747.endif
748.endif
749INSTKERNNAME?=      kernel
750
751KRNLSRCDIR=         ${.CURDIR}/sys
752KRNLCONFDIR=        ${KRNLSRCDIR}/config
753KRNLOBJDIR=         ${OBJTREE}${KRNLSRCDIR}
754KERNCONFDIR?=       ${KRNLCONFDIR}
755
756BUILDKERNELS=
757INSTALLKERNEL=
758.for _kernel in ${KERNCONF}
759.if exists(${KERNCONFDIR}/${_kernel})
760BUILDKERNELS+=      ${_kernel}
761.if empty(INSTALLKERNEL)
762INSTALLKERNEL= ${_kernel}
763.endif
764.endif
765.endfor
766
767# kernel version numbers survive rm -rf
768#
769.for _kernel in ${BUILDKERNELS}
770.if exists(${KRNLOBJDIR}/${_kernel}/version)
771KERNEL_VERSION_${_kernel} != cat ${KRNLOBJDIR}/${_kernel}/version
772.endif
773.endfor
774
775# buildkernel
776#
777# Builds all kernels defined by BUILDKERNELS.
778#
779bk_tools:
780          @if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
781              echo "You must buildworld before buildkernel.  If you wish"; \
782              echo "to build a kernel using native tools, config it manually"; \
783              echo "or use the nativekernel target if you are in a rush"; \
784              /usr/bin/false; \
785          fi
786
787maybe_bk_tools:
788.for _kernel in ${BUILDKERNELS}
789          @if [ ! -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
790              if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
791                    echo "The kernel was built using buildworld tools which no" ; \
792                    echo "longer appear to exist, (real)quickkernel failed!" ; \
793                    /usr/bin/false; \
794              fi; \
795          fi
796.endfor
797
798bk_build_list:
799.if empty(BUILDKERNELS)
800          @echo ">>> ERROR: Missing kernel configuration file(s)."
801          @echo ">>> ${KERNCONF} not found in ${KERNCONFDIR}."
802          @false
803.endif
804
805bk_kernwarn:
806.if defined(KERNWARN)
807          @echo "--------------------------------------------------------------"
808          @echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
809          @echo "--------------------------------------------------------------"
810          @sleep 3
811.endif
812          @echo
813
814# The buildkernel target rebuilds the specified kernels from scratch
815# using the crossbuild tools generated by the last buildworld.  It is
816# the safest (but also the most time consuming) way to build a new kernel.
817#
818buildkernel:        bk_tools bk_build_list bk_kernwarn
819.for _kernel in ${BUILDKERNELS}
820          @echo "--------------------------------------------------------------"
821          @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
822          @echo "--------------------------------------------------------------"
823          @echo "===> ${_kernel}"
824.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
825          rm -rf ${KRNLOBJDIR}/${_kernel}
826.else
827          @if [ -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
828                    echo "YOU ARE REBUILDING WITH BUILDKERNEL, REMOVING OLD NATIVEKERNEL BUILD"; \
829                    rm -rf ${KRNLOBJDIR}/${_kernel}; fi
830.endif
831          mkdir -p ${KRNLOBJDIR}
832.if !defined(NO_KERNELCONFIG)
833          cd ${KRNLCONFDIR}; \
834                    PATH=${STRICTTMPPATH} \
835                        config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
836                              ${KERNCONFDIR}/${_kernel}
837.endif
838.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
839          echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
840.endif
841          touch ${KRNLOBJDIR}/${_kernel}/.buildkernel_run
842.if !defined(NO_KERNELDEPEND)
843          cd ${KRNLOBJDIR}/${_kernel}; \
844              ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
845.endif
846          cd ${KRNLOBJDIR}/${_kernel}; \
847              ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
848          @echo "--------------------------------------------------------------"
849          @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
850          @echo "--------------------------------------------------------------"
851.endfor
852
853# The nativekernel target rebuilds the specified kernels from scratch
854# using the system's standard compiler rather than using the crossbuild
855# tools generated by the last buildworld.  This is fairly safe if your
856# system is reasonable up-to-date.
857#
858nativekernel:       bk_build_list bk_kernwarn
859.for _kernel in ${BUILDKERNELS}
860          @echo "--------------------------------------------------------------"
861          @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
862          @echo "--------------------------------------------------------------"
863          @echo "===> ${_kernel}"
864.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
865          rm -rf ${KRNLOBJDIR}/${_kernel}
866.else
867          @if [ -f ${KRNLOBJDIR}/${_kernel}/.buildkernel_run ]; then \
868                    echo "YOU ARE REBUILDING WITH NATIVEKERNEL, REMOVING OLD BUILDKERNEL BUILD"; \
869                    rm -rf ${KRNLOBJDIR}/${_kernel}; fi
870.endif
871          mkdir -p ${KRNLOBJDIR}
872.if !defined(NO_KERNELCONFIG)
873          cd ${KRNLCONFDIR}; \
874                        config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
875                              ${KERNCONFDIR}/${_kernel}
876.endif
877.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
878          echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
879.endif
880          touch ${KRNLOBJDIR}/${_kernel}/.nativekernel_run
881.if !defined(NO_KERNELDEPEND)
882          cd ${KRNLOBJDIR}/${_kernel}; \
883              make KERNEL=${INSTKERNNAME} depend
884.endif
885          cd ${KRNLOBJDIR}/${_kernel}; \
886              make KERNEL=${INSTKERNNAME} all
887          @echo "--------------------------------------------------------------"
888          @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
889          @echo "--------------------------------------------------------------"
890.endfor
891
892# The (real)quickkernel target rebuilds the specified kernels as quickly
893# as possible.  It will use the native tools or the buildworld cross tools
894# based on whether the kernel was originally generated via buildkernel or
895# nativekernel.  Config is rerun but the object hierarchy is not rebuilt.
896# realquickkernel skips the depend step (analogous to realquickworld).
897#
898quickkernel realquickkernel:  maybe_bk_tools bk_build_list bk_kernwarn
899.for _kernel in ${BUILDKERNELS}
900          @echo "--------------------------------------------------------------"
901          @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
902          @echo "--------------------------------------------------------------"
903          @echo "===> ${_kernel}"
904.if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run)
905.if !defined(NO_KERNELCONFIG)
906          cd ${KRNLCONFDIR}; \
907                    PATH=${STRICTTMPPATH} \
908                        config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
909                              ${KERNCONFDIR}/${_kernel}
910.endif
911.if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
912          cd ${KRNLOBJDIR}/${_kernel}; \
913              ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
914.endif
915          cd ${KRNLOBJDIR}/${_kernel}; \
916              ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
917.else
918.if !defined(NO_KERNELCONFIG)
919          cd ${KRNLCONFDIR}; \
920              config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
921                    ${KERNCONFDIR}/${_kernel}
922.endif
923.if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
924          cd ${KRNLOBJDIR}/${_kernel}; \
925              make KERNEL=${INSTKERNNAME} depend
926.endif
927          cd ${KRNLOBJDIR}/${_kernel}; \
928              make KERNEL=${INSTKERNNAME} all
929.endif
930          @echo "--------------------------------------------------------------"
931          @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
932          @echo "--------------------------------------------------------------"
933.endfor
934
935
936# installkernel
937#
938# Install the kernel defined by INSTALLKERNEL
939#
940installkernel reinstallkernel:
941          @echo "--------------------------------------------------------------"
942          @echo ">>> Kernel install for ${INSTALLKERNEL} started on `LC_ALL=C date`"
943          @echo "--------------------------------------------------------------"
944.if exists(${KRNLOBJDIR}/${INSTALLKERNEL}/.buildkernel_run)
945          cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
946              ${IMAKEENV} make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
947.else
948          cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
949              make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
950.endif
951          @echo "--------------------------------------------------------------"
952          @echo ">>> Kernel install for ${INSTALLKERNEL} completed on `LC_ALL=C date`"
953          @echo "--------------------------------------------------------------"
954
955
956# ------------------------------------------------------------------------
957#
958# From here onwards are utility targets used by the 'make world' and
959# related targets.  If your 'world' breaks, you may like to try to fix
960# the problem and manually run the following targets to attempt to
961# complete the build.  Beware, this is *not* guaranteed to work, you
962# need to have a pretty good grip on the current state of the system
963# to attempt to manually finish it.  If in doubt, 'make world' again.
964#
965
966# bootstrap-tools: Build all tools required to build all tools.  Note that
967# order is important in a number of cases and also note that the bootstrap
968# and build tools stages have access to earlier binaries they themselves
969# had generated.
970#
971# [x]install:       dependencies on various new install features
972# rpcgen: old rpcgen used a hardwired cpp path, newer OBJFORMAT_PATH
973#                   envs are not compatible with older objformat binaries.
974#
975
976# BSTRAPDIRS1 - must be built in strict order, no parallelism
977#
978# order is very important. yacc before m4 before flex.  flex exec's m4,
979# m4's parser file needs the latest byacc (insanity!).
980#
981BSTRAPDIRS1= \
982          bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo \
983          bin/test bin/cat bin/ln bin/mv bin/expr bin/sh \
984          bin/hostname bin/kill \
985          usr.bin/yacc usr.bin/m4 usr.bin/localedef \
986          usr.bin/uudecode usr.bin/xinstall \
987          usr.bin/rpcgen usr.bin/bmake usr.bin/awk usr.bin/stat \
988          usr.bin/find usr.bin/flex
989
990# BSTRAPDIRS2 - may built in parallel
991#
992BSTRAPDIRS2= \
993          usr.bin/sed usr.bin/uname usr.bin/touch \
994          usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
995          usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
996          usr.bin/gencat usr.bin/chflags \
997          usr.bin/uuencode usr.bin/cap_mkdb usr.bin/true usr.bin/false \
998          usr.bin/cmp usr.bin/xargs usr.bin/env usr.bin/dirname \
999          usr.bin/tail usr.bin/unifdef \
1000          usr.sbin/chown usr.sbin/mtree usr.sbin/config \
1001          usr.sbin/tzsetup usr.sbin/zic usr.sbin/pwd_mkdb \
1002          gnu/usr.bin/grep usr.bin/sort usr.bin/gzip \
1003          usr.bin/mkcsmapper usr.bin/mkesdb usr.bin/crunch
1004
1005bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
1006          touch ${BTOOLSDEST}/.bootstrap_done
1007
1008bootstrap-tools-before:
1009          ${LN} -fs /bin/date ${BTOOLSDEST}/bin/date
1010
1011bootstrap-tools-targets1: ${BSTRAPDIRS1:S/^/bstrap-/}
1012
1013bootstrap-tools-targets2: ${BSTRAPDIRS2:S/^/bstrap-/}
1014
1015.ORDER: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
1016
1017.ORDER: ${BSTRAPDIRS1:S/^/bstrap-/}
1018
1019.for _tool in ${BSTRAPDIRS1} ${BSTRAPDIRS2}
1020bstrap-${_tool}!
1021          ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
1022                    cd ${.CURDIR}/${_tool}; \
1023                    make DIRPRFX=${_tool}/ obj && \
1024                    make DIRPRFX=${_tool}/ depend && \
1025                    make DIRPRFX=${_tool}/ all && \
1026                    make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
1027.endfor
1028
1029# build-tools: Build special purpose build tools.
1030#
1031# XXX we may be able to remove or consolidate this into bootstrap-tools
1032# now that we have the native helper (.nx/.no) infrastructure.
1033#
1034# XXX we should separate this into new Makefile.inc2.
1035# Just to prepare for reduction of ORDER: that slows down parallel crossworld.
1036
1037# Make sure Makefile.inc1 logic is intact.
1038.if !defined(WORLD_ALTCOMPILER)
1039.warning undefined WORLD_ALTCOMPILER
1040.endif
1041
1042# gcc80 is now the default compiler.  See sys.mk for WORLD_ALTCOMPILER default
1043# and this file for WORLD_CCVER.
1044#
1045_gcc47_cross= gnu/usr.bin/cc47
1046_gcc80_cross= gnu/usr.bin/cc80
1047_gcc_common_cross= lib/libz gnu/usr.bin/gmp gnu/usr.bin/mpfr gnu/usr.bin/mpc
1048
1049.if !defined(NO_ALTCOMPILER)
1050. if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1051_altcompiler_cross+= ${_gcc47_cross}
1052. endif
1053.endif
1054
1055_basecompiler_cross= ${_gcc80_cross}
1056
1057_custom_cross= libexec/customcc
1058_binutils= gnu/usr.bin/${WORLD_BINUTILSVER}
1059
1060build-tools: build-tools-targets
1061          touch ${BTOOLSDEST}/.build_done
1062
1063build-tools-targets: ${BTOOLSDIRS:S/^/btools-/}
1064
1065#
1066# cross-tools: Build cross-building tools
1067#
1068
1069CTOOLSDIRS= usr.bin/objformat
1070
1071CTOOLSDIRS+=        ${_binutils} \
1072                    ${_gcc_common_cross} \
1073                    ${_altcompiler_cross} \
1074                    ${_basecompiler_cross} ${_custom_cross}
1075
1076cross-tools: cross-tools-targets
1077          touch ${CTOOLSDEST}/.cross_done
1078
1079cross-tools-targets: ${CTOOLSDIRS:S/^/ctools-/}
1080
1081.for _tool in ${CTOOLSDIRS}
1082ctools-${_tool}!
1083          ${ECHODIR} "===> ${_tool} (cross-tools)"; \
1084                    cd ${.CURDIR}/${_tool}; \
1085                    make DIRPRFX=${_tool}/ obj && \
1086                    make DIRPRFX=${_tool}/ depend && \
1087                    make DIRPRFX=${_tool}/ all && \
1088                    make DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
1089.endfor
1090
1091#
1092# hierarchy - ensure that all the needed directories are present
1093#
1094hierarchy:
1095          cd ${.CURDIR}/etc;            make distrib-dirs
1096
1097#
1098# libraries - build all libraries, and install them under ${DESTDIR}.
1099#
1100# The list of libraries with dependents (${_prebuild_libs}) and their
1101# interdependencies (__L) are built automatically by the
1102# ${.CURDIR}/tools/make_libdeps.sh script.
1103#
1104# .makeenv does not work when bootstrapping from 4.x, so we must be sure
1105# to specify the correct CCVER or 'cc' will not exec the correct compiler.
1106#
1107libraries:
1108          cd ${.CURDIR}; \
1109              HOST_CCVER=${HOST_CCVER} CCVER=gcc80 \
1110                    make -f Makefile.inc1 _startup_libs80 -DSYSBUILD -DLIBGCC_ONLY;
1111.if !defined(NO_ALTCOMPILER)
1112. if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1113          cd ${.CURDIR}; \
1114              HOST_CCVER=${HOST_CCVER} CCVER=gcc47 \
1115                    make -f Makefile.inc1 _startup_libs47 -DSYSBUILD -DLIBGCC_ONLY;
1116. endif
1117.endif
1118          cd ${.CURDIR}; \
1119              make -f Makefile.inc1 _startup_libs -DSYSBUILD && \
1120              make -f Makefile.inc1 _prebuild_libs -DSYSBUILD && \
1121              make -f Makefile.inc1 _generic_libs -DSYSBUILD && \
1122              touch ${WORLDDEST}/.libraries_done
1123
1124# These dependencies are not automatically generated:
1125#
1126# gnu/lib/${CCVER}/libgcc and gnu/lib/${CCVER}/csu must be built before all
1127# shared libraries for ELF.  The target for _startup_libsXX is
1128# specifically built using gccXX.
1129#
1130_startup_libs47=    gnu/usr.bin/cc47/cc_prep \
1131                              gnu/usr.bin/cc47/cc_tools \
1132                              gnu/lib/gcc47/csu \
1133                              gnu/lib/gcc47/libgcc \
1134                              gnu/lib/gcc47/libgcc_eh \
1135                              gnu/lib/gcc47/libgcc_pic
1136
1137_startup_libs80=    gnu/usr.bin/cc80/cc_prep \
1138                              gnu/usr.bin/cc80/cc_tools \
1139                              gnu/lib/gcc80/csu \
1140                              gnu/lib/gcc80/libgcc \
1141                              gnu/lib/gcc80/libgcc_eh \
1142                              gnu/lib/gcc80/libgcc_pic
1143
1144.if !defined(NO_ALTCOMPILER)
1145. if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1146_startup_libs_alt+= _startup_libs47
1147. endif
1148.endif
1149
1150_startup_libs_base= _startup_libs80
1151
1152_startup_libs=                lib/csu lib/libc lib/libc_rtld
1153lib/libc__L: lib/csu__L
1154
1155_prebuild_libs=               lib/libbz2 lib/liblzma lib/libz lib/libzstd
1156_prebuild_libs+=    lib/libutil
1157
1158_prebuild_libs+=    lib/libpcap
1159
1160_generic_libs=      gnu/lib
1161
1162_prebuild_libs+= lib/libcrypt lib/libncurses/libncurses
1163
1164_generic_libs+=     lib
1165
1166_prebuild_libs+=    lib/librecrypto lib/libressl
1167lib/libressl__L: lib/librecrypto__L
1168
1169_prebuild_libs+=       lib/libldns
1170lib/libldns__L: lib/librecrypto__L
1171
1172_prebuild_libs+= lib/libsbuf lib/libm \
1173                    lib/libpam/libpam lib/libypclnt lib/lib${THREAD_LIB} \
1174                    lib/libpthread lib/libprop
1175
1176_generic_libs+=     usr.bin/flex/lib
1177
1178.for _alib in ${_startup_libs_alt} ${_startup_libs_base}
1179__startup_alibs+= ${${_alib}}
1180.endfor
1181
1182.for _lib in ${__startup_alibs} \
1183                    ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
1184${_lib}__L: .PHONY
1185.if exists(${.CURDIR}/${_lib})
1186          @${ECHODIR} "===> ${_lib}"; \
1187                    cd ${.CURDIR}/${_lib}; \
1188                    echo "STEP DEP ${_lib}" && \
1189                    make DIRPRFX=${_lib}/ depend && \
1190                    echo "STEP ALL ${_lib}" && \
1191                    make DIRPRFX=${_lib}/ all && \
1192                    echo "STEP INSTALL ${_lib}" && \
1193                    make DIRPRFX=${_lib}/ install && \
1194                    echo "STEP DONE ${_lib}";
1195.else
1196.warning missing ${.CURDIR}/${_lib} directory.
1197.endif
1198.endfor
1199
1200_startup_libs: ${_startup_libs:S/$/__L/}
1201.for _alib in ${_startup_libs_alt} ${_startup_libs_base}
1202${_alib}: ${${_alib}:C/$/__L/}
1203.endfor
1204_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1205_generic_libs: ${_generic_libs:S/$/__L/}
1206
1207# library targets must be ordered because there are inter-library
1208# races (e.g. generation of tconfig.h)
1209#
1210.for _alib in ${_startup_libs_base} ${_startup_libs_alt}
1211.ORDER: ${${_alib}:C/$/__L/}
1212.endfor
1213
1214# uncomment if there are missing dependencies
1215.if 0
1216.ORDER: ${_prebuild_libs:S/$/__L/}
1217# we can disable this one, no lib/* depend on libstdc++
1218.ORDER: ${_generic_libs:S/$/__L/}
1219.endif
1220
1221.for __target in clean cleandepend cleandir obj depend includes
1222.for entry in ${SUBDIR}
1223${entry}.${__target}__D: .PHONY
1224          @if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1225                    ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
1226                    edir=${entry}.${MACHINE_ARCH}; \
1227                    cd ${.CURDIR}/$${edir}; \
1228          else \
1229                    ${ECHODIR} "===> ${DIRPRFX}${entry}"; \
1230                    edir=${entry}; \
1231                    cd ${.CURDIR}/$${edir}; \
1232          fi; \
1233          make ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1234.endfor
1235par-${__target}: ${SUBDIR:C/$/.${__target}__D/}
1236.ORDER: ${SUBDIR:C/$/.${__target}__D/}
1237.endfor
1238.ORDER: par-clean par-cleandepend par-cleandir par-obj par-depend par-includes
1239
1240# The wmake target is used by /usr/bin/wmake to run make in a
1241# world build environment.
1242#
1243wmake:
1244          @echo '${WMAKEENV} make ${WMAKE_ARGS} -DSYSBUILD'
1245
1246wmakeenv:
1247          @echo '${WMAKEENV} /bin/sh'
1248
1249bmake:
1250          @echo '${BMAKEENV} make ${BMAKE_ARGS} -DSYSBUILD'
1251
1252bmakeenv:
1253          @echo '${BMAKEENV} /bin/sh'
1254
1255tmake:
1256          @echo '${TMAKEENV} make ${TMAKE_ARGS} -DSYSBUILD'
1257
1258tmakeenv:
1259          @echo '${TMAKEENV} /bin/sh'
1260
1261xmake:
1262          @echo '${XMAKEENV} make ${XMAKE_ARGS} -DSYSBUILD'
1263
1264xmakeenv:
1265          @echo '${XMAKEENV} /bin/sh'
1266
1267.if !defined(NO_BACKUP)
1268backupworld: backup-clean
1269          @mkdir -p ${WORLD_BACKUP}
1270.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1271     exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1272     exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1273          tar -czf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1274                    --options gzip:compression-level=1 \
1275                    sbin bin usr/sbin usr/bin usr/lib usr/libexec
1276.endif
1277
1278backupworld-auto:
1279          rm -f ${AUTO_BACKUP}/binaries.tar.gz
1280          @mkdir -p ${AUTO_BACKUP}
1281.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1282     exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1283     exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1284          /usr/bin/tar -czf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1285                    --options gzip:compression-level=1 \
1286                    sbin bin usr/sbin usr/bin usr/lib usr/libexec
1287.endif
1288
1289backup-auto-clean:
1290          rm -f ${AUTO_BACKUP}/binaries.tar.gz
1291
1292backup-clean:
1293          rm -f ${WORLD_BACKUP}/binaries.tar.gz
1294
1295restoreworld:
1296.if !exists(${WORLD_BACKUP}/binaries.tar.gz)
1297          @echo "There does not seem to be a valid archive present."
1298.else
1299          @echo "Restoring system binaries from manual backup archive..."
1300          @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1301                    ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1302                    ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1303          tar -xzf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1304.endif
1305
1306restoreworld-auto:
1307.if !exists(${AUTO_BACKUP}/binaries.tar.gz)
1308          @echo "There does not seem to be a valid archive present."
1309.else
1310          @echo "Restoring system binaries from auto-backup archive..."
1311          @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1312                    ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1313                    ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1314          tar -xzf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1315.endif
1316.endif
1317
1318# Take advantage of bmake error response
1319#
1320MAKE_PRINT_VAR_ON_ERROR= \
1321          .CURDIR \
1322          .OBJDIR \
1323          .TARGETS \
1324          .ERROR_TARGET \
1325          .MAKE.LEVEL \
1326          .MAKE.MODE \
1327          PATH \
1328          LD_LIBRARY_PATH \
1329          MACHINE_ARCH \
1330          MACHINE \
1331          MAKEFILE \
1332          MAKESYSPATH \
1333          MAKEOBJDIRPREFIX \
1334          WORLD_ALTCOMPILER \
1335          DESTDIR \
1336          SHELL .SHELL
1337.if ${.MAKE.LEVEL} > 0
1338MAKE_PRINT_VAR_ON_ERROR+= .MAKE.MAKEFILES .PATH
1339.endif
1340
1341.include <bsd.subdir.mk>
1342