summaryrefslogtreecommitdiff
path: root/Makefile.inc1
diff options
context:
space:
mode:
authorAlex Richardson <arichardson@FreeBSD.org>2020-08-25 13:29:57 +0000
committerAlex Richardson <arichardson@FreeBSD.org>2020-08-25 13:29:57 +0000
commit5bb9250e0af4626bb9524ce4ed77b9efaf30ce46 (patch)
tree2edbf09bb6dcd61b441da105db6a371f2efc6071 /Makefile.inc1
parent7ec1ec4fdb98d87602c8501dae9b9cbd24b7d22b (diff)
downloadsrc-test-5bb9250e0af4626bb9524ce4ed77b9efaf30ce46.tar.gz
src-test-5bb9250e0af4626bb9524ce4ed77b9efaf30ce46.zip
Add necessary Makefile.inc1 infrastructure for building on non-FreeBSD
The most awkward bit in this patch is the bootstrapping of m4: We can't simply use the host version of m4 since that is not compatible with the flags passed by lex (at least on macOS, possibly also on Linux). Therefore we need to bootstrap m4, but lex needs m4 to build and m4 also depends on lex (which needs m4 to generate any files). To work around this cyclic dependency we can build a bootstrap version of m4 (with pre-generated files) then use that to build the real m4. This patch also changes the xz/unxz/dd tools to always use the host version since the version in the source tree cannot easily be bootstrapped on macOS or Linux. Reviewed By: brooks, imp (earlier version) Differential Revision: https://reviews.freebsd.org/D25992
Notes
Notes: svn path=/head/; revision=364760
Diffstat (limited to 'Makefile.inc1')
-rw-r--r--Makefile.inc1158
1 files changed, 117 insertions, 41 deletions
diff --git a/Makefile.inc1 b/Makefile.inc1
index 6b77bb195bfd9..0a85d6be6be97 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -167,6 +167,19 @@ _t= ${TARGET_ARCH}/${TARGET}
.endif
.endfor
+.if ${.MAKE.OS} != "FreeBSD"
+CROSSBUILD_HOST=${.MAKE.OS}
+.if ${.MAKE.OS} != "Linux" && ${.MAKE.OS} != "Darwin"
+.warning "Unsupported crossbuild system: ${.MAKE.OS}. Build will probably fail!"
+.endif
+# We need to force NO_ROOT/DB_FROM_SRC builds when building on other operating
+# systems since the BSD.foo.dist specs contain users and groups that do not
+# exist by default on a Linux/MacOS system.
+NO_ROOT:= 1
+DB_FROM_SRC:= 1
+.export NO_ROOT
+.endif
+
# If all targets are disabled for system llvm then don't expect it to work
# for cross-builds.
.if !defined(TOOLS_PREFIX) && ${MK_LLVM_TARGET_ALL} == "no" && \
@@ -568,13 +581,16 @@ _CPUTYPE!= MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} -f /dev/null \
.endif
.if make(buildworld)
BUILD_ARCH!= uname -p
-.if ${MACHINE_ARCH} != ${BUILD_ARCH}
+# On some Linux systems uname -p returns "unknown" so skip this check there.
+# This check only exists to tell people to use TARGET_ARCH instead of
+# MACHINE_ARCH so skipping it when crossbuilding on non-FreeBSD should be fine.
+.if ${MACHINE_ARCH} != ${BUILD_ARCH} && ${.MAKE.OS} == "FreeBSD"
.error To cross-build, set TARGET_ARCH.
.endif
.endif
WORLDTMP?= ${OBJTOP}/tmp
BPATH= ${CCACHE_WRAPPER_PATH_PFX}${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin:${WORLDTMP}/legacy/usr/libexec
-XPATH= ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
+XPATH= ${WORLDTMP}/bin:${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin
# When building we want to find the cross tools before the host tools in ${BPATH}.
# We also need to add UNIVERSE_TOOLCHAIN_PATH so that we can find the shared
@@ -589,6 +605,13 @@ STRICTTMPPATH= ${XPATH}:${BPATH}:${UNIVERSE_TOOLCHAIN_PATH}
# USING_SYSTEM_LINKER/USING_SYSTEM_COMPILER. Once these issues have been
# resolved it will be turned on by default.
BUILD_WITH_STRICT_TMPPATH?=0
+.if defined(CROSSBUILD_HOST)
+# When building on non-FreeBSD we can't rely on the tools in /usr/bin being compatible
+# with what FreeBSD expects. Therefore we only use tools from STRICTTMPPATH
+# during the world build stage. We build most tools during the bootstrap-tools
+# phase but symlink host tools that are known to work instead of building them
+BUILD_WITH_STRICT_TMPPATH:=1
+.endif
.if ${BUILD_WITH_STRICT_TMPPATH} != 0
TMPPATH= ${STRICTTMPPATH}
.else
@@ -724,7 +747,9 @@ XMAKE= ${BMAKE} \
# kernel-tools stage
KTMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \
PATH=${BPATH}:${PATH} \
- WORLDTMP=${WORLDTMP}
+ WORLDTMP=${WORLDTMP} \
+ MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
+
KTMAKE= \
TOOLS_PREFIX=${TOOLS_PREFIX_UNDEF:U${WORLDTMP}} \
${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
@@ -845,7 +870,13 @@ NO_META_IGNORE_HOST_HEADERS= 1
# allows tracking the oldest osreldate to force rebuilds via
# META_MODE_BADABI_REVS above.
host-osreldate.h: # DO NOT ADD /usr/include/osreldate.h here
+.if !defined(CROSSBUILD_HOST)
@cp -f /usr/include/osreldate.h ${.TARGET}
+.else
+ @echo "#ifndef __FreeBSD_version" > ${.TARGET}
+ @echo "#define __FreeBSD_version ${OSRELDATE}" >> ${.TARGET}
+ @echo "#endif" >> ${.TARGET}
+.endif
WMAKE= ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \
BWPHASE=${.TARGET:C,^_,,} \
@@ -1022,7 +1053,8 @@ _bootstrap-tools:
@echo ">>> stage 1.2: bootstrap tools"
@echo "--------------------------------------------------------------"
${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
- mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom
+ mkdir -p ${WORLDTMP}/usr ${WORLDTMP}/lib/casper ${WORLDTMP}/lib/geom \
+ ${WORLDTMP}/bin
${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
-p ${WORLDTMP}/usr >/dev/null
${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
@@ -1277,11 +1309,15 @@ __installcheck_sh_check: .PHONY
_zoneinfo= zic tzsetup
.endif
+.if !defined(CROSSBUILD_HOST)
+_sysctl=sysctl
+.endif
+
ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \
date echo egrep find grep id install ${_install-info} \
ln make mkdir mtree mv pwd_mkdb \
- rm sed services_mkdb sh sort strip sysctl test true uname wc ${_zoneinfo} \
- ${LOCAL_ITOOLS}
+ rm sed services_mkdb sh sort strip ${_sysctl} test true uname wc \
+ ${_zoneinfo} ${LOCAL_ITOOLS}
# Needed for share/man
.if ${MK_MAN_UTILS} != "no"
@@ -1317,23 +1353,25 @@ MTREE_MAGIC?= mtree 2.0
distributeworld installworld stageworld: _installcheck_world .PHONY
mkdir -p ${INSTALLTMP}
progs=$$(for prog in ${ITOOLS}; do \
- if progpath=`which $$prog`; then \
+ if progpath=`env PATH=${TMPPATH} which $$prog`; then \
echo $$progpath; \
else \
- echo "Required tool $$prog not found in PATH." >&2; \
- exit 1; \
- fi; \
- done); \
- libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
- while read line; do \
- set -- $$line; \
- if [ "$$2 $$3" != "not found" ]; then \
- echo $$2; \
- else \
- echo "Required library $$1 not found." >&2; \
+ echo "Required tool $$prog not found in PATH ($$PATH)." >&2; \
exit 1; \
fi; \
done); \
+ if [ -z "${CROSSBUILD_HOST}" ] ; then \
+ libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
+ while read line; do \
+ set -- $$line; \
+ if [ "$$2 $$3" != "not found" ]; then \
+ echo $$2; \
+ else \
+ echo "Required library $$1 not found." >&2; \
+ exit 1; \
+ fi; \
+ done); \
+ fi; \
cp $$libs $$progs ${INSTALLTMP}
cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
.if defined(NO_ROOT)
@@ -2043,10 +2081,9 @@ update: .PHONY
# build-tools or cross-tools.
#
-
-# libnv is a requirement for config(8), which is an unconditional
+# libnv and libsbuf are requirements for config(8), which is an unconditional
# bootstrap-tool.
-_config_deps= lib/libnv
+_config_deps= lib/libnv lib/libsbuf
legacy: .PHONY
.if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0
@@ -2054,7 +2091,7 @@ legacy: .PHONY
false
.endif
-.for _tool in tools/build ${_config_deps}
+.for _tool in tools/build
${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \
cd ${.CURDIR}/${_tool}; \
if [ -z "${NO_OBJWALK}" ]; then ${MAKE} DIRPRFX=${_tool}/ obj; fi; \
@@ -2090,12 +2127,23 @@ _bt= _bootstrap-tools
# If BOOTSTRAP_ALL_TOOLS is set we will build all the required tools from the
# current source tree. Otherwise we create a symlink to the version found in
# $PATH during the bootstrap-tools stage.
+# When building on non-FreeBSD systems we can't assume that the host binaries
+# accept compatible flags or produce compatible output. Therefore we force
+# BOOTSTRAP_ALL_TOOLS and just build the FreeBSD version of the binary.
+.if defined(CROSSBUILD_HOST)
+BOOTSTRAP_ALL_TOOLS:= 1
+.endif
.if defined(BOOTSTRAP_ALL_TOOLS)
# BOOTSTRAPPING will be set on the command line so we can't override it here.
# Instead set BOOTSTRAPPING_OSRELDATE so that the value 0 is set ${BSARGS}
BOOTSTRAPPING_OSRELDATE:= 0
.endif
+# libnv and libsbuf are requirements for config(8), which is an unconditional
+# bootstrap-tool.
+_config=usr.sbin/config lib/libnv lib/libsbuf
+${_bt}-usr.sbin/config: ${_bt}-lib/libnv ${_bt}-lib/libsbuf
+
.if ${MK_GAMES} != "no"
_strfile= usr.bin/fortune/strfile
.endif
@@ -2111,13 +2159,20 @@ _vtfontcvt= usr.bin/vtfontcvt
# please ensure that you also add a .else case where you add the tool to the
# _bootstrap_tools_links variable.
.if ${BOOTSTRAPPING} < 1000033
-_m4= usr.bin/m4
+# Note: lex needs m4 to build but m4 also depends on lex (which needs m4 to
+# generate any files). To fix this cyclic dependency we can build a bootstrap
+# version of m4 (with pre-generated files) then use that to build the real m4.
+# We can't simply use the host m4 since e.g. the macOS version does not accept
+# the flags that are passed by lex.
+# For lex we also use the pre-gerated files since we would otherwise need to
+# build awk and sed first (which need lex to build)
+# TODO: add a _bootstrap_lex and then build the real lex afterwards
_lex= usr.bin/lex
-# Note: lex needs m4 to build but m4 also depends on lex. However, lex can be
-# bootstrapped so we build lex first.
-${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc ${_bt}-${_lex}
-_bt_m4_depend=${_bt}-${_m4}
-_bt_lex_depend=${_bt}-${_lex} ${_bt_m4_depend}
+_m4= tools/build/bootstrap-m4 usr.bin/m4
+${_bt}-tools/build/bootstrap-m4: ${_bt}-usr.bin/lex ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc
+${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/yacc ${_bt}-usr.bin/lex ${_bt}-tools/build/bootstrap-m4
+_bt_m4_depend=${_bt}-usr.bin/m4
+_bt_lex_depend=${_bt}-usr.bin/lex ${_bt_m4_depend}
.else
_bootstrap_tools_links+=m4 lex
.endif
@@ -2183,12 +2238,15 @@ _bootstrap_tools_links+=crunchgen
.endif
# r296926 -P keymap search path, MFC to stable/10 in r298297
-.if ${BOOTSTRAPPING} < 1003501 || \
- (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103)
+# Note: kbdcontrol can not be bootstrapped on non-FreeBSD systems
+.if !defined(CROSSBUILD_HOST)
+.if (${BOOTSTRAPPING} < 1003501 || \
+ (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103))
_kbdcontrol= usr.sbin/kbdcontrol
.else
_bootstrap_tools_links+=kbdcontrol
.endif
+.endif
_yacc= usr.bin/yacc
@@ -2215,6 +2273,7 @@ ${_bt}-usr.bin/clang/lldb-tblgen: ${_bt}-lib/clang/libllvmminimal
.if ${MK_LOCALES} != "no"
_localedef= usr.bin/localedef
+${_bt}-usr.bin/localedef: ${_bt}-usr.bin/yacc ${_bt_lex_depend}
.endif
.if ${MK_KERBEROS} != "no"
@@ -2244,8 +2303,8 @@ ${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd
_basic_bootstrap_tools_multilink=usr.bin/grep grep,egrep,fgrep
_basic_bootstrap_tools_multilink+=bin/test test,[
# bootstrap tools needed by buildworld:
-_basic_bootstrap_tools=usr.bin/cut bin/expr usr.bin/gencat \
- usr.bin/join usr.bin/mktemp bin/rmdir usr.bin/sed usr.bin/sort \
+_basic_bootstrap_tools+=usr.bin/cut bin/expr usr.bin/gencat usr.bin/join \
+ usr.bin/mktemp bin/realpath bin/rmdir usr.bin/sed usr.bin/sort \
usr.bin/truncate usr.bin/tsort
# Some build scripts use nawk instead of awk (this happens at least in
# cddl/contrib/opensolaris/lib/libdtrace/common/mknames.sh) so we need both awk
@@ -2259,24 +2318,29 @@ _basic_bootstrap_tools+=usr.bin/uuencode usr.bin/uudecode
_basic_bootstrap_tools+=usr.bin/xargs
# cap_mkdb is required for share/termcap:
_basic_bootstrap_tools+=usr.bin/cap_mkdb
-# ldd is required for installcheck (TODO: just always use /usr/bin/ldd instead?)
-_basic_bootstrap_tools+=usr.bin/ldd
# services_mkdb/pwd_mkdb are required for installworld:
_basic_bootstrap_tools+=usr.sbin/services_mkdb usr.sbin/pwd_mkdb
+# ldd is required for installcheck (TODO: just always use /usr/bin/ldd instead?)
+.if !defined(CROSSBUILD_HOST)
+# ldd is only needed for updating the running system so we don't need to
+# bootstrap ldd on non-FreeBSD systems
+_basic_bootstrap_tools+=usr.bin/ldd
+.endif
# sysctl/chflags are required for installkernel:
+.if !defined(CROSSBUILD_HOST)
_basic_bootstrap_tools+=sbin/sysctl bin/chflags
+.else
+# When building on non-FreeBSD, install a fake chflags instead since the
+# version from the source tree cannot work. We also don't need sysctl since we
+# are install with -DNO_ROOT.
+_other_bootstrap_tools+=tools/build/cross-build/fake_chflags
+.endif
# mkfifo is used by sys/conf/newvers.sh
_basic_bootstrap_tools+=usr.bin/mkfifo
.if ${MK_BOOT} != "no"
-_basic_bootstrap_tools+=bin/dd
-# xz/unxz is used by EFI
-_basic_bootstrap_tools_multilink+=usr.bin/xz xz,unxz
# md5 is used by boot/beri (and possibly others)
_basic_bootstrap_tools+=sbin/md5
-.if defined(BOOTSTRAP_ALL_TOOLS)
-${_bt}-sbin/md5: ${_bt}-lib/libmd
-.endif
.endif
.if ${MK_ZONEINFO} != "no"
@@ -2297,6 +2361,10 @@ ${_bt}-usr.sbin/config: ${_bt}-usr.bin/file2c ${_bt_lex_depend}
# `make legacy` step. Not adding a link to make is important on non-FreeBSD
# since "make" will usually point to GNU make there.
_other_bootstrap_tools+=usr.bin/bmake
+
+# Avoid dependency on host bz2 headers:
+_other_bootstrap_tools+=lib/libbz2
+${_bt}-usr.bin/grep: ${_bt}-lib/libbz2
.else
# All tools in _basic_bootstrap_tools have the same name as the subdirectory
# so we can use :T to get the name of the symlinks that we need to create.
@@ -2346,7 +2414,7 @@ bootstrap-tools: ${_bt}-links .PHONY
${_other_bootstrap_tools} \
usr.bin/xinstall \
${_gensnmptree} \
- usr.sbin/config \
+ ${_config} \
${_flua} \
${_crunchide} \
${_crunchgen} \
@@ -2365,6 +2433,14 @@ ${_bt}-${_tool}: ${_bt}-links .PHONY .MAKE
bootstrap-tools: ${_bt}-${_tool}
.endfor
+.if target(${_bt}-lib/libmd)
+# If we are bootstrapping libmd (e.g. when building on macOS/Linux) add the
+# necessary dependencies:
+${_bt}-usr.bin/sort: ${_bt}-lib/libmd
+${_bt}-usr.bin/xinstall: ${_bt}-lib/libmd
+${_bt}-sbin/md5: ${_bt}-lib/libmd
+.endif
+
#
# build-tools: Build special purpose build tools