diff --git a/Makefile b/Makefile index 5ec9c3b..50af407 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ RELEASE = 0.3-beta VERSION = $(RELEASE).$(shell git rev-parse --short=6 HEAD) +OS:=$(shell uname -s) ifdef DEBUG CFLAGS ?= -ggdb -DDEBUG @@ -23,14 +24,29 @@ else # $ LUA_LDFLAGS=-llua make # ################################################# + +ifeq ($(OS), Darwin) +LUA_LDFLAGS ?= -L/usr/local/lib -llua +endif + +ifeq ($(OS), Linux) LUA_CFLAGS ?= -I/usr/include/lua5.1 LUA_LDFLAGS ?= -L/usr/lib -llua5.1 +endif + LUA_LUAC ?= luac endif CFLAGS += -DVERSION='"$(VERSION)"' +ifeq ($(OS), Linux) CFLAGS += $(LUA_CFLAGS) -I/usr/include/freetype2/ -I/usr/include/ffmpeg -std=c99 -Wall -Wno-unused-function -Wno-unused-variable -Wno-deprecated-declarations -LDFLAGS += $(LUA_LDFLAGS) -levent -lglfw -lGL -lGLU -lGLEW -lftgl -lIL -lILU -lILUT -lavformat -lavcodec -lavutil -lswscale -lz +LDFLAGS += $(LUA_LDFLAGS) -levent -lglfw -lGL -lGLU -lGLEW -lftgl -lIL -lILU -lavformat -lavcodec -lavutil -lswscale -lz +endif + +ifeq ($(OS), Darwin) +CFLAGS += $(LUA_CFLAGS) -I/usr/X11/include -I /usr/X11/include/freetype2 -FOpenGL -std=c99 -Wall -Wno-unused-function -Wno-unused-variable -Wno-deprecated-declarations +LDFLAGS += $(LUA_LDFLAGS) -framework OpenGL -levent -lglfw -lGLEW -lftgl -lIL -lILU -lavformat -lavcodec -lavutil -lswscale -lz +endif all: info-beamer diff --git a/font.c b/font.c index 1467ebf..201ee15 100644 --- a/font.c +++ b/font.c @@ -4,7 +4,12 @@ #include #include +#ifdef __APPLE__ +#include +#else #include +#endif + #include #include #include diff --git a/framebuffer.h b/framebuffer.h index bbca4a6..7b98fa1 100644 --- a/framebuffer.h +++ b/framebuffer.h @@ -3,7 +3,11 @@ #ifndef FRAMEBUFFER_H #define FRAMEBUFFER_H +#ifdef __APPLE__ +#include +#else #include +#endif void make_framebuffer(int width, int height, GLuint *tex, GLuint *fbo); void recycle_framebuffer(int width, int height, GLuint tex, GLuint fbo); diff --git a/image.c b/image.c index 79107f4..8e50750 100644 --- a/image.c +++ b/image.c @@ -5,7 +5,13 @@ #include #include + +#ifdef __APPLE__ +#include +#else #include +#endif + #include #include #include diff --git a/main.c b/main.c index e3aeef9..c9ae85b 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,6 @@ #define _BSD_SOURCE #define _GNU_SOURCE -#include #include #include #include @@ -15,19 +14,35 @@ #include #include #include + + +#ifdef __linux__ #include +#endif + +#ifndef memrchr +#include "memrchr.c" +#endif + #include #include #include #include #include +#include + +#ifdef __APPLE__ +#include +#include +#else #include #include -#include +#endif + + #include #include -#include #include #include #include @@ -748,11 +763,13 @@ static void node_reset_profiler(node_t *node) { static void node_init(node_t *node, node_t *parent, const char *path, const char *name) { // add directory watcher +#ifdef __linux__ node->wd = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF| IN_MOVE); if (node->wd == -1) die("cannot start watching directory %s: %s", path, strerror(errno)); +#endif node->parent = parent; node->path = strdup(path); @@ -933,6 +950,7 @@ static void node_profiler() { /*======= inotify ==========*/ +#ifdef __linux__ static void check_inotify() { static char inotify_buffer[sizeof(struct inotify_event) + PATH_MAX + 1]; while (1) { @@ -1012,6 +1030,12 @@ static void check_inotify() { } } } +#else +/* Work around for non-Linux systems, just reload all content with a timer event */ +static void reload_all(int fd, short ev, void *arg) { + node_search_and_boot(&root); +} +#endif /*============ GUI ===========*/ @@ -1254,7 +1278,9 @@ static void open_tcp(struct event *event) { static void tick() { now = glfwGetTime(); +#ifdef __linux__ check_inotify(); +#endif event_loop(EVLOOP_NONBLOCK); @@ -1329,9 +1355,11 @@ int main(int argc, char *argv[]) { root_name = split+1; } + #ifdef __linux__ inotify_fd = inotify_init1(IN_NONBLOCK); if (inotify_fd == -1) die("cannot open inotify: %s", strerror(errno)); +#endif av_register_all(); @@ -1348,6 +1376,16 @@ int main(int argc, char *argv[]) { struct event tcp_event; open_tcp(&tcp_event); + +#ifndef __linux__ + struct event reload_event; + struct timeval reload_tv; + reload_tv.tv_sec = 1; + reload_tv.tv_usec = 0; + event_set(&reload_event, -1, EV_PERSIST, &reload_all, NULL); + evtimer_add(&reload_event, &reload_tv); +#endif + glfwInit(); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); @@ -1372,7 +1410,6 @@ int main(int argc, char *argv[]) { ilInit(); iluInit(); - ilutRenderer(ILUT_OPENGL); signal(SIGVTALRM, deadline_signal); diff --git a/memrchr.c b/memrchr.c new file mode 100644 index 0000000..ba788f5 --- /dev/null +++ b/memrchr.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2007 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +/* + * Reverse memchr() + * Find the last occurrence of 'c' in the buffer 's' of size 'n'. + */ +void * +memrchr(s, c, n) + const void *s; + int c; + size_t n; +{ + const unsigned char *cp; + + if (n != 0) { + cp = (unsigned char *)s + n; + do { + if (*(--cp) == (unsigned char)c) + return((void *)cp); + } while (--n != 0); + } + return((void *)0); +} diff --git a/misc.h b/misc.h index 8008031..c1c67dc 100644 --- a/misc.h +++ b/misc.h @@ -6,7 +6,12 @@ #include #include +#ifdef __APPLE__ +#include +#else #include +#endif + #include #define LITERAL_SIZE(x) (sizeof(x) - 1)