fix to use the correct version of linker flag depending on version of LLVM. Also check for existance of AOCC, also warn if AOCC version is different than AOMP version
@@ -4,15 +4,47 @@ TESTNAME = lto_teams
TESTSRC_MAIN = lto_teams.c
TESTSRC_AUX =
TESTSRC_ALL = $(TESTSRC_MAIN) $(TESTSRC_AUX)
-# ALT_LINKER = <PATH to AOCC ld.lld>
-ALT_LINKER = lld
-CFLAGS = -O3 -flto=thin -fuse-ld=$(ALT_LINKER)
+# NOTE: It is possible to test this with ROCM compiler by setting these two variables
+# export AOMP=/opt/rocm/llvm
+# export AOMP_GPU=`/opt/rocm/aomp/bin/mygpu`
+
+# FIXME: Change this to the correct location of AOCC llvm linker when released and installed
+AOCC ?= /opt/AMD/AOCC23-REL-BUILD-83
+_aocc_lld = $(shell ls $(AOCC)/bin/ld.lld 2>/dev/null)
+ifeq ($(_aocc_lld),)
+ $(info )
+ $(info ERROR Cannot find alternate linker $(AOCC)/bin/ld.lld )
+ $(info Check value of AOCC environment variable. AOCC=$(AOCC))
+ $(info )
+ $(error Alternate linker $(AOCC)/bin/ld.lld does not exist)
+endif
+_aocc_llvm_version=$(shell $(_aocc_lld) --version | grep "LLD" | cut -d" " -f2 | cut -d"." -f1)
+_aomp_llvm_version=$(shell $(AOMP)/bin/ld.lld --version | grep "LLD" | cut -d" " -f2 | cut -d"." -f1)
+ifneq ($(_aomp_llvm_version),$(_aocc_llvm_version))
+ $(info )
+ $(info WARNING LLVM version $(_aomp_llvm_version) is different that AOCC LLVM version $(_aocc_llvm_version) )
+ $(info Alternate linker is $(_aocc_lld) )
+ $(info )
+endif
+# The alternate linker flag changed to --ld-path in LLVM 12
+ifeq ($(_aomp_llvm_version),11)
+ _ldflag=-fuse-ld=
+else
+ _ldflag=--ld-path=
+endif
+
+# This fails when gnu linker does not have LLVM linker plugin
+#ALT_LINKER =
+# This option works because it the llvm linker that is part of AOMP installation
+#ALT_LINKER = $(ld_flag)lld
+# This option uses AOCC as the alternative linker called by AOMP driver
+ALT_LINKER = $(_ldflag)$(_aocc_lld)
+
+CFLAGS = -O3 -flto=thin $(ALT_LINKER)
CLANG = clang
OMP_BIN = $(AOMP)/bin/$(CLANG)
CC = $(OMP_BIN) $(VERBOSE)
-#-ccc-print-phases
-#"-\#\#\#"
include ../Makefile.rules
