migueldeoleiros / turtile

turtile 🐢 is a simple Wayland compositor written in C, based on wlroots
GNU General Public License v3.0
1 stars 0 forks source link

Build as static/dynamic library to allow embedding in another applications. #29

Open PerryWerneck opened 1 week ago

PerryWerneck commented 1 week ago

A quick patch putting the application in 'main.c' and all other code as a library

diff --git a/Makefile b/Makefile
index 87223f1..499529d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,16 @@
 WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
 WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner)
 LIBS=\
-    $(shell pkg-config --cflags --libs wlroots-0.18) \
-    $(shell pkg-config --cflags --libs wayland-server) \
-    $(shell pkg-config --cflags --libs xkbcommon) \
-    $(shell pkg-config --cflags --libs libconfig)
+    $(shell pkg-config --libs wlroots-0.18) \
+    $(shell pkg-config --libs wayland-server) \
+    $(shell pkg-config --libs xkbcommon) \
+    $(shell pkg-config --libs libconfig)

-CFLAGS=-g -Werror -I. -DWLR_USE_UNSTABLE 
+CFLAGS=-g -fPIC -Werror -I. -DWLR_USE_UNSTABLE  \
+    $(shell pkg-config --cflags wlroots-0.18) \
+    $(shell pkg-config --cflags wayland-server) \
+    $(shell pkg-config --cflags xkbcommon) \
+    $(shell pkg-config --cflags libconfig)

 # wayland-scanner is a tool which generates C headers and rigging for Wayland
 # protocols, which are specified in XML. wlroots requires you to rig these up
@@ -15,17 +19,28 @@ xdg-shell-protocol.h:
    $(WAYLAND_SCANNER) server-header \
        $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@

-turtile: src/main.c src/cursor.c src/keyboard.c src/output.c src/server.c src/toplevel.c src/popup.c xdg-shell-protocol.h src/config.h src/socket_server.h src/commands.h
+src/%.o: src/%.c src/socket_server.h src/commands.h xdg-shell-protocol.h src/config.h
+   @$(CC) $(CFLAGS) -g -Werror -I. -DWLR_USE_UNSTABLE -o $@ -c $<
+
+SOURCES=src/cursor.c src/keyboard.c src/output.c src/server.c src/toplevel.c src/popup.c src/config.c src/socket_server.c src/commands.c
+
+libturtile.a: $(foreach SRC, $(basename $(SOURCES)), $(SRC).o) 
+   @$(AR) rcs $@ $^
+
+libturtile.so.1.0: $(foreach SRC, $(basename $(SOURCES)), $(SRC).o) 
+   $(CC) -shared -Wl,-soname,$(@F) -o $@ $^ $(LIBS)
+
+turtile: src/main.o libturtile.so.1.0
    $(CC) $(CFLAGS) \
        -g -Werror -I. \
        -DWLR_USE_UNSTABLE \
-       -o $@ $< src/cursor.c src/keyboard.c src/output.c src/server.c src/toplevel.c src/popup.c src/config.c src/socket_server.c src/commands.c\
+       -o $@ $^ \
        $(LIBS)

 ttcli: src/ttcli.c
    $(CC) $(CFLAGS) -Wall -Wextra -o $@ $<

-all: turtile ttcli
+all: turtile ttcli libturtile.a libturtile.so.1.0

 clean:
    rm -f turtile ttcli xdg-shell-protocol.h xdg-shell-protocol.c *.o
migueldeoleiros commented 1 week ago

Hey Perry, thanks for being interested in the project! I wasn't expecting any contributions this soon since I haven't added the proper documentation to the repo. I'm not quite sure I understand what your goal with this issue is. My vision for turtile is a simple standalone compositor like sway,dwl,hyprland etc.

PerryWerneck commented 1 week ago

I'm testing it as an embedded compositor in a kiosk application, that's why I did a few changes in the code to allow packaging the compositor, the sdk and libraries. It's being packaged only as rpm in https://build.opensuse.org/package/show/home:PerryWerneck/turtile if you want to take a look. Can be package in many other formats using the same tools.

migueldeoleiros commented 1 week ago

Oh cool! Would it cause issues if I deprecate the makefile in favor of the new meson system you submitted in #31 ?

I can't promise that I won't be making braking changes, since the project is very much in the making. There still is no window management, but I'll be working on that soon, and I may add some options for both tiling, floating and kiosk-like fullscreen windows

PerryWerneck commented 1 week ago

Yes, but will be minor and easy to fix issues, actually, using meson will be even better to me since I'm already using it in my kiosk app.