brewery
notashelf /
c0b893887d9ad56984ab61f55e64a4e43b89f634

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git
Makefile267 lines9.7 KB
1
PROJECT_NAME = chroma
2
VERSION = 1.1.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 += -fstack-protector-strong -fstack-clash-protection
21
CFLAGS += -fno-common -Wconversion -Wshadow -Wstrict-prototypes
22
CFLAGS += -Wdouble-promotion -Wformat=2 -Wnormalized=nfc
23
CFLAGS += -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)\"
24
25
# Include path for generated headers
26
CPPFLAGS = -I$(INCDIR) -I$(INCDIR)/vendor -isystem $(INCDIR)/vendor
27
28
# Debug build flags
29
DEBUG_CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -Og -g3 -DDEBUG
30
DEBUG_CFLAGS += -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)-debug\"
31
DEBUG_CFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
32
33
# Libraries using pkg-config
34
PKG_DEPS = wayland-client wayland-egl egl glesv2 wayland-protocols
35
CFLAGS += $(shell pkg-config --cflags $(PKG_DEPS))
36
LDFLAGS += $(shell pkg-config --libs $(PKG_DEPS))
37
38
# Protocol files
39
PROTOCOL_XML = $(PROTOCOLDIR)/xdg-shell.xml $(PROTOCOLDIR)/wlr-layer-shell-unstable-v1.xml
40
PROTOCOL_HEADERS = $(PROTOCOL_XML:$(PROTOCOLDIR)/%.xml=$(INCDIR)/%.h)
41
PROTOCOL_SOURCES = $(PROTOCOL_XML:$(PROTOCOLDIR)/%.xml=$(SRCDIR)/%.c)
42
PROTOCOL_OBJECTS = $(PROTOCOL_SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
43
44
# Additional libraries
45
LDFLAGS += -lm -ldl
46
47
# Source files (excluding generated protocol files)
48
SOURCES = $(filter-out $(PROTOCOL_SOURCES), $(wildcard $(SRCDIR)/*.c))
49
OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) $(PROTOCOL_OBJECTS)
50
DEPENDS = $(OBJECTS:.o=.d)
51
52
# Override object files for image.c and render.c to suppress third-party warnings
53
OBJECTS := $(filter-out $(OBJDIR)/image.o $(OBJDIR)/render.o,$(OBJECTS))
54
OBJECTS += $(OBJDIR)/image.o $(OBJDIR)/render.o
55
56
# Default target
57
TARGET = $(BINDIR)/$(PROJECT_NAME)
58
all: $(TARGET)
59
60
# Create directories
61
$(OBJDIR):
62
	@mkdir -p $(OBJDIR)
63
64
$(BINDIR):
65
	@mkdir -p $(BINDIR)
66
67
# Protocol generation
68
$(INCDIR)/%.h: $(PROTOCOLDIR)/%.xml | $(INCDIR)
69
	@echo "  PROTO $<"
70
	@wayland-scanner client-header $< $@
71
72
$(SRCDIR)/%.c: $(PROTOCOLDIR)/%.xml
73
	@echo "  PROTO $<"
74
	@wayland-scanner private-code $< $@
75
76
# Make sure include directory exists
77
$(INCDIR):
78
	@mkdir -p $(INCDIR)
79
80
# Build main executable
81
$(TARGET): version-header $(PROTOCOL_HEADERS) $(OBJECTS) | $(BINDIR)
82
	@echo "  LINK  $@"
83
	@$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
84
85
# Compile source files
86
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(PROTOCOL_HEADERS) | $(OBJDIR)
87
	@echo "  CC    $<"
88
	@$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -Wno-error -c $< -o $@
89
90
$(OBJDIR)/image.o: $(SRCDIR)/image.c $(PROTOCOL_HEADERS) | $(OBJDIR)
91
	@echo "  CC    $<"
92
	@$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion -MMD -MP -Wno-error -c $< -o $@
93
94
$(OBJDIR)/render.o: $(SRCDIR)/render.c $(PROTOCOL_HEADERS) | $(OBJDIR)
95
	@echo "  CC    $<"
96
	@$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion -MMD -MP -Wno-error -c $< -o $@
97
98
# Debug build
99
debug: CFLAGS = $(DEBUG_CFLAGS)
100
debug: $(TARGET)
101
102
# Static build (for distribution)
103
static: LDFLAGS += -static
104
static: $(TARGET)
105
106
# Check if required dependencies are available
107
check-deps:
108
	@echo "Checking dependencies..."
109
	@pkg-config --exists $(PKG_DEPS) || (echo "Missing dependencies. Install: wayland-protocols libwayland-dev libegl1-mesa-dev libgl1-mesa-dev wayland-scanner" && exit 1)
110
	@which wayland-scanner >/dev/null || (echo "wayland-scanner not found. Please install wayland-scanner." && exit 1)
111
	@echo "All dependencies found."
112
113
# Install
114
install: $(TARGET)
115
	@echo "Installing $(PROJECT_NAME)..."
116
	install -Dm755 $(TARGET) $(DESTDIR)$(BINDIR_INSTALL)/$(PROJECT_NAME)
117
	@if [ -f $(SYSTEMD_DIR)/$(PROJECT_NAME).service ]; then \
118
		echo "Installing systemd service..."; \
119
		install -Dm644 $(SYSTEMD_DIR)/$(PROJECT_NAME).service $(DESTDIR)$(SYSTEMD_INSTALL)/$(PROJECT_NAME).service; \
120
	fi
121
	@echo "Installation complete."
122
123
# Uninstall
124
uninstall:
125
	@echo "Uninstalling $(PROJECT_NAME)..."
126
	rm -f $(DESTDIR)$(BINDIR_INSTALL)/$(PROJECT_NAME)
127
	rm -f $(DESTDIR)$(SYSTEMD_INSTALL)/$(PROJECT_NAME).service
128
	@echo "Uninstall complete."
129
130
# Create version header
131
version-header:
132
	@echo "Generating version header..."
133
	@echo "#ifndef CHROMA_VERSION_H" > $(INCDIR)/chroma_version.h
134
	@echo "#define CHROMA_VERSION_H" >> $(INCDIR)/chroma_version.h
135
	@echo "" >> $(INCDIR)/chroma_version.h
136
	@echo "#ifndef CHROMA_VERSION" >> $(INCDIR)/chroma_version.h
137
	@echo "#define CHROMA_VERSION \"$(VERSION)\"" >> $(INCDIR)/chroma_version.h
138
	@echo "#endif" >> $(INCDIR)/chroma_version.h
139
	@echo "" >> $(INCDIR)/chroma_version.h
140
	@echo "#endif // CHROMA_VERSION_H" >> $(INCDIR)/chroma_version.h
141
142
# Create systemd service file
143
systemd-service: $(SYSTEMD_DIR)/$(PROJECT_NAME).service
144
145
# Create sample configuration file
146
sample-config:
147
	@echo "Creating sample configuration..."
148
	@cp chroma.conf.sample $(CONFIG_FILE_NAME)
149
	@echo "Sample configuration created at $(CONFIG_FILE_NAME)"
150
151
# Clean build artifacts
152
clean:
153
	@echo "Cleaning build artifacts..."
154
	rm -rf $(OBJDIR) $(BINDIR)
155
	rm -f $(PROTOCOL_HEADERS) $(PROTOCOL_SOURCES)
156
	rm -f "vcore.*"
157
158
# Format source code (requires clang-format)
159
format:
160
	@echo "Formatting source code..."
161
	@find $(SRCDIR) -name "*.c" -o -name "*.h" | grep -v '/vendor/' | xargs clang-format -i
162
163
# Static analysis (requires cppcheck)
164
analyze:
165
	@echo "Running static analysis..."
166
	@cppcheck --enable=all --std=c11 --language=c \
167
		--include=$(INCDIR) \
168
		--suppress=missingIncludeSystem \
169
		--quiet \
170
		$(SRCDIR)
171
172
# Run tests
173
test: $(TARGET)
174
	@echo "Running unit tests..."
175
	@$(CC) -o bin/test tests/test.c lib/test_common.c \
176
		-I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
177
	@./bin/test
178
179
# Run benchmarks
180
bench:
181
	@echo "Running performance benchmarks..."
182
	@$(CC) -o bin/bench benchmarks/bench.c lib/test_common.c \
183
		-I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
184
	@./bin/bench
185
186
# Memory analysis tests
187
test-memory:
188
	@echo "Building memory tests..."
189
	@$(CC) -o bin/test tests/test.c lib/test_common.c \
190
		-I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
191
	@valgrind --leak-check=full --show-leak-kinds=all ./bin/test 2>&1 | tee tests/memory_report.txt
192
	@echo "Analysis complete. See tests/memory_report.txt"
193
194
# Generate memory profile CSVs
195
profile-memory:
196
	@$(CC) -o bin/test tests/test.c lib/test_common.c \
197
		-I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
198
	@./bin/test --profile
199
	@echo "CSV files generated in /tmp/"
200
201
# Version management targets
202
bump-patch:
203
	@echo "Bumping patch version..."
204
	@$(eval NEW_VERSION := $(shell echo $(VERSION) | awk -F. '{print $$1"."$$2"."$$3+1}'))
205
	@sed -i 's/^VERSION = .*/VERSION = $(NEW_VERSION)/' Makefile
206
	@echo "Version bumped to $(NEW_VERSION)"
207
208
bump-minor:
209
	@echo "Bumping minor version..."
210
	@$(eval NEW_VERSION := $(shell echo $(VERSION) | awk -F. '{print $$1"."$$2+1".0"}'))
211
	@sed -i 's/^VERSION = .*/VERSION = $(NEW_VERSION)/' Makefile
212
	@echo "Version bumped to $(NEW_VERSION)"
213
214
bump-major:
215
	@echo "Bumping major version..."
216
	@$(eval NEW_VERSION := $(shell echo $(VERSION) | awk -F. '{print $$1+1".0.0"}'))
217
	@sed -i 's/^VERSION = .*/VERSION = $(NEW_VERSION)/' Makefile
218
	@echo "Version bumped to $(NEW_VERSION)"
219
220
set-version:
221
	@if [ -z "$(NEW_VER)" ]; then \
222
		echo "Usage: make set-version NEW_VER=X.Y.Z"; \
223
		exit 1; \
224
	fi
225
	@echo "Setting version to $(NEW_VER)..."
226
	@sed -i 's/^VERSION = .*/VERSION = $(NEW_VER)/' Makefile
227
	@echo "Version set to $(NEW_VER)"
228
229
# Help target
230
help:
231
	@echo "Available targets:"
232
	@echo "  all             - Build main executable (default)"
233
	@echo "  debug           - Build with debug symbols and sanitizers"
234
	@echo "  static          - Build statically linked executable"
235
	@echo "  check-deps      - Check if all dependencies are available"
236
	@echo "  install         - Install executable and systemd service"
237
	@echo "  uninstall       - Remove installed files"
238
	@echo "  sample-config   - Create sample configuration file"
239
	@echo "  clean           - Remove build artifacts"
240
	@echo "  distclean       - Remove all generated files"
241
	@echo "  format          - Format source code (requires clang-format)"
242
	@echo "  analyze         - Run static analysis (requires cppcheck)"
243
	@echo "  test            - Run tests"
244
	@echo "  version-header  - Generate version header from Makefile"
245
	@echo "  bump-patch      - Increment patch version (X.Y.Z+1)"
246
	@echo "  bump-minor      - Increment minor version (X.Y+1.0)"
247
	@echo "  bump-major      - Increment major version (X+1.0.0)"
248
	@echo "  set-version     - Set specific version (use NEW_VER=X.Y.Z)"
249
	@echo "  help            - Show this help message"
250
	@echo ""
251
	@echo "Examples:"
252
	@echo "  make                           # Build with default settings"
253
	@echo "  make debug                     # Build debug version"
254
	@echo "  make PREFIX=/usr install       # Install to /usr instead of /usr/local"
255
	@echo "  make CC=clang                  # Use clang instead of gcc"
256
	@echo "  make bump-patch                # Bump to 1.0.2"
257
	@echo "  make set-version NEW_VER=2.0.0 # Set to 2.0.0"
258
259
# Include dependency files
260
-include $(DEPENDS)
261
262
# Phony targets
263
.PHONY: all debug static check-deps install uninstall systemd-service sample-config version-header clean distclean format analyze test test-memory memory-report help bump-patch bump-minor bump-major set-version
264
265
# Print variables
266
print-%:
267
	@echo '$*=$($*)'