From a4f92ea894da9989c9ce5ec998e91fec9cdd4995 Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Sun, 2 Apr 2023 15:05:55 -0400 Subject: [PATCH] termbox -> termbox2 (#53) --- .gitignore | 10 +++++----- Makefile | 24 ++++++++++++------------ README.md | 14 +++++++------- demo/example.go | 2 +- demo/example.php | 2 +- demo/example.py | 2 +- demo/example.rb | 2 +- demo/example.zig | 4 ++-- demo/keyboard.c | 2 +- termbox.h => termbox2.h | 0 tests/test_ffi.php | 10 +++++----- 11 files changed, 36 insertions(+), 36 deletions(-) rename termbox.h => termbox2.h (100%) diff --git a/.gitignore b/.gitignore index ef45477..13e6010 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -termbox.o -libtermbox.a -libtermbox.so* -termbox.ffi.h -termbox.h.lib +termbox2.o +libtermbox2.a +libtermbox2.so* +termbox2.ffi.h +termbox2.h.lib demo/keyboard diff --git a/Makefile b/Makefile index 6a77e38..ecc294a 100644 --- a/Makefile +++ b/Makefile @@ -2,26 +2,26 @@ prefix?=/usr/local termbox_cflags:=-std=c99 -Wall -Wextra -pedantic -Wno-unused-result -g -O0 -D_XOPEN_SOURCE -D_DEFAULT_SOURCE $(CFLAGS) termbox_demos:=$(patsubst demo/%.c,demo/%,$(wildcard demo/*.c)) -termbox_h:=termbox.h -termbox_h_lib:=termbox.h.lib -termbox_ffi_h:=termbox.ffi.h -termbox_o:=termbox.o +termbox_h:=termbox2.h +termbox_h_lib:=termbox2.h.lib +termbox_ffi_h:=termbox2.ffi.h +termbox_o:=termbox2.o termbox_so_version_abi:=2 termbox_so_version_minor_patch:=0.0 -termbox_so:=libtermbox.so +termbox_so:=libtermbox2.so termbox_so_x:=$(termbox_so).$(termbox_so_version_abi) termbox_so_x_y_z:=$(termbox_so_x).$(termbox_so_version_minor_patch) termbox_ld_soname:=soname -termbox_a:=libtermbox.a +termbox_a:=libtermbox2.a ifeq ($(shell $(CC) -dumpmachine | grep -q apple && echo 1), 1) - termbox_so:=libtermbox.dylib - termbox_so_x:=libtermbox.$(termbox_so_version_abi).dylib - termbox_so_x_y_z:=libtermbox.$(termbox_so_version_abi).$(termbox_so_version_minor_patch).dylib + termbox_so:=libtermbox2.dylib + termbox_so_x:=libtermbox2.$(termbox_so_version_abi).dylib + termbox_so_x_y_z:=libtermbox2.$(termbox_so_version_abi).$(termbox_so_version_minor_patch).dylib termbox_ld_soname:=install_name endif -all: $(termbox_demos) $(termbox_so) $(termbox_a) +all: $(termbox_demos) $(termbox_so) $(termbox_so_x) $(termbox_a) $(termbox_demos): %: %.c $(CC) -DTB_IMPL -DTB_LIB_OPTS $(termbox_cflags) $^ -o $@ @@ -48,8 +48,8 @@ $(termbox_h_lib): $(termbox_h) sed 's|0 // __tb_lib_opts|1 // __tb_lib_opts|' $(termbox_h) >$@ terminfo: - awk -vg=0 'g==0{print} /BEGIN codegen h/{g=1; system("./codegen.sh h")} /END codegen h/{g=0; print} g==1{next}' termbox.h >termbox.h.tmp && mv -vf termbox.h.tmp termbox.h - awk -vg=0 'g==0{print} /BEGIN codegen c/{g=1; system("./codegen.sh c")} /END codegen c/{g=0; print} g==1{next}' termbox.h >termbox.h.tmp && mv -vf termbox.h.tmp termbox.h + awk -vg=0 'g==0{print} /BEGIN codegen h/{g=1; system("./codegen.sh h")} /END codegen h/{g=0; print} g==1{next}' termbox2.h >termbox2.h.tmp && mv -vf termbox2.h.tmp termbox2.h + awk -vg=0 'g==0{print} /BEGIN codegen c/{g=1; system("./codegen.sh c")} /END codegen c/{g=0; print} g==1{next}' termbox2.h >termbox2.h.tmp && mv -vf termbox2.h.tmp termbox2.h test: $(termbox_so) $(termbox_ffi_h) docker build -f tests/Dockerfile --build-arg=cflags="$(termbox_cflags)" . diff --git a/README.md b/README.md index 1c6a164..12f4b63 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ stand-alone shared or static library. ```c #define TB_IMPL -#include "termbox.h" +#include "termbox2.h" #include int main(int argc, char **argv) { @@ -73,12 +73,12 @@ int tb_printf(int x, int y, uintattr_t fg, uintattr_t bg, const char *fmt, ...); As mentioned above, there are two options: -1. Copy (or `git submodule`) `termbox.h` into your C project. As normal, include - the header file wherever you want to use `tb_*` functions, but also be sure - to `#define TB_IMPL` in exactly one of your source files. (This is a common - pattern for single file header libraries.) -2. Build termbox2 as a library (either `make libtermbox.so` or - `make libtermbox.a`) and link as normal. +1. Copy (or `git submodule`) `termbox2.h` into your C project. As normal, + include the header file wherever you want to use `tb_*` functions, but also + be sure to `#define TB_IMPL` in exactly one of your source files. (This is a + common pattern for single file header libraries.) +2. Build termbox2 as a library (either `make libtermbox2.so` or + `make libtermbox2.a`) and link as normal. ### Language bindings (FFI and ABI compats) diff --git a/demo/example.go b/demo/example.go index 0a1d34c..2f87c51 100644 --- a/demo/example.go +++ b/demo/example.go @@ -3,7 +3,7 @@ package main /* -#cgo LDFLAGS: -L.. -Wl,-rpath,.. -ltermbox +#cgo LDFLAGS: -L.. -Wl,-rpath,.. -ltermbox2 #include typedef struct tb_event_s { uint8_t _type; diff --git a/demo/example.php b/demo/example.php index 29f5a10..f5bc489 100755 --- a/demo/example.php +++ b/demo/example.php @@ -19,7 +19,7 @@ $termbox_h = <<<'EOD' int tb_printf(int x, int y, uint32_t fg, uint32_t bg, const char *fmt, ...); EOD; -$termbox = FFI::cdef($termbox_h, '../libtermbox.so'); +$termbox = FFI::cdef($termbox_h, '../libtermbox2.so'); $ev = $termbox->new('struct tb_event'); diff --git a/demo/example.py b/demo/example.py index df6c7ba..7d8e788 100755 --- a/demo/example.py +++ b/demo/example.py @@ -20,7 +20,7 @@ ffi.cdef(""" int tb_poll_event(struct tb_event *event); int tb_printf(int x, int y, uint32_t fg, uint32_t bg, const char *fmt, ...); """) -termbox = ffi.dlopen("../libtermbox.so") +termbox = ffi.dlopen("../libtermbox2.so") ev = ffi.new("struct tb_event *") termbox.tb_init() diff --git a/demo/example.rb b/demo/example.rb index a14be6a..7f1b97b 100755 --- a/demo/example.rb +++ b/demo/example.rb @@ -3,7 +3,7 @@ require 'ffi' module Termbox extend FFI::Library - ffi_lib '../libtermbox.so' + ffi_lib '../libtermbox2.so' class Event < FFI::Struct layout :type, :uint8, :mod, :uint8, diff --git a/demo/example.zig b/demo/example.zig index 1d580e0..b935f3a 100644 --- a/demo/example.zig +++ b/demo/example.zig @@ -1,7 +1,7 @@ -// zig run -I.. -I/usr/include -I/usr/include/x86_64-linux-gnu/ -rpath .. -L.. -ltermbox -lc example.zig +// zig run -I.. -I/usr/include -I/usr/include/x86_64-linux-gnu/ -rpath .. -L.. -ltermbox2 -lc example.zig // (Is there a way to avoid the explicit system library paths?) -const c = @cImport(@cInclude("termbox.h")); +const c = @cImport(@cInclude("termbox2.h")); const std = @import("std"); pub fn main() void { diff --git a/demo/keyboard.c b/demo/keyboard.c index aeb7a93..e22b2d8 100644 --- a/demo/keyboard.c +++ b/demo/keyboard.c @@ -2,7 +2,7 @@ #include #include #include -#include "../termbox.h" +#include "../termbox2.h" struct key { unsigned char x; diff --git a/termbox.h b/termbox2.h similarity index 100% rename from termbox.h rename to termbox2.h diff --git a/tests/test_ffi.php b/tests/test_ffi.php index 17c1143..fb14bbd 100644 --- a/tests/test_ffi.php +++ b/tests/test_ffi.php @@ -4,13 +4,13 @@ declare(strict_types=1); return (function() { // This is a little whacky. `FFI::cdef` isn't smart enough to handle // preprocessor directives, so we feed it a `gcc -E` version of - // termbox.h (termbox.ffi.h, created by the Makefile). On the other + // termbox2.h (termbox2.ffi.h, created by the Makefile). On the other // hand, it's useful to have `#define` constants for tests, so we parse - // those out from the raw `termbox.h`. + // those out from the raw `termbox2.h`. $repo_dir = dirname(__DIR__); - $termbox_h = "$repo_dir/termbox.h"; - $termbox_ffi_h = "$repo_dir/termbox.ffi.h"; - $libtermbox_so = "$repo_dir/libtermbox.so"; + $termbox_h = "$repo_dir/termbox2.h"; + $termbox_ffi_h = "$repo_dir/termbox2.ffi.h"; + $libtermbox_so = "$repo_dir/libtermbox2.so"; $termbox_h_data = file_get_contents($termbox_h); // Look at only the content in between `__TERMBOX_H` -- 2.39.5