rewrite perl scripts in universal shell

This commit is contained in:
Owen Rafferty 2022-05-12 18:58:10 -05:00
parent ce814e84dc
commit 42c7a27e6b
No known key found for this signature in database
GPG Key ID: A68B10E2554DEBCB
9 changed files with 4638 additions and 4635 deletions

View File

@ -245,7 +245,7 @@ endif()
if (APPLE AND DYNAMIC_ARCH AND BUILD_SHARED_LIBS)
set (CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
if (NOT NOFORTRAN)
if (NOT NOFORTRAN)
set (CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set (CMAKE_Fortran_CREATE_SHARED_LIBRARY
"sh -c 'cat ${CMAKE_BINARY_DIR}/CMakeFiles/openblas_shared.dir/objects*.rsp | xargs -n 1024 ar -ru libopenblas.a && exit 0' "
@ -395,7 +395,7 @@ if (BUILD_SHARED_LIBS AND NOT ${SYMBOLPREFIX}${SYMBOLSUFFIX} STREQUAL "")
endif()
add_custom_command(TARGET ${OpenBLAS_LIBNAME}_shared POST_BUILD
COMMAND perl ${PROJECT_SOURCE_DIR}/exports/gensymbol "objcopy" "${ARCH}" "${BU}" "${EXPRECISION_IN}" "${NO_CBLAS_IN}" "${NO_LAPACK_IN}" "${NO_LAPACKE_IN}" "${NEED2UNDERSCORES_IN}" "${ONLY_CBLAS_IN}" \"${SYMBOLPREFIX}\" \"${SYMBOLSUFFIX}\" "${BUILD_LAPACK_DEPRECATED}" > ${PROJECT_BINARY_DIR}/objcopy.def
COMMAND ${PROJECT_SOURCE_DIR}/exports/gensymbol "objcopy" "${ARCH}" "${BU}" "${EXPRECISION_IN}" "${NO_CBLAS_IN}" "${NO_LAPACK_IN}" "${NO_LAPACKE_IN}" "${NEED2UNDERSCORES_IN}" "${ONLY_CBLAS_IN}" \"${SYMBOLPREFIX}\" \"${SYMBOLSUFFIX}\" "${BUILD_LAPACK_DEPRECATED}" > ${PROJECT_BINARY_DIR}/objcopy.def
COMMAND objcopy -v --redefine-syms ${PROJECT_BINARY_DIR}/objcopy.def ${PROJECT_BINARY_DIR}/lib/lib${OpenBLAS_LIBNAME}.so
COMMENT "renaming symbols"
)

View File

@ -54,9 +54,9 @@ all: getarch_2nd
./getarch_2nd 1 >> $(TARGET_CONF)
$(TARGET_CONF): c_check f_check getarch
perl ./c_check $(TARGET_MAKE) $(TARGET_CONF) $(CC) $(TARGET_FLAGS) $(CFLAGS)
./c_check $(TARGET_MAKE) $(TARGET_CONF) $(CC) $(TARGET_FLAGS) $(CFLAGS)
ifneq ($(ONLY_CBLAS), 1)
perl ./f_check $(TARGET_MAKE) $(TARGET_CONF) $(FC) $(TARGET_FLAGS)
./f_check $(TARGET_MAKE) $(TARGET_CONF) $(FC) $(TARGET_FLAGS)
else
#When we only build CBLAS, we set NOFORTRAN=2
echo "NOFORTRAN=2" >> $(TARGET_MAKE)
@ -71,8 +71,8 @@ endif
getarch : getarch.c cpuid.S dummy $(CPUIDEMU)
avx512=$$(perl c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_AVX512); \
rv64gv=$$(perl c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_RV64GV); \
avx512=$$(./c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_AVX512); \
rv64gv=$$(./c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_RV64GV); \
$(HOSTCC) $(HOST_CFLAGS) $(EXFLAGS) $${avx512:+-D$${avx512}} $${rv64gv:+-D$${rv64gv}} -o $(@F) getarch.c cpuid.S $(CPUIDEMU)
getarch_2nd : getarch_2nd.c $(TARGET_CONF) dummy

790
c_check Normal file → Executable file
View File

@ -1,451 +1,413 @@
#!/usr/bin/env perl
#use File::Basename;
# use File::Temp qw(tempfile);
#!/bin/sh
# Checking cross compile
$hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
$hostarch = `uname -m | sed -e s/i.86/x86/`;
$hostarch = `uname -p` if ($hostos eq "AIX" || $hostos eq "SunOS");
chop($hostarch);
$hostarch = "x86_64" if ($hostarch eq "amd64");
$hostarch = "arm" if ($hostarch ne "arm64" && $hostarch =~ /^arm.*/);
$hostarch = "arm64" if ($hostarch eq "aarch64");
$hostarch = "power" if ($hostarch =~ /^(powerpc|ppc).*/);
$hostarch = "zarch" if ($hostarch eq "s390x");
hostos=`uname -s | sed -e 's/\-.*//'`
hostarch=`uname -m | sed -e 's/i.86/x86/'`
if [ "$hostos" = "AIX" ] || [ "$hostos" = "SunOS" ]; then
hostarch=`uname -p`
fi
case "$hostarch" in
amd64) hostarch=x86_64 ;;
arm*) [ "$hostarch" = "arm64" ] || hostarch='arm' ;;
aarch64) hostarch=arm64 ;;
powerpc*|ppc*) hostarch=power ;;
s390x) hostarch=zarch ;;
esac
#$tmpf = new File::Temp( UNLINK => 1 );
$binary = $ENV{"BINARY"};
makefile="$1"
config="$2"
$makefile = shift(@ARGV);
$config = shift(@ARGV);
$compiler_name = shift(@ARGV);
$flags = join(" ", @ARGV);
compiler_name="$3"
shift 3
flags="$*"
# First, we need to know the target OS and compiler name
$data = `$compiler_name $flags -E ctest.c`;
if ($?) {
printf STDERR "C Compiler ($compiler_name) is something wrong.\n";
die 1;
{
data=`$compiler_name $flags -E ctest.c`
} || {
printf '%s\n' "C Compiler ($compiler_name) is something wrong." >&2
exit 1
}
$cross_suffix = "";
cross_suffix=""
eval "use File::Basename";
if ($@){
warn "could not load PERL module File::Basename, emulating its functionality";
my $dirnam = substr($compiler_name, 0, rindex($compiler_name, "/")-1 );
if ($dirnam ne ".") {
$cross_suffix .= $dirnam . "/";
}
my $basnam = substr($compiler_name, rindex($compiler_name,"/")+1, length($compiler_name)-rindex($compiler_name,"/")-1);
if ($basnam =~ /([^\s]*-)(.*)/) {
$cross_suffix .= $1;
}
} else {
if (dirname($compiler_name) ne ".") {
$cross_suffix .= dirname($compiler_name) . "/";
}
if [ "`dirname $compiler_name`" != '.' ]; then
cross_suffix="$cross_suffix`dirname $compiler_name`/"
fi
if (basename($compiler_name) =~ /([^\s]*-)(.*)/) {
$cross_suffix .= $1;
}
}
bn=`basename $compiler_name`
case "$bn" in
*-*) cross_suffix="$cross_suffix${bn%-*}-"
esac
$compiler = "";
$compiler = LSB if ($data =~ /COMPILER_LSB/);
$compiler = CLANG if ($data =~ /COMPILER_CLANG/);
$compiler = PGI if ($data =~ /COMPILER_PGI/);
$compiler = PATHSCALE if ($data =~ /COMPILER_PATHSCALE/);
$compiler = INTEL if ($data =~ /COMPILER_INTEL/);
$compiler = OPEN64 if ($data =~ /COMPILER_OPEN64/);
$compiler = SUN if ($data =~ /COMPILER_SUN/);
$compiler = IBM if ($data =~ /COMPILER_IBM/);
$compiler = DEC if ($data =~ /COMPILER_DEC/);
$compiler = GCC if ($compiler eq "");
compiler=""
case "$data" in
*COMPILER_LSB*) compiler=LSB ;;
*COMPILER_CLANG*) compiler=CLANG ;;
*COMPILER_PGI*) compiler=PGI ;;
*COMPILER_PATHSCALE*) compiler=PATHSCALE ;;
*COMPILER_INTEL*) compiler=INTEL ;;
*COMPILER_OPEN64*) compiler=OPEN64 ;;
*COMPILER_SUN*) compiler=SUN ;;
*COMPILER_IBM*) compiler=IBM ;;
*COMPILER_DEC*) compiler=DEC ;;
esac
if [ -z "$compiler" ]; then
compiler=GCC
fi
$os = Linux if ($data =~ /OS_LINUX/);
$os = FreeBSD if ($data =~ /OS_FREEBSD/);
$os = NetBSD if ($data =~ /OS_NETBSD/);
$os = OpenBSD if ($data =~ /OS_OPENBSD/);
$os = DragonFly if ($data =~ /OS_DRAGONFLY/);
$os = Darwin if ($data =~ /OS_DARWIN/);
$os = SunOS if ($data =~ /OS_SUNOS/);
$os = AIX if ($data =~ /OS_AIX/);
$os = osf if ($data =~ /OS_OSF/);
$os = WINNT if ($data =~ /OS_WINNT/);
$os = CYGWIN_NT if ($data =~ /OS_CYGWIN_NT/);
$os = Interix if ($data =~ /OS_INTERIX/);
$os = Android if ($data =~ /OS_ANDROID/);
$os = Haiku if ($data =~ /OS_HAIKU/);
case "$data" in *OS_LINUX*) os=Linux ;; esac
case "$data" in *OS_FREEBSD*) os=FreeBSD ;; esac
case "$data" in *OS_NETBSD*) os=NetBSD ;; esac
case "$data" in *OS_OPENBSD*) os=OpenBSD ;; esac
case "$data" in *OS_DRAGONFLY*) os=DragonFly ;; esac
case "$data" in *OS_DARWIN*) os=Darwin ;; esac
case "$data" in *OS_SUNOS*) os=SunOS ;; esac
case "$data" in *OS_AIX*) os=AIX ;; esac
case "$data" in *OS_OSF*) os=osf ;; esac
case "$data" in *OS_WINNT*) os=WINNT ;; esac
case "$data" in *OS_CYGWIN_NT*) os=CYGWIN_NT ;; esac
case "$data" in *OS_INTERIX*) os=Interix ;; esac
case "$data" in *OS_ANDROID*) os=Android ;; esac
case "$data" in *OS_HAIKU*) os=Haiku ;; esac
$architecture = x86 if ($data =~ /ARCH_X86/);
$architecture = x86_64 if ($data =~ /ARCH_X86_64/);
$architecture = e2k if ($data =~ /ARCH_E2K/);
$architecture = power if ($data =~ /ARCH_POWER/);
$architecture = mips if ($data =~ /ARCH_MIPS/);
$architecture = mips64 if ($data =~ /ARCH_MIPS64/);
$architecture = alpha if ($data =~ /ARCH_ALPHA/);
$architecture = sparc if ($data =~ /ARCH_SPARC/);
$architecture = ia64 if ($data =~ /ARCH_IA64/);
$architecture = arm if ($data =~ /ARCH_ARM/);
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
$architecture = riscv64 if ($data =~ /ARCH_RISCV64/);
$architecture = loongarch64 if ($data =~ /ARCH_LOONGARCH64/);
case "$data" in
*ARCH_X86_64*) architecture=x86_64 ;;
*ARCH_X86*) architecture=x86 ;;
*ARCH_E2K*) architecture=e2k ;;
*ARCH_POWER*) architecture=power ;;
*ARCH_MIPS64*) architecture=mips64 ;;
*ARCH_MIPS*) architecture=mips ;;
*ARCH_ALPHA*) architecture=alpha ;;
*ARCH_SPARC*) architecture=sparc ;;
*ARCH_IA64*) architecture=ia64 ;;
*ARCH_ARM64*) architecture=arm64 ;;
*ARCH_ARM*) architecture=arm ;;
*ARCH_ZARCH*) architecture=zarch ;;
*ARCH_RISCV64*) architecture=riscv64 ;;
*ARCH_LOONGARCH64*) architecture=loongarch64 ;;
esac
$defined = 0;
defined=0
if ($os eq "AIX") {
$compiler_name .= " -maix32" if ($binary eq "32");
$compiler_name .= " -maix64" if ($binary eq "64");
$defined = 1;
}
if [ "$os" = "AIX" ]; then
case "$BINARY" in
32) compiler_name="$compiler_name -maix32" ;;
64) compiler_name="$compiler_name -maix64" ;;
esac
defined=1
fi
if ($architecture eq "mips") {
$compiler_name .= " -mabi=32";
$defined = 1;
}
case "$architecture" in
mips)
compiler_name="$compiler_name -mabi=32"
defined=1
;;
mips64)
case "$BINARY" in
32) compiler_name="$compiler_name -mabi=n32" ;;
64) compiler_name="$compiler_name -mabi=64" ;;
esac
defined=1
;;
arm|arm64) defined=1 ;;
zarch|e2k|alpha|ia64|riscv64|loonarch64)
defined=1
BINARY=64
;;
x86)
[ "$os" != "Darwin" ] && [ "$os" != "SunOS" ] && {
defined=1
BINARY=32
}
;;
esac
if ($architecture eq "mips64") {
$compiler_name .= " -mabi=n32" if ($binary eq "32");
$compiler_name .= " -mabi=64" if ($binary eq "64");
$defined = 1;
}
case "$compiler" in
PGI)
case "$BINARY" in
32) compiler_name="$compiler_name -tp p7" ;;
64) compiler_name="$compiler_name -tp p7-64" ;;
esac
openmp='-mp'
defined=1
;;
IBM)
case "$BINARY" in
32) compiler_name="$compiler_name -q32" ;;
64) compiler_name="$compiler_name -q64" ;;
esac
openmp='-qsmp=omp'
defined=1
;;
INTEL) openmp='-openmp' ;;
PATHSCALE|OPEN64) openmp='-mp' ;;
CLANG|GCC|LSB) openmp='-fopenmp' ;;
esac
if (($architecture eq "arm") || ($architecture eq "arm64")) {
$defined = 1;
}
if ($architecture eq "zarch") {
$defined = 1;
$binary = 64;
}
if ($architecture eq "e2k") {
$defined = 1;
$binary = 64;
}
if ($architecture eq "alpha") {
$defined = 1;
$binary = 64;
}
if ($architecture eq "ia64") {
$defined = 1;
$binary = 64;
}
if (($architecture eq "x86") && ($os ne Darwin) && ($os ne SunOS)) {
$defined = 1;
$binary =32;
}
if ($architecture eq "riscv64") {
$defined = 1;
$binary = 64;
}
if ($architecture eq "loongarch64") {
$defined = 1;
$binary = 64;
}
if ($compiler eq "PGI") {
$compiler_name .= " -tp p7" if ($binary eq "32");
$compiler_name .= " -tp p7-64" if ($binary eq "64");
$openmp = "-mp";
$defined = 1;
}
if ($compiler eq "IBM") {
$compiler_name .= " -q32" if ($binary eq "32");
$compiler_name .= " -q64" if ($binary eq "64");
$openmp = "-qsmp=omp";
$defined = 1;
}
if ($compiler eq "INTEL") {
$openmp = "-openmp";
}
if ($compiler eq "PATHSCALE") {
$openmp = "-mp";
}
if ($compiler eq "OPEN64") {
$openmp = "-mp";
}
if ($compiler eq "CLANG") {
$openmp = "-fopenmp";
}
if ($compiler eq "GCC" || $compiler eq "LSB") {
$openmp = "-fopenmp";
}
if ($defined == 0) {
$compiler_name .= " -m32" if ($binary eq "32");
$compiler_name .= " -m64" if ($binary eq "64");
}
if [ "$defined" -eq 0 ]; then
case "$BINARY" in
32) compiler_name="$compiler_name -m32" ;;
64) compiler_name="$compiler_name -m64" ;;
esac
fi
# Do again
$data = `$compiler_name $flags -E ctest.c`;
if ($?) {
printf STDERR "C Compiler ($compiler_name) is something wrong.\n";
die 1;
}
$have_msa = 0;
if (($architecture eq "mips") || ($architecture eq "mips64")) {
eval "use File::Temp qw(tempfile)";
if ($@){
warn "could not load PERL module File::Temp, so could not check MSA capatibility";
} else {
$tmpf = new File::Temp( SUFFIX => '.c' , UNLINK => 1 );
$code = '"addvi.b $w0, $w1, 1"';
$msa_flags = "-mmsa -mfp64 -mload-store-pairs";
print $tmpf "#include <msa.h>\n\n";
print $tmpf "void main(void){ __asm__ volatile($code); }\n";
$args = "$msa_flags -o $tmpf.o $tmpf";
my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
system(@cmd) == 0;
if ($? != 0) {
$have_msa = 0;
} else {
$have_msa = 1;
}
unlink("$tmpf.o");
}
}
$architecture = x86 if ($data =~ /ARCH_X86/);
$architecture = x86_64 if ($data =~ /ARCH_X86_64/);
$architecture = e2k if ($data =~ /ARCH_E2K/);
$architecture = power if ($data =~ /ARCH_POWER/);
$architecture = mips if ($data =~ /ARCH_MIPS/);
$architecture = mips64 if ($data =~ /ARCH_MIPS64/);
$architecture = alpha if ($data =~ /ARCH_ALPHA/);
$architecture = sparc if ($data =~ /ARCH_SPARC/);
$architecture = ia64 if ($data =~ /ARCH_IA64/);
$architecture = arm if ($data =~ /ARCH_ARM/);
$architecture = arm64 if ($data =~ /ARCH_ARM64/);
$architecture = zarch if ($data =~ /ARCH_ZARCH/);
$architecture = loongarch64 if ($data =~ /ARCH_LOONGARCH64/);
$binformat = bin32;
$binformat = bin64 if ($data =~ /BINARY_64/);
$no_avx512= 0;
if (($architecture eq "x86") || ($architecture eq "x86_64")) {
eval "use File::Temp qw(tempfile)";
if ($@){
warn "could not load PERL module File::Temp, so could not check compiler compatibility with AVX512";
$no_avx512 = 0;
} else {
# $tmpf = new File::Temp( UNLINK => 1 );
($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 );
$code = '"vbroadcastss -4 * 4(%rsi), %zmm2"';
print $fh "#include <immintrin.h>\n\nint main(void){ __asm__ volatile($code); }\n";
$args = " -march=skylake-avx512 -c -o $tmpf.o $tmpf";
if ($compiler eq "PGI") {
$args = " -tp skylake -c -o $tmpf.o $tmpf";
}
my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
system(@cmd) == 0;
if ($? != 0) {
$no_avx512 = 1;
} else {
$no_avx512 = 0;
}
unlink("$tmpf.o");
}
}
$no_rv64gv= 0;
if (($architecture eq "riscv64")) {
eval "use File::Temp qw(tempfile)";
if ($@){
warn "could not load PERL module File::Temp, so could not check compiler compatibility with the RISCV vector extension";
$no_rv64gv = 0;
} else {
# $tmpf = new File::Temp( UNLINK => 1 );
($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 );
$code = '"vsetvli zero, zero, e8, m1\n"';
print $fh "int main(void){ __asm__ volatile($code); }\n";
$args = " -march=rv64gv -c -o $tmpf.o $tmpf";
my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
system(@cmd) == 0;
if ($? != 0) {
$no_rv64gv = 1;
} else {
$no_rv64gv = 0;
}
unlink("$tmpf.o");
}
}
$c11_atomics = 0;
if ($data =~ /HAVE_C11/) {
eval "use File::Temp qw(tempfile)";
if ($@){
warn "could not load PERL module File::Temp, so could not check compiler compatibility with C11";
$c11_atomics = 0;
} else {
($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 );
print $fh "#include <stdatomic.h>\nint main(void){}\n";
$args = " -c -o $tmpf.o $tmpf";
my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
system(@cmd) == 0;
if ($? != 0) {
$c11_atomics = 0;
} else {
$c11_atomics = 1;
}
unlink("$tmpf.o");
}
}
if ($compiler eq "GCC" &&( ($architecture eq "x86") || ($architecture eq "x86_64"))) {
$no_avx2 = 0;
$oldgcc = 0;
$data = `$compiler_name -dumpversion`;
if ($data <= 4.6) {
$no_avx2 = 1;
$oldgcc = 1;
}
}
$data = `$compiler_name $flags -S ctest1.c && grep globl ctest1.s | head -n 1 && rm -f ctest1.s`;
$data =~ /globl\s([_\.]*)(.*)/;
$need_fu = $1;
$cross = 0;
if ($architecture ne $hostarch) {
$cross = 1;
$cross = 0 if (($hostarch eq "x86_64") && ($architecture eq "x86"));
$cross = 0 if (($hostarch eq "mips64") && ($architecture eq "mips"));
}
$cross = 1 if ($os ne $hostos);
$cross = 0 if (($os eq "Android") && ($hostos eq "Linux") && ($ENV{TERMUX_APP_PID} != ""));
$openmp = "" if $ENV{USE_OPENMP} != 1;
$linker_L = "";
$linker_l = "";
$linker_a = "";
{
$link = `$compiler_name $flags -c ctest2.c -o ctest2.o 2>&1 && $compiler_name $flags $openmp -v ctest2.o -o ctest2 2>&1 && rm -f ctest2.o ctest2 ctest2.exe`;
$link =~ s/\-Y\sP\,/\-Y/g;
@flags = split(/[\s\,\n]/, $link);
# remove leading and trailing quotes from each flag.
@flags = map {s/^['"]|['"]$//g; $_} @flags;
foreach $flags (@flags) {
if (
($flags =~ /^\-L/)
&& ($flags !~ /^-LIST:/)
&& ($flags !~ /^-LANG:/)
) {
$linker_L .= $flags . " "
}
if ($flags =~ /^\-Y/) {
$linker_L .= "-Wl,". $flags . " "
}
if ($flags =~ /^\--exclude-libs/) {
$linker_L .= "-Wl,". $flags . " ";
$flags="";
}
if (
($flags =~ /^\-l/)
&& ($flags !~ /gfortranbegin/)
&& ($flags !~ /frtbegin/)
&& ($flags !~ /pathfstart/)
&& ($flags !~ /numa/)
&& ($flags !~ /crt[0-9]/)
&& ($flags !~ /gcc/)
&& ($flags !~ /user32/)
&& ($flags !~ /kernel32/)
&& ($flags !~ /advapi32/)
&& ($flags !~ /shell32/)
&& ($flags !~ /omp/)
&& ($flags !~ /[0-9]+/)
) {
$linker_l .= $flags . " "
}
$linker_a .= $flags . " " if $flags =~ /\.a$/;
}
data="$($compiler_name $flags -E ctest.c)"
} || {
printf '%s\n' "C Compiler ($compiler_name) is something wrong." >&2
exit 1
}
open(MAKEFILE, "> $makefile") || die "Can't create $makefile";
open(CONFFILE, "> $config" ) || die "Can't create $config";
have_msa=0
if [ "$architecture" = "mips" ] || [ "$architecture" = "mips64" ]; then
tmpd="$(mktemp -d)"
tmpf="$tmpd/a.c"
code='"addvi.b $w0, $w1, 1"'
msa_flags='-mmsa -mfp64 -mload-store-pairs'
printf "#include <msa.h>\n\n" >> "$tmpf"
printf "void main(void){ __asm__ volatile(%s); }\n" "$code" >> "$tmpf"
args="$msa_flags -o $tmpf.o $tmpf"
have_msa=1
{
$compiler_name $flags $args >/dev/null 2>&1
} || {
have_msa=0
}
rm -rf "$tmpd"
fi
case "$data" in
*ARCH_X86_64*) architecture=x86_64 ;;
*ARCH_X86*) architecture=x86 ;;
*ARCH_E2K*) architecture=e2k ;;
*ARCH_POWER*) architecture=power ;;
*ARCH_MIPS64*) architecture=mips64 ;;
*ARCH_MIPS*) architecture=mips ;;
*ARCH_ALPHA*) architecture=alpha ;;
*ARCH_SPARC*) architecture=sparc ;;
*ARCH_IA64*) architecture=ia64 ;;
*ARCH_ARM64*) architecture=arm64 ;;
*ARCH_ARM*) architecture=arm ;;
*ARCH_ZARCH*) architecture=zarch ;;
*ARCH_LOONGARCH64*) architecture=loongarch64 ;;
esac
binformat='bin32'
case "$data" in
*BINARY_64*) binformat='bin64' ;;
esac
no_avx512=0
if [ "$architecture" = "x86" ] || [ "$architecture" = "x86_64" ]; then
tmpd=`mktemp -d`
tmpf="$tmpd/a.c"
code='"vbroadcastss -4 * 4(%rsi), %zmm2"'
printf "#include <immintrin.h>\n\nint main(void){ __asm__ volatile(%s); }\n" "$code" >> "$tmpf"
if [ "$compiler" = "PGI" ]; then
args=" -tp skylake -c -o $tmpf.o $tmpf"
else
args=" -march=skylake-avx512 -c -o $tmpf.o $tmpf"
fi
no_avx512=0
{
$compiler_name $flags $args >/dev/null 2>&1
} || {
no_avx512=1
}
rm -rf "$tmpd"
fi
no_rv64gv=0
if [ "$architecture" = "riscv64" ]; then
tmpd=`mktemp -d`
tmpf="$tmpd/a.c"
code='"vsetvli zero, zero, e8, m1\n"'
printf "int main(void){ __asm__ volatile(%s); }\n" "$code" >> "$tmpf"
args=" -march=rv64gv -c -o $tmpf.o $tmpf"
no_rv64gv=0
{
$compiler_name $flags $args >/dev/null 2>&1
} || {
no_rv64gv=1
}
rm -rf "$tmpd"
fi
c11_atomics=0
case "$data" in
*HAVE_C11*)
tmpd=`mktemp -d`
tmpf="$tmpd/a.c"
printf "#include <stdatomic.h>\nint main(void){}\n" >> "$tmpf"
args=' -c -o $tmpf.o $tmpf'
c11_atomics=1
{
$compiler_name $flags $args >/dev/null 2>&1
} || {
c11_atomics=0
}
rm -rf "$tmpd"
;;
esac
oldgcc=0
no_avx2=0
if [ "$compiler" = "GCC" ]; then
case "$architecture" in x86|x86_64)
no_avx2=0
oldgcc=0
data=`$compiler_name -dumpversion`
case "$data" in *.*.*)
data="${data%.*}"
esac
if awk -v n1=$data -v n2=4.6 'BEGIN { exit !(n1 <= n2) }'; then
no_avx2=1
oldgcc=1
fi
esac
fi
data=`$compiler_name $flags -S ctest1.c && grep globl ctest1.s | head -n 1 && rm -f ctest1.s`
need_fu=''
if echo "$data" | grep 'globl[[:space:]][_\.]'; then
need_fu="${data##*globl[[:space:]]}"
need_fu="${need_fu%%[!_\.]*}"
fi
cross=0
if [ "$architecture" != "$hostarch" ]; then
cross=1
[ "$hostarch" = "x86_64" ] && [ "$architecture" = "x86" ] && cross=0
[ "$hostarch" = "mips64" ] && [ "$architecture" = "mips" ] && cross=0
fi
[ "$os" != "$hostos" ] && cross=1
[ "$os" = "Android" ] && [ "$hostos" = "Linux" ] && [ -n "$TERMUX_APP_PID" ] \
&& cross=0
[ "$USE_OPENMP" != 1 ] && openmp=''
linker_L=""
linker_l=""
linker_a=""
link=`$compiler_name $flags -c ctest2.c -o ctest2.o 2>&1 && $compiler_name $flags $openmp -v ctest2.o -o ctest2 2>&1 && rm -f ctest2.o ctest2 ctest2.exe`
link=`echo "$link" | sed 's/\-Y[[:space:]]P\,/\-Y/g'`
flags=`echo $link | tr '[[:space:]],\n' ' '`
# Strip trailing quotes
old_flags="$flags"
flags=''
for flag in $old_flags; do
f=`echo "$flag" | tr '"' ' '`
flags="$flags $f"
done
for flag in $flags; do
case "$flag" in -L*)
case "$flag" in
-LIST:*|-LANG:*) ;;
*) linker_L="$linker_L $flag" ;;
esac
esac
case "$flag" in -Y*)
linker_L="$linker_L -Wl,$flag" ;;
esac
case "$flag" in --exclude-libs*)
linker_L="$linker_L -Wl,$flag"
flags=""
;;
esac
case "$flag" in -l*)
case "$flag" in
*gfortranbegin*|*frtbegin*|*pathfstart*|*numa*|*crt[0-9]*|\
*gcc*|*user32*|*kernel32*|*advapi32*|*shell32*|*omp*|\
*[0-9]*) ;;
*) linker_l="$linker_l $flag" ;;
esac
esac
case "$flag" in *.a) linker_a="$linker_a $flag" ;; esac
done
[ "$makefile" = "-" ] && {
[ "$no_rv64gv" -eq 1 ] && printf "NO_RV64GV=1\n"
[ "$no_avx512" -eq 1 ] && printf "NO_AVX512=1\n"
[ "$no_avx2" -eq 1 ] && printf "NO_AVX2=1\n"
[ "$oldgcc" -eq 1 ] && printf "OLDGCC=1\n"
exit 0
}
:> "$makefile" || exit 1
:> "$config" || exit 1
# print $data, "\n";
print MAKEFILE "OSNAME=$os\n";
print MAKEFILE "ARCH=$architecture\n";
print MAKEFILE "C_COMPILER=$compiler\n";
print MAKEFILE "BINARY32=\n" if $binformat ne bin32;
print MAKEFILE "BINARY64=\n" if $binformat ne bin64;
print MAKEFILE "BINARY32=1\n" if $binformat eq bin32;
print MAKEFILE "BINARY64=1\n" if $binformat eq bin64;
print MAKEFILE "FU=$need_fu\n" if $need_fu ne "";
print MAKEFILE "CROSS_SUFFIX=$cross_suffix\n" if $cross != 0 && $cross_suffix ne "";
print MAKEFILE "CROSS=1\n" if $cross != 0;
print MAKEFILE "CEXTRALIB=$linker_L $linker_l $linker_a\n";
print MAKEFILE "HAVE_MSA=1\n" if $have_msa eq 1;
print MAKEFILE "MSA_FLAGS=$msa_flags\n" if $have_msa eq 1;
print MAKEFILE "NO_RV64GV=1\n" if $no_rv64gv eq 1;
print MAKEFILE "NO_AVX512=1\n" if $no_avx512 eq 1;
print MAKEFILE "NO_AVX2=1\n" if $no_avx2 eq 1;
print MAKEFILE "OLDGCC=1\n" if $oldgcc eq 1;
{
printf "OSNAME=%s\n" "$os"
printf "ARCH=%s\n" "$architecture"
printf "C_COMPILER=%s\n" "$compiler"
[ $binformat != 'bin32' ] && printf "BINARY32=\n"
[ $binformat != 'bin64' ] && printf "BINARY64=\n"
[ "$binformat" = "bin32" ] && printf "BINARY32=1\n"
[ "$binformat" = "bin64" ] && printf "BINARY64=1\n"
[ -n "$need_fu" ] && printf 'FU=%s\n' "$need_fu"
[ "$cross" -ne 0 ] && [ -n "$cross_suffix" ] && \
printf "CROSS_SUFFIX=%s\n" "$cross_suffix"
[ "$cross" -ne 0 ] && printf "CROSS=1\n"
printf "CEXTRALIB=%s %s %s\n" "$linker_L" "$linker_l" "$linker_a"
[ "$have_msa" -eq 1 ] && {
printf "HAVE_MSA=1\n"
printf "MSA_FLAGS=%s\n" "$msa_flags"
}
[ "$no_rv64gv" -eq 1 ] && printf "NO_RV64GV=1\n"
[ "$no_avx512" -eq 1 ] && printf "NO_AVX512=1\n"
[ "$no_avx2" -eq 1 ] && printf "NO_AVX2=1\n"
[ "$oldgcc" -eq 1 ] && printf "OLDGCC=1\n"
} >> "$makefile"
$os =~ tr/[a-z]/[A-Z]/;
$architecture =~ tr/[a-z]/[A-Z]/;
$compiler =~ tr/[a-z]/[A-Z]/;
os=`echo "$os" | tr '[[:lower:]]' '[[:upper:]]'/ `
architecture=`echo "$architecture" | tr '[[:lower:]]' '[[:upper:]]' `
compiler=`echo "$compiler" | tr '[[:lower:]]' '[[:upper:]]' `
print CONFFILE "#define OS_$os\t1\n";
print CONFFILE "#define ARCH_$architecture\t1\n";
print CONFFILE "#define C_$compiler\t1\n";
print CONFFILE "#define __32BIT__\t1\n" if $binformat eq bin32;
print CONFFILE "#define __64BIT__\t1\n" if $binformat eq bin64;
print CONFFILE "#define FUNDERSCORE\t$need_fu\n" if $need_fu ne "";
print CONFFILE "#define HAVE_MSA\t1\n" if $have_msa eq 1;
print CONFFILE "#define HAVE_C11\t1\n" if $c11_atomics eq 1;
{
printf "#define OS_%s\t1\n" "$os"
printf "#define ARCH_%s\t1\n" "$architecture"
printf "#define C_%s\t1\n" "$compiler"
[ "$binformat" = "bin32" ] && printf "#define __32BIT__\t1\n"
[ "$binformat" = "bin64" ] && printf "#define __64BIT__\t1\n"
[ -n "$need_fu" ] && printf "#define FUNDERSCORE\t%s\n" "$need_fu"
[ "$have_msa" -eq 1 ] && printf "#define HAVE_MSA\t1\n"
[ "$c11_atomics" -eq 1 ] && printf "#define HAVE_C11\t1\n"
} >> "$config"
if ($os eq "LINUX") {
if [ "$os" = "LINUX" ]; then
# @pthread = split(/\s+/, `nm /lib/libpthread.so* | grep _pthread_create`);
# if ($pthread[2] ne "") {
# print CONFFILE "#define PTHREAD_CREATE_FUNC $pthread[2]\n";
# } else {
print CONFFILE "#define PTHREAD_CREATE_FUNC pthread_create\n";
printf "#define PTHREAD_CREATE_FUNC pthread_create\n" >> "$config"
# }
} else {
print CONFFILE "#define PTHREAD_CREATE_FUNC pthread_create\n";
}
close(MAKEFILE);
close(CONFFILE);
else
printf "#define PTHREAD_CREATE_FUNC pthread_create\n" >> "$config"
fi

