xref: /freebsd/contrib/bmake/mk/compiler.mk (revision a91a246563dffa876a52f53a98de4af9fa364c52)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: compiler.mk,v 1.14 2024/02/19 00:05:50 sjg Exp $
4#
5#	@(#) Copyright (c) 2019, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18.if !target(__${.PARSEFILE}__)
19__${.PARSEFILE}__: .NOTMAIN
20
21.if ${MACHINE} == "common"
22COMPILER_TYPE = none
23COMPILER_VERSION = 0
24.endif
25.if empty(COMPILER_TYPE) || empty(COMPILER_VERSION)
26# gcc does not always say gcc
27_v != (${CC} --version) 2> /dev/null | \
28	${EGREP:Uegrep} -i 'clang|cc|[1-9]\.[0-9]|Free Software Foundation'; echo
29.if empty(COMPILER_TYPE)
30.if ${_v:Mclang} != ""
31COMPILER_TYPE = clang
32.elif ${_v:M[Gg][Cc][Cc]} != "" || ${_v:MFoundation*} != "" || ${CC:Ucc:T:M*gcc*} != ""
33COMPILER_TYPE = gcc
34.endif
35.endif
36.if empty(COMPILER_VERSION)
37COMPILER_VERSION != echo "${_v:M[1-9][0-9]*.[0-9]*}:[1]" | \
38	awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
39.endif
40.undef _v
41.endif
42# just in case we don't recognize compiler
43COMPILER_TYPE ?= unknown
44COMPILER_VERSION ?= 0
45.endif
46