1# SPDX-License-Identifier: BSD-2-Clause
2#
3# RCSid:
4#	$Id: host-target.mk,v 1.20 2024/02/17 17:26:57 sjg Exp $
5#
6#	@(#) Copyright (c) 2007-2023 Simon J. Gerraty
7#
8#	This file is provided in the hope that it will
9#	be of use.  There is absolutely NO WARRANTY.
10#	Permission to copy, redistribute or otherwise
11#	use this file is hereby granted provided that
12#	the above copyright notice and this notice are
13#	left intact.
14#
15#	Please send copies of changes and bug-fixes to:
16#	sjg@crufty.net
17
18# Host platform information; may be overridden
19.if !target(__${.PARSEFILE}__)
20__${.PARSEFILE}__: .NOTMAIN
21
22.if !defined(_HOST_OSNAME)
23# use .MAKE.OS if available
24_HOST_OSNAME := ${.MAKE.OS:U${uname -s:L:sh}}
25.export _HOST_OSNAME
26.endif
27.if !defined(_HOST_OSREL)
28_HOST_OSREL  !=	uname -r
29.export _HOST_OSREL
30.endif
31.if !defined(_HOST_ARCH)
32_HOST_ARCH != uname -p 2> /dev/null || uname -m
33# uname -p may produce garbage on linux
34.if ${_HOST_ARCH:[\#]} > 1 || ${_HOST_ARCH:Nunknown} == ""
35_HOST_ARCH = ${_HOST_MACHINE}
36.elif ${_HOST_OSNAME:NDarwin} == "" && ${_HOST_ARCH:Narm:Ni386} == ""
37# _HOST_MACHINE is more explicit/useful
38_HOST_ARCH = ${_HOST_MACHINE}
39.endif
40.export _HOST_ARCH
41.endif
42.if !defined(_HOST_MACHINE)
43_HOST_MACHINE != uname -m
44# just in case
45_HOST_ARCH := ${_HOST_ARCH}
46# uname -m may produce garbage on darwin ppc
47.if ${_HOST_MACHINE:[\#]} > 1
48_HOST_MACHINE := ${_HOST_ARCH}
49.endif
50.export _HOST_MACHINE
51.endif
52.if !defined(HOST_MACHINE)
53HOST_MACHINE := ${_HOST_MACHINE}
54.export HOST_MACHINE
55.endif
56
57HOST_OSMAJOR := ${_HOST_OSREL:C/[^0-9].*//}
58HOST_OSTYPE  :=	${_HOST_OSNAME:S,/,,g}-${_HOST_OSREL:C/\([^\)]*\)//}-${_HOST_ARCH}
59HOST_OS      :=	${_HOST_OSNAME}
60host_os      :=	${_HOST_OSNAME:tl}
61HOST_TARGET  := ${host_os:S,/,,g}${HOST_OSMAJOR}-${_HOST_ARCH}
62# sometimes we want HOST_TARGET32
63MACHINE32.amd64 = i386
64MACHINE32.x86_64 = i386
65.if !defined(_HOST_ARCH32)
66_HOST_ARCH32 := ${MACHINE32.${_HOST_ARCH}:U${_HOST_ARCH:S,64$,,}}
67.export _HOST_ARCH32
68.endif
69HOST_TARGET32 := ${host_os:S,/,,g}${HOST_OSMAJOR}-${_HOST_ARCH32}
70
71.export HOST_TARGET HOST_TARGET32
72
73# tr is insanely non-portable, accommodate the lowest common denominator
74TR ?= tr
75toLower = ${TR} 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
76toUpper = ${TR} 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
77
78.endif
79