Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package request: flang #3719

Closed
kb-1000 opened this issue Apr 26, 2019 · 8 comments
Closed

Package request: flang #3719

kb-1000 opened this issue Apr 26, 2019 · 8 comments
Labels
fortran Issue is about Fortran related stuff, including gfortran help wanted Help is wanted in order to solve the issue package request A new package was requested

Comments

@kb-1000
Copy link
Contributor

kb-1000 commented Apr 26, 2019

Package description
This package is an LLVM-based Fortran compiler, and as GCC has been removed no Fortran compiler is available anymore.

Link to home page and sources

  1. Home page: https://flang-compiler.github.io
  2. Source code: /~https://github.com/flang-compiler/flang

Additional information
Have you compiled or tried to compile the package on device? No, as it looks like it needs a custom LLVM fork and I unfortunately have not enough space on-device for that.

@Grimler91
Copy link
Member

Might not be possible for 32 bit arches, see discussion in #3263

@kb-1000
Copy link
Contributor Author

kb-1000 commented Apr 26, 2019

Well, it could at least be built for 64-bit arches then

@Grimler91
Copy link
Member

@kb-1000 Yepp, that would be cool!

@Grimler91 Grimler91 added the package request A new package was requested label Apr 26, 2019
@ghost ghost added the help wanted Help is wanted in order to solve the issue label May 6, 2020
@ihsakashi ihsakashi mentioned this issue Mar 27, 2021
@licy183
Copy link
Member

licy183 commented Apr 26, 2022

I have just compiled classic flang successfully under a x86_64 termux docker container. Following are the steps, maybe helpful for cross-compile. But it seems that classic flang is not friendly to cross compile.

1. Get source

Follow the steps on the Flang Wiki.

mkdir -p flang-src-android && cd flang-src-android

INSTALL_PREFIX=$PREFIX/opt/classic-flang/install

# Targets to build should be one of: X86 PowerPC AArch64
CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
    -DLLVM_CONFIG=$INSTALL_PREFIX/bin/llvm-config \
    -DCMAKE_CXX_COMPILER=$INSTALL_PREFIX/bin/clang++ \
    -DCMAKE_C_COMPILER=$INSTALL_PREFIX/bin/clang \
    -DCMAKE_Fortran_COMPILER=$INSTALL_PREFIX/bin/flang 
    -DCMAKE_Fortran_COMPILER_ID=Flang \
    -DLLVM_TARGETS_TO_BUILD=X86"

git clone -b release_100 /~https://github.com/flang-compiler/classic-flang-llvm-project.git

git clone /~https://github.com/flang-compiler/flang.git

2. Apply some patches.

Patches
diff -uNr flang-src/classic-flang-llvm-project/clang/lib/Driver/ToolChain.cpp flang-src-android/classic-flang-llvm-project/clang/lib/Driver/ToolChain.cpp
--- flang-src/classic-flang-llvm-project/clang/lib/Driver/ToolChain.cpp	2022-04-17 14:35:26.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/clang/lib/Driver/ToolChain.cpp	2022-04-19 21:07:30.000000000 +0800
@@ -899,7 +899,7 @@
 
   switch (Type) {
   case ToolChain::CST_Libcxx:
-    CmdArgs.push_back("-lc++");
+    CmdArgs.push_back("-lc++_shared");
     break;
 
   case ToolChain::CST_Libstdcxx:
diff -uNr flang-src/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp flang-src-android/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp
--- flang-src/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp	2022-04-17 14:35:26.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp	2022-04-19 21:24:49.000000000 +0800
@@ -178,15 +178,7 @@
       A.render(Args, CmdArgs);
     }
   }
-
-  const std::string &customGCCName = D.getCCCGenericGCCName();
-  const char *GCCName;
-  if (!customGCCName.empty())
-    GCCName = customGCCName.c_str();
-  else if (D.CCCIsCXX()) {
-    GCCName = "g++";
-  } else
-    GCCName = "gcc";
+  const char *GCCName = "false";
 
   const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
   C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
@@ -548,7 +540,7 @@
       if (OnlyLibstdcxxStatic)
         CmdArgs.push_back("-Bdynamic");
     }
-    CmdArgs.push_back("-lm");
+    // CmdArgs.push_back("-lm");
   }
   // Silence warnings when linking C code with a C++ '-stdlib' argument.
   Args.ClaimAllArgs(options::OPT_stdlib_EQ);
