diff options
author | Anna Arad <4895022+annagrram@users.noreply.github.com> | 2019-12-27 19:02:20 +0100 |
---|---|---|
committer | Mischievous Meerkat <engineerarun@gmail.com> | 2019-12-27 23:32:20 +0530 |
commit | fd9fcf741e6660a1344dafd33956fcdc64fdc643 (patch) | |
tree | 5d202c1d5691f54571def4edc285b7e9282942fa /misc/haiku | |
parent | d3ddff6690aa27e02e4fb3504830137b2d7da5ef (diff) | |
download | nnn-fd9fcf741e6660a1344dafd33956fcdc64fdc643.tar.gz |
Get nnn compile and run on Haiku (#403)
* Add support for Haiku OS
* Adjust DISTFILES and dist rule in haiku
Diffstat (limited to 'misc/haiku')
-rw-r--r-- | misc/haiku/Makefile | 117 | ||||
-rw-r--r-- | misc/haiku/haiku_interop.h | 14 | ||||
-rw-r--r-- | misc/haiku/nm.cpp | 83 | ||||
-rw-r--r-- | misc/haiku/nnn-master.recipe | 52 |
4 files changed, 266 insertions, 0 deletions
diff --git a/misc/haiku/Makefile b/misc/haiku/Makefile new file mode 100644 index 0000000..6fd576d --- /dev/null +++ b/misc/haiku/Makefile @@ -0,0 +1,117 @@ +include VERSION.mk + +PREFIX ?= /boot/system/non-packaged +MANPREFIX ?= /boot/system/non-packaged/documentation/man +STRIP ?= strip +PKG_CONFIG ?= pkg-config +INSTALL ?= install +CP ?= cp + +CFLAGS_OPTIMIZATION ?= -O3 + +O_DEBUG := 0 +O_NORL := 0 # no readline support +O_NOLOC := 0 # no locale support + +# convert targets to flags for backwards compatibility +ifneq ($(filter debug,$(MAKECMDGOALS)),) + O_DEBUG := 1 +endif +ifneq ($(filter norl,$(MAKECMDGOALS)),) + O_NORL := 1 +endif +ifneq ($(filter noloc,$(MAKECMDGOALS)),) + O_NORL := 1 + O_NOLOC := 1 +endif + +ifeq ($(O_DEBUG),1) + CPPFLAGS += -DDBGMODE + CFLAGS += -g + LDLIBS += -lrt +endif + +ifeq ($(O_NORL),1) + CPPFLAGS += -DNORL +else + LDLIBS += -lreadline +endif + +ifeq ($(O_NOLOC),1) + CPPFLAGS += -DNOLOCALE +endif + +ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1) + CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw) + LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncursesw) +else ifeq ($(shell $(PKG_CONFIG) ncurses && echo 1),1) + CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncurses) + LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncurses) +else + LDLIBS_CURSES ?= -lncurses +endif + +ifeq ($(shell uname -s), Haiku) + LDLIBS_HAIKU ?= -lstdc++ -lbe + SRC_HAIKU ?= misc/haiku/nm.cpp + OBJS_HAIKU ?= misc/haiku/nm.o +endif + +CFLAGS += -Wall -Wextra +CFLAGS += $(CFLAGS_OPTIMIZATION) +CFLAGS += $(CFLAGS_CURSES) + +LDLIBS += $(LDLIBS_CURSES) $(LDLIBS_HAIKU) + +DISTFILES = src nnn.1 Makefile README.md LICENSE VERSION.mk +SRC = src/nnn.c +HEADERS = src/nnn.h +BIN = nnn +OBJS := nnn.o $(OBJS_HAIKU) + +all: $(BIN) + +ifeq ($(shell uname -s), Haiku) +$(OBJS_HAIKU): $(SRC_HAIKU) + $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< +endif + +nnn.o: $(SRC) $(HEADERS) + $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< + +$(BIN): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) + +# targets for backwards compatibility +debug: $(BIN) +norl: $(BIN) +noloc: $(BIN) + +install: all + $(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin + $(INSTALL) -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin + $(INSTALL) -m 0755 -d $(DESTDIR)$(MANPREFIX)/man1 + $(INSTALL) -m 0644 $(BIN).1 $(DESTDIR)$(MANPREFIX)/man1 + +uninstall: + $(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN) + $(RM) $(DESTDIR)$(MANPREFIX)/man1/$(BIN).1 + +strip: $(BIN) + $(STRIP) $^ + +dist: + mkdir -p nnn-$(VERSION) + $(CP) -r $(DISTFILES) nnn-$(VERSION) + mkdir -p nnn-$(VERSION)/misc + $(CP) -r misc/haiku nnn-$(VERSION)/misc + tar -cf nnn-$(VERSION).tar nnn-$(VERSION) + gzip nnn-$(VERSION).tar + $(RM) -r nnn-$(VERSION) + +clean: + $(RM) -f $(BIN) $(OBJS) nnn-$(VERSION).tar.gz + +skip: ; + +.PHONY: all debug install uninstall strip dist clean diff --git a/misc/haiku/haiku_interop.h b/misc/haiku/haiku_interop.h new file mode 100644 index 0000000..b422412 --- /dev/null +++ b/misc/haiku/haiku_interop.h @@ -0,0 +1,14 @@ +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct haiku_nm_t *haiku_nm_h; +haiku_nm_h haiku_init_nm(); +void haiku_close_nm(haiku_nm_h hnd); +int haiku_watch_dir(haiku_nm_h hnd, const char *path); +int haiku_stop_watch(haiku_nm_h hnd); +int haiku_is_update_needed(haiku_nm_h hnd); + +#ifdef __cplusplus +} +#endif diff --git a/misc/haiku/nm.cpp b/misc/haiku/nm.cpp new file mode 100644 index 0000000..ede1d37 --- /dev/null +++ b/misc/haiku/nm.cpp @@ -0,0 +1,83 @@ +#include <Directory.h> +#include <Looper.h> +#include <NodeMonitor.h> +#include <MessageFilter.h> + +#include "haiku_interop.h" + +filter_result dir_mon_flt(BMessage *message, BHandler **hnd, BMessageFilter *fltr) { + (void) hnd; + (void) fltr; + + if (message->what == B_NODE_MONITOR) { + int32 val; + message->FindInt32("opcode", &val); + + switch (val) { + case B_ENTRY_CREATED: + case B_ENTRY_MOVED: + case B_ENTRY_REMOVED: + return B_DISPATCH_MESSAGE; + } + } + + return B_SKIP_MESSAGE; +} + +class DirectoryListener : public BLooper { +public: + bool recv_reset() { + Lock(); + bool val = _ev_on; + _ev_on = false; + Unlock(); + + return val; + } +private: + void MessageReceived(BMessage * message) override { + Lock(); + _ev_on = true; + Unlock(); + BLooper::MessageReceived(message); + } + + bool _ev_on = false; +}; + +struct haiku_nm_t { + haiku_nm_t() { + dl = new DirectoryListener(); + flt = new BMessageFilter(B_PROGRAMMED_DELIVERY, B_LOCAL_SOURCE, dir_mon_flt); + dl->AddCommonFilter(flt); + dl->Run(); + } + + DirectoryListener *dl; + BMessageFilter *flt; + node_ref nr; +}; + +haiku_nm_h haiku_init_nm() { + return new haiku_nm_t(); +} + +void haiku_close_nm(haiku_nm_h hnd) { + delete hnd->flt; + // This is the way of deleting a BLooper + hnd->dl->PostMessage(B_QUIT_REQUESTED); + delete hnd; +} +int haiku_watch_dir(haiku_nm_h hnd, const char *path) { + BDirectory dir(path); + dir.GetNodeRef(&(hnd->nr)); + + return watch_node(&(hnd->nr), B_WATCH_DIRECTORY, nullptr, hnd->dl); +} +int haiku_stop_watch(haiku_nm_h hnd) { + return watch_node(&(hnd->nr), B_STOP_WATCHING, nullptr, hnd->dl); +} + +int haiku_is_update_needed(haiku_nm_h hnd) { + return hnd->dl->recv_reset(); +} diff --git a/misc/haiku/nnn-master.recipe b/misc/haiku/nnn-master.recipe new file mode 100644 index 0000000..7e2e463 --- /dev/null +++ b/misc/haiku/nnn-master.recipe @@ -0,0 +1,52 @@ +SUMMARY="The missing terminal file manager for X" +DESCRIPTION=" +nnn is a full-featured terminal file manager. It's tiny and nearly 0-config with an incredible performance. + +nnn is also a du analyzer, an app launcher, a batch renamer and a file picker. The plugin repository has tons of plugins and documentation to extend the capabilities further. You can plug new functionality and play with a custom keybind instantly. There's an independent (neo)vim plugin. + +It runs smoothly on the Raspberry Pi, Termux on Android, Linux, macOS, BSD, Cygwin, WSL and works seamlessly with DEs and GUI utilities. + +Visit the Wiki for concepts, program usage, how-tos and troubleshooting. +" +HOMEPAGE="https://github.com/jarun/nnn" +COPYRIGHT="2016-2019 Arun Prakash Jana" +LICENSE="BSD (2-clause)" +REVISION="1" +SOURCE_URI="git://github.com/jarun/nnn.git" + +ARCHITECTURES="x86 x86_64" + +PROVIDES=" + nnn = $portVersion + cmd:nnn = $portVersion + " +REQUIRES=" + haiku + lib:libncurses + lib:libreadline + " + +BUILD_REQUIRES=" + haiku_devel + pkgconfig + devel:libncurses + devel:libreadline + " + +BUILD_PREREQUIRES=" + cmd:make + cmd:gcc + cmd:g++ + cmd:ld + cmd:install +" + +BUILD() +{ + make -f misc/haiku/Makefile +} + +INSTALL() +{ + make -f misc/haiku/Makefile PREFIX=$prefix MANPREFIX=$manDir install +} |