summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-21 04:00:58 +0100
committerNao Pross <naopross@thearcway.org>2019-01-21 04:02:18 +0100
commitf40251efc21a4e2db446af73c810d1b063cf84fb (patch)
treedce905174d6020d11e885a860b3dbce6c7899b6e
downloadlibwsdl2-f40251efc21a4e2db446af73c810d1b063cf84fb.tar.gz
libwsdl2-f40251efc21a4e2db446af73c810d1b063cf84fb.zip
Initial commit, add makefile, .gitignore and debug header
-rw-r--r--.gitignore1
-rw-r--r--debug.hpp77
-rw-r--r--include/wrapsdl.hpp6
-rw-r--r--makefile19
-rw-r--r--wrapsdl.cpp19
5 files changed, 122 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..378eac2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build
diff --git a/debug.hpp b/debug.hpp
new file mode 100644
index 0000000..16dc5a8
--- /dev/null
+++ b/debug.hpp
@@ -0,0 +1,77 @@
+#pragma once
+
+#include <iostream>
+#include <sstream>
+
+#ifdef DEBUG
+
+ #warning building in debug mode!
+ #ifdef __builtin_strrchr
+ #define __FILENAME__ (\
+ __builtin_strrchr(__FILE__, '/') ? \
+ __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
+
+ #define npdebug_fname(); { \
+ std::cerr << "[" << __FILENAME__ << ":" << __LINE__ << "] "; \
+ }
+
+ #define npdebug(...); { \
+ npdebug_fname(); \
+ np::va_debug(__VA_ARGS__); \
+ }
+ #else
+ #define npdebug(...); np::va_debug(__VA_ARGS__);
+ #endif
+
+ namespace np {
+ template<typename... Args>
+ inline void va_debug(Args&... args) {
+ (std::cerr << ... << args) << std::endl;
+ }
+
+ template<typename T>
+ void range_debug(const T& t) {
+ range_debug("", t);
+ }
+
+ template<typename T>
+ void range_debug(const std::string& msg, const T& t) {
+ std::string out;
+ for (auto elem : t)
+ out += elem += ", ";
+
+ npdebug(msg, out);
+ }
+
+ template<typename T>
+ T inspect(const T& t) {
+ npdebug(t);
+ return t;
+ }
+
+ template<typename T>
+ T inspect(const std::string& msg, const T& t) {
+ npdebug(msg, t);
+ return t;
+ }
+ }
+#else
+ #define npdebug(...) {}
+
+ namespace np {
+ template<typename... Args>
+ inline void va_debug(Args&... args) {}
+
+ template<typename T>
+ inline void range_debug(const T& t) {}
+
+ template<typename T>
+ inline void range_debug(const std::string& msg, const T& t) {}
+
+ template<typename T>
+ T inspect(const T& t) { return t; }
+
+ template<typename T>
+ T inspect(const std::string& msg, const T& t) { return t; }
+ }
+#endif
diff --git a/include/wrapsdl.hpp b/include/wrapsdl.hpp
new file mode 100644
index 0000000..9b9a72c
--- /dev/null
+++ b/include/wrapsdl.hpp
@@ -0,0 +1,6 @@
+#pragma once
+
+namespace wrapsdl {
+ bool initialize(void);
+ void quit(void);
+} \ No newline at end of file
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..2c13834
--- /dev/null
+++ b/makefile
@@ -0,0 +1,19 @@
+# Compiler
+CPP := c++
+CFLAGS := -Wall -pedantic -std=c++17 -fPIC -shared -I include -DDEBUG
+LFLAGS := -lSDL2
+
+SRCS := $(wildcard *.cpp)
+OBJS := $(patsubst %.cpp,build/%.o,$(SRCS))
+
+# Recipes
+all: build/libwrapsdl2.so
+
+build/libwrapsdl2.so: $(OBJS)
+ $(CPP) $(CFLAGS) -o $@ $(LFLAGS) $(OBJS)
+
+build/%.o: %.cpp build
+ $(CPP) $(CFLAGS) -o $@ -c $<
+
+build:
+ mkdir -p build
diff --git a/wrapsdl.cpp b/wrapsdl.cpp
new file mode 100644
index 0000000..e91ec8c
--- /dev/null
+++ b/wrapsdl.cpp
@@ -0,0 +1,19 @@
+#include "wrapsdl.hpp"
+#include "debug.hpp"
+
+extern "C" {
+#include <SDL2/SDL.h>
+}
+
+bool wrapsdl::initialize(void) {
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
+ npdebug("failed to initialize sdl video subsystem");
+ return false;
+ }
+
+ return true;
+}
+
+void wrapsdl::quit(void) {
+ SDL_Quit();
+}