From a77f27ed59bccc1b76e24f9cbcca8c0b621a63c3 Mon Sep 17 00:00:00 2001 From: WHC Date: Mon, 5 Oct 2026 01:55:49 +0800 Subject: [PATCH] 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). --- Makefile | 11 +++++++++-- README.md | 9 +++++++-- scripts/bootstrap_termux.sh | 25 ++++++++++--------------- src/tui.c | 4 +++- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 88faf92..74ae8dc 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,13 @@ PKG_CONFIG ?= pkg-config PREFIX ?= /usr/local DESTDIR ?= 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 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) LDFLAGS += -L$(SD_DIR) -LDLIBS += -lsashidown -lm $(PKG_LIBS) -lpthread +LDLIBS += -lsashidown -lm $(PKG_LIBS) $(PTHREAD_LIBS) CORE_SRC = \ $(CJSON_DIR)/cJSON.c \ @@ -91,7 +98,7 @@ TESTS = \ tests/test_undo \ 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 diff --git a/README.md b/README.md index b88b390..5fd1583 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,13 @@ API Key:TUI 里输入并按 provider 保存到配置目录的 `credentials`( ### Termux ```bash -pkg install clang make cmake libcurl ncurses-ui-libs -cmake -B build -DCST_BUILD_TUI=ON && cmake --build build +# 一键:装依赖、克隆、编译、安装到 $PREFIX/bin +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 # ./scripts/build_third_party_mingw.sh busybox-unix ``` diff --git a/scripts/bootstrap_termux.sh b/scripts/bootstrap_termux.sh index 203c82f..6f8f846 100755 --- a/scripts/bootstrap_termux.sh +++ b/scripts/bootstrap_termux.sh @@ -1,13 +1,12 @@ #!/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 REPO_URL="${CST_AGENT_REPO:-https://git.whcself.xyz/WHC/CST-agent.git}" DIR="${1:-CST-agent}" echo "==> Termux packages" -pkg install -y git clang make cmake libcurl ncurses-ui-libs 2>/dev/null \ - || pkg install -y git clang make cmake curl ncurses +pkg install -y git clang make pkg-config binutils libcurl ncurses if [[ ! -f "$DIR/Makefile" ]]; then echo "==> git clone $REPO_URL -> $DIR" @@ -15,17 +14,13 @@ if [[ ! -f "$DIR/Makefile" ]]; then fi cd "$DIR" -echo "==> cmake build (TUI)" -cmake -B build -DCMAKE_C_COMPILER=clang -DCST_BUILD_TUI=ON -cmake --build build -j"$(nproc 2>/dev/null || echo 4)" -# Also keep Makefile binary path convenience -cp -f build/cst-agent ./cst-agent 2>/dev/null || true +echo "==> build" +make -j"$(nproc 2>/dev/null || echo 4)" +make check || echo "warning: some tests failed (see above)" + +echo "==> install to $PREFIX/bin" +make install echo -echo "OK: ./cst-agent (or ./build/cst-agent)" -echo "OpenAI-compatible:" -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" +echo "OK: run 'cst-agent' inside a project directory." +echo "The first start asks for the provider and its API key and saves them." diff --git a/src/tui.c b/src/tui.c index 6ebd514..9bdc458 100644 --- a/src/tui.c +++ b/src/tui.c @@ -369,7 +369,9 @@ static void theme_init(void) { const char *nc = getenv("NO_COLOR"); g_nocolor = nc && nc[0]; 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); g_utf8 = cs && (strcasecmp(cs, "UTF-8") == 0 || strcasecmp(cs, "utf8") == 0); #endif