Makefile 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. #
  2. # $FreeBSD$
  3. #
  4. # The user-driven targets are:
  5. #
  6. # universe - *Really* build *everything* (buildworld and
  7. # all kernels on all architectures). Define
  8. # MAKE_JUST_KERNELS or WITHOUT_WORLDS to only build kernels,
  9. # MAKE_JUST_WORLDS or WITHOUT_KERNELS to only build userland.
  10. # tinderbox - Same as universe, but presents a list of failed build
  11. # targets and exits with an error if there were any.
  12. # worlds - Same as universe, except just makes the worlds.
  13. # kernels - Same as universe, except just makes the kernels.
  14. # buildworld - Rebuild *everything*, including glue to help do
  15. # upgrades.
  16. # installworld - Install everything built by "buildworld".
  17. # world - buildworld + installworld, no kernel.
  18. # buildkernel - Rebuild the kernel and the kernel-modules.
  19. # installkernel - Install the kernel and the kernel-modules.
  20. # installkernel.debug
  21. # reinstallkernel - Reinstall the kernel and the kernel-modules.
  22. # reinstallkernel.debug
  23. # kernel - buildkernel + installkernel.
  24. # kernel-toolchain - Builds the subset of world necessary to build a kernel
  25. # kernel-toolchains - Build kernel-toolchain for all universe targets.
  26. # doxygen - Build API documentation of the kernel, needs doxygen.
  27. # update - Convenient way to update your source tree(s).
  28. # checkworld - Run test suite on installed world.
  29. # check-old - List obsolete directories/files/libraries.
  30. # check-old-dirs - List obsolete directories.
  31. # check-old-files - List obsolete files.
  32. # check-old-libs - List obsolete libraries.
  33. # delete-old - Delete obsolete directories/files.
  34. # delete-old-dirs - Delete obsolete directories.
  35. # delete-old-files - Delete obsolete files.
  36. # delete-old-libs - Delete obsolete libraries.
  37. # targets - Print a list of supported TARGET/TARGET_ARCH pairs
  38. # for world and kernel targets.
  39. # toolchains - Build a toolchain for all world and kernel targets.
  40. # makeman - Regenerate src.conf(5)
  41. # sysent - (Re)build syscall entries from syscalls.master.
  42. # xdev - xdev-build + xdev-install for the architecture
  43. # specified with TARGET and TARGET_ARCH.
  44. # xdev-build - Build cross-development tools.
  45. # xdev-install - Install cross-development tools.
  46. # xdev-links - Create traditional links in /usr/bin for cc, etc
  47. # native-xtools - Create host binaries that produce target objects
  48. # for use in qemu user-mode jails. TARGET and
  49. # TARGET_ARCH should be defined.
  50. # native-xtools-install
  51. # - Install the files to the given DESTDIR/NXTP where
  52. # NXTP defaults to /nxb-bin.
  53. #
  54. # This makefile is simple by design. The FreeBSD make automatically reads
  55. # the /usr/share/mk/sys.mk unless the -m argument is specified on the
  56. # command line. By keeping this makefile simple, it doesn't matter too
  57. # much how different the installed mk files are from those in the source
  58. # tree. This makefile executes a child make process, forcing it to use
  59. # the mk files from the source tree which are supposed to DTRT.
  60. #
  61. # Most of the user-driven targets (as listed above) are implemented in
  62. # Makefile.inc1. The exceptions are universe, tinderbox and targets.
  63. #
  64. # If you want to build your system from source, be sure that /usr/obj has
  65. # at least 6 GB of disk space available. A complete 'universe' build of
  66. # r340283 (2018-11) required 167 GB of space. ZFS lz4 compression
  67. # achieved a 2.18x ratio, reducing actual space to 81 GB.
  68. #
  69. # For individuals wanting to build from the sources currently on their
  70. # system, the simple instructions are:
  71. #
  72. # 1. `cd /usr/src' (or to the directory containing your source tree).
  73. # 2. Define `HISTORICAL_MAKE_WORLD' variable (see README).
  74. # 3. `make world'
  75. #
  76. # For individuals wanting to upgrade their sources (even if only a
  77. # delta of a few days):
  78. #
  79. # 1. `cd /usr/src' (or to the directory containing your source tree).
  80. # 2. `make buildworld'
  81. # 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
  82. # 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
  83. # [steps 3. & 4. can be combined by using the "kernel" target]
  84. # 5. `reboot' (in single user mode: boot -s from the loader prompt).
  85. # 6. `mergemaster -p'
  86. # 7. `make installworld'
  87. # 8. `mergemaster' (you may wish to use -i, along with -U or -F).
  88. # 9. `make delete-old'
  89. # 10. `reboot'
  90. # 11. `make delete-old-libs' (in case no 3rd party program uses them anymore)
  91. #
  92. # For individuals wanting to build from source with GCC from ports, first
  93. # install the appropriate GCC cross toolchain package:
  94. # `pkg install ${TARGET_ARCH}-gccN`
  95. #
  96. # Once you have installed the necessary cross toolchain, simply pass
  97. # CROSS_TOOLCHAIN=${TARGET_ARCH}-gccN while building with the above steps,
  98. # e.g., `make buildworld CROSS_TOOLCHAIN=amd64-gcc6`.
  99. #
  100. # The ${TARGET_ARCH}-gccN packages are provided as flavors of the
  101. # devel/freebsd-gccN ports.
  102. #
  103. # See src/UPDATING `COMMON ITEMS' for more complete information.
  104. #
  105. # If TARGET=machine (e.g. powerpc, arm64, ...) is specified you can
  106. # cross build world for other machine types using the buildworld target,
  107. # and once the world is built you can cross build a kernel using the
  108. # buildkernel target.
  109. #
  110. # Define the user-driven targets. These are listed here in alphabetical
  111. # order, but that's not important.
  112. #
  113. # Targets that begin with underscore are internal targets intended for
  114. # developer convenience only. They are intentionally not documented and
  115. # completely subject to change without notice.
  116. #
  117. # For more information, see the build(7) manual page.
  118. #
  119. .if defined(UNIVERSE_TARGET) || defined(MAKE_JUST_WORLDS) || defined(WITHOUT_KERNELS)
  120. __DO_KERNELS=no
  121. .endif
  122. .if defined(MAKE_JUST_KERNELS) || defined(WITHOUT_WORLDS)
  123. __DO_WORLDS=no
  124. .endif
  125. __DO_WORLDS?=yes
  126. __DO_KERNELS?=yes
  127. # This is included so CC is set to ccache for -V, and COMPILER_TYPE/VERSION
  128. # can be cached for sub-makes. We can't do this while still running on the
  129. # old fmake from FreeBSD 9.x or older, so avoid including it then to avoid
  130. # heartburn upgrading from older systems. The need for CC is done with new
  131. # make later in the build, and caching COMPILER_TYPE/VERSION is only an
  132. # optimization. Also sinclude it to be friendlier to foreign OS hosted builds.
  133. .if ${MAKE_VERSION} >= 20140620 && defined(.PARSEDIR)
  134. .sinclude <bsd.compiler.mk>
  135. .endif
  136. # Note: we use this awkward construct to be compatible with FreeBSD's
  137. # old make used in 10.0 and 9.2 and earlier.
  138. .if defined(MK_DIRDEPS_BUILD) && ${MK_DIRDEPS_BUILD} == "yes" && \
  139. !make(showconfig) && !make(print-dir)
  140. # targets/Makefile plays the role of top-level
  141. .include "targets/Makefile"
  142. .else
  143. TGTS= all all-man buildenv buildenvvars buildkernel buildworld \
  144. check check-old check-old-dirs check-old-files check-old-libs \
  145. checkdpadd checkworld clean cleandepend cleandir cleanworld \
  146. cleanuniverse \
  147. delete-old delete-old-dirs delete-old-files delete-old-libs \
  148. depend distribute distributekernel distributekernel.debug \
  149. distributeworld distrib-dirs distribution doxygen \
  150. everything hier hierarchy install installcheck installkernel \
  151. installkernel.debug packagekernel packageworld \
  152. reinstallkernel reinstallkernel.debug \
  153. installworld kernel-toolchain libraries maninstall \
  154. obj objlink showconfig tags toolchain update \
  155. makeman sysent \
  156. _worldtmp _legacy _bootstrap-tools _cleanobj _obj \
  157. _build-tools _build-metadata _cross-tools _includes _libraries \
  158. build32 distribute32 install32 buildsoft distributesoft installsoft \
  159. builddtb xdev xdev-build xdev-install \
  160. xdev-links native-xtools native-xtools-install stageworld stagekernel \
  161. stage-packages stage-packages-kernel stage-packages-world \
  162. create-packages-world create-packages-kernel create-packages \
  163. update-packages packages installconfig real-packages real-update-packages \
  164. sign-packages package-pkg print-dir test-system-compiler test-system-linker
  165. # These targets require a TARGET and TARGET_ARCH be defined.
  166. XTGTS= native-xtools native-xtools-install xdev xdev-build xdev-install \
  167. xdev-links
  168. # XXX: r156740: This can't work since bsd.subdir.mk is not included ever.
  169. # It will only work for SUBDIR_TARGETS in make.conf.
  170. TGTS+= ${SUBDIR_TARGETS}
  171. BITGTS= files includes
  172. BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
  173. TGTS+= ${BITGTS}
  174. # Only some targets are allowed to use meta mode. Others get it
  175. # disabled. In some cases, such as 'install', meta mode can be dangerous
  176. # as a cookie may be used to prevent redundant installations (such as
  177. # for WORLDTMP staging). For DESTDIR=/ we always want to install though.
  178. # For other cases, such as delete-old-libs, meta mode may break
  179. # the interactive tty prompt. The safest route is to just whitelist
  180. # the ones that benefit from it.
  181. META_TGT_WHITELIST+= \
  182. _* build32 buildfiles buildincludes buildkernel buildsoft \
  183. buildworld everything kernel-toolchain kernel-toolchains kernel \
  184. kernels libraries native-xtools showconfig test-system-compiler \
  185. test-system-linker tinderbox toolchain \
  186. toolchains universe universe-toolchain world worlds xdev xdev-build
  187. .ORDER: buildworld installworld
  188. .ORDER: buildworld distrib-dirs
  189. .ORDER: buildworld distribution
  190. .ORDER: buildworld distribute
  191. .ORDER: buildworld distributeworld
  192. .ORDER: buildworld buildkernel
  193. .ORDER: distrib-dirs distribute
  194. .ORDER: distrib-dirs distributeworld
  195. .ORDER: distrib-dirs installworld
  196. .ORDER: distribution distribute
  197. .ORDER: distributeworld distribute
  198. .ORDER: distributeworld distribution
  199. .ORDER: installworld distribute
  200. .ORDER: installworld distribution
  201. .ORDER: installworld installkernel
  202. .ORDER: buildkernel installkernel
  203. .ORDER: buildkernel installkernel.debug
  204. .ORDER: buildkernel reinstallkernel
  205. .ORDER: buildkernel reinstallkernel.debug
  206. PATH= /sbin:/bin:/usr/sbin:/usr/bin
  207. MAKEOBJDIRPREFIX?= /usr/obj
  208. _MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} MK_AUTO_OBJ=no \
  209. ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
  210. SRCCONF=${SRCCONF} SRC_ENV_CONF= \
  211. -f /dev/null -V MAKEOBJDIRPREFIX dummy
  212. .if !empty(_MAKEOBJDIRPREFIX)
  213. .error MAKEOBJDIRPREFIX can only be set in environment or src-env.conf(5),\
  214. not as a global (in make.conf(5) or src.conf(5)) or command-line variable.
  215. .endif
  216. # We often need to use the tree's version of make to build it.
  217. # Choices add to complexity though.
  218. # We cannot blindly use a make which may not be the one we want
  219. # so be explicit - until all choice is removed.
  220. WANT_MAKE= bmake
  221. .if !empty(.MAKE.MODE:Mmeta)
  222. # 20160604 - support missing-meta,missing-filemon and performance improvements
  223. WANT_MAKE_VERSION= 20160604
  224. .else
  225. # 20160220 - support .dinclude for FAST_DEPEND.
  226. WANT_MAKE_VERSION= 20160220
  227. .endif
  228. MYMAKE= ${OBJROOT}make.${MACHINE}/${WANT_MAKE}
  229. .if defined(.PARSEDIR)
  230. HAVE_MAKE= bmake
  231. .else
  232. HAVE_MAKE= fmake
  233. .endif
  234. .if defined(ALWAYS_BOOTSTRAP_MAKE) || \
  235. ${HAVE_MAKE} != ${WANT_MAKE} || \
  236. (defined(WANT_MAKE_VERSION) && ${MAKE_VERSION} < ${WANT_MAKE_VERSION})
  237. NEED_MAKE_UPGRADE= t
  238. .endif
  239. .if exists(${MYMAKE})
  240. SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
  241. .elif defined(NEED_MAKE_UPGRADE)
  242. # It may not exist yet but we may cause it to.
  243. # In the case of fmake, upgrade_checks may cause a newer version to be built.
  244. SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
  245. -m ${.CURDIR}/share/mk
  246. .else
  247. SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
  248. .endif
  249. _MAKE= PATH=${PATH} MAKE_CMD="${MAKE}" ${SUB_MAKE} -f Makefile.inc1 \
  250. TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH} ${_MAKEARGS}
  251. .if defined(MK_META_MODE) && ${MK_META_MODE} == "yes"
  252. # Only allow meta mode for the whitelisted targets. See META_TGT_WHITELIST
  253. # above. If overridden as a make argument then don't bother trying to
  254. # disable it.
  255. .if empty(.MAKEOVERRIDES:MMK_META_MODE)
  256. .for _tgt in ${META_TGT_WHITELIST}
  257. .if make(${_tgt})
  258. _CAN_USE_META_MODE?= yes
  259. .endif
  260. .endfor
  261. .if !defined(_CAN_USE_META_MODE)
  262. _MAKE+= MK_META_MODE=no
  263. MK_META_MODE= no
  264. .if defined(.PARSEDIR)
  265. .unexport META_MODE
  266. .endif
  267. .endif # !defined(_CAN_USE_META_MODE)
  268. .endif # empty(.MAKEOVERRIDES:MMK_META_MODE)
  269. .if ${MK_META_MODE} == "yes"
  270. .if !exists(/dev/filemon) && !defined(NO_FILEMON) && !make(showconfig)
  271. # Require filemon be loaded to provide a working incremental build
  272. .error ${.newline}ERROR: The filemon module (/dev/filemon) is not loaded. \
  273. ${.newline}ERROR: WITH_META_MODE is enabled but requires filemon for an incremental build. \
  274. ${.newline}ERROR: 'kldload filemon' or pass -DNO_FILEMON to suppress this error.
  275. .endif # !exists(/dev/filemon) && !defined(NO_FILEMON)
  276. .endif # ${MK_META_MODE} == yes
  277. .endif # defined(MK_META_MODE) && ${MK_META_MODE} == yes
  278. # Guess target architecture from target type, and vice versa, based on
  279. # historic FreeBSD practice of tending to have TARGET == TARGET_ARCH
  280. # expanding to TARGET == TARGET_CPUARCH in recent times, with known
  281. # exceptions.
  282. .if !defined(TARGET_ARCH) && defined(TARGET)
  283. # T->TA mapping is usually TARGET with arm64 the odd man out
  284. _TARGET_ARCH= ${TARGET:S/arm64/aarch64/:S/riscv/riscv64/:S/arm/armv7/}
  285. .elif !defined(TARGET) && defined(TARGET_ARCH) && \
  286. ${TARGET_ARCH} != ${MACHINE_ARCH}
  287. # TA->T mapping is accidentally CPUARCH with aarch64 the odd man out
  288. _TARGET= ${TARGET_ARCH:${__TO_CPUARCH}:C/aarch64/arm64/}
  289. .endif
  290. .if defined(TARGET) && !defined(_TARGET)
  291. _TARGET=${TARGET}
  292. .endif
  293. .if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
  294. _TARGET_ARCH=${TARGET_ARCH}
  295. .endif
  296. # for historical compatibility for xdev targets
  297. .if defined(XDEV)
  298. _TARGET= ${XDEV}
  299. .endif
  300. .if defined(XDEV_ARCH)
  301. _TARGET_ARCH= ${XDEV_ARCH}
  302. .endif
  303. # Some targets require a set TARGET/TARGET_ARCH, check before the default
  304. # MACHINE and after the compatibility handling.
  305. .if !defined(_TARGET) || !defined(_TARGET_ARCH)
  306. ${XTGTS}: _assert_target
  307. .endif
  308. # Otherwise, default to current machine type and architecture.
  309. _TARGET?= ${MACHINE}
  310. _TARGET_ARCH?= ${MACHINE_ARCH}
  311. .if make(native-xtools*)
  312. NXB_TARGET:= ${_TARGET}
  313. NXB_TARGET_ARCH:= ${_TARGET_ARCH}
  314. _TARGET= ${MACHINE}
  315. _TARGET_ARCH= ${MACHINE_ARCH}
  316. _MAKE+= NXB_TARGET=${NXB_TARGET} \
  317. NXB_TARGET_ARCH=${NXB_TARGET_ARCH}
  318. .endif
  319. .if make(print-dir)
  320. .SILENT:
  321. .endif
  322. _assert_target: .PHONY .MAKE
  323. .for _tgt in ${XTGTS}
  324. .if make(${_tgt})
  325. @echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${_tgt}\" target"
  326. @false
  327. .endif
  328. .endfor
  329. #
  330. # Make sure we have an up-to-date make(1). Only world and buildworld
  331. # should do this as those are the initial targets used for upgrades.
  332. # The user can define ALWAYS_CHECK_MAKE to have this check performed
  333. # for all targets.
  334. #
  335. .if defined(ALWAYS_CHECK_MAKE) || !defined(.PARSEDIR)
  336. ${TGTS}: upgrade_checks
  337. .else
  338. buildworld: upgrade_checks
  339. .endif
  340. #
  341. # Handle the user-driven targets, using the source relative mk files.
  342. #
  343. tinderbox toolchains kernel-toolchains: .MAKE
  344. ${TGTS}: .PHONY .MAKE
  345. ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
  346. # The historic default "all" target creates files which may cause stale
  347. # or (in the cross build case) unlinkable results. Fail with an error
  348. # when no target is given. The users can explicitly specify "all"
  349. # if they want the historic behavior.
  350. .MAIN: _guard
  351. _guard: .PHONY
  352. @echo
  353. @echo "Explicit target required. Likely \"${SUBDIR_OVERRIDE:Dall:Ubuildworld}\" is wanted. See build(7)."
  354. @echo
  355. @false
  356. STARTTIME!= LC_ALL=C date
  357. CHECK_TIME!= cmp=`mktemp`; find ${.CURDIR}/sys/sys/param.h -newer "$$cmp" && rm "$$cmp"; echo
  358. .if !empty(CHECK_TIME)
  359. .error check your date/time: ${STARTTIME}
  360. .endif
  361. .if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
  362. #
  363. # world
  364. #
  365. # Attempt to rebuild and reinstall everything. This target is not to be
  366. # used for upgrading an existing FreeBSD system, because the kernel is
  367. # not included. One can argue that this target doesn't build everything
  368. # then.
  369. #
  370. world: upgrade_checks .PHONY
  371. @echo "--------------------------------------------------------------"
  372. @echo ">>> make world started on ${STARTTIME}"
  373. @echo "--------------------------------------------------------------"
  374. .if target(pre-world)
  375. @echo
  376. @echo "--------------------------------------------------------------"
  377. @echo ">>> Making 'pre-world' target"
  378. @echo "--------------------------------------------------------------"
  379. ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
  380. .endif
  381. ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
  382. ${_+_}@cd ${.CURDIR}; ${_MAKE} installworld MK_META_MODE=no
  383. .if target(post-world)
  384. @echo
  385. @echo "--------------------------------------------------------------"
  386. @echo ">>> Making 'post-world' target"
  387. @echo "--------------------------------------------------------------"
  388. ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
  389. .endif
  390. @echo
  391. @echo "--------------------------------------------------------------"
  392. @echo ">>> make world completed on `LC_ALL=C date`"
  393. @echo " (started ${STARTTIME})"
  394. @echo "--------------------------------------------------------------"
  395. .else
  396. world: .PHONY
  397. @echo "WARNING: make world will overwrite your existing FreeBSD"
  398. @echo "installation without also building and installing a new"
  399. @echo "kernel. This can be dangerous. Please read the handbook,"
  400. @echo "'Rebuilding world', for how to upgrade your system."
  401. @echo "Define DESTDIR to where you want to install FreeBSD,"
  402. @echo "including /, to override this warning and proceed as usual."
  403. @echo ""
  404. @echo "Bailing out now..."
  405. @false
  406. .endif
  407. #
  408. # kernel
  409. #
  410. # Short hand for `make buildkernel installkernel'
  411. #
  412. kernel: buildkernel installkernel .PHONY
  413. #
  414. # Perform a few tests to determine if the installed tools are adequate
  415. # for building the world.
  416. #
  417. upgrade_checks: .PHONY
  418. .if defined(NEED_MAKE_UPGRADE)
  419. @${_+_}(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
  420. .endif
  421. #
  422. # Upgrade make(1) to the current version using the installed
  423. # headers, libraries and tools. Also, allow the location of
  424. # the system bsdmake-like utility to be overridden.
  425. #
  426. MMAKEENV= \
  427. DESTDIR= \
  428. INSTALL="sh ${.CURDIR}/tools/install.sh"
  429. MMAKE= ${MMAKEENV} ${MAKE} \
  430. OBJTOP=${MYMAKE:H}/obj \
  431. OBJROOT='$${OBJTOP}/' \
  432. MAKEOBJDIRPREFIX= \
  433. MAN= -DNO_SHARED \
  434. -DNO_CPU_CFLAGS MK_WERROR=no \
  435. -DNO_SUBDIR \
  436. DESTDIR= PROGNAME=${MYMAKE:T}
  437. bmake: .PHONY
  438. @echo
  439. @echo "--------------------------------------------------------------"
  440. @echo ">>> Building an up-to-date ${.TARGET}(1)"
  441. @echo "--------------------------------------------------------------"
  442. ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
  443. ${MMAKE} obj; \
  444. ${MMAKE} depend; \
  445. ${MMAKE} all; \
  446. ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
  447. regress: .PHONY
  448. @echo "'make regress' has been renamed 'make check'" | /usr/bin/fmt
  449. @false
  450. tinderbox toolchains kernel-toolchains kernels worlds: upgrade_checks
  451. tinderbox: .PHONY
  452. @cd ${.CURDIR}; ${SUB_MAKE} DOING_TINDERBOX=YES universe
  453. toolchains: .PHONY
  454. @cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
  455. kernel-toolchains: .PHONY
  456. @cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
  457. kernels: .PHONY
  458. @cd ${.CURDIR}; ${SUB_MAKE} universe -DWITHOUT_WORLDS
  459. worlds: .PHONY
  460. @cd ${.CURDIR}; ${SUB_MAKE} UNIVERSE_TARGET=buildworld universe
  461. #
  462. # universe
  463. #
  464. # Attempt to rebuild *everything* for all supported architectures,
  465. # with a reasonable chance of success, regardless of how old your
  466. # existing system is.
  467. #
  468. .if make(universe) || make(universe_kernels) || make(tinderbox) || \
  469. make(targets) || make(universe-toolchain)
  470. #
  471. # Don't build rarely used, semi-supported architectures unless requested.
  472. #
  473. .if defined(EXTRA_TARGETS)
  474. EXTRA_ARCHES_mips= mipsel mipshf mipselhf mips64el mips64hf mips64elhf
  475. EXTRA_ARCHES_mips+= mipsn32
  476. # powerpcspe excluded from main list until clang fixed
  477. EXTRA_ARCHES_powerpc= powerpcspe powerpc64le
  478. .endif
  479. TARGETS?=amd64 arm arm64 i386 mips powerpc riscv
  480. _UNIVERSE_TARGETS= ${TARGETS}
  481. TARGET_ARCHES_arm?= armv6 armv7
  482. TARGET_ARCHES_arm64?= aarch64
  483. TARGET_ARCHES_mips?= mips mips64 ${EXTRA_ARCHES_mips}
  484. TARGET_ARCHES_powerpc?= powerpc powerpc64 ${EXTRA_ARCHES_powerpc}
  485. TARGET_ARCHES_riscv?= riscv64 riscv64sf
  486. .for target in ${TARGETS}
  487. TARGET_ARCHES_${target}?= ${target}
  488. .endfor
  489. .if defined(USE_GCC_TOOLCHAINS)
  490. TOOLCHAINS_amd64= amd64-gcc6
  491. TOOLCHAINS_arm64= aarch64-gcc6
  492. TOOLCHAINS_i386= i386-gcc6
  493. TOOLCHAINS_mips= mips-gcc6
  494. TOOLCHAINS_powerpc= powerpc-gcc6 powerpc64-gcc6
  495. TOOLCHAIN_powerpc64= powerpc64-gcc6
  496. .endif
  497. # If a target is using an external toolchain, set MAKE_PARAMS to enable use
  498. # of the toolchain. If the external toolchain is missing, exclude the target
  499. # from universe.
  500. .for target in ${_UNIVERSE_TARGETS}
  501. .if !empty(TOOLCHAINS_${target})
  502. .for toolchain in ${TOOLCHAINS_${target}}
  503. .if !exists(/usr/local/share/toolchains/${toolchain}.mk)
  504. _UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:N${target}}
  505. universe: universe_${toolchain}_skip .PHONY
  506. universe_epilogue: universe_${toolchain}_skip .PHONY
  507. universe_${toolchain}_skip: universe_prologue .PHONY
  508. @echo ">> ${target} skipped - install ${toolchain} port or package to build"
  509. .endif
  510. .endfor
  511. .for arch in ${TARGET_ARCHES_${target}}
  512. TOOLCHAIN_${arch}?= ${TOOLCHAINS_${target}:[1]}
  513. MAKE_PARAMS_${arch}?= CROSS_TOOLCHAIN=${TOOLCHAIN_${arch}}
  514. .endfor
  515. .endif
  516. .endfor
  517. UNIVERSE_TARGET?= buildworld
  518. KERNSRCDIR?= ${.CURDIR}/sys
  519. targets: .PHONY
  520. @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
  521. .for target in ${TARGETS}
  522. .for target_arch in ${TARGET_ARCHES_${target}}
  523. @echo " ${target}/${target_arch}"
  524. .endfor
  525. .endfor
  526. .if defined(DOING_TINDERBOX)
  527. FAILFILE=${.CURDIR}/_.tinderbox.failed
  528. MAKEFAIL=tee -a ${FAILFILE}
  529. .else
  530. MAKEFAIL=cat
  531. .endif
  532. universe_prologue: upgrade_checks
  533. universe: universe_prologue
  534. universe_prologue: .PHONY
  535. @echo "--------------------------------------------------------------"
  536. @echo ">>> make universe started on ${STARTTIME}"
  537. @echo "--------------------------------------------------------------"
  538. .if defined(DOING_TINDERBOX)
  539. @rm -f ${FAILFILE}
  540. .endif
  541. universe-toolchain: .PHONY universe_prologue
  542. @echo "--------------------------------------------------------------"
  543. @echo "> Toolchain bootstrap started on `LC_ALL=C date`"
  544. @echo "--------------------------------------------------------------"
  545. ${_+_}@cd ${.CURDIR}; \
  546. env PATH=${PATH} ${SUB_MAKE} ${JFLAG} kernel-toolchain \
  547. TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH} \
  548. OBJTOP="${HOST_OBJTOP}" \
  549. WITHOUT_SYSTEM_COMPILER=yes \
  550. WITHOUT_SYSTEM_LINKER=yes \
  551. TOOLS_PREFIX_UNDEF= \
  552. kernel-toolchain \
  553. MK_LLVM_TARGET_ALL=yes \
  554. > _.${.TARGET} 2>&1 || \
  555. (echo "${.TARGET} failed," \
  556. "check _.${.TARGET} for details" | \
  557. ${MAKEFAIL}; false)
  558. @if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/cc" ]; then \
  559. echo "Missing host compiler at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \
  560. false; \
  561. fi
  562. @if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \
  563. echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/ld?" >&2; \
  564. false; \
  565. fi
  566. @echo "--------------------------------------------------------------"
  567. @echo "> Toolchain bootstrap completed on `LC_ALL=C date`"
  568. @echo "--------------------------------------------------------------"
  569. .for target in ${_UNIVERSE_TARGETS}
  570. universe: universe_${target}
  571. universe_epilogue: universe_${target}
  572. universe_${target}: universe_${target}_prologue .PHONY
  573. universe_${target}_prologue: universe_prologue .PHONY
  574. @echo ">> ${target} started on `LC_ALL=C date`"
  575. universe_${target}_worlds: .PHONY
  576. .if !make(targets) && !make(universe-toolchain)
  577. .for target_arch in ${TARGET_ARCHES_${target}}
  578. .if !defined(_need_clang_${target}_${target_arch})
  579. _need_clang_${target}_${target_arch} != \
  580. env TARGET=${target} TARGET_ARCH=${target_arch} \
  581. ${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-compiler \
  582. ${MAKE_PARAMS_${target_arch}} -V MK_CLANG_BOOTSTRAP 2>/dev/null || \
  583. echo unknown
  584. .export _need_clang_${target}_${target_arch}
  585. .endif
  586. .if !defined(_need_lld_${target}_${target_arch})
  587. _need_lld_${target}_${target_arch} != \
  588. env TARGET=${target} TARGET_ARCH=${target_arch} \
  589. ${SUB_MAKE} -C ${.CURDIR} -f Makefile.inc1 test-system-linker \
  590. ${MAKE_PARAMS_${target_arch}} -V MK_LLD_BOOTSTRAP 2>/dev/null || \
  591. echo unknown
  592. .export _need_lld_${target}_${target_arch}
  593. .endif
  594. # Setup env for each arch to use the one clang.
  595. .if defined(_need_clang_${target}_${target_arch}) && \
  596. ${_need_clang_${target}_${target_arch}} == "yes"
  597. # No check on existing XCC or CROSS_BINUTILS_PREFIX, etc, is needed since
  598. # we use the test-system-compiler logic to determine if clang needs to be
  599. # built. It will be no from that logic if already using an external
  600. # toolchain or /usr/bin/cc.
  601. # XXX: Passing HOST_OBJTOP into the PATH would allow skipping legacy,
  602. # bootstrap-tools, and cross-tools. Need to ensure each tool actually
  603. # supports all TARGETS though.
  604. # For now we only pass UNIVERSE_TOOLCHAIN_PATH which will be added at the end
  605. # of STRICTTMPPATH to ensure that the target-specific binaries come first.
  606. MAKE_PARAMS_${target_arch}+= \
  607. XCC="${HOST_OBJTOP}/tmp/usr/bin/cc" \
  608. XCXX="${HOST_OBJTOP}/tmp/usr/bin/c++" \
  609. XCPP="${HOST_OBJTOP}/tmp/usr/bin/cpp" \
  610. UNIVERSE_TOOLCHAIN_PATH=${HOST_OBJTOP}/tmp/usr/bin
  611. .endif
  612. .if defined(_need_lld_${target}_${target_arch}) && \
  613. ${_need_lld_${target}_${target_arch}} == "yes"
  614. MAKE_PARAMS_${target_arch}+= \
  615. XLD="${HOST_OBJTOP}/tmp/usr/bin/ld"
  616. .endif
  617. .endfor
  618. .endif # !make(targets)
  619. .if ${__DO_WORLDS} == "yes"
  620. universe_${target}_done: universe_${target}_worlds .PHONY
  621. .for target_arch in ${TARGET_ARCHES_${target}}
  622. universe_${target}_worlds: universe_${target}_${target_arch} .PHONY
  623. .if (defined(_need_clang_${target}_${target_arch}) && \
  624. ${_need_clang_${target}_${target_arch}} == "yes") || \
  625. (defined(_need_lld_${target}_${target_arch}) && \
  626. ${_need_lld_${target}_${target_arch}} == "yes")
  627. universe_${target}_${target_arch}: universe-toolchain
  628. universe_${target}_prologue: universe-toolchain
  629. .endif
  630. universe_${target}_${target_arch}: universe_${target}_prologue .MAKE .PHONY
  631. @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
  632. @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
  633. ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
  634. TARGET=${target} \
  635. TARGET_ARCH=${target_arch} \
  636. ${MAKE_PARAMS_${target_arch}} \
  637. > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
  638. (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
  639. "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
  640. ${MAKEFAIL}))
  641. @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
  642. .endfor
  643. .endif # ${__DO_WORLDS} == "yes"
  644. .if ${__DO_KERNELS} == "yes"
  645. universe_${target}_done: universe_${target}_kernels .PHONY
  646. universe_${target}_kernels: universe_${target}_worlds .PHONY
  647. universe_${target}_kernels: universe_${target}_prologue .MAKE .PHONY
  648. @cd ${.CURDIR}; ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
  649. universe_kernels
  650. .endif # ${__DO_KERNELS} == "yes"
  651. # Tell the user the worlds and kernels have completed
  652. universe_${target}: universe_${target}_done
  653. universe_${target}_done:
  654. @echo ">> ${target} completed on `LC_ALL=C date`"
  655. .endfor
  656. .if make(universe_kernconfs) || make(universe_kernels)
  657. .if !defined(TARGET)
  658. TARGET!= uname -m
  659. .endif
  660. universe_kernels_prologue: .PHONY
  661. @echo ">> ${TARGET} kernels started on `LC_ALL=C date`"
  662. universe_kernels: universe_kernconfs .PHONY
  663. @echo ">> ${TARGET} kernels completed on `LC_ALL=C date`"
  664. .if defined(MAKE_ALL_KERNELS)
  665. _THINNER=cat
  666. .elif defined(MAKE_LINT_KERNELS)
  667. _THINNER=grep 'LINT' || true
  668. .else
  669. _THINNER=xargs grep -L "^.NO_UNIVERSE" || true
  670. .endif
  671. KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \
  672. find [[:upper:][:digit:]]*[[:upper:][:digit:]] \
  673. -type f -maxdepth 0 \
  674. ! -name DEFAULTS ! -name NOTES | \
  675. ${_THINNER}
  676. universe_kernconfs: universe_kernels_prologue .PHONY
  677. .for kernel in ${KERNCONFS}
  678. TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \
  679. env PATH=${HOST_OBJTOP}/tmp/legacy/bin:${PATH:Q} \
  680. config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
  681. grep -v WARNING: | cut -f 2
  682. .if empty(TARGET_ARCH_${kernel})
  683. .error "Target architecture for ${TARGET}/conf/${kernel} unknown. config(8) likely too old."
  684. .endif
  685. universe_kernconfs_${TARGET_ARCH_${kernel}}: universe_kernconf_${TARGET}_${kernel}
  686. universe_kernconf_${TARGET}_${kernel}: .MAKE
  687. @echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel started on `LC_ALL=C date`"
  688. @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
  689. ${SUB_MAKE} ${JFLAG} buildkernel \
  690. TARGET=${TARGET} \
  691. TARGET_ARCH=${TARGET_ARCH_${kernel}} \
  692. ${MAKE_PARAMS_${TARGET_ARCH_${kernel}}} \
  693. KERNCONF=${kernel} \
  694. > _.${TARGET}.${kernel} 2>&1 || \
  695. (echo "${TARGET} ${kernel} kernel failed," \
  696. "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
  697. @echo ">> ${TARGET}.${TARGET_ARCH_${kernel}} ${kernel} kernel completed on `LC_ALL=C date`"
  698. .endfor
  699. .for target_arch in ${TARGET_ARCHES_${TARGET}}
  700. universe_kernconfs: universe_kernconfs_${target_arch} .PHONY
  701. universe_kernconfs_${target_arch}:
  702. .endfor
  703. .endif # make(universe_kernels)
  704. universe: universe_epilogue
  705. universe_epilogue: .PHONY
  706. @echo "--------------------------------------------------------------"
  707. @echo ">>> make universe completed on `LC_ALL=C date`"
  708. @echo " (started ${STARTTIME})"
  709. @echo "--------------------------------------------------------------"
  710. .if defined(DOING_TINDERBOX)
  711. @if [ -e ${FAILFILE} ] ; then \
  712. echo "Tinderbox failed:" ;\
  713. cat ${FAILFILE} ;\
  714. exit 1 ;\
  715. fi
  716. .endif
  717. .endif
  718. .if defined(.PARSEDIR)
  719. # This makefile does not run in meta mode
  720. .MAKE.MODE= normal
  721. # Normally the things we run from here don't either.
  722. # Using -DWITH_META_MODE
  723. # we can buildworld with meta files created which are useful
  724. # for debugging, but without any of the rest of a meta mode build.
  725. MK_DIRDEPS_BUILD= no
  726. MK_STAGING= no
  727. # tell meta.autodep.mk to not even think about updating anything.
  728. UPDATE_DEPENDFILE= NO
  729. .if !make(showconfig)
  730. .export MK_DIRDEPS_BUILD MK_STAGING UPDATE_DEPENDFILE
  731. .endif
  732. .if make(universe)
  733. # we do not want a failure of one branch abort all.
  734. MAKE_JOB_ERROR_TOKEN= no
  735. .export MAKE_JOB_ERROR_TOKEN
  736. .endif
  737. .endif # bmake
  738. .endif # DIRDEPS_BUILD