new package: notcurses

This commit is contained in:
Tee KOBAYASHI 2022-11-16 13:37:50 +09:00 committed by xtkoba
parent 459ccd8746
commit db8d8a3afb
8 changed files with 366 additions and 0 deletions

View File

@ -0,0 +1,43 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -86,7 +86,7 @@
# under msys2 (and all other operating systems) we want pkgconfig. when
# building with visual studio, don't require it.
if(NOT MSVC)
-if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
set(PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
elseif(APPLE)
# surely there's a better way to do this? alas, seems necessary to pull the
@@ -146,11 +146,11 @@
# platform-specific logics
if(WIN32)
set(LIBRT wsock32 ws2_32 secur32)
-elseif(NOT APPLE)
+elseif(NOT APPLE AND NOT ANDROID)
find_library(LIBM m REQUIRED)
find_library(LIBRT rt REQUIRED)
endif()
-if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
include_directories(/usr/local/include)
link_directories(/usr/local/lib)
set(CMAKE_REQUIRED_INCLUDES /usr/local/include)
@@ -222,7 +222,7 @@
add_library(notcurses-core-static STATIC EXCLUDE_FROM_ALL ${NCCORESRCS} ${COMPATSRC})
endif()
# don't want these on freebsd/dragonfly/osx
-if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
target_compile_definitions(notcurses-core
PUBLIC
_XOPEN_SOURCE=700 # wcwidth(3) requires _XOPEN_SOURCE, and is in our headers
@@ -417,7 +417,7 @@
target_compile_options(notcurses-ffi PUBLIC -fkeep-inline-functions)
target_compile_definitions(notcurses-ffi PUBLIC NOTCURSES_FFI)
# don't want these on freebsd/dragonfly/osx
-if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
target_compile_definitions(notcurses-ffi
PUBLIC
_XOPEN_SOURCE=700 # wcwidth(3) requires _XOPEN_SOURCE, and is in our headers

View File

@ -0,0 +1,19 @@
TERMUX_PKG_HOMEPAGE=https://notcurses.com/
TERMUX_PKG_DESCRIPTION="blingful TUIs and character graphics"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=3.0.8
TERMUX_PKG_SRCURL=https://github.com/dankamongmen/notcurses/archive/refs/tags/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=56c33ffe2a2bc4d0b6e3ac14bdf620cf41e3293789135f76825057d0166974fd
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_DEPENDS="ffmpeg, libandroid-spawn, libc++, libunistring, ncurses, zlib"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DUSE_DOCTEST=OFF
-DUSE_DEFLATE=OFF
-DUSE_PANDOC=OFF
-DUSE_STATIC=OFF
"
termux_step_pre_configure() {
LDFLAGS+=" -landroid-spawn -lm"
}

View File

@ -0,0 +1,13 @@
--- a/include/notcurses/ncport.h
+++ b/include/notcurses/ncport.h
@@ -16,6 +16,10 @@
#if defined(__linux__) // Linux
#include <byteswap.h>
+#ifdef __ANDROID__
+#undef __bswap_32
+#define __bswap_32 bswap_32
+#endif
#define htole(x) (__bswap_32(htonl(x)))
#elif defined(__APPLE__) // macOS
#include <libkern/OSByteOrder.h>

View File

@ -0,0 +1,3 @@
TERMUX_SUBPKG_DESCRIPTION="Platform-independent data for notcurses"
TERMUX_SUBPKG_PLATFORM_INDEPENDENT=true
TERMUX_SUBPKG_INCLUDE="share/notcurses/"

View File

@ -0,0 +1,3 @@
TERMUX_SUBPKG_DESCRIPTION="Tools and demos for notcurses"
TERMUX_SUBPKG_INCLUDE="bin/"
TERMUX_SUBPKG_DEPENDS="notcurses-data"

View File

@ -0,0 +1,40 @@
--- a/tools/notcurses++.pc.in
+++ b/tools/notcurses++.pc.in
@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+libdir=@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@++
--- a/tools/notcurses-core.pc.in
+++ b/tools/notcurses-core.pc.in
@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+libdir=@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@-core
--- a/tools/notcurses-ffi.pc.in
+++ b/tools/notcurses-ffi.pc.in
@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+libdir=@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@
--- a/tools/notcurses.pc.in
+++ b/tools/notcurses.pc.in
@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+libdir=@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@

View File

@ -0,0 +1,234 @@
--- a/src/demo/input.c
+++ b/src/demo/input.c
@@ -4,6 +4,15 @@
#include <pthread.h>
#include "demo.h"
+#ifdef __ANDROID__
+#define PTHREAD_CANCELED ((void *)-1)
+static void
+thread_signal_handler(int signum)
+{
+ pthread_exit(PTHREAD_CANCELED);
+}
+#endif
+
typedef struct nciqueue {
ncinput ni;
struct nciqueue *next;
@@ -118,6 +127,15 @@
static void *
ultramegaok_demo(void* vnc){
+#ifdef __ANDROID__
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
+
ncinput ni;
struct notcurses* nc = vnc;
uint32_t id;
@@ -176,7 +194,11 @@
int stop_input(void){
int ret = 0;
if(input_pipefds[0] >= 0){
+#ifndef __ANDROID__
ret |= pthread_cancel(tid);
+#else
+ ret |= pthread_kill(tid, SIGUSR2);
+#endif
ret |= pthread_join(tid, NULL);
ret |= close(input_pipefds[0]);
ret |= close(input_pipefds[1]);
--- a/src/demo/reel.c
+++ b/src/demo/reel.c
@@ -7,6 +7,15 @@
#include <pthread.h>
#include "demo.h"
+#ifdef __ANDROID__
+#define PTHREAD_CANCELED ((void *)-1)
+static void
+thread_signal_handler(int signum)
+{
+ pthread_exit(PTHREAD_CANCELED);
+}
+#endif
+
#define INITIAL_TABLET_COUNT 4
static pthread_mutex_t renderlock = PTHREAD_MUTEX_INITIALIZER;
@@ -27,9 +36,13 @@
kill_tablet(tabletctx** tctx){
tabletctx* t = *tctx;
if(t){
+#ifndef __ANDROID__
if(pthread_cancel(t->tid)){
fprintf(stderr, "Warning: error sending pthread_cancel (%s)\n", strerror(errno));
}
+#else
+ pthread_kill(t->tid, SIGUSR2);
+#endif
if(pthread_join(t->tid, NULL)){
fprintf(stderr, "Warning: error joining pthread (%s)\n", strerror(errno));
}
@@ -117,6 +130,15 @@
// events for its tablet.
static void*
tablet_thread(void* vtabletctx){
+#ifdef __ANDROID__
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
+
static int MINSECONDS = 0;
tabletctx* tctx = vtabletctx;
while(true){
--- a/src/demo/outro.c
+++ b/src/demo/outro.c
@@ -1,6 +1,10 @@
#include <pthread.h>
#include "demo.h"
+#ifdef __ANDROID__
+#define PTHREAD_CANCELED ((void *)-1)
+#endif
+
static int y;
static int targy;
static unsigned xstart;
--- a/src/lib/fd.c
+++ b/src/lib/fd.c
@@ -23,6 +23,15 @@
#define NCPOLLEVENTS (POLLIN)
#endif
+#ifdef __ANDROID__
+#define PTHREAD_CANCELED ((void *)-1)
+static void
+thread_signal_handler(int signum)
+{
+ pthread_exit(PTHREAD_CANCELED);
+}
+#endif
+
// release the memory and fd, but don't join the thread (since we might be
// getting called within the thread's context, on a callback).
static int
@@ -85,6 +94,15 @@
static void *
ncfdplane_thread(void* vncfp){
+#ifdef __ANDROID__
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
+
fdthread(vncfp, -1);
return NULL;
}
@@ -266,6 +284,15 @@
// need a poll on both main fd and pidfd
static void *
ncsubproc_thread(void* vncsp){
+#ifdef __ANDROID__
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
+
int* status = malloc(sizeof(*status));
if(status){
ncsubproc* ncsp = vncsp;
@@ -287,6 +314,15 @@
// wake up our poll()ing thread).
static void *
ncsubproc_waiter(void* vncsp){
+#ifdef __ANDROID__
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
+
ncsubproc* ncsp = vncsp;
int* status = malloc(sizeof(*status));
pid_t pid;
@@ -425,7 +461,11 @@
// then exits. don't try to cancel the thread in that case; rely instead on
// killing the subprocess.
if(n->pidfd < 0){
+#ifndef __ANDROID__
pthread_cancel(n->nfp->tid);
+#else
+ pthread_kill(n->nfp->tid, SIGUSR2);
+#endif
// shouldn't need a cancellation of waittid thanks to SIGKILL
pthread_join(n->waittid, &vret);
}
--- a/src/lib/in.c
+++ b/src/lib/in.c
@@ -7,6 +7,15 @@
#include "render.h"
#include "in.h"
+#ifdef __ANDROID__
+#define PTHREAD_CANCELED ((void *)-1)
+static void
+thread_signal_handler(int signum)
+{
+ pthread_exit(PTHREAD_CANCELED);
+}
+#endif
+
// Notcurses takes over stdin, and if it is not connected to a terminal, also
// tries to make a connection to the controlling terminal. If such a connection
// is made, it will read from that source (in addition to stdin). We dump one or
@@ -2498,6 +2507,14 @@
static void*
input_thread(void* vmarshall){
setup_alt_sig_stack();
+#ifdef __ANDROID__
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = SA_ONSTACK;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
inputctx* ictx = vmarshall;
if(prep_all_keys(ictx) || build_cflow_automaton(ictx)){
ictx->failed = true;
--- a/src/lib/internal.h
+++ b/src/lib/internal.h
@@ -1832,9 +1832,13 @@
// have already exited), and then join it (an error here is propagated).
static inline int
cancel_and_join(const char* name, pthread_t tid, void** res){
+#ifndef __ANDROID__
if(pthread_cancel(tid)){
logerror("couldn't cancel %s thread", name); // tid might have died
}
+#else
+ pthread_kill(tid, SIGUSR2);
+#endif
if(pthread_join(tid, res)){
logerror("error joining %s thread", name);
return -1;

View File

@ -0,0 +1,11 @@
--- a/src/lib/termdesc.h
+++ b/src/lib/termdesc.h
@@ -290,7 +290,7 @@
static inline int
ncfputs(const char* ext, FILE* out){
int r;
-#ifdef __USE_GNU
+#if defined __USE_GNU && (!defined __ANDROID__ || __ANDROID_API__ >= 28)
r = fputs_unlocked(ext, out);
#else
r = fputs(ext, out);