Termux: build with make, install to $PREFIX, no nl_langinfo on Android

- bootstrap_termux.sh installs pkg-config/binutils, builds with make,
  runs the tests and installs into Termux's $PREFIX/bin.
- Makefile drops -lpthread on Android (pthreads are in bionic libc).
- TUI assumes UTF-8 on Android: nl_langinfo needs API 26, Termux
  targets 24. All sources compile for aarch64-linux-android24 (NDK 27).
This commit is contained in:
WHC
2026-10-05 01:55:49 +08:00
parent 2fde898da0
commit a77f27ed59
4 changed files with 29 additions and 20 deletions
+9 -2
View File
@@ -6,6 +6,13 @@ PKG_CONFIG ?= pkg-config
PREFIX ?= /usr/local PREFIX ?= /usr/local
DESTDIR ?= DESTDIR ?=
UNAME_S := $(shell uname -s 2>/dev/null) UNAME_S := $(shell uname -s 2>/dev/null)
UNAME_O := $(shell uname -o 2>/dev/null)
# Android (Termux): pthreads live in libc.
PTHREAD_LIBS := -lpthread
ifeq ($(UNAME_O),Android)
PTHREAD_LIBS :=
endif
# macOS: Homebrew ncurses/curl are keg-only, so point pkg-config at them. # macOS: Homebrew ncurses/curl are keg-only, so point pkg-config at them.
# (macOS ships GNU make 3.81, whose $(shell) ignores exported variables.) # (macOS ships GNU make 3.81, whose $(shell) ignores exported variables.)
@@ -41,7 +48,7 @@ PKG_LIBS := $(CURL_LIBS) $(CURSES_LIBS)
CPPFLAGS += -Iinclude -I$(SD_DIR)/include -I$(CJSON_DIR) -D_XOPEN_SOURCE_EXTENDED $(PKG_CFLAGS) CPPFLAGS += -Iinclude -I$(SD_DIR)/include -I$(CJSON_DIR) -D_XOPEN_SOURCE_EXTENDED $(PKG_CFLAGS)
LDFLAGS += -L$(SD_DIR) LDFLAGS += -L$(SD_DIR)
LDLIBS += -lsashidown -lm $(PKG_LIBS) -lpthread LDLIBS += -lsashidown -lm $(PKG_LIBS) $(PTHREAD_LIBS)
CORE_SRC = \ CORE_SRC = \
$(CJSON_DIR)/cJSON.c \ $(CJSON_DIR)/cJSON.c \
@@ -91,7 +98,7 @@ TESTS = \
tests/test_undo \ tests/test_undo \
tests/test_config tests/test_config
TEST_LIBS = -lm $(CURL_LIBS) -lpthread TEST_LIBS = -lm $(CURL_LIBS) $(PTHREAD_LIBS)
.PHONY: all clean check demo sashidown-lib cmake-gcc cmake-clang asan install uninstall .PHONY: all clean check demo sashidown-lib cmake-gcc cmake-clang asan install uninstall
+7 -2
View File
@@ -118,8 +118,13 @@ API Key:TUI 里输入并按 provider 保存到配置目录的 `credentials`(
### Termux ### Termux
```bash ```bash
pkg install clang make cmake libcurl ncurses-ui-libs # 一键:装依赖、克隆、编译、安装到 $PREFIX/bin
cmake -B build -DCST_BUILD_TUI=ON && cmake --build build curl -fsSL https://git.whcself.xyz/WHC/CST-agent/raw/branch/main/scripts/bootstrap_termux.sh | bash
# 或手动
pkg install git clang make pkg-config binutils libcurl ncurses
git clone https://git.whcself.xyz/WHC/CST-agent.git && cd CST-agent
make && make install # 装到 Termux 的 $PREFIX/bin,之后任意目录运行 cst-agent
# 可选:旁路 Unix busybox # 可选:旁路 Unix busybox
# ./scripts/build_third_party_mingw.sh busybox-unix # ./scripts/build_third_party_mingw.sh busybox-unix
``` ```
+10 -15
View File
@@ -1,13 +1,12 @@
#!/data/data/com.termux/files/usr/bin/bash #!/data/data/com.termux/files/usr/bin/bash
# One-shot: clone + build CST-Agent on Android Termux. # One-shot: clone, build and install CST-Agent on Android Termux.
set -euo pipefail set -euo pipefail
REPO_URL="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}" REPO_URL="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}"
DIR="${1:-CST-agent}" DIR="${1:-CST-agent}"
echo "==> Termux packages" echo "==> Termux packages"
pkg install -y git clang make cmake libcurl ncurses-ui-libs 2>/dev/null \ pkg install -y git clang make pkg-config binutils libcurl ncurses
|| pkg install -y git clang make cmake curl ncurses
if [[ ! -f "$DIR/Makefile" ]]; then if [[ ! -f "$DIR/Makefile" ]]; then
echo "==> git clone $REPO_URL -> $DIR" echo "==> git clone $REPO_URL -> $DIR"
@@ -15,17 +14,13 @@ if [[ ! -f "$DIR/Makefile" ]]; then
fi fi
cd "$DIR" cd "$DIR"
echo "==> cmake build (TUI)" echo "==> build"
cmake -B build -DCMAKE_C_COMPILER=clang -DCST_BUILD_TUI=ON make -j"$(nproc 2>/dev/null || echo 4)"
cmake --build build -j"$(nproc 2>/dev/null || echo 4)" make check || echo "warning: some tests failed (see above)"
# Also keep Makefile binary path convenience
cp -f build/cst-agent ./cst-agent 2>/dev/null || true echo "==> install to $PREFIX/bin"
make install
echo echo
echo "OK: ./cst-agent (or ./build/cst-agent)" echo "OK: run 'cst-agent' inside a project directory."
echo "OpenAI-compatible:" echo "The first start asks for the provider and its API key and saves them."
echo " export OPENAI_API_KEY=sk-..."
echo " export OPENAI_BASE_URL=https://api.openai.com/v1"
echo " export OPENAI_MODEL=gpt-4.1-mini"
echo " ./cst-agent --workspace \$HOME"
echo "Docs: docs/env_openai.md"
+3 -1
View File
@@ -369,7 +369,9 @@ static void theme_init(void) {
const char *nc = getenv("NO_COLOR"); const char *nc = getenv("NO_COLOR");
g_nocolor = nc && nc[0]; g_nocolor = nc && nc[0];
const char *asc = getenv("CST_ASCII"); const char *asc = getenv("CST_ASCII");
#ifndef _WIN32 #if defined(__ANDROID__)
g_utf8 = 1; /* bionic is UTF-8 only; nl_langinfo needs API 26 */
#elif !defined(_WIN32)
const char *cs = nl_langinfo(CODESET); const char *cs = nl_langinfo(CODESET);
g_utf8 = cs && (strcasecmp(cs, "UTF-8") == 0 || strcasecmp(cs, "utf8") == 0); g_utf8 = cs && (strcasecmp(cs, "UTF-8") == 0 || strcasecmp(cs, "utf8") == 0);
#endif #endif