View File

@ -53,8 +53,8 @@ endif()
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/openblas.def
#TARGET ${OpenBLAS_LIBNAME} PRE_LINK
COMMAND perl
ARGS "${PROJECT_SOURCE_DIR}/exports/gensymbol" "win2k" "${ARCH_IN}" "dummy" "${EXPRECISION_IN}" "${NO_CBLAS_IN}" "${NO_LAPACK_IN}" "${NO_LAPACKE_IN}" "${NEED2UNDERSCORES_IN}" "${ONLY_CBLAS_IN}" "${SYMBOLPREFIX}" "${SYMBOLSUFFIX}" > "${PROJECT_BINARY_DIR}/openblas.def"
COMMAND "${PROJECT_SOURCE_DIR}/exports/gensymbol"
ARGS "win2k" "${ARCH_IN}" "dummy" "${EXPRECISION_IN}" "${NO_CBLAS_IN}" "${NO_LAPACK_IN}" "${NO_LAPACKE_IN}" "${NEED2UNDERSCORES_IN}" "${ONLY_CBLAS_IN}" "${SYMBOLPREFIX}" "${SYMBOLSUFFIX}" > "${PROJECT_BINARY_DIR}/openblas.def"
COMMENT "Create openblas.def file"
VERBATIM)

View File

