Skip to content

Commit b6423d2

Browse files
committed
Fixed build files for Termux.
1 parent aca747d commit b6423d2

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if (LUA_LIBRARIES MATCHES "LUA_LIBRARIES-NOTFOUND")
4444
endif()
4545
else ()
4646
message(STATUS "Lua: using information from luarocks")
47-
endif()
47+
endif()
4848

4949
message(STATUS "Lua: " ${LUA})
5050
message(STATUS "Lua include: " ${LUA_INCLUDE_DIR})
@@ -54,6 +54,24 @@ enable_language(CXX)
5454
include_directories(src src/3rdParty ${LUA_INCLUDE_DIR})
5555
add_definitions(-std=c++17 -O3 -fPIC)
5656

57+
# Detect Android Termux environment
58+
# Termux typically has ANDROID_ROOT environment variable set and PREFIX points to Termux directory
59+
set(IS_TERMUX FALSE)
60+
if (DEFINED ENV{ANDROID_ROOT})
61+
# Check if PREFIX environment variable points to Termux directory
62+
if (DEFINED ENV{PREFIX})
63+
if ("$ENV{PREFIX}" MATCHES "com.termux")
64+
set(IS_TERMUX TRUE)
65+
message(STATUS "Detected Android Termux environment (via PREFIX: $ENV{PREFIX})")
66+
endif()
67+
endif()
68+
# Alternative check: verify if Termux installation path exists
69+
if (NOT IS_TERMUX AND EXISTS "/data/data/com.termux/files/usr")
70+
set(IS_TERMUX TRUE)
71+
message(STATUS "Detected Android Termux environment (via filesystem check)")
72+
endif()
73+
endif()
74+
5775
if (APPLE)
5876
add_compile_options(-Wno-deprecated-declarations)
5977
endif ()
@@ -70,6 +88,11 @@ set_target_properties(libyue PROPERTIES PREFIX "")
7088
set_target_properties(libyue PROPERTIES OUTPUT_NAME "yue")
7189
target_link_libraries(libyue ${LUA_LIBRARIES})
7290

91+
# Add YUE_NO_WATCHER macro for Termux environment
92+
if (IS_TERMUX)
93+
target_compile_definitions(libyue PRIVATE YUE_NO_WATCHER)
94+
endif()
95+
7396
add_executable(yue
7497
src/yuescript/ast.cpp
7598
src/yuescript/parser.cpp
@@ -154,6 +177,11 @@ else ()
154177
target_compile_options(yue PRIVATE -Wall -Wno-long-long -fPIC)
155178
endif()
156179

180+
# Add YUE_NO_WATCHER macro for Termux environment
181+
if (IS_TERMUX)
182+
target_compile_definitions(yue PRIVATE YUE_NO_WATCHER)
183+
endif()
184+
157185
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
158186
target_compile_definitions(yue PRIVATE DEBUG)
159187
elseif (${CMAKE_BUILD_TYPE} MATCHES "Release")
@@ -169,9 +197,9 @@ elseif (NOT (${CMAKE_SYSTEM_NAME} MATCHES "Haiku") AND NOT WIN32)
169197
else ()
170198
target_link_libraries(yue PRIVATE ${LUA_LIBRARIES})
171199
endif()
172-
200+
173201
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
174-
target_link_options(yue PRIVATE -lstdc++fs -ldl)
202+
target_link_options(yue PRIVATE -ldl)
175203
endif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
176204

177205
install(CODE "")

makefile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,42 @@ endif
5454
INCLUDES += -I $(SRC_PATH)/3rdParty/lua
5555
LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl
5656
endif
57+
58+
# Detect Android Termux environment
59+
# Termux typically has ANDROID_ROOT environment variable set and PREFIX points to Termux directory
60+
IS_TERMUX := false
61+
ANDROID_ROOT_VAR := $(shell echo $$ANDROID_ROOT)
62+
PREFIX_VAR := $(shell echo $$PREFIX)
63+
ifneq ($(ANDROID_ROOT_VAR),)
64+
# Check if PREFIX environment variable points to Termux directory
65+
ifneq ($(PREFIX_VAR),)
66+
ifneq ($(findstring com.termux,$(PREFIX_VAR)),)
67+
IS_TERMUX := true
68+
endif
69+
endif
70+
# Alternative check: verify if Termux installation path exists
71+
ifeq ($(IS_TERMUX),false)
72+
ifneq ($(shell test -d /data/data/com.termux/files/usr && echo yes),)
73+
IS_TERMUX := true
74+
endif
75+
endif
76+
endif
77+
78+
# Auto-set NO_WATCHER for Termux environment if not explicitly set
79+
ifeq ($(IS_TERMUX),true)
80+
ifeq ($(NO_WATCHER),)
81+
NO_WATCHER := true
82+
$(info Detected Android Termux environment, automatically setting NO_WATCHER=true)
83+
endif
84+
endif
85+
5786
ifeq ($(NO_WATCHER),true)
5887
COMPILE_FLAGS += -DYUE_NO_WATCHER
5988
endif
6089

6190
# Add platform related linker flag
6291
ifneq ($(UNAME_S),Darwin)
63-
LINK_FLAGS += -lstdc++fs -Wl,-E
92+
LINK_FLAGS += -Wl,-E
6493
PLAT = linux
6594
else
6695
LINK_FLAGS += -framework CoreFoundation -framework CoreServices

0 commit comments

Comments
 (0)