From cf2dd5dd0cd4348ee1dcdfe80d1d1b73f19d79ed Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Fri, 2 Dec 2022 21:22:21 +0800 Subject: [PATCH] lfortran: enable llvm --- packages/lfortran/build.sh | 11 ++++- packages/lfortran/src-bin-lfortran.cpp.patch | 43 +++++++++++--------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/packages/lfortran/build.sh b/packages/lfortran/build.sh index c46b13d976..77ffd5eb4c 100644 --- a/packages/lfortran/build.sh +++ b/packages/lfortran/build.sh @@ -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 # ``` diff --git a/packages/lfortran/src-bin-lfortran.cpp.patch b/packages/lfortran/src-bin-lfortran.cpp.patch index 0e26fb0082..a52290e68f 100644 --- a/packages/lfortran/src-bin-lfortran.cpp.patch +++ b/packages/lfortran/src-bin-lfortran.cpp.patch @@ -1,25 +1,39 @@ --- a/src/bin/lfortran.cpp +++ b/src/bin/lfortran.cpp -@@ -95,10 +95,15 @@ +@@ -2,6 +2,10 @@ + #include + #include + ++#ifdef __ANDROID__ ++#include ++#endif ++ + #define CLI11_HAS_FILESYSTEM 0 + #include + +@@ -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; -