@ -199,12 +199,12 @@ if (DEFINED CORE AND CMAKE_CROSSCOMPILING AND NOT (${HOST_OS} STREQUAL "WINDOWSS
"#define HAVE_VFP\n"
"#define HAVE_NEON\n"
"#define ARMV8\n")
if ("${TCORE}" STREQUAL "CORTEXA57")
if ("${TCORE}" STREQUAL "CORTEXA57")
set(SGEMM_UNROLL_M 16)
set(SGEMM_UNROLL_N 4)
else ()
set(SGEMM_UNROLL_M 8)
set(SGEMM_UNROLL_N 8)
set(SGEMM_UNROLL_N 8)
endif ()
set(DGEMM_UNROLL_M 8)
set(DGEMM_UNROLL_N 4)
@ -603,7 +603,7 @@ endif ()
"#define GEMM_MULTITHREAD_THRESHOLD\t${GEMM_MULTITHREAD_THRESHOLD}\n")
# Move to where gen_config_h would place it
file(MAKE_DIRECTORY ${TARGET_CONF_DIR})
file(RENAME ${TARGET_CONF_TEMP} "${TARGET_CONF_DIR}/${TARGET_CONF}")
file(RENAME ${TARGET_CONF_TEMP} "${TARGET_CONF_DIR}/${TARGET_CONF}")
else(NOT CMAKE_CROSSCOMPILING)
# compile getarch
@ -639,7 +639,7 @@ else(NOT CMAKE_CROSSCOMPILING)
OUTPUT_VARIABLE GETARCH_LOG
COPY_FILE ${PROJECT_BINARY_DIR}/${GETARCH_BIN}
)
if (NOT ${GETARCH_RESULT})
MESSAGE(FATAL_ERROR "Compiling getarch failed ${GETARCH_LOG}")
endif ()

