Makefile 30 KB

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