Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Oct 2017 13:11:59 +0200
From:      Dimitry Andric <dim@FreeBSD.org>
To:        =?utf-8?Q?Eddy_Petri=C8=99or?= <eddy.petrisor@gmail.com>
Cc:        freebsd-toolchain@freebsd.org, freebsd-arm@freebsd.org
Subject:   Re: lib/clan/llvm.build.mk: Shouldn't BUILD_TRIPLE definition rely host 'cc -dumpmachine'?
Message-ID:  <CDAA0CB5-F1FC-40FE-AEC5-56FD64654671@FreeBSD.org>
In-Reply-To: <CAK0XTWczya8vg_sQZPqz-ZyYZRMq1v6p%2Bjs90S%2BjaDHxo2=1gA@mail.gmail.com>
References:  <CAK0XTWczya8vg_sQZPqz-ZyYZRMq1v6p%2Bjs90S%2BjaDHxo2=1gA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_4487EF25-E903-4C28-9200-AB2D7E95F7F3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

On 27 Oct 2017, at 08:23, Eddy Petri=C8=99or <eddy.petrisor@gmail.com> =
wrote:
>=20
> I am trying to make the FreeBSD code base build from a Linux host and
> found this bit which defines BUILD_TRIPLE in a way which to my
> untrained eyes look like overengineering.
>=20
> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} =
=3D=3D "")
> TARGET_ABI=3D    -gnueabihf
> .elif ${TARGET_ARCH:Marm*}
> TARGET_ABI=3D    -gnueabi
> .else
> TARGET_ABI=3D
> .endif
> VENDOR=3D        unknown
> OS_VERSION=3D    freebsd12.0
>=20
> TARGET_TRIPLE?=3D
> =
${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${T=
ARGET_ABI}
> BUILD_TRIPLE?=3D
> ${BUILD_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}

I don't see much overengineering here? :)  We simply trust BUILD_ARCH,
as it is passed in by the top-level Makefile.inc1.  This is how most of
these down-level Makefiles work.  Running all kinds of commands to
figure out architectures and the like should be avoided in such
Makefiles.

> To support a Linux host I made these changes that is using 'cc
> -dumpmachine' to get the correct BUILD_TRIPLE,

Unfortunately, this is the wrong option to do so.  The gcc manual says:

-dumpmachine
  Print the compiler=E2=80=99s target machine (for example, =
=E2=80=98i686-pc-linux-gnu=E2=80=99)
  -and don=E2=80=99t do anything else.

E.g, it prints the *target* tripe, not the build triple.


> but I am wondering if
> it shouldn't be OK for building on a FreeBSD host
>=20
> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} =
=3D=3D "")
> TARGET_ABI=3D    -gnueabihf
> .elif ${TARGET_ARCH:Marm*}
> TARGET_ABI=3D    -gnueabi
> .else
> TARGET_ABI=3D
> .endif
> VENDOR=3D        unknown
> OS_VERSION=3D    freebsd12.0
> +BUILD_OS!=3D    uname -s
> +

Again, this should be set by the top-level Makefiles, not in this one.

>=20
> TARGET_TRIPLE?=3D
> =
${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${T=
ARGET_ABI}
> +.if ${BUILD_OS} =3D=3D FreeBSD
> BUILD_TRIPLE?=3D
> ${BUILD_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}
> +.else
> +HOST_CC_DUMPMACHINE!=3D    cc -dumpmachine
> +BUILD_TRIPLE?=3D    ${HOST_CC_DUMPMACHINE}
> +.endif
>=20
> What do you think, should the code be instead:
>=20
> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} =
=3D=3D "")
> TARGET_ABI=3D    -gnueabihf
> .elif ${TARGET_ARCH:Marm*}
> TARGET_ABI=3D    -gnueabi
> .else
> TARGET_ABI=3D
> .endif
> VENDOR=3D        unknown
> OS_VERSION=3D    freebsd12.0
>=20
> TARGET_TRIPLE?=3D
> =
${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${T=
ARGET_ABI}
> +HOST_CC_DUMPMACHINE!=3D    cc -dumpmachine
> +BUILD_TRIPLE?=3D    ${HOST_CC_DUMPMACHINE}

No, this is definitely incorrect, as stated above.

-Dimitry


--Apple-Mail=_4487EF25-E903-4C28-9200-AB2D7E95F7F3
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename=signature.asc
Content-Type: application/pgp-signature;
	name=signature.asc
Content-Description: Message signed with OpenPGP

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.2

iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCWfRl/wAKCRCwXqMKLiCW
o8fKAJ9cFTHTwp5Xa5nkDxxiefnU9mgmhACgiunmA7tOZhsUH2EPq4GNJQ5Ruqc=
=9N23
-----END PGP SIGNATURE-----

--Apple-Mail=_4487EF25-E903-4C28-9200-AB2D7E95F7F3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CDAA0CB5-F1FC-40FE-AEC5-56FD64654671>