From f457e666b35287678bf85a79ebe452db8fd75a68 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 30 Jun 2026 22:03:04 -0400 Subject: [PATCH 01/13] Add CI for CMake based build --- .github/workflows/ci.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e41dded..422d50a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - # Test the minimum supported cmake. linux: runs-on: ubuntu-latest timeout-minutes: 15 @@ -32,3 +31,19 @@ jobs: - name: Run tests run: make test + + linux-cmake: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7.0.0 + with: + persist-credentials: false + + - name: Install dependencies + run: sudo apt --update install build-essential libncurses-dev cmake + + - name: Build + run: | + cmake -B build . + cmake --build build From e73c957217bf0c1d2842e2841d8555f01550744c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 30 Jun 2026 22:05:02 -0400 Subject: [PATCH 02/13] cmake: Support specifying the TERMINFO directory --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4b90f0..d838265 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,23 @@ if(NOT WIN32) OUTPUT_VARIABLE TERMINFO_DIRS_DEFAULT) # Remove trailing newline string(STRIP "${TERMINFO_DIRS_DEFAULT}" TERMINFO_DIRS_DEFAULT) + + execute_process(COMMAND sh -c "ncursesw6-config --terminfo 2>/dev/null || \ + ncurses6-config --terminfo 2>/dev/null || \ + ncursesw5-config --terminfo 2>/dev/null || \ + ncurses5-config --terminfo 2>/dev/null || \ + echo '/usr/share/terminfo'" + OUTPUT_VARIABLE TERMINFO_DEFAULT) + # Remove trailing newline + string(STRIP "${TERMINFO_DEFAULT}" TERMINFO_DEFAULT) else() set(TERMINFO_DIRS_DEFAULT "") + set(TERMINFO_DEFAULT "") endif() set(TERMINFO_DIRS "${TERMINFO_DIRS_DEFAULT}" CACHE STRING "Colon-separated list of directories where unibilium should look for compiled terminfo files at runtime") target_compile_definitions(unibilium PUBLIC "TERMINFO_DIRS=\"${TERMINFO_DIRS}\"") +set(TERMINFO "${TERMINFO_DEFAULT}" CACHE STRING "Directory where unibilium should look for compiled terminfo files at runtime") +target_compile_definitions(unibilium PUBLIC "TERMINFO=\"${TERMINFO}\"") include(GNUInstallDirs) install(TARGETS unibilium From 0246b923ee9ebfcce4ea72b1194208c60e6ea680 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 30 Jun 2026 23:11:59 -0400 Subject: [PATCH 03/13] cmake: Add tools/ to build --- .gitignore | 2 ++ CMakeLists.txt | 2 ++ tools/CMakeLists.txt | 9 +++++++++ 3 files changed, 13 insertions(+) create mode 100644 tools/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 8b5c56d..70d8854 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ tools/* /.maint /tags +!CMakeLists.txt + # autoreconf aclocal.m4 autom4te.cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index d838265..743d278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ target_compile_definitions(unibilium PUBLIC "TERMINFO_DIRS=\"${TERMINFO_DIRS}\"" set(TERMINFO "${TERMINFO_DEFAULT}" CACHE STRING "Directory where unibilium should look for compiled terminfo files at runtime") target_compile_definitions(unibilium PUBLIC "TERMINFO=\"${TERMINFO}\"") +add_subdirectory(tools) + include(GNUInstallDirs) install(TARGETS unibilium PUBLIC_HEADER diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..261b28a --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,9 @@ +macro(unibi_tool basename) + add_executable(${basename} "${basename}.c") + target_link_libraries(${basename} unibilium) + target_include_directories(${basename} PRIVATE ${PROJECT_SOURCE_DIR}) +endmacro() + +unibi_tool(unibi-dump) +unibi_tool(unibi-put) +unibi_tool(gen-static-test) From e2a20519ae247f58cbf2ab763bb8f59ef2d6b2b9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 1 Jul 2026 06:50:23 -0400 Subject: [PATCH 04/13] cmake: Align SOVERSION/VERSION properties with Makefile build These properties specify the ABI related versioning of the library. --- CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 743d278..3d9c0dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,13 @@ project(unibilium LANGUAGES C VERSION 2.1.3) file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.c) add_library(unibilium ${SRC_FILES}) -set_target_properties(unibilium PROPERTIES PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h - VERSION "${VERSION_MAJOR}.${VERSION_MINOR}") +set_target_properties(unibilium PROPERTIES + PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h + # Keep in sync with Makefile.in + # "$LT_CURRENT - $LT_AGE.$LT_AGE.$LT_REVISION" + VERSION "4.0.1" + # "$LT_CURRENT - $LT_AGE" + SOVERSION "4") if(NOT WIN32) execute_process(COMMAND sh -c "ncursesw6-config --terminfo-dirs 2>/dev/null || \ From ef4c006ff6698050ecdcff2cc269c5a993c7abdd Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 1 Jul 2026 06:55:43 -0400 Subject: [PATCH 05/13] cmake: Explicitly list source files for the library This ensures repeatable ordering of the files and thus reproducibility of the build. --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d9c0dc..52b6c28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,11 @@ cmake_minimum_required(VERSION 3.10) project(unibilium LANGUAGES C VERSION 2.1.3) -file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.c) -add_library(unibilium ${SRC_FILES}) +add_library(unibilium + unibilium.c + uninames.c + uniutil.c +) set_target_properties(unibilium PROPERTIES PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h # Keep in sync with Makefile.in From 31c83d812a0abeeb6cdb07bd41ac115417fd4e36 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 24 Aug 2026 18:12:08 -0400 Subject: [PATCH 06/13] cmake: Build and install man pages --- CMakeLists.txt | 6 +++- doc/CMakeLists.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 doc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 52b6c28..efed351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,9 +41,13 @@ target_compile_definitions(unibilium PUBLIC "TERMINFO_DIRS=\"${TERMINFO_DIRS}\"" set(TERMINFO "${TERMINFO_DEFAULT}" CACHE STRING "Directory where unibilium should look for compiled terminfo files at runtime") target_compile_definitions(unibilium PUBLIC "TERMINFO=\"${TERMINFO}\"") +include(GNUInstallDirs) + +if(NOT WIN32) + add_subdirectory(doc) +endif() add_subdirectory(tools) -include(GNUInstallDirs) install(TARGETS unibilium PUBLIC_HEADER ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 0000000..65e7705 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,86 @@ +if(NOT CMAKE_SKIP_INSTALL_RULES) + find_program(PROG_GZIP gzip) + if(NOT PROG_GZIP) + message(FATAL_ERROR "Missing gzip. Set CMAKE_SKIP_INSTALL_RULES to skip man pages.") + endif() + + find_program(PROG_POD2MAN pod2man) + if(NOT PROG_POD2MAN) + message(FATAL_ERROR "Missing pod2man. Set CMAKE_SKIP_INSTALL_RULES to skip man pages.") + endif() + + macro(unibi_pod2man basename) + set(OUT_MAN_FILE "${CMAKE_CURRENT_BINARY_DIR}/${basename}.3") + set(OUT_GZ_FILE "${CMAKE_CURRENT_BINARY_DIR}/${basename}.3.gz") + add_custom_command( + OUTPUT "${OUT_MAN_FILE}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${basename}.pod" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND pod2man --center "${PROJECT_NAME}" --section 3 --release "${PROJECT_NAME}-${PROJECT_VERSION}" "${basename}.pod" "${OUT_MAN_FILE}") + add_custom_command( + OUTPUT "${OUT_GZ_FILE}" + DEPENDS "${OUT_MAN_FILE}" + COMMAND gzip --stdout "${OUT_MAN_FILE}" > "${OUT_GZ_FILE}") + add_custom_target(man_page_${basename} + DEPENDS "${OUT_GZ_FILE}") + add_dependencies(man_pages man_page_${basename}) + install(FILES "${OUT_GZ_FILE}" + DESTINATION "${CMAKE_INSTALL_MANDIR}/man3/") + endmacro() + + add_custom_target(man_pages ALL) + + unibi_pod2man(unibi_add_ext_bool) + unibi_pod2man(unibi_add_ext_num) + unibi_pod2man(unibi_add_ext_str) + unibi_pod2man(unibi_count_ext_bool) + unibi_pod2man(unibi_count_ext_num) + unibi_pod2man(unibi_count_ext_str) + unibi_pod2man(unibi_del_ext_bool) + unibi_pod2man(unibi_destroy) + unibi_pod2man(unibi_dummy) + unibi_pod2man(unibi_dump) + unibi_pod2man(unibi_format) + unibi_pod2man(unibi_from_env) + unibi_pod2man(unibi_from_fd) + unibi_pod2man(unibi_from_file) + unibi_pod2man(unibi_from_fp) + unibi_pod2man(unibi_from_mem) + unibi_pod2man(unibi_from_term) + unibi_pod2man(unibi_get_aliases) + unibi_pod2man(unibi_get_bool) + unibi_pod2man(unibi_get_ext_bool_name) + unibi_pod2man(unibi_get_ext_bool) + unibi_pod2man(unibi_get_ext_num_name) + unibi_pod2man(unibi_get_ext_num) + unibi_pod2man(unibi_get_ext_str_name) + unibi_pod2man(unibi_get_ext_str) + unibi_pod2man(unibi_get_name) + unibi_pod2man(unibi_get_num) + unibi_pod2man(unibi_get_str) + unibi_pod2man(unibi_int_from_var) + unibi_pod2man(unibilium.h) + unibi_pod2man(unibi_name_bool) + unibi_pod2man(unibi_name_num) + unibi_pod2man(unibi_name_str) + unibi_pod2man(unibi_num_from_var) + unibi_pod2man(unibi_run) + unibi_pod2man(unibi_set_aliases) + unibi_pod2man(unibi_set_bool) + unibi_pod2man(unibi_set_ext_bool_name) + unibi_pod2man(unibi_set_ext_bool) + unibi_pod2man(unibi_set_ext_num_name) + unibi_pod2man(unibi_set_ext_num) + unibi_pod2man(unibi_set_ext_str_name) + unibi_pod2man(unibi_set_ext_str) + unibi_pod2man(unibi_set_name) + unibi_pod2man(unibi_set_num) + unibi_pod2man(unibi_set_str) + unibi_pod2man(unibi_short_name_bool) + unibi_pod2man(unibi_short_name_num) + unibi_pod2man(unibi_short_name_str) + unibi_pod2man(unibi_str_from_var) + unibi_pod2man(unibi_terminfo_dirs) + unibi_pod2man(unibi_var_from_num) + unibi_pod2man(unibi_var_from_str) +endif() From bf8427af7001a93f33ea9052e86a31ec03e31745 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 24 Aug 2026 21:46:06 -0400 Subject: [PATCH 07/13] cmake: Require C99 support when building library / tools --- CMakeLists.txt | 1 + tools/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index efed351..f31fc76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set_target_properties(unibilium PROPERTIES VERSION "4.0.1" # "$LT_CURRENT - $LT_AGE" SOVERSION "4") +target_compile_features(unibilium PRIVATE c_std_99) if(NOT WIN32) execute_process(COMMAND sh -c "ncursesw6-config --terminfo-dirs 2>/dev/null || \ diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 261b28a..c327268 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,6 +2,7 @@ macro(unibi_tool basename) add_executable(${basename} "${basename}.c") target_link_libraries(${basename} unibilium) target_include_directories(${basename} PRIVATE ${PROJECT_SOURCE_DIR}) + target_compile_features(${basename} PRIVATE c_std_99) endmacro() unibi_tool(unibi-dump) From acef2d51b04cd49d158fcd3c26d54cefa7f1168e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 25 Aug 2026 06:57:43 -0400 Subject: [PATCH 08/13] cmake: Build tests and integrate with ctest --- .github/workflows/ci.yml | 3 +++ CMakeLists.txt | 3 +++ t/CMakeLists.txt | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 t/CMakeLists.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 422d50a..a4d6a49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,3 +47,6 @@ jobs: run: | cmake -B build . cmake --build build + + - name: Run tests + run: ctest --test-dir build --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index f31fc76..b68db0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,9 @@ if(NOT WIN32) endif() add_subdirectory(tools) +enable_testing() +add_subdirectory(t) + install(TARGETS unibilium PUBLIC_HEADER ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt new file mode 100644 index 0000000..2d480b5 --- /dev/null +++ b/t/CMakeLists.txt @@ -0,0 +1,19 @@ +macro(unibi_test basename) + add_executable(${basename} "${basename}.c") + target_include_directories(${basename} PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(${basename} unibilium) + add_test( + NAME ${basename} + COMMAND prove -f $ + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) +endmacro() + +unibi_test(00_load) +unibi_test(if-then-else) +unibi_test(new-extended-format-static_screen) +unibi_test(static_screen-256color) +unibi_test(static_screen) +unibi_test(static_tmux) +unibi_test(static_xterm-256color) +unibi_test(static_xterm) +unibi_test(wide-format) From 4c782972d1301c764a3aa4843774507c3a5a6c75 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 26 Aug 2026 21:41:06 -0400 Subject: [PATCH 09/13] cmake: Configure and install unibilium.pc --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b68db0a..2f98c78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,15 @@ include(GNUInstallDirs) if(NOT WIN32) add_subdirectory(doc) + set(LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}) + set(INCDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}) + set(VERSION ${PROJECT_VERSION}) + configure_file(unibilium.pc.in unibilium.pc @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unibilium.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + unset(LIBDIR) + unset(INCDIR) + unset(VERSION) endif() add_subdirectory(tools) From e9f07006f7974568230efebfda60268af66a0fee Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 26 Aug 2026 22:48:03 -0400 Subject: [PATCH 10/13] cmake: Add regenerate-tests target --- t/CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index 2d480b5..bb55ca9 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -17,3 +17,20 @@ unibi_test(static_tmux) unibi_test(static_xterm-256color) unibi_test(static_xterm) unibi_test(wide-format) + +macro(regen termname) + set(OUT_STATIC_FILE "static_${termname}.c") + add_custom_target(regen-${termname} + COMMAND gen-static-test "${termname}" > "${CMAKE_CURRENT_BINARY_DIR}/${OUT_STATIC_FILE}") + add_custom_target(copy-${termname} + DEPENDS regen-${termname} + COMMAND cmake -E copy "${CMAKE_CURRENT_BINARY_DIR}/${OUT_STATIC_FILE}" ${CMAKE_CURRENT_SOURCE_DIR}) + add_dependencies(regenerate-tests regen-${termname}) +endmacro() + +add_custom_target(regenerate-tests) +regen(screen-256color) +regen(screen) +regen(tmux) +regen(xterm-256color) +regen(xterm) From 770ac7b4e0e7955b54a7bc3f025a4ed5166c0277 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 26 Aug 2026 23:08:16 -0400 Subject: [PATCH 11/13] fix(make): Use order-only prereq variable for regenerate-tests 7c36f7f920df changed tools/gen-static-test from a prereq to an order-only prereq, but the $< variable only substitutes for the first normal prereq. --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index b16efcb..f62c469 100644 --- a/Makefile.in +++ b/Makefile.in @@ -148,4 +148,4 @@ regenerate-tests: $(MAKE) $(STATIC_TEST_FILES) t/static_%.c: | tools/gen-static-test - $< $(patsubst t/static_%.c,%,$@) > $@ + $| $(patsubst t/static_%.c,%,$@) > $@ From 6fb6da9e51422cdcdc5592caebff05c8d18bc9d9 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 26 Aug 2026 23:09:54 -0400 Subject: [PATCH 12/13] fix(make): Regenerate static_xterm.c as part of regenerate-tests --- Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index f62c469..5a401d7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -141,7 +141,8 @@ STATIC_TEST_FILES:= \ t/static_screen-256color.c \ t/static_screen.c \ t/static_tmux.c \ - t/static_xterm-256color.c + t/static_xterm-256color.c \ + t/static_xterm.c .PHONY: regenerate-tests regenerate-tests: $(RM) $(STATIC_TEST_FILES) From 6fc863980699f6f67a1ec74caabf0baa6c175e3e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 26 Aug 2026 23:16:09 -0400 Subject: [PATCH 13/13] fix(gen-static-test): Support up to 32k terminfo files --- tools/gen-static-test.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/gen-static-test.c b/tools/gen-static-test.c index d6c4cde..deec39d 100644 --- a/tools/gen-static-test.c +++ b/tools/gen-static-test.c @@ -49,6 +49,7 @@ static void print_str_esc(const char *s, int twice) { } } +enum {MAX_BUF = 32768}; int main(int argc, char **argv) { unibi_term *ut; if (argc < 2) { @@ -68,10 +69,15 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - char buf[4096]; - size_t r = unibi_dump(ut, buf, sizeof buf); - if (r > sizeof buf) { + char *buf = malloc(MAX_BUF); + if (!buf) { + perror("malloc()"); + return EXIT_FAILURE; + } + size_t r = unibi_dump(ut, buf, MAX_BUF); + if (r > MAX_BUF) { perror("unibi_dump()"); + free(buf); return EXIT_FAILURE; } @@ -324,6 +330,7 @@ int main(int argc, char **argv) { say("}"); unibi_destroy(ut); + free(buf); say(""); say("static void setup(void) {");