View File

@ -120,10 +120,10 @@ dll : ../$(LIBDLLNAME)
-Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB)
$(LIBPREFIX).def : gensymbol
perl ./gensymbol win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
./gensymbol win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
libgoto_hpl.def : gensymbol
perl ./gensymbol win2khpl $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
./gensymbol win2khpl $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
ifeq ($(OSNAME), Darwin)
INTERNALNAME = $(LIBPREFIX).$(MAJOR_VERSION).dylib
@ -266,23 +266,23 @@ static : ../$(LIBNAME)
rm -f goto.$(SUFFIX)
osx.def : gensymbol ../Makefile.system ../getarch.c
perl ./gensymbol osx $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
./gensymbol osx $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
aix.def : gensymbol ../Makefile.system ../getarch.c
perl ./gensymbol aix $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
./gensymbol aix $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
objcopy.def : gensymbol ../Makefile.system ../getarch.c
perl ./gensymbol objcopy $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
./gensymbol objcopy $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
objconv.def : gensymbol ../Makefile.system ../getarch.c
perl ./gensymbol objconv $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
./gensymbol objconv $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
test : linktest.c
$(CC) $(CFLAGS) $(LDFLAGS) -w -o linktest linktest.c ../$(LIBSONAME) -lm && echo OK.
rm -f linktest
linktest.c : gensymbol ../Makefile.system ../getarch.c
perl ./gensymbol linktest $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > linktest.c
./gensymbol linktest $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > linktest.c
clean ::
@rm -f *.def *.dylib __.SYMDEF* *.renamed