@@ -582,6 +574,9 @@
 
       AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+      if (D.CCCIsCXX())
+        CmdArgs.push_back("-lm");
+
       if (WantPthread && !isAndroid)
         CmdArgs.push_back("-lpthread");
 
diff -uNr flang-src/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Linux.cpp flang-src-android/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Linux.cpp
--- flang-src/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Linux.cpp	2022-04-17 14:35:26.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/clang/lib/Driver/ToolChains/Linux.cpp	2022-04-26 15:43:01.338619668 +0800
@@ -194,8 +194,8 @@
   // FIXME: This is a bit of a hack. We should really unify this code for
   // reasoning about oslibdir spellings with the lib dir spellings in the
   // GCCInstallationDetector, but that is a more significant refactoring.
-  if (Triple.getArch() == llvm::Triple::x86 ||
-      Triple.getArch() == llvm::Triple::ppc)
+  if (!Triple.isAndroid() && (Triple.getArch() == llvm::Triple::x86 ||
+      Triple.getArch() == llvm::Triple::ppc))
     return "lib32";
 
   if (Triple.getArch() == llvm::Triple::x86_64 &&
@@ -451,7 +451,16 @@
     addPathIfExists(D, D.Dir + "/../lib", Paths);
 
   addPathIfExists(D, SysRoot + "/lib", Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  // addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  bool nativeBuild = MultiarchTriple == llvm::sys::getDefaultTargetTriple();
+  if (nativeBuild || !IsAndroid)
+    addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+
+  if (IsAndroid) {
+    addPathIfExists(D, SysRoot + "/usr/" + MultiarchTriple + "/lib", Paths);
+    addPathIfExists(D, "/system/" + OSLibDir, Paths);
+    ExtraOpts.push_back("-rpath=" + SysRoot + "/usr/lib");
+  }
 }
 
 ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const {
diff -uNr flang-src/classic-flang-llvm-project/llvm/tools/llvm-shlib/CMakeLists.txt flang-src-android/classic-flang-llvm-project/llvm/tools/llvm-shlib/CMakeLists.txt
--- flang-src/classic-flang-llvm-project/llvm/tools/llvm-shlib/CMakeLists.txt	2022-04-17 14:35:29.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/llvm/tools/llvm-shlib/CMakeLists.txt	2022-04-19 21:16:56.000000000 +0800
@@ -39,6 +39,7 @@
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
+     OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")) # FIXME: It should be "GNU ld for elf"
     configure_file(
     ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
diff -uNr flang-src/classic-flang-llvm-project/openmp/runtime/cmake/config-ix.cmake flang-src-android/classic-flang-llvm-project/openmp/runtime/cmake/config-ix.cmake
--- flang-src/classic-flang-llvm-project/openmp/runtime/cmake/config-ix.cmake	2022-04-17 14:35:29.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/openmp/runtime/cmake/config-ix.cmake	2022-04-19 21:19:10.000000000 +0800
@@ -60,7 +60,6 @@
 check_cxx_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG)
 check_cxx_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
 libomp_check_architecture_flag(-mmic LIBOMP_HAVE_MMIC_FLAG)
-libomp_check_architecture_flag(-m32 LIBOMP_HAVE_M32_FLAG)
 if(WIN32)
   if(MSVC)
     # Check Windows MSVC style flags.
diff -uNr flang-src/classic-flang-llvm-project/openmp/runtime/src/CMakeLists.txt flang-src-android/classic-flang-llvm-project/openmp/runtime/src/CMakeLists.txt
--- flang-src/classic-flang-llvm-project/openmp/runtime/src/CMakeLists.txt	2022-04-17 14:35:29.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/openmp/runtime/src/CMakeLists.txt	2022-04-19 21:18:04.000000000 +0800
@@ -49,6 +49,9 @@
 if(${LIBOMP_USE_HWLOC})
   include_directories(${LIBOMP_HWLOC_INSTALL_DIR}/include)
 endif()
+if(ANDROID)
+	include_directories(${LIBOMP_SRC_DIR}/android)
+endif()
 
 # Getting correct source files to build library
 set(LIBOMP_CXXFILES)
@@ -92,6 +95,9 @@
     libomp_append(LIBOMP_CXXFILES kmp_gsupport.cpp)
     libomp_append(LIBOMP_ASMFILES z_Linux_asm.S) # Unix assembly file
   endif()
+  if(ANDROID)
+    libomp_append(LIBOMP_CXXFILES android/nltypes_stubs.cpp)
+  endif()
   libomp_append(LIBOMP_CXXFILES thirdparty/ittnotify/ittnotify_static.cpp LIBOMP_USE_ITT_NOTIFY)
   libomp_append(LIBOMP_CXXFILES kmp_debugger.cpp LIBOMP_USE_DEBUGGER)
   libomp_append(LIBOMP_CXXFILES kmp_stats.cpp LIBOMP_STATS)
diff -uNr flang-src/classic-flang-llvm-project/openmp/runtime/src/android/nl_types.h flang-src-android/classic-flang-llvm-project/openmp/runtime/src/android/nl_types.h
--- flang-src/classic-flang-llvm-project/openmp/runtime/src/android/nl_types.h	1970-01-01 08:00:00.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/openmp/runtime/src/android/nl_types.h	2022-04-19 21:22:39.000000000 +0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef ANDROID_NLTYPES_H
+#define ANDROID_NLTYPES_H
+
+#include_next <nl_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+nl_catd  catopen(const char*, int);
+char*    catgets(nl_catd, int, int, const char*);
+int      catclose(nl_catd);
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
+#endif  /* ANDROID_NLTYPES_H */
diff -uNr flang-src/classic-flang-llvm-project/openmp/runtime/src/android/nltypes_stubs.cpp flang-src-android/classic-flang-llvm-project/openmp/runtime/src/android/nltypes_stubs.cpp
--- flang-src/classic-flang-llvm-project/openmp/runtime/src/android/nltypes_stubs.cpp	1970-01-01 08:00:00.000000000 +0800
+++ flang-src-android/classic-flang-llvm-project/openmp/runtime/src/android/nltypes_stubs.cpp	2022-04-19 21:23:40.000000000 +0800
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <nl_types.h>
+
+#include <errno.h>
+
+__attribute__((weak,visibility("hidden")))
+nl_catd catopen(const char*, int) {
+  return reinterpret_cast<nl_catd>(-1);
+}
+
+__attribute__((weak,visibility("hidden")))
+char* catgets(nl_catd, int, int, const char* message) {
+  return const_cast<char*>(message);
+}
+
+__attribute__((weak,visibility("hidden")))
+int catclose(nl_catd) {
+  // Since we didn't hand out a valid nl_catd, you can't be returning one to us.
+  errno = EBADF;
+  return -1;
+}

diff -uNr flang-src/flang/CMakeLists.txt flang-src-android/flang/CMakeLists.txt
--- flang-src/flang/CMakeLists.txt	2022-04-17 15:47:09.000000000 +0800
+++ flang-src-android/flang/CMakeLists.txt	2022-04-26 23:23:49.643854823 +0800
@@ -30,6 +30,10 @@
 if( ${TARGET_OS} STREQUAL "Linux" )
   set(OS "LINUX")
   set(OSNAME "Linux")
+# Android on-device building is an alias of linux
+elseif( ${TARGET_OS} STREQUAL "Android" )
+  set(OS "LINUX")
+  set(OSNAME "Linux")
 elseif( ${TARGET_OS} STREQUAL "Darwin" )
   set(OS "OSX")
   set(OSNAME "macOS")
@@ -301,6 +305,10 @@
   endif ()
 endif ()
 
+set(CMAKE_SHARED_LINKER_FLAGS "-L/data/data/com.termux/file/usr/lib -Wl,-ldl -Wl,-l:libunwind.a -Wl,--rpath=/data/data/com.termux/file/usr/lib")
+set(CMAKE_EXE_LINKER_FLAGS "-L/data/data/com.termux/file/usr/lib -Wl,-ldl -Wl,-l:libunwind.a -Wl,--rpath=/data/data/com.termux/file/usr/lib")
+set(CMAKE_MODULE_LINKER_FLAGS "-L/data/data/com.termux/file/usr/lib -Wl,-ldl -Wl,-l:libunwind.a -Wl,--rpath=/data/data/com.termux/file/usr/lib")
+
 if (APPLE)
   set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
 endif ()
diff -uNr flang-src/flang/runtime/flang/CMakeLists.txt flang-src-android/flang/runtime/flang/CMakeLists.txt
--- flang-src/flang/runtime/flang/CMakeLists.txt	2022-04-17 15:47:09.000000000 +0800
+++ flang-src-android/flang/runtime/flang/CMakeLists.txt	2022-04-26 23:23:06.073854857 +0800
@@ -517,7 +517,7 @@
 elseif (APPLE)
   target_link_libraries(flang_shared m)
 else()
-  target_link_libraries(flang_shared m rt)
+  target_link_libraries(flang_shared m posix-aio)
 endif()
 
 set(SHARED_LIBRARY FALSE)
diff -uNr flang-src/flang/runtime/flangrti/tempnam.c flang-src-android/flang/runtime/flangrti/tempnam.c
--- flang-src/flang/runtime/flangrti/tempnam.c	2022-04-17 15:47:09.000000000 +0800
+++ flang-src-android/flang/runtime/flangrti/tempnam.c	2022-04-26 16:24:05.418592963 +0800
@@ -64,7 +64,7 @@
 static char *
 gentmp(char *dir, char *pfx)
 {
-  extern long getpid(void);
+  extern pid_t getpid(void);
   extern long time(void *);
   char *buf;
   char *p, *q;
diff -uNr flang-src/flang/runtime/flangrti/trace_lin.c flang-src-android/flang/runtime/flangrti/trace_lin.c
--- flang-src/flang/runtime/flangrti/trace_lin.c	2022-04-17 15:47:09.000000000 +0800
+++ flang-src-android/flang/runtime/flangrti/trace_lin.c	2022-04-26 16:26:29.728591399 +0800
@@ -11,7 +11,9 @@
 #ifdef _WIN64
 #include <windows.h>
 #else
+#ifndef __ANDROID__
 #include <execinfo.h>
+#endif
 #include <unistd.h>
 #include <limits.h>
 #include <sys/types.h>
@@ -95,7 +97,14 @@
 /* walk the stack back */
 
 #define MAXTRACE (32 * 1024)
-
+#ifdef __ANDROID__
+void
+__abort_trace(int skip)
+{
+  // TODO: Maybe introduce libandroid-execinfo?
+  return;
+}
+#else
 void
 print_back_trace_line(char *bt_str, void const *const addr)
 {
@@ -200,7 +209,7 @@
   }
   free(strings);
 }
-
+#endif 
 /*
  * this routine is a signal handler, it prints a message and terminates the
  * process

diff -uNr flang-src/flang/runtime/libpgmath/CMakeLists.txt flang-src-android/flang/runtime/libpgmath/CMakeLists.txt
--- flang-src/flang/runtime/libpgmath/CMakeLists.txt	2022-04-17 15:47:09.000000000 +0800
+++ flang-src-android/flang/runtime/libpgmath/CMakeLists.txt	2022-04-26 16:20:49.228595089 +0800
@@ -44,6 +44,8 @@
 set(LIBPGMATH_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
 if ("${LIBPGMATH_SYSTEM_NAME}" STREQUAL "OpenBSD")
   set(LIBPGMATH_SYSTEM_NAME "Linux")
+elseif ("${LIBPGMATH_SYSTEM_NAME}" STREQUAL "Android")
+  set(LIBPGMATH_SYSTEM_NAME "Linux")
 endif ()
 
 set(LIBPGMATH_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")

A lot of them are from the libllvm packages. And some are needed to compile on Android as classic-flang may not recognize OS type Android.

3. Find a posix-aio implementation, and compile it then install it.

Classic flang needs posix aio, but Bionic libc doesn't provide it. I use stealth/aio and it seems to work fine.

clang -c aio.c -o aio.o
clang -shared aio.o -o libposix-aio.so
cp {aio.h,aio_abi.h} $PREFIX/include
cp libposix-aio.so $PREFIX/lib

4. Make llvm and flang-driver.

Just as the wiki.

cd classic-flang-llvm-project
mkdir -p build && cd build
# From the wiki and libllvm/build.sh
cmake $CMAKE_OPTIONS \
        -DCMAKE_C_COMPILER=$PREFIX/bin/clang \
        -DCMAKE_CXX_COMPILER=$PREFIX/bin/clang++ \
        -DLLVM_ENABLE_CLASSIC_FLANG=ON \
        -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;openmp;polly" \
        -DCLANG_DEFAULT_RTLIB=compiler-rt \
        -DLLVM_HOST_TRIPLE=x86_64-unknown-linux-android24 \
        -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-android24 \
        -DANDROID_PLATFORM_LEVEL=24 -DLLVM_ENABLE_PIC=ON \ 
        -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_INCLUDE_TESTS=OFF \
        -DCLANG_DEFAULT_CXX_STDLIB=libc++ -DCLANG_DEFAULT_LINKER=lld \
        -DCLANG_INCLUDE_TESTS=OFF -DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF \
        -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON -DLIBCXX_USE_COMPILER_RT=YES \
        -DLIBCXXABI_USE_COMPILER_RT=YES -DDEFAULT_SYSROOT=$(dirname $PREFIX) \
        -DLLVM_LINK_LLVM_DYLIB=ON -DLLDB_ENABLE_PYTHON=OFF -DLLVM_ENABLE_FFI=ON \
        -DLIBOMP_ENABLE_SHARED=FALSE -DOPENMP_ENABLE_LIBOMPTARGET=OFF \
        ../llvm

make
make install

ln -s $PREFIX/lib/{crtbegin_dynamic.o,crtbegin_so.o,crtend_android.o,crtend_so.o,libc++_shared.so,libposix-aio.so,libunwind.a} $INSTALL_PREFIX/lib

ln -s $INSTALL_PREFIX/lib/libLLVM-10.so $PREFIX/lib

ln -sr $INSTALL_PREFIX/lib/clang/10.0.1/lib/android $INSTALL_PREFIX/lib/clang/10.0.1/lib/linux 

(cd flang/runtime/libpgmath
 mkdir -p build && cd build
 cmake $CMAKE_OPTIONS \
    -DDEFAULT_SYSROOT=$(dirname $PREFIX) \
    -DCLANG_DEFAULT_RTLIB=compiler-rt \
    -DLLVM_HOST_TRIPLE=x86_64-none-linux-android \ -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-none-linux-android \ 
    -DLLVM_ENABLE_PIC=ON \
    ..
 make
 make install)

cd flang
mkdir -p build && cd build
cmake $CMAKE_OPTIONS -DFLANG_LLVM_EXTENSIONS=ON ..
make
make install

ln -s $INSTALL_PREFIX/lib/{libflang.so,libflangrti.so,libompstub.so,libpgmath.so} $PREFIX/lib

5. Test a program

program main
write(*,*) "Hello world"
end program main
$PREFIX/opt/classic-flang/install/bin/flang main.f90
./a.out

PS

  1. Seems that stealth/aio could provide the posix aio for Android. Maybe we could add it to the repo with name libandroid-posix-aio, but more tests are needed.
  2. <execinfo.h> has been introduced in API level 32. Maybe we could provide a lib named libandoid-execinfo. Ref: https://android.googlesource.com/platform/bionic/+/refs/heads/master/libc/bionic/execinfo.cpp.
  3. Is there any reason that we provide a lot of packages named libandroid-* rather than including them in one package, like the package libandroid-support?

@xtkoba
Copy link
Contributor

xtkoba commented Apr 26, 2022

libandroid-support only provides multibyte functionality, despite its name coming from upstream (NDK). I would prefer libandroid-multibyte for that.

As for other libandroid-* packages, they derive from various origins, like musl or BSD (directly or through Bionic codebase). So it is natural to have them separately packaged and maintained. Finally, libandroid-wordexp is licensed under a copyleft license, which may cause legal issues when aggregated with others.

@licy183
Copy link
Member

licy183 commented Apr 27, 2022

libandroid-support only provides multibyte functionality, despite its name coming from upstream (NDK). I would prefer libandroid-multibyte for that.

As for other libandroid-* packages, they derive from various origins, like musl or BSD (directly or through Bionic codebase). So it is natural to have them separately packaged and maintained. Finally, libandroid-wordexp is licensed under a copyleft license, which may cause legal issues when aggregated with others.

OK, thanks for your reply.

@xtkoba xtkoba added the fortran Issue is about Fortran related stuff, including gfortran label Dec 4, 2022
@joshcangit
Copy link

joshcangit commented Sep 22, 2023

There's some error building __ppc_intrinsics.f90.
Don't know how to fix it.

@twaik
Copy link
Member

twaik commented Oct 9, 2024

Fixed by 44c7f74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fortran Issue is about Fortran related stuff, including gfortran help wanted Help is wanted in order to solve the issue package request A new package was requested
Projects
None yet
Development

No branches or pull requests

6 participants