Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Make it run on non-Linux systems #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions font.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
#include <stdlib.h>
#include <unistd.h>

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

#include <GL/glfw.h>
#include <FTGL/ftgl.h>
#include <lauxlib.h>
Expand Down
4 changes: 4 additions & 0 deletions framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

void make_framebuffer(int width, int height, GLuint *tex, GLuint *fbo);
void recycle_framebuffer(int width, int height, GLuint tex, GLuint fbo);
Expand Down
6 changes: 6 additions & 0 deletions image.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
#include <unistd.h>

#include <GL/glew.h>

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

#include <IL/il.h>
#include <IL/ilu.h>
#include <lauxlib.h>
Expand Down
45 changes: 41 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#define _BSD_SOURCE
#define _GNU_SOURCE
#include <linux/limits.h>
#include <strings.h>
#include <unistd.h>
#include <stdio.h>
Expand All @@ -15,19 +14,35 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>


#ifdef __linux__
#include <sys/inotify.h>
#endif

#ifndef memrchr
#include "memrchr.c"
#endif

#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <GL/glew.h>
#include <GL/glfw.h>

#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#else
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glfw.h>
#endif


#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <libavformat/avformat.h>
#include <event.h>
#include <event2/dns.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ===========*/

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand 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);

Expand All @@ -1372,7 +1410,6 @@ int main(int argc, char *argv[]) {

ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);

signal(SIGVTALRM, deadline_signal);

Expand Down
39 changes: 39 additions & 0 deletions memrchr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2007 Todd C. Miller <[email protected]>
*
* 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 <sys/types.h>

/*
* 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);
}
5 changes: 5 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
#include <sys/time.h>
#include <stdint.h>

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

#include <lualib.h>

#define LITERAL_SIZE(x) (sizeof(x) - 1)
Expand Down