@@ -486,17 +486,33 @@ def pre_configure_hook_openblas_optarch_generic(self, *args, **kwargs):
486486 """
487487 Pre-configure hook for OpenBLAS: add DYNAMIC_ARCH=1 to build/test/install options when using --optarch=GENERIC
488488 """
489+ # note: OpenBLAS easyblock was updated in https://github.com/easybuilders/easybuild-easyblocks/pull/3492
490+ # to take care of this already, so at some point this hook can be removed...
489491 if self .name == 'OpenBLAS' :
490492 if build_option ('optarch' ) == OPTARCH_GENERIC :
493+ dynamic_arch = 'DYNAMIC_ARCH=1'
491494 for step in ('build' , 'test' , 'install' ):
492- self .cfg .update (f'{ step } opts' , "DYNAMIC_ARCH=1" )
495+ if dynamic_arch not in self .cfg [f'{ step } opts' ]:
496+ self .cfg .update (f'{ step } opts' , dynamic_arch )
493497
494- # use -mtune=generic rather than -mcpu=generic in $CFLAGS on aarch64,
495- # because -mcpu=generic implies a particular -march=armv* which clashes with those used by OpenBLAS
496- # when building with DYNAMIC_ARCH=1
497498 if get_cpu_architecture () == AARCH64 :
498- cflags = os .getenv ('CFLAGS' ).replace ('-mcpu=generic' , '-mtune=generic' )
499- env .setvar ('CFLAGS' , cflags )
499+ # when building for aarch64/generic, we also need to set TARGET=ARMV8 to make sure
500+ # that the driver parts of OpenBLAS are compiled generically;
501+ # see also https://github.com/OpenMathLib/OpenBLAS/issues/4945
502+ target_armv8 = 'TARGET=ARMV8'
503+ for step in ('build' , 'test' , 'install' ):
504+ if target_armv8 not in self .cfg [f'{ step } opts' ]:
505+ self .cfg .update (f'{ step } opts' , target_armv8 )
506+
507+ # use -mtune=generic rather than -mcpu=generic in $CFLAGS for aarch64/generic,
508+ # because -mcpu=generic implies a particular -march=armv* which clashes with those used by OpenBLAS
509+ # when building with DYNAMIC_ARCH=1
510+ mcpu_generic = '-mcpu=generic'
511+ cflags = os .getenv ('CFLAGS' )
512+ if mcpu_generic in cflags :
513+ cflags = cflags .replace (mcpu_generic , '-mtune=generic' )
514+ self .log .info ("Replaced -mcpu=generic with -mtune=generic in $CFLAGS" )
515+ env .setvar ('CFLAGS' , cflags )
500516 else :
501517 raise EasyBuildError ("OpenBLAS-specific hook triggered for non-OpenBLAS easyconfig?!" )
502518
0 commit comments