lfortran: enable llvm

This commit is contained in:
Chongyun Lee 2022-12-02 21:22:21 +08:00 committed by Uchiha Kakashi
parent 609ee0f0d5
commit cf2dd5dd0c
2 changed files with 33 additions and 21 deletions

View File

@ -3,9 +3,16 @@ TERMUX_PKG_DESCRIPTION="A modern open-source interactive Fortran compiler"
TERMUX_PKG_LICENSE="BSD 3-Clause"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.18.0
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://github.com/lfortran/lfortran.git
TERMUX_PKG_DEPENDS="clang, libc++, libkokkos, zlib"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="-DBUILD_SHARED_LIBS=ON"
TERMUX_PKG_DEPENDS="clang, libc++, libllvm, zlib"
TERMUX_PKG_BUILD_DEPENDS="libllvm-static"
TERMUX_PKG_SUGGESTS="libkokkos"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DBUILD_SHARED_LIBS=ON
-DWITH_LLVM=yes
-DLLVM_DIR=$TERMUX_PREFIX/lib/cmake/llvm
"
TERMUX_PKG_HOSTBUILD=true
# ```

View File

@ -1,25 +1,39 @@
--- a/src/bin/lfortran.cpp
+++ b/src/bin/lfortran.cpp
@@ -95,10 +95,15 @@
@@ -2,6 +2,10 @@
#include <iostream>
#include <stdlib.h>
+#ifdef __ANDROID__
+#include <unistd.h>
+#endif
+
#define CLI11_HAS_FILESYSTEM 0
#include <bin/CLI11.hpp>
@@ -93,9 +97,18 @@
{
char *env_p = std::getenv("LFORTRAN_KOKKOS_DIR");
if (env_p) return env_p;
+#ifdef __ANDROID__
+ static std::string lfortran_kokkos_dir_default = "@TERMUX_PREFIX@";
+ return lfortran_kokkos_dir_default;
+#else
+ if (access((lfortran_kokkos_dir_default + "/lib/libkokkoscore.so").c_str(), R_OK) == 0) {
+ return lfortran_kokkos_dir_default;
+ }
+#endif
std::cerr << "The code C++ generated by the C++ LFortran backend uses the Kokkos library" << std::endl;
std::cerr << "(https://github.com/kokkos/kokkos). Please define the LFORTRAN_KOKKOS_DIR" << std::endl;
std::cerr << "environment variable to point to the Kokkos installation." << std::endl;
throw LFortran::LCompilersException("LFORTRAN_KOKKOS_DIR is not defined");
+#ifdef __ANDROID__
+ std::cerr << "Or install this package through \"pkg install libkokkos\"." << std::endl;
+#endif
throw LFortran::LCompilersException("LFORTRAN_KOKKOS_DIR is not defined");
}
#ifdef HAVE_LFORTRAN_LLVM
@@ -1082,7 +1087,11 @@
@@ -1086,7 +1099,11 @@
out << src;
}
+#ifdef __ANDROID__
+ std::string CXX = "clang++";
+#else
@ -28,7 +42,7 @@
std::string options;
if (compiler_options.openmp) {
options += "-fopenmp ";
@@ -1212,7 +1221,11 @@
@@ -1240,7 +1257,11 @@
}
return 0;
} else if (backend == Backend::cpp) {
@ -40,7 +54,7 @@
std::string options, post_options;
if (static_executable) {
options += " -static ";
@@ -1222,8 +1235,13 @@
@@ -1250,8 +1271,13 @@
}
if (kokkos) {
std::string kokkos_dir = get_kokkos_dir();
@ -56,12 +70,3 @@
}
std::string cmd = CXX + options + " -o " + outfile + " ";
for (auto &s : infiles) {
@@ -1304,7 +1322,7 @@
bool show_asm = false;
bool time_report = false;
bool static_link = false;
- std::string arg_backend = "llvm";
+ std::string arg_backend = "cpp";
std::string arg_kernel_f;
bool print_targets = false;