7686
exports/gensymbol Normal file → Executable file

File diff suppressed because it is too large Load Diff

731
f_check Normal file → Executable file
View File

@ -1,6 +1,16 @@
#!/usr/bin/env perl
#!/bin/sh
$hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
split() {
set -f
old_ifs=$IFS
IFS=$2
set -- $1
printf '%s ' "$@"
IFS=$old_ifs
set +f
}
hostos="$(uname -s | sed 's/\-.*//')"
#
# 1. Not specified
@ -12,407 +22,386 @@ $hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
# 2.2.2 Path is not correct, invalid compiler name, then gfortran is default with NOFORTRAN definition
#
$makefile = shift(@ARGV);
$config = shift(@ARGV);
makefile="$1"
config="$2"
$nofortran = 0;
nofortran=0
shift 2
compiler="$*"
compiler_bin="$1"
$compiler = join(" ", @ARGV);
$compiler_bin = shift(@ARGV);
# f77 is too ambiguous
$compiler = "" if $compiler eq "f77";
[ "$compiler" = "f77" ] && compiler=''
@path = split(/:/, $ENV{"PATH"});
path=`split "$PATH" ':'`
if ($compiler eq "") {
if [ -z "$compiler" ]; then
@lists = ("gfortran", "g95", "frt", "fort", "openf90", "openf95",
"sunf77", "sunf90", "sunf95",
"xlf95", "xlf90", "xlf",
"ppuf77", "ppuf95", "ppuf90", "ppuxlf",
"pathf90", "pathf95",
"pgf95", "pgf90", "pgf77", "pgfortran", "nvfortran",
"flang", "egfortran",
"ifort", "nagfor");
lists="gfortran g95 frt fort openf90 openf95
sunf77 sunf90 sunf95
xlf95 xlf90 xlf
ppuf77 ppuf95 ppuf90 ppuxlf
pathf90 pathf95
pgf95 pgf90 pgf77 pgfortran nvfortran
flang egfortran
ifort nagfor"
OUTER:
foreach $lists (@lists) {
foreach $path (@path) {
if (-x $path . "/" . $lists) {
$compiler = $lists;
$compiler_bin = $lists;
last OUTER;
for list in $lists; do
for p in $path; do
if [ -x "$p/$list" ]; then
compiler=$list
compiler_bin=$list
break 2
fi
done
done
fi
if [ -z "$compiler" ]; then
nofortran=1
compiler=gfortran
vendor=GFORTRAN
bu="_"
else
{
data="$(command -v "$compiler_bin" >/dev/null 2>&1)"
vendor=""
} && {
data=`$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`
if [ -z "$data" ]; then
data=`$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.c && rm -f ftest.c`
fi
case "$data" in *zhoge_*) bu=_ ;; esac
case "$data" in
*Fujitsu*)
vendor=FUJITSU
openmp='-Kopenmp'
;;
*GNU*|*GCC*)
v="${data##*GCC: *\) }"
v="${v%%\"*}"
major="${v%%.*}"
if [ "$major" -ge 4 ]; then
vendor=GFORTRAN
openmp='-fopenmp'
else
case "$compiler" in
*flang*)
vendor=FLANG
openmp='-fopenmp'
;;
*pgf*|*nvf*)
vendor=PGI
openmp='-mp'
;;
*)
vendor=G77
openmp=''
;;
esac
fi
;;
*g95*)
vendor=G95
openmp=''
;;
*Intel*)
vendor=INTEL
openmp='-fopenmp'
;;
*'Sun Fortran'*)
vendor=SUN
openmp='-xopenmp=parallel'
;;
*PathScale*)
vendor=PATHSCALE
openmp='-openmp'
;;
*Open64*)
vendor=OPEN64
openmp='-mp'
;;
*PGF*|*NVF*)
vendor=PGI
openmp='-mp'
;;
*'IBM XL'*)
vendor=IBM
openmp='-openmp'
;;
*NAG*)
vendor=NAG
openmp='-openmp'
;;
esac
# for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
data=`$compiler -O2 -S ftest3.f >/dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`
[ -z "$data" ] && {
data=`$compiler -O2 -S ftest3.f >/dev/null 2>&1 && cat ftest3.c && rm -f ftest3.c`
}
case "$data" in *' zho_ge__'*) need2bu=1 ;; esac
case "$vendor" in *G95*) [ "$NO_LAPACKE" != 1 ] && need2bu='' ;; esac
}
if [ -z "$vendor" ]; then
case "$compiler" in
*g77*)
vendor=G77
bu=_
openmp=''
;;
*g95*)
vendor=G95
bu=_
openmp=''
;;
*gfortran*)
vendor=GFORTRAN
bu=_
openmp='-fopenmp'
;;
*ifort*)
vendor=INTEL
bu=_
openmp='-fopenmp'
;;
*pathf*)
vendor=PATHSCALE
bu=_
openmp='-mp'
;;
*pgf*|*nvf*)
vendor=PGI
bu=_
openmp='-mp'
;;
*ftn*)
vendor=PGI
bu=_
openmp=-openmp
;;
*frt*)
vendor=FUJITSU
bu=_
openmp='-openmp'
;;
*sunf77*|*sunf90*|*sunf95*)
vendor=SUN
bu=_
openmp='-xopenmp=parallel'
;;
*ppuf*|*xlf*)
vendor=IBM
openmp='-openmp'
;;
*open64*)
vendor=OPEN64
openmp='-mp'
;;
*flang*)
vendor=FLANG
bu=_
openmp='-fopenmp'
;;
*nagfor*)
vendor=NAG
bu=_
openmp='-openmp'
;;
esac
if [ -z "$vendor" ]; then
nofortran=1
compiler="gfortran"
vendor=GFORTRAN
bu=_
openmp=''
fi
fi
fi
{
data=`command -v $compiler_bin >/dev/null 2>&1`
} && {
binary=$BINARY
[ "$USE_OPENMP" != 1 ] && openmp=''
case "$binary" in
32)
{
link=`$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
link=`$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
# for AIX
link=`$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
# for gfortran MIPS
mips_data=`$compiler_bin -E -dM - < /dev/null`
case "$mips_data" in
*_MIPS_ISA_MIPS64*)
link=`$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`
;;
*)
link=`$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`
;;
esac
} || {
binary=''
}
}
}
;;
64)
{
link=`$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
link=`$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
# for AIX
link=`$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
# for gfortran MIPS
link=`$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
# for nagfor
link=`$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`
} || {
binary=''
}
;;
esac
if [ -z "$binary" ]; then
link=`$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`
fi
}
if ($compiler eq "") {
if [ "$vendor" = "NAG" ]; then
link=`$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`
fi
linker_L=""
linker_l=""
linker_a=""
$nofortran = 1;
$compiler = "gfortran";
$vendor = GFORTRAN;
$bu = "_";
if [ -n "$link" ]; then
} else {
link=`echo "$link" | sed 's/\-Y[[:space:]]P\,/\-Y/g'`
$data = `which $compiler_bin > /dev/null 2> /dev/null`;
$vendor = "";
link=`echo "$link" | sed 's/\-R[[:space:]]*/\-rpath\%/g'`
if (!$?) {
link=`echo "$link" | sed 's/\-rpath[[:space:]]+/\-rpath\%/g'`
$data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
if ($data eq "") {
$data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.c && rm -f ftest.c`;
}
if ($data =~ /zhoge_/) {
$bu = "_";
}
link=`echo "$link" | sed 's/\-rpath-link[[:space:]]+/\-rpath-link\%/g'`
if ($data =~ /Fujitsu/) {
$vendor = FUJITSU;
$openmp = "-Kopenmp";
} elsif ($data =~ /GNU/ || $data =~ /GCC/ ) {
$data =~ s/\(+.*?\)+//g;
$data =~ /(\d+)\.(\d+).(\d+)/;
$major = $1;
$minor = $2;
if ($major >= 4) {
$vendor = GFORTRAN;
$openmp = "-fopenmp";
} else {
if ($compiler =~ /flang/) {
$vendor = FLANG;
$openmp = "-fopenmp";
} elsif ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
$vendor = PGI;
$openmp = "-mp";
} else {
$vendor = G77;
$openmp = "";
}
}
}
if ($data =~ /g95/) {
$vendor = G95;
$openmp = "";
}
if ($data =~ /Intel/) {
$vendor = INTEL;
$openmp = "-fopenmp";
}
if ($data =~ /Sun Fortran/) {
$vendor = SUN;
$openmp = "-xopenmp=parallel";
}
if ($data =~ /PathScale/) {
$vendor = PATHSCALE;
$openmp = "-openmp";
}
if ($data =~ /Open64/) {
$vendor = OPEN64;
$openmp = "-mp";
}
if ($data =~ /PGF/ || $data =~ /NVF/) {
$vendor = PGI;
$openmp = "-mp";
}
if ($data =~ /IBM XL/) {
$vendor = IBM;
$openmp = "-openmp";
}
if ($data =~ /NAG/) {
$vendor = NAG;
$openmp = "-openmp";
}
# for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
$data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
if ($data eq "") {
$data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.c && rm -f ftest3.c`;
}
if ($data =~ / zho_ge__/) {
$need2bu = 1;
}
if ($vendor =~ /G95/) {
if ($ENV{NO_LAPACKE} != 1) {
$need2bu = "";
}
}
}
if ($vendor eq "") {
if ($compiler =~ /g77/) {
$vendor = G77;
$bu = "_";
$openmp = "";
}
if ($compiler =~ /g95/) {
$vendor = G95;
$bu = "_";
$openmp = "";
}
if ($compiler =~ /gfortran/) {
$vendor = GFORTRAN;
$bu = "_";
$openmp = "-fopenmp";
}
if ($compiler =~ /ifort/) {
$vendor = INTEL;
$bu = "_";
$openmp = "-fopenmp";
}
if ($compiler =~ /pathf/) {
$vendor = PATHSCALE;
$bu = "_";
$openmp = "-mp";
}
if ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
$vendor = PGI;
$bu = "_";
$openmp = "-mp";
}
if ($compiler =~ /ftn/) {
$vendor = PGI;
$bu = "_";
$openmp = "-openmp";
}
if ($compiler =~ /frt/) {
$vendor = FUJITSU;
$bu = "_";
$openmp = "-openmp";
}
if ($compiler =~ /sunf77|sunf90|sunf95/) {
$vendor = SUN;
$bu = "_";
$openmp = "-xopenmp=parallel";
}
if ($compiler =~ /ppuf/) {
$vendor = IBM;
$openmp = "-openmp";
}
if ($compiler =~ /xlf/) {
$vendor = IBM;
$openmp = "-openmp";
}
if ($compiler =~ /open64/) {
$vendor = OPEN64;
$openmp = "-mp";
}
if ($compiler =~ /flang/) {
$vendor = FLANG;
$bu = "_";
$openmp = "-fopenmp";
}
if ($compiler =~ /nagfor/) {
$vendor = NAG;
$bu = "_";
$openmp = "-openmp";
}
if ($vendor eq "") {
$nofortran = 1;
$compiler = "gfortran";
$vendor = GFORTRAN;
$bu = "_";
$openmp = "";
}
}
}
$data = `which $compiler_bin > /dev/null 2> /dev/null`;
if (!$?) {
$binary = $ENV{"BINARY"};
$openmp = "" if $ENV{USE_OPENMP} != 1;
if ($binary == 32) {
$link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
if ($?) {
$link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
# for AIX
if ($?) {
$link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
#For gfortran MIPS
if ($?) {
$mips_data = `$compiler_bin -E -dM - < /dev/null`;
if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
$link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
} else {
$link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
}
$binary = "" if ($?);
}
if ($binary == 64) {
$link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
if ($?) {
$link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
# for AIX
if ($?) {
$link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
#For gfortran MIPS
if ($?) {
$link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
#For nagfor
if ($?) {
$link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
}
$binary = "" if ($?);
}
if ($binary eq "") {
$link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
}
if ( $vendor eq "NAG") {
$link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
}
$linker_L = "";
$linker_l = "";
$linker_a = "";
if ($link ne "") {
$link =~ s/\-Y\sP\,/\-Y/g;
$link =~ s/\-R\s*/\-rpath\%/g;
$link =~ s/\-rpath\s+/\-rpath\%/g;
$link =~ s/\-rpath-link\s+/\-rpath-link\%/g;
@flags = split(/[\s\,\n]/, $link);
flags=`echo "$link" | tr ',\n' ' '`
# remove leading and trailing quotes from each flag.
@flags = map {s/^['"]|['"]$//g; $_} @flags;
#@flags = map {s/^['"]|['"]$//g; $_} @flags;
foreach $flags (@flags) {
if (
($flags =~ /^\-L/)
&& ($flags !~ /^-LIST:/)
&& ($flags !~ /^-LANG:/)
) {
$linker_L .= $flags . " ";
}
for flag in $flags; do
case "$flag" in -L*)
case "$flag" in
-LIST:*|-LANG:*) ;;
*) linker_L="$linker_L $flag" ;;
esac
esac
if ($flags =~ /^\-Y/) {
next if ($hostos eq 'SunOS');
$linker_L .= "-Wl,". $flags . " ";
}
case "$flag" in -Y*)
[ "$hostos" = "SunOS" ] && continue
linker_L="$linker_L -Wl,$flag"
;;
esac
if ($flags =~ /^\--exclude-libs/) {
$linker_L .= "-Wl,". $flags . " ";
$flags="";
}
case "$flag" in --exclude-libs*)
linker_L="$linker_L -Wl,$flag"
flag=""
;;
esac
case "$flag" in -rpath%*)
flag=`echo "$flag" | sed 's/\%/\,/g'`
linker_L="$linker_L -Wl,$flag"
esac
if ($flags =~ /^\-rpath\%/) {
$flags =~ s/\%/\,/g;
$linker_L .= "-Wl,". $flags . " " ;
}
case "$flag" in -rpath-link%*)
flag=`echo "$flag" | sed 's/\%/\,/g'`
linker_L="$linker_L -Wl,$flag"
;;
esac
if ($flags =~ /^\-rpath-link\%/) {
$flags =~ s/\%/\,/g;
$linker_L .= "-Wl,". $flags . " " ;
}
if ($flags =~ /-lgomp/ && $ENV{"CC"} =~ /clang/) {
$flags = "-lomp";
}
case "$flag" in *-lgomp*)
case "$CC" in *clang*)
flag="-lomp"
;;
esac
esac
if (
($flags =~ /^\-l/)
&& ($flags !~ /ibrary/)
&& ($flags !~ /gfortranbegin/)
&& ($flags !~ /flangmain/)
&& ($flags !~ /frtbegin/)
&& ($flags !~ /pathfstart/)
&& ($flags !~ /crt[0-9]/)
&& ($flags !~ /gcc/)
&& ($flags !~ /user32/)
&& ($flags !~ /kernel32/)
&& ($flags !~ /advapi32/)
&& ($flags !~ /shell32/)
&& ($flags !~ /omp/ || ($vendor !~ /PGI/ && $vendor !~ /FUJITSU/ && $flags =~ /omp/))
&& ($flags !~ /[0-9]+/ || ($vendor == FUJITSU && $flags =~ /^-lfj90/))
&& ($flags !~ /^\-l$/)
) {
$linker_l .= $flags . " ";
}
case "$flag" in -l*)
case "$flag" in
*ibrary*|*gfortranbegin*|*flangmain*|*frtbegin*|*pathfstart*|\
*crt[0-9]*|*gcc*|*user32*|*kernel32*|*advapi32*|*shell32*|\
-l) ;;
*omp*)
case "$vendor" in
*PGI*|*FUJITSU*) ;;
*) linker_l="$linker_l $flag" ;;
esac
;;
*[0-9]*)
if [ "$vendor" = "FUJITSU" ]; then
case "$flag" in
-lfj90*) linker_l="$linker_l $flag" ;;
*) ;;
esac
fi
;;
*) linker_l="$linker_l $flag" ;;
esac
esac
if ( $flags =~ /quickfit.o/ && $vendor == NAG) {
$linker_l .= $flags . " ";
}
if ( $flags =~ /safefit.o/ && $vendor == NAG) {
$linker_l .= $flags . " ";
}
if ( $flags =~ /thsafe.o/ && $vendor == NAG) {
$linker_l .= $flags . " ";
}
case "$flag" in *quickfit.o*)
[ "$vendor" = "NAG" ] && linker_l="$linker_l $flag" ;;
esac
$linker_a .= $flags . " " if $flags =~ /\.a$/;
}
case "$flag" in *safefit.o*)
[ "$vendor" = "NAG" ] && linker_l="$linker_l $flag" ;;
esac
}
case "$flag" in *thsafe.o*)
[ "$vendor" = "NAG" ] && linker_l="$linker_l $flag" ;;
esac
if ($vendor eq "FLANG"){
$linker_a .= "-lflang"
}
case "$flag" in *.a) linker_a="$linker_a $flag" ;; esac
done
fi
open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
open(CONFFILE, ">> $config" ) || die "Can't append $config";
if [ "$vendor" = "FLANG" ]; then
linker_a="$linker_a -lflang"
fi
print MAKEFILE "F_COMPILER=$vendor\n";
print MAKEFILE "FC=$compiler\n";
print MAKEFILE "BU=$bu\n" if $bu ne "";
print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
printf "F_COMPILER=%s\n" "$vendor" >> "$makefile"
printf "FC=%s\n" "$compiler" >> "$makefile"
[ -n "$bu" ] && printf 'BU=%s\n' "$bu" >> "$makefile"
[ "$nofortran" -eq 1 ] && printf 'NOFORTRAN=1\n' >> "$makefile"
print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
[ -n "$bu" ] && printf '#define BUNDERSCORE\t%s\n' "$bu" >> "$config"
[ -n "$bu" ] && printf '#define NEEDBUNDERSCORE\t1\n' >> "$config"
[ -n "$need2bu" ] && printf "#define NEED2UNDERSCORES\t1\n" >> "$config"
print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
[ -n "$need2bu" ] && printf "#define NEED2UNDERSCORES=1\n" >> "$config"
if (($linker_l ne "") || ($linker_a ne "")) {
print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";
}
if [ -n "$linker_l" ] || [ -n "$linker_a" ]; then
printf "FEXTRALIB=%s %s %s\n" "$linker_L" "$linker_l" "$linker_a" >> "$makefile"
fi
close(MAKEFILE);
close(CONFFILE);

View File

@ -1,22 +1,22 @@
#!/usr/bin/env perl
#!/bin/sh
$count = 0;
count=0
foreach (@ARGV) {
print "#define\tinterface_", $_, "\t\t", $count, "\n";
$count ++;
}
for arg in "$@"; do
printf "#define\tinterface_%s\t\t%d\n" "$arg" "$count"
count=`expr $count + 1`
done
print "#ifdef USE_FUNCTABLE\n";
printf "#ifdef USE_FUNCTABLE\n"
print "#define MAX_PROF_TABLE ", $count, "\n";
printf "#define MAX_PROF_TABLE %d\n" "$count"
print "static char *func_table[] = {\n";
printf "static char *func_table[] = {\n"
foreach (@ARGV) {
print "\"", $_, "\",\n";
}
for arg in "$@"; do
printf "\"%s\",\n" "$arg"
done
print "};\n";
print "#endif\n";
printf "};\n"
printf "#endif\n"