11.24Smrg$NetBSD: README.mknative,v 1.24 2025/07/21 05:27:20 mrg Exp $
21.1Smrg
31.2SskrllThis file describes how to bootstrap the native toolchain on a new NetBSD
41.2Sskrllplatform (and how to update the new toolchain files, if needed).  These
51.2Sskrllfiles may be generated on a cross-compile host without problems.
61.1Smrg
71.2SskrllNOTE:  DO NOT RUN "mknative" BY HAND!  It requires the Makefile in this
81.2Sskrlldirectory to set up certain environments first.
91.2Sskrll
101.2SskrllSince libc's features change over time, the config.h files can change as a
111.2Sskrllresult; thus the instructions below are the same no matter whether
121.2Sskrllbootstrapping on a cross or native host.  This is important: even on a
131.2Sskrll"native" host, you should bootstrap the toolchain by building from an
141.2Sskrllup-to-date source tree to a $DESTDIR using the exact same instructions.
151.2Sskrll
161.2SskrllIn these notes, MACHINE is the $MACHINE of the target.  These files can be
171.2Sskrllcross-generated.  Though a $MACHINE_ARCH all uses the same config files, you
181.2Sskrllmust pick a specific $MACHINE so that building the requisite bits below will
191.2Sskrllwork.
201.2Sskrll
211.18Smrg0. Note that example paths like src/external/gpl3/gcc/lib/libgcc/arch will
221.18Smrg   really be src/external/gpl3/gcc.old/lib/libgcc/arch for the previous GCC.
231.18Smrg
241.2Sskrll1. Set MKMAINTAINERTOOLS=yes in mk.conf.  (Needed so that src/tools/gettext
251.2Sskrll   gets built, eliciting proper HAVE_*GETTEXT* defns in config.h files.)
261.2Sskrll
271.2Sskrll2. Build and install a cross toolchain (via "build.sh -m MACHINE tools").
281.14Smartin   Note that while PR #47353 is not fixed, you can not use the -O option
291.16Sskrll   to build.sh. Use -M instead. (The differences are in layout and pathname
301.16Sskrll   prefixes in the object directory pointed to by each option.)
311.2Sskrll
321.23Smrg3. In src/tools/gcc, do "nbmake-MACHINE HAVE_GCC=8 bootstrap-libgcc".
331.2Sskrll
341.10Sskrll   This will create just enough glue in src/external/gpl3/gcc/lib/libgcc/arch
351.10Sskrll   to make it possible to build, based on the toolchain built in
361.10Sskrll   ${.OBJDIR}/build.
371.2Sskrll   Because the files generated in this step contain things like
381.4Smartin   -DCROSS_COMPILE, they are not suitable for committing.  Step 8 below
391.2Sskrll   will regenerate the "proper" libgcc config files.
401.2Sskrll
411.2Sskrll4. At top level, do
421.23Smrg   "nbmake-MACHINE obj do-distrib-dirs MKGCC=no MKBINUTILS=no HAVE_GCC=8", and
431.23Smrg   "nbmake-MACHINE includes HAVE_GCC= MKGCC=no MKBINUTILS=no HAVE_GCC=8".
441.23Smrg   (Note: replace 8 [for GCC 8.x] with the appropriate version you are going
451.22Smrg   to mknative-for, the MKGCC=no prevents the standard makefiles from picking
461.22Smrg   up any gcc version info automatically)
471.2Sskrll
481.13Sskrll5. In src/lib/csu, do
491.13Sskrll   "nbmake-MACHINE dependall". and "nbmake-MACHINE install".
501.10Sskrll
511.19Sjoerg6. In src/external/gpl3/gcc/lib/libgcc, do
521.11Sskrll   "nbmake-MACHINE obj includes dependall install".
531.4Smartin
541.19Sjoerg7. In each of src/external/lgpl3/gmp/lib/libgmp,
551.24Smrg   src/external/lgpl3/mpfr/lib/libmpfr, src/external/lgpl3/mpc/lib/libmpc,
561.24Smrg   and src/external/mit/isl, do "nbmake-MACHINE obj dependall".
571.11Sskrll
581.19Sjoerg8. In src/lib, do
591.23Smrg   "nbmake-MACHINE dependall install MKGCC=no HAVE_GCC=8".
601.2Sskrll
611.2Sskrll   Optionally, all of the following may be set in the environment to reduce
621.2Sskrll   the amount of code needed to build at this step.  Basically, it must be
631.2Sskrll   possible for static binaries to build and base system libs to exist so
641.2Sskrll   that "configure" can do its job for the target--these MK* options omit
651.11Sskrll   the rest for this stage of the build. 
661.2Sskrll
671.2Sskrll   MKLINT=no
681.2Sskrll   MKPROFILE=no
691.2Sskrll   MKSHARE=no
701.14Smartin   MKRUMP=no
711.2Sskrll
721.19Sjoerg9. In src/tools/gcc, do "nbmake-MACHINE native-gcc".
731.2Sskrll
741.2Sskrll   This will do a full configury in ${.OBJDIR}/.native that is a "Canadian"
751.2Sskrll   cross toolchain (--build reflects the host platform, but --host and
761.2Sskrll   --target are the target).  The result is a tree that would build a
771.2Sskrll   native-to-NetBSD compiler on a cross host, and mknative pulls glue data
781.2Sskrll   from this.
791.2Sskrll
801.19Sjoerg10. Try out a full build using "nbmake-MACHINE"; the result should include
811.2Sskrll   a native compiler.
821.2Sskrll
831.19Sjoerg11. If all is well, commit the glue files added to src/gnu/{lib,usr.bin}/*.
84