commit de4855b
uint
·
2026-06-13 15:35:33 +0000 UTC
parent 4b84be0
Move to source, include, add Makefile (compile as static library), use static library in basic-window
+6,
-1
1@@ -1,7 +1,12 @@
2 *.o
3 *.swp
4+*.a
5+
6+compile_flags.txt
7
8 fenster/
9
10-tests/basic-window/basic-window
11+examples/basic-window/basic-window
12+
13+config.mk
14
A
Makefile
+45,
-0
1@@ -0,0 +1,45 @@
2+include config.mk
3+
4+CC = cc
5+AR = ar
6+CFLAGS = -std=c99 -Wall -Wextra -O2
7+CPPFLAGS = ${CONF_CPPFLAGS} -Iinclude
8+LDFLAGS = ${CONF_LDFLAGS}
9+
10+LIB_NAME = build/${CONF_LIB_NAME}
11+LIB_SRCS = source/maus.c \
12+ source/maus_font.c \
13+ source/utils.c \
14+ ${CONF_SRC}
15+LIB_OBJS = build/maus.o \
16+ build/maus_font.o \
17+ build/utils.o \
18+ ${CONF_OBJS}
19+
20+all: ${LIB_NAME}
21+
22+${LIB_NAME}: ${LIB_OBJS}
23+ ${AR} -rcs $@ ${LIB_OBJS}
24+
25+build/maus.o: source/maus.c
26+ mkdir -p build
27+ ${CC} ${CFLAGS} ${CPPFLAGS} -c source/maus.c -o $@
28+build/maus_font.o: source/maus_font.c
29+ mkdir -p build
30+ ${CC} ${CFLAGS} ${CPPFLAGS} -c source/maus_font.c -o $@
31+build/utils.o: source/utils.c
32+ mkdir -p build
33+ ${CC} ${CFLAGS} ${CPPFLAGS} -c source/utils.c -o $@
34+build/maus_x11.o: source/maus_x11.c
35+ mkdir -p build
36+ ${CC} ${CFLAGS} ${CPPFLAGS} -c source/maus_x11.c -o $@
37+
38+clean:
39+ rm -rf build ${LIB_NAME} config.mk compile_flags.txt
40+
41+compile_flags:
42+ rm -f compile_flags.txt
43+ for f in ${CFLAGS} ${CPPFLAGS}; do echo $$f >> compile_flags.txt; done
44+
45+.PHONY: all clean compile_flags
46+
M
TODO
+2,
-0
1@@ -7,5 +7,7 @@ MausFont:
2 X11:
3 Wayland:
4 Windows:
5+[-] Build script
6+
7 macOS:
8
+0,
-4
1@@ -1,4 +0,0 @@
2--std=c99
3--Wall
4--Wextra
5-
+46,
-0
1@@ -0,0 +1,46 @@
2+#!/bin/sh
3+
4+for arg do
5+ case "$arg" in
6+ --backend=*) backend="${arg#*=}" ;;
7+ --help)
8+ echo "Usage: ./configure [--backend=x11|wayland|win|mac]"
9+ exit 0
10+ ;;
11+ *)
12+ echo "Unknown argument: $arg"
13+ exit 1
14+ ;;
15+ esac
16+done
17+
18+cat > config.mk << EOF
19+# Generated by configure script
20+BACKEND = $backend
21+EOF
22+
23+case "$backend" in
24+ x11)
25+ echo "CONF_CPPFLAGS = -DBACKEND_X11" >> config.mk
26+ echo "CONF_LDFLAGS = -lX11 -lXext" >> config.mk
27+ echo "CONF_SRC = source/maus_x11.c" >> config.mk
28+ echo "CONF_OBJS = build/maus_x11.o" >> config.mk
29+ echo "CONF_LIB_NAME = libmaus_x11.a" >> config.mk
30+ ;;
31+ wayland)
32+ # TODO
33+ ;;
34+ win)
35+ # TODO
36+ ;;
37+ mac)
38+ # TODO
39+ ;;
40+ *)
41+ echo "Unsupported backend '$backend'"
42+ rm -f config.mk
43+ exit 1
44+ ;;
45+esac
46+echo "Configuration done"
47+
+4,
-7
1@@ -1,13 +1,10 @@
2 CC = cc
3 CFLAGS = -std=c99 -Wall -Wextra -g
4-CPPFLAGS = -DBACKEND_X11
5+CPPFLAGS = -DBACKEND_X11 -I../../include
6 LIBS = -lX11 -lXext
7+MAUS_LIB = ../../build/libmaus_x11.a
8
9-SRC = main.c \
10- ../../maus.c \
11- ../../maus_x11.c \
12- ../../maus_font.c
13+SRC = main.c
14
15 all:
16- ${CC} ${SRC} -o basic-window ${CFLAGS} ${LIBS}
17-
18+ ${CC} ${CFLAGS} ${CPPFLAGS} ${SRC} ${MAUS_LIB} ${LIBS} -o basic-window
+0,
-0
+2,
-2
1@@ -2,8 +2,8 @@
2 #include <stdint.h>
3 #include <stdlib.h>
4
5-#include "../../maus.h"
6-#include "../../maus_font.h"
7+#include "maus.h"
8+#include "maus_font.h"
9
10 int mx, my;
11 bool cur_visible = true;
R maus.h =>
include/maus.h
+2,
-0
1@@ -21,6 +21,8 @@
2 #define BACKEND_X11
3
4 #endif
5+#else
6+#define MAUS_WARN_BACKEND_AUTO_SEL 0
7 #endif /* auto selection */
8
9 #if defined(BACKEND_X11)
R maus_font.h =>
include/maus_font.h
+0,
-0
R maus_input.h =>
include/maus_input.h
+0,
-0
R maus_x11.h =>
include/maus_x11.h
+0,
-0
R utils.h =>
include/utils.h
+0,
-0
R maus.c =>
source/maus.c
+0,
-0
R maus_font.c =>
source/maus_font.c
+0,
-0
R maus_x11.c =>
source/maus_x11.c
+0,
-0
+27,
-0
1@@ -0,0 +1,27 @@
2+#ifndef MAUS_X11_H
3+#define MAUS_X11_H
4+
5+#include <stdbool.h>
6+
7+#include <X11/Xlib.h>
8+#include <X11/extensions/XShm.h>
9+
10+typedef enum {
11+ MAUS_ATOM_WM_DELETE_WINDOW,
12+ MAUS_ATOM_LAST,
13+} MausX11Atoms;
14+
15+typedef struct {
16+ Display* display;
17+ Window root;
18+ Window win;
19+ Atom atoms[MAUS_ATOM_LAST];
20+ GC gc;
21+
22+ XImage* image;
23+ XShmSegmentInfo shm;
24+ bool shmat;
25+} MausBackend;
26+
27+#endif /* MAUS_X11_H */
28+
R utils.c =>
source/utils.c
+0,
-0
+11,
-0
1@@ -0,0 +1,11 @@
2+#ifndef UTIL_H
3+#define UTIL_H
4+
5+/* duplicate a string. returns pointer to address of
6+ newly allocated string buffer. if NULL, allocation
7+ failed or src is NULL
8+ note: you must free this newly allocated string */
9+char* strdup(const char* src);
10+
11+#endif /* UTIL_H */
12+