Skip to content

Commit

Permalink
Add some Android-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Nov 23, 2024
1 parent 9af4c05 commit 86c04e0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 8 deletions.
5 changes: 5 additions & 0 deletions far/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ set_target_properties(far2m
PROPERTIES
ENABLE_EXPORTS TRUE)

if (DEFINED USELUA AND ${CMAKE_SYSTEM_NAME} MATCHES "Android")
target_include_directories(far2m PRIVATE ${LIBLUA_INCLUDE_DIR})
target_link_libraries(far2m PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libluajit.a)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_libraries(far2m
PRIVATE ${WINPORT}
Expand Down
16 changes: 16 additions & 0 deletions far/src/macro/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "headers.hpp"

#if defined(USELUA) && defined(__ANDROID__)
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#endif

#include "Bookmarks.hpp"
#include "clipboard.hpp"
#include "cmdline.hpp"
Expand Down Expand Up @@ -60,6 +68,14 @@ static long long msValues[constMsLAST];

int Log(const char* Format, ...)
{
#if defined(USELUA) && defined(__ANDROID__)
if (lua_open == nullptr && luaL_openlibs == nullptr) //ensure libluajit.a linkage
return 0;
// lua_State *L = lua_open();
// luaL_openlibs(L);
// lua_close(L);
#endif

va_list valist;
va_start(valist, Format);

Expand Down
10 changes: 6 additions & 4 deletions far/src/plug/PluginW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ static const MacroPrivateInfo MacroInfo
// This seems to prevent irregular segfaults related to unloading luafar.so in the process of Far termination.
static BOOL LoadLuafar()
{
#ifdef USELUA
#if !defined(USELUA)
return FALSE;
#elif defined(__ANDROID__)
return TRUE;
#else
// 1. Load Lua
const char *libs[] = {"libluajit-5.1.so", "liblua5.1.so", nullptr};
void *handle = nullptr;
Expand Down Expand Up @@ -463,9 +467,7 @@ static BOOL LoadLuafar()
Message(MSG_WARNING, 1, Msg::Error, L"Cannot load luafar.so", Msg::Ok);
}
return LuafarLoaded;
#else
return FALSE;
#endif // #ifdef USELUA
#endif // #if defined(USELUA)
}

void CreatePluginStartupInfo(Plugin *pPlugin, PluginStartupInfo *PSI, FarStandardFunctions *FSF)
Expand Down
5 changes: 5 additions & 0 deletions far/src/setattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "interf.hpp" // for BoxSymbols

#if defined __ANDROID__ && __ANDROID_API__ < 26
#define getpwent() (NULL)
#define setpwent() ((void)0)
#endif

struct FSFileFlagsSafe : FSFileFlags
{
FSFileFlagsSafe(const FARString &path, DWORD attrs)
Expand Down
8 changes: 8 additions & 0 deletions hlfviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ target_include_directories(${PROJECT_NAME} PRIVATE ../far/far2sdk)

set(INSTALL_DIR "${INSTALL_DIR}/Plugins/luafar/${PROJECT_NAME}")

if (${CMAKE_SYSTEM_NAME} MATCHES "Android")
target_link_libraries(${PROJECT_NAME} PUBLIC luafar)
set(LINK_FLAGS "-Wl,-rpath,../../")
else()
set(LINK_FLAGS "")
endif()

set_target_properties(${PROJECT_NAME}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${INSTALL_DIR}/plug"
LINK_FLAGS "${LINK_FLAGS}"
PREFIX ""
SUFFIX ".far-plug-wide")

Expand Down
6 changes: 5 additions & 1 deletion luafar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ add_custom_command(
DEPENDS ${SDK}/farplug-wide.h ${SDK}/farcolor.h ${SDK}/farkeys.h ${MAKEFLAGS} ${FARSRC}/DlgGuid.hpp
)

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(MYTIMER_C src/mytimer.c)
endif()

set(SOURCES
${CMAKE_CURRENT_BINARY_DIR}/farflags.c
src/bit64.c
Expand All @@ -23,7 +27,7 @@ set(SOURCES
src/luamacro.c
src/lusercontrol.c
src/lutf8lib.c
src/mytimer.c
${MYTIMER_C}
src/service.c
src/slnunico.c
src/sysutils.c
Expand Down
2 changes: 1 addition & 1 deletion luafar/src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -6277,7 +6277,7 @@ static int luaopen_far (lua_State *L)
lua_setfield(L, -2, "__index");
luaL_register(L, NULL, filefilter_methods);

#if !defined(__FreeBSD__) && !defined(__DragonFly__)
#if !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__ANDROID__)
lua_getglobal(L, "far");
lua_pushcfunction(L, luaopen_timer);
lua_call(L, 0, 1);
Expand Down
11 changes: 9 additions & 2 deletions luamacro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ target_include_directories(${PROJECT_NAME} PRIVATE ../far/far2sdk)

set(INSTALL_DIR "${INSTALL_DIR}/Plugins/luafar/${PROJECT_NAME}")

if (${CMAKE_SYSTEM_NAME} MATCHES "Android")
target_link_libraries(${PROJECT_NAME} PUBLIC luafar)
set(LINK_FLAGS "-Wl,-rpath,../../")
else()
set(LINK_FLAGS "")
endif()

set_target_properties(${PROJECT_NAME}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${INSTALL_DIR}/plug"
LINK_FLAGS "${LINK_FLAGS}"
PREFIX ""
SUFFIX ".far-plug-wide"
)
SUFFIX ".far-plug-wide")

function(Generate_Constants)
set(TRG "${INSTALL_DIR}/plug/constants.lua")
Expand Down

0 comments on commit 86c04e0

Please sign in to comment.