termux-packages/packages/lfortran/src-bin-lfortran.cpp.patch

73 lines
2.3 KiB
Diff

--- a/src/bin/lfortran.cpp
+++ b/src/bin/lfortran.cpp
@@ -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@";
+ 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;
+#ifdef __ANDROID__
+ std::cerr << "Or install this package through \"pkg install libkokkos\"." << std::endl;
+#endif
throw LCompilers::LCompilersException("LFORTRAN_KOKKOS_DIR is not defined");
}
@@ -1086,7 +1099,11 @@
out << src;
}
+#ifdef __ANDROID__
+ std::string CXX = "clang++";
+#else
std::string CXX = "g++";
+#endif
std::string options;
if (compiler_options.openmp) {
options += "-fopenmp ";
@@ -1240,7 +1257,11 @@
}
return 0;
} else if (backend == Backend::cpp) {
+#ifdef __ANDROID__
+ std::string CXX = "clang++";
+#else
std::string CXX = "g++";
+#endif
std::string options, post_options;
if (static_executable) {
options += " -static ";
@@ -1250,8 +1271,13 @@
}
if (kokkos) {
std::string kokkos_dir = get_kokkos_dir();
- post_options += kokkos_dir + "/lib/libkokkoscontainers.a "
- + kokkos_dir + "/lib/libkokkoscore.a -ldl";
+ if (static_executable) {
+ post_options += kokkos_dir + "/lib/libkokkoscontainers.a "
+ + kokkos_dir + "/lib/libkokkoscore.a -ldl";
+ } else {
+ post_options += kokkos_dir + "/lib/libkokkoscontainers.so "
+ + kokkos_dir + "/lib/libkokkoscore.so -ldl";
+ }
}
std::string cmd = CXX + options + " -o " + outfile + " ";
for (auto &s : infiles) {