+LIBRARY = framework
+LIBFILE = libmspframework
+
TMP = $(HOME)/nightwatch/tmp
TGT = $(HOME)/nightwatch
CC = gcc
AR = ar
CP = cp
+
INCLUDE = -Isource -I$(TMP)/include
LIB = -L$(TMP)
DEBUG =
-CFLAGS = $(DEBUG) $(INCLUDE) -pipe -Wall `pkg-config --cflags sigc++-2.0` `sdl-config --cflags`
+CFLAGS = $(DEBUG) $(INCLUDE) -pipe -Wall `pkg-config --cflags sigc++-2.0`
CXXFLAGS = $(CFLAGS)
+LIBLDFLAGS = -lpthreadGC2 -lsigc-2.0
+MAKEFLAGS += -s --no-print-directory
+
+PIC = -fPIC
+SHARED = .so
+STATIC = .a
-LIBRARY = framework
-LIBFILE = libmspframework
SRC = source
LIBOBJS = $(addprefix $(TMP)/, $(addsuffix .o, $(notdir $(basename $(wildcard $(SRC)/*.cpp)))))
libdir = lib
.PHONY: all
-all: $(TMP) $(TMP)/$(LIBFILE).so $(TMP)/$(LIBFILE).a tmpheaders
+all: $(TMP) $(TMP)/$(LIBFILE)$(SHARED) $(TMP)/$(LIBFILE)$(STATIC) tmpheaders
# Create temp directory
$(TMP):
mkdir -p $@
# Dynamic library
-$(TMP)/$(LIBFILE).so: $(LIBOBJS)
+$(TMP)/$(LIBFILE)$(SHARED): $(LIBOBJS)
echo "Compiling $(notdir $@)"
- $(CXX) $^ -shared -o $@ $(LIB) $(LIBRARYLIBS)
+ $(CXX) $^ -shared -o $@ $(LIB) $(LIBLDFLAGS)
# Static library
-$(TMP)/$(LIBFILE).a: $(LIBOBJS)
+$(TMP)/$(LIBFILE)$(STATIC): $(LIBOBJS)
echo "Compiling $(notdir $@)"
$(AR) rcs $@ $^
# Library object file
$(TMP)/%.o: $(SRC)/%.cpp $(wildcard $(SRC)/*.h)
echo "Compiling $(LIBRARY)/$(notdir $(basename $@))"
- $(CXX) -fPIC $(CXXFLAGS) -c $< -o $@
+ $(CXX) $(PIC) $(CXXFLAGS) -c $< -o $@
# Installs
.PHONY: install
poller_->poll(-1);
else
{
+#ifdef WIN32
+ Sleep(1);
+#else
timespec ts={1000,0};
nanosleep(&ts, 0);
+#endif
}
if(tick_mode_!=NONE)
tick();
#ifndef MSP_FRAMEWORK_APPLICATION_H_
#define MSP_FRAMEWORK_APPLICATION_H_
+#ifdef WIN32
+#include "win32signum.h"
+#endif
+
#include <pthread.h>
#include "event.h"
#include "poller.h"
Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
+#ifdef WIN32
+#include <io.h>
+#include <fcntl.h>
+#endif
+
#include "application.h"
#include "event.h"
EventManager::Pipe::Pipe()
{
+#ifdef WIN32
+ _pipe(fd, 1024, _O_BINARY);
+#else
::pipe(fd);
+#endif
}
int EventManager::Pipe::write(char *buf, unsigned len)
{
+#ifdef WIN32
+ return _write(fd[1], buf, len);
+#else
return ::write(fd[1], buf, len);
+#endif
}
int EventManager::Pipe::read(char *buf, unsigned len)
{
+#ifdef WIN32
+ return _read(fd[0], buf, len);
+#else
return ::read(fd[0], buf, len);
+#endif
}
} // namespace Msp
Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
+#ifdef WIN32
+#include <winsock2.h>
+#include "win32poll.h"
+#else
#include <poll.h>
+#endif
#include "pollable.h"
namespace Msp {
short Pollable::poll(short events, int timeout)
{
+#ifdef WIN32
+ return 0;
+#else
pollfd pfd={get_fd(), events, 0};
+ int result=select(&pfd, 1, timeout);
int result=::poll(&pfd, 1, timeout);
if(result<=0)
return result;
return pfd.revents;
+#endif
}
}
#ifndef MSP_FRAMEWORK_POLLABLE_H_
#define MSP_FRAMEWORK_POLLABLE_H_
+#ifdef WIN32
+#include "win32poll.h"
+#endif
+
#include <sigc++/sigc++.h>
namespace Msp {
int Poller::poll(int timeout)
{
+#ifdef WIN32
+ return 0;
+#else
slots_mutex.lock();
for(list<Slot *>::iterator i=slots.begin(); i!=slots.end();)
{
pfd_mutex.unlock();
return result;
+#endif
}
void Poller::rebuild_pfd()
#ifndef MSP_FRAMEWORK_POLLER_H_
#define MSP_FRAMEWORK_POLLER_H_
+#ifdef WIN32
+#include "win32poll.h"
+#else
#include <sys/poll.h>
+#endif
#include <vector>
#include <sigc++/sigc++.h>
#include "mutex.h"
Thread::~Thread()
{
- if(valid)
+ if(valid_)
kill(SIGKILL);
}
#ifndef MSP_FRAMEWORK_THREAD_H_
#define MSP_FRAMEWORK_THREAD_H_
+#ifdef WIN32
+#include "win32signum.h"
+#endif
+
#include <pthread.h>
namespace Msp {
--- /dev/null
+/*
+This file is part of libmspframework
+Copyright © 2006 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#ifndef MSP_FRAMEWORK_WIN32POLL_H_
+#define MSP_FRAMEWORK_WIN32POLL_H_
+
+#ifdef WIN32
+// From Linux sys/poll.h
+struct pollfd
+{
+ int fd; /* File descriptor to poll. */
+ short int events; /* Types of events poller cares about. */
+ short int revents; /* Types of events that actually occurred. */
+};
+
+#ifndef POLLIN
+// From Linux pth.h
+#define POLLIN 0x0001 /* any readable data available */
+#endif
+
+#ifndef POLLNVAL
+// From Linux pth.h
+#define POLLNVAL 0x0020 /* requested events "invalid" */
+#endif
+
+#endif // Win32
+#endif