From 4120b1855a8847d16bd8f3e7fc5ecebad59af4ec Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Tue, 26 Jan 2021 15:37:05 +0100 Subject: [PATCH] Added skeleton and script for creating new module --- newmodule | 7 +++++ skeleton/MODULE.cpp | 30 ++++++++++++++++++++++ skeleton/MODULE.hpp | 10 ++++++++ skeleton/Makefile | 62 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100755 newmodule create mode 100644 skeleton/MODULE.cpp create mode 100644 skeleton/MODULE.hpp create mode 100644 skeleton/Makefile diff --git a/newmodule b/newmodule new file mode 100755 index 0000000..766ddca --- /dev/null +++ b/newmodule @@ -0,0 +1,7 @@ +#!/bin/sh +mkdir modules/$1 +cp skeleton/Makefile modules/$1/ +srchead screensaver-modules/$1/$1.hpp > modules/$1/$1.hpp +sed -e "s/{MODULE}/$1/" skeleton/MODULE.hpp >> modules/$1/$1.hpp +srchead screensaver-modules/$1/$1.cpp > modules/$1/$1.cpp +sed -e "s/{MODULE}/$1/" skeleton/MODULE.cpp >> modules/$1/$1.cpp diff --git a/skeleton/MODULE.cpp b/skeleton/MODULE.cpp new file mode 100644 index 0000000..9873699 --- /dev/null +++ b/skeleton/MODULE.cpp @@ -0,0 +1,30 @@ +#include "{MODULE}.hpp" +#include + +class {MODULE} : public ScreensaverPlugin { + public: + {MODULE}() = default; + ~{MODULE}() = default; + + int fps() const override; + void update() override; + void render() override; +}; + +ScreensaverPlugin* create_instance() { + return new {MODULE}; +} + +int {MODULE}::fps() const { + return 30; +} + +void {MODULE}::update() { + // adjust state for next render + +} + +void {MODULE}::render() { + // render one frame based on current state + +} diff --git a/skeleton/MODULE.hpp b/skeleton/MODULE.hpp new file mode 100644 index 0000000..68a176c --- /dev/null +++ b/skeleton/MODULE.hpp @@ -0,0 +1,10 @@ +#ifndef _{MODULE}_H_ +#define _{MODULE}_H_ + +class ScreensaverPlugin; + +extern "C" { + ScreensaverPlugin* create_instance(); +} + +#endif // _{MODULE}_H_ diff --git a/skeleton/Makefile b/skeleton/Makefile new file mode 100644 index 0000000..1fc6883 --- /dev/null +++ b/skeleton/Makefile @@ -0,0 +1,62 @@ +LIBNAME := $(shell basename $$(pwd)) +MAJOR := 1 +MINOR := 0.0 + +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S),Darwin) + LINKERNAME := $(LIBNAME).dylib + SONAME := $(LIBNAME).$(MAJOR).dylib + REALNAME := $(LINKERNAME) +else + LINKERNAME := $(LIBNAME).so + SONAME := $(LINKERNAME).$(MAJOR) + REALNAME := $(SONAME).$(MINOR) +endif + +PREFIX ?= ../.. +LIBDIR ?= $(PREFIX)/plugins + +SRCS := $(wildcard *.cpp) +OBJS := $(subst .cpp,.o,$(SRCS)) +DEPS := $(subst .cpp,.d,$(SRCS)) +HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp)) + +CXX ?= g++ + +CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC +ifeq ($(DEBUG),1) + CXXFLAGS += -D DEBUG -O0 +else + CXXFLAGS += -D NDEBUG -O3 +endif + +LDLIBS := -lcairo -lscscreensaver + +RM := /bin/rm -f +INSTALL := /usr/bin/install -c + +.PHONY: all clean install + +all: $(REALNAME) + +$(REALNAME): $(OBJS) $(DEPS) +ifeq ($(UNAME_S),Darwin) + $(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS) +else + $(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS) +endif + +%.o: %.cpp %.d Makefile + $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< + +-include *.d + +%.d: ; + +clean: + $(RM) $(OBJS) $(DEPS) $(REALNAME) + +install: $(REALNAME) + $(INSTALL) -d $(LIBDIR) + $(INSTALL) -m 644 $(REALNAME) $(LIBDIR)/$(LIBNAME).saver