brewery
notashelf /
87d445340a666b2f700aedcc26fabe8f771b7272

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git
Makefile173 lines5.3 KB
1
PROJECT_NAME = chroma
2
VERSION = 1.0.0
3
4
# Directories
5
SRCDIR = src
6
INCDIR = include
7
OBJDIR = obj
8
BINDIR = bin
9
SYSTEMD_DIR = systemd
10
PROTOCOLDIR = protocols
11
12
# Install directories
13
PREFIX ?= /usr/local
14
BINDIR_INSTALL = $(PREFIX)/bin
15
SYSTEMD_INSTALL = $(HOME)/.config/systemd/user
16
17
# Compiler and flags
18
CC = gcc
19
CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -O2 -g
20
CFLAGS += -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)\"
21
CPPFLAGS = -I$(INCDIR)
22
23
# Debug build flags
24
DEBUG_CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -Og -g3 -DDEBUG
25
DEBUG_CFLAGS += -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)-debug\"
26
DEBUG_CFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
27
28
# Libraries using pkg-config
29
PKG_DEPS = wayland-client wayland-egl egl glesv2 wayland-protocols
30
CFLAGS += $(shell pkg-config --cflags $(PKG_DEPS))
31
LDFLAGS += $(shell pkg-config --libs $(PKG_DEPS))
32
33
# Protocol files
34
PROTOCOL_XML = $(PROTOCOLDIR)/xdg-shell.xml $(PROTOCOLDIR)/wlr-layer-shell-unstable-v1.xml
35
PROTOCOL_HEADERS = $(PROTOCOL_XML:$(PROTOCOLDIR)/%.xml=$(INCDIR)/%.h)
36
PROTOCOL_SOURCES = $(PROTOCOL_XML:$(PROTOCOLDIR)/%.xml=$(SRCDIR)/%.c)
37
PROTOCOL_OBJECTS = $(PROTOCOL_SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
38
39
# Additional libraries
40
LDFLAGS += -lm -ldl
41
42
# Source files (excluding generated protocol files)
43
SOURCES = $(filter-out $(PROTOCOL_SOURCES), $(wildcard $(SRCDIR)/*.c))
44
OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) $(PROTOCOL_OBJECTS)
45
DEPENDS = $(OBJECTS:.o=.d)
46
47
# Default target
48
TARGET = $(BINDIR)/$(PROJECT_NAME)
49
all: $(TARGET)
50
51
# Create directories
52
$(OBJDIR):
53
	@mkdir -p $(OBJDIR)
54
55
$(BINDIR):
56
	@mkdir -p $(BINDIR)
57
58
# Protocol generation
59
$(INCDIR)/%.h: $(PROTOCOLDIR)/%.xml | $(INCDIR)
60
	@echo "  PROTO $<"
61
	@wayland-scanner client-header $< $@
62
63
$(SRCDIR)/%.c: $(PROTOCOLDIR)/%.xml
64
	@echo "  PROTO $<"
65
	@wayland-scanner private-code $< $@
66
67
# Make sure include directory exists
68
$(INCDIR):
69
	@mkdir -p $(INCDIR)
70
71
# Build main executable
72
$(TARGET): $(PROTOCOL_HEADERS) $(OBJECTS) | $(BINDIR)
73
	@echo "  LINK  $@"
74
	@$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
75
76
# Compile source files
77
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(PROTOCOL_HEADERS) | $(OBJDIR)
78
	@echo "  CC    $<"
79
	@$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
80
81
# Debug build
82
debug: CFLAGS = $(DEBUG_CFLAGS)
83
debug: $(TARGET)
84
85
# Static build (for distribution)
86
static: LDFLAGS += -static
87
static: $(TARGET)
88
89
# Check if required dependencies are available
90
check-deps:
91
	@echo "Checking dependencies..."
92
	@pkg-config --exists $(PKG_DEPS) || (echo "Missing dependencies. Install: wayland-protocols libwayland-dev libegl1-mesa-dev libgl1-mesa-dev wayland-scanner" && exit 1)
93
	@which wayland-scanner >/dev/null || (echo "wayland-scanner not found. Please install wayland-scanner." && exit 1)
94
	@echo "All dependencies found."
95
96
# Install
97
install: $(TARGET)
98
	@echo "Installing $(PROJECT_NAME)..."
99
	install -Dm755 $(TARGET) $(DESTDIR)$(BINDIR_INSTALL)/$(PROJECT_NAME)
100
	@if [ -f $(SYSTEMD_DIR)/$(PROJECT_NAME).service ]; then \
101
		echo "Installing systemd service..."; \
102
		install -Dm644 $(SYSTEMD_DIR)/$(PROJECT_NAME).service $(DESTDIR)$(SYSTEMD_INSTALL)/$(PROJECT_NAME).service; \
103
	fi
104
	@echo "Installation complete."
105
106
# Uninstall
107
uninstall:
108
	@echo "Uninstalling $(PROJECT_NAME)..."
109
	rm -f $(DESTDIR)$(BINDIR_INSTALL)/$(PROJECT_NAME)
110
	rm -f $(DESTDIR)$(SYSTEMD_INSTALL)/$(PROJECT_NAME).service
111
	@echo "Uninstall complete."
112
113
# Create systemd service file
114
systemd-service: $(SYSTEMD_DIR)/$(PROJECT_NAME).service
115
116
117
# Clean build artifacts
118
clean:
119
	@echo "Cleaning build artifacts..."
120
	rm -rf $(OBJDIR) $(BINDIR)
121
	rm -f $(PROTOCOL_HEADERS) $(PROTOCOL_SOURCES)
122
123
# Format source code (requires clang-format)
124
format:
125
	@echo "Formatting source code..."
126
	@find $(SRCDIR) $(INCDIR) -name "*.c" -o -name "*.h" | xargs clang-format -i
127
128
# Static analysis (requires cppcheck)
129
analyze:
130
	@echo "Running static analysis..."
131
	@cppcheck --enable=all --std=c11 --language=c \
132
		--include=$(INCDIR) \
133
		--suppress=missingIncludeSystem \
134
		--quiet \
135
		$(SRCDIR)
136
137
# Run tests
138
# FIXME: add tests
139
test: $(TARGET)
140
	@echo "Running tests..."
141
	@echo "Tests not implemented yet."
142
143
# Help target
144
help:
145
	@echo "Available targets:"
146
	@echo "  all             - Build the main executable (default)"
147
	@echo "  debug           - Build with debug symbols and sanitizers"
148
	@echo "  static          - Build statically linked executable"
149
	@echo "  check-deps      - Check if all dependencies are available"
150
	@echo "  install         - Install the executable and systemd service"
151
	@echo "  uninstall       - Remove installed files"
152
	@echo "  clean           - Remove build artifacts"
153
	@echo "  distclean       - Remove all generated files"
154
	@echo "  format          - Format source code (requires clang-format)"
155
	@echo "  analyze         - Run static analysis (requires cppcheck)"
156
	@echo "  test            - Run tests"
157
	@echo "  help            - Show this help message"
158
	@echo ""
159
	@echo "Examples:"
160
	@echo "  make                    # Build with default settings"
161
	@echo "  make debug              # Build debug version"
162
	@echo "  make PREFIX=/usr install # Install to /usr instead of /usr/local"
163
	@echo "  make CC=clang           # Use clang instead of gcc"
164
165
# Include dependency files
166
-include $(DEPENDS)
167
168
# Phony targets
169
.PHONY: all debug static check-deps install uninstall systemd-service sample-config clean distclean format analyze test help
170
171
# Print variables
172
print-%:
173
	@echo '$*=$($*)'