@@ -70,7 +70,7 @@ WARNING_FLAGS["armclang"] = WARNING_FLAGS["clang"]
7070TFM_CONFIG = "tfm_mbedcrypto_config_profile_medium.h"
7171TFM_CRYPTO_CONFIG = "crypto_config_profile_medium.h"
7272
73- Target = namedtuple ("Target" , ["compiler" , "arch" , "baremetal" , "isa" , "arch_isa" , "is_native" , "arm_arch" , "cflags" , "ldflags" , "config" ])
73+ Target = namedtuple ("Target" , ["compiler" , "compiler_family" , " arch" , "baremetal" , "isa" , "arch_isa" , "is_native" , "arm_arch" , "cflags" , "ldflags" , "config" ])
7474
7575
7676gitresult = subprocess .run (["git" , "rev-parse" , "--show-toplevel" ], stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
@@ -150,7 +150,7 @@ def toolchain_exes(target):
150150 triple_abi = "gnuabi64"
151151 triple = f"{ triple_arch } -linux-{ triple_abi } "
152152
153- if target .compiler == "gcc" :
153+ if target .compiler_family == "gcc" :
154154 if not target .is_native :
155155 # see https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
156156 if "-march" in target .cflags or "-mcpu" in target .cflags :
@@ -166,15 +166,25 @@ def toolchain_exes(target):
166166 if (v [0 ] == 'm' ): triple = "arm-linux-gnueabi"
167167 if "-mcpu=arm" in target .cflags : triple = "arm-linux-gnueabi"
168168
169- compiler_exe = f"{ triple } -gcc"
170- for i in range (25 , 1 , - 1 ):
171- if shutil .which (compiler_exe ) is not None : break
172- compiler_exe = f"{ triple } -gcc-{ i } "
169+ compiler_exe = f"{ triple } -{ target .compiler } "
170+ else :
171+ compiler_exe = target .compiler
172+
173+ if "-" not in target .compiler :
174+ # search for versioned compiler, e.g. "gcc-10", if version not already specified by user
175+ if shutil .which (compiler_exe ) is None :
176+ for i in range (25 , 1 , - 1 ):
177+ c = f"{ compiler_exe } -{ i } "
178+ if shutil .which (c ) is not None :
179+ compiler_exe = c
180+ break
173181
174182 if shutil .which (compiler_exe ) is None :
175183 compiler_exe = None
176184 if target .compiler == "gcc" :
177- compiler_error = f"could not locate gcc executable { triple } -gcc or { triple } -gcc-<majorversion>"
185+ compiler_error = f"could not locate gcc executable { compiler_exe } or { compiler_exe } -<majorversion>"
186+ elif target .compiler_family == "gcc" :
187+ compiler_error = f"could not locate gcc executable { compiler_exe } "
178188 else :
179189 compiler_error = f"could not locate { target .compiler } executable"
180190
@@ -230,18 +240,18 @@ def toolchain(target, exit_on_failure=True):
230240 # basic CFLAGS setup
231241 c_flags = f"-I{ ROOT } /include"
232242 if "-O" not in target .cflags :
233- if args .size_tfm and target . compiler in { "clang" , "armclang" } :
243+ if args .size_tfm and "clang" in target . compiler :
234244 c_flags += " -Oz"
235245 else :
236246 c_flags += " -Os"
237247 if "-std" not in target .cflags : c_flags += " -std=c99"
238248 if args .no_warnings :
239- if "clang" in target . compiler :
249+ if target . compiler_family == "clang" :
240250 c_flags += " -Wno-everything"
241251 else :
242252 c_flags += " -Wno-all -Wno-extra"
243253 else :
244- c_flags += " " + WARNING_FLAGS .get (target .compiler , "" )
254+ c_flags += " " + WARNING_FLAGS .get (target .compiler_family , "" )
245255 if target .cflags :
246256 c_flags += " " + target .cflags .strip ()
247257 c_flags = c_flags .strip ()
@@ -264,7 +274,7 @@ def toolchain(target, exit_on_failure=True):
264274 else :
265275 if exit_on_failure : error (f"unsupported ISA { target .isa } for armclang" )
266276
267- elif target .compiler == "gcc" :
277+ elif target .compiler_family == "gcc" :
268278 if not target .is_native :
269279 # see https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
270280 if not ("-march" in c_flags or "-mcpu" in c_flags ):
@@ -295,7 +305,7 @@ def toolchain(target, exit_on_failure=True):
295305 # Support AESNI intrinsics
296306 c_flags += " -mpclmul -msse2 -maes"
297307
298- elif target .compiler == "clang" :
308+ elif target .compiler_family == "clang" :
299309 if not target .is_native :
300310 # non-native clang build
301311 if target .arch == "armv5" and target .isa == "thumb1" :
@@ -665,7 +675,7 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
665675 # extract compilers
666676 args .compilers = [x [3 :].strip () for x in args .rest if x .startswith ("CC=" )]
667677 for x in list (args .rest ):
668- if x in ALL_COMPILERS :
678+ if x in ALL_COMPILERS or x . startswith ( "clang-" ) or x . startswith ( "gcc-" ) :
669679 args .compilers .append (x )
670680 args .rest .remove (x )
671681
@@ -793,8 +803,9 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
793803 else :
794804 target_config = config [:]
795805 target_config += config_xprod
796- t = Target (compiler = c , arch = a , baremetal = baremetal , isa = i , arch_isa = arch , is_native = arch == NATIVE_TARGET ,
797- arm_arch = arm_arch_v , cflags = cf , ldflags = ldflags , config = target_config )
806+ t = Target (compiler = c , compiler_family = c , arch = a , baremetal = baremetal , isa = i ,
807+ arch_isa = arch , is_native = arch == NATIVE_TARGET ,
808+ arm_arch = arm_arch_v , cflags = cf , ldflags = ldflags , config = target_config )
798809 args .targets .append (t )
799810 else :
800811 for c , arch in itertools .product (args .compilers , args .archs ):
@@ -804,9 +815,14 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
804815 a , i = arch , None
805816
806817 # determine if combo is valid for non-native compilers
807- # TODO handle e.g. CC=clang-15
818+ if c .startswith ("clang-" ):
819+ compiler_family = "clang"
820+ elif c .startswith ("gcc-" ):
821+ compiler_family = "gcc"
822+ else :
823+ compiler_family = c
808824 if arch != NATIVE_TARGET :
809- for x in NON_NATIVE_SUPPORT .get (c , []):
825+ for x in NON_NATIVE_SUPPORT .get (compiler_family , []):
810826 if "-" in x :
811827 sa , si = x .split ("-" )
812828 if (a == "" or a == sa ) and (i == "" or i == si ):
@@ -830,8 +846,9 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
830846 else :
831847 target_config = config [:]
832848 target_config += config_xprod
833- t = Target (compiler = c , arch = a , baremetal = baremetal , isa = i , arch_isa = arch , is_native = arch == NATIVE_TARGET ,
834- arm_arch = arm_arch_v , cflags = cflags , ldflags = ldflags , config = target_config )
849+ t = Target (compiler = c , compiler_family = compiler_family , arch = a , baremetal = baremetal ,
850+ isa = i , arch_isa = arch , is_native = arch == NATIVE_TARGET ,
851+ arm_arch = arm_arch_v , cflags = cflags , ldflags = ldflags , config = target_config )
835852 args .targets .append (t )
836853 if not args .targets :
837854 error ("no valid targets specified" )
0 commit comments