On 27 Oct 2017, at 08:23, Eddy Petrișor <eddy.petri...@gmail.com> wrote:
> 
> 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.
> 
> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
> TARGET_ABI=    -gnueabihf
> .elif ${TARGET_ARCH:Marm*}
> TARGET_ABI=    -gnueabi
> .else
> TARGET_ABI=
> .endif
> VENDOR=        unknown
> OS_VERSION=    freebsd12.0
> 
> TARGET_TRIPLE?=
> ${TARGET_ARCH:C/amd64/x86_64/:C/arm64/aarch64/}-${VENDOR}-${OS_VERSION}${TARGET_ABI}
> BUILD_TRIPLE?=
> ${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’s target machine (for example, ‘i686-pc-linux-gnu’)
  -and don’t 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
> 
> .if ${TARGET_ARCH:Marmv6*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
> TARGET_ABI=    -gnueabihf
> .elif ${TARGET_ARCH:Marm*}
> TARGET_ABI=    -gnueabi
> .else
> TARGET_ABI=
> .endif
> VENDOR=        unknown
> OS_VERSION=    freebsd12.0
> +BUILD_OS!=    uname -s
> +

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

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

No, this is definitely incorrect, as stated above.

-Dimitry

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to