-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
162 lines (135 loc) · 6.27 KB
/
Makefile
File metadata and controls
162 lines (135 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
.DEFAULT_GOAL := debug
PROG := scran
BUILD_DIR := build
wayland_protocols_generated_source_dir := $(BUILD_DIR)/wayland-protocols-generated-source
WL_PROTOCOLS_DIR_LOCAL := $(wayland_protocols_generated_source_dir)
PKG_CONFIG ?= pkg-config
SD_BUS_LIB := $(shell if $(PKG_CONFIG) --exists basu 2>/dev/null; then echo "basu"; \
elif $(PKG_CONFIG) --exists libsystemd 2>/dev/null; then echo "libsystemd"; \
fi)
ffmpeg_libs := libavcodec libavutil libavformat libavfilter
PKGCONF_LIBS := xkbcommon wayland-client $(ffmpeg_libs) $(SD_BUS_LIB)
_LDLIBS := -lblend2d -lm
_LDLIBS += $(shell $(PKG_CONFIG) --libs $(PKGCONF_LIBS))
ALL_LDLIBS = $(_LDLIBS) $(LDLIBS)
# TODO: Separate Makefile for scranrot
INCDIRS := include/ scranrot/include
INCDIRS += $(WL_PROTOCOLS_DIR_LOCAL)
# TODO: CPPFLAGS?
_CFLAGS := $(addprefix -I, $(INCDIRS))
_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(PKGCONF_LIBS))
ifeq ($(SD_BUS_LIB),libsystemd)
_CFLAGS += -DSCRAN_LIBSYSTEMD_SD_BUS
endif
ALL_CFLAGS = $(_CFLAGS) $(CFLAGS)
CFLAGS_REL ?= -DNDEBUG
ALL_CFLAGS_REL = $(ALL_CFLAGS) $(CFLAGS_REL)
CFLAGS_DBG ?= -gdwarf-5 -O0 -U_FORTIFY_SOURCE
ALL_CFLAGS_DBG = $(ALL_CFLAGS) $(CFLAGS_DBG)
# $(1): Package name
# $(2): Version
# TODO: Don't fail instantly - let user see all failed first.
define shell_validate_dependency
$(if $(strip $(2)),\
echo -n "Checking dependency: $(1) >=$(2): "; \
$(PKG_CONFIG) --atleast-version=$(2) $(1),\
echo -n "Checking dependency: $(1): "; \
$(PKG_CONFIG) --exists $(1)\
) && echo "OK." || { echo "Failed."; exit 1; }
endef
.PHONY: validate_dependencies
# TODO: Add flake as well
# TODO: More comprehensive version validation
validate_dependencies:
@# wayland-scanner private-code subcommand introduced in 1.14.91
@$(call shell_validate_dependency,wayland-scanner,1.14.91)
@# TODO: Verify protocol versions, or just bundle the xmls with scran
@$(call shell_validate_dependency,wayland-protocols)
@if [ -z "$(SD_BUS_LIB)" ]; then \
echo "No sd-bus library found. Please install 'basu' or 'libsystemd'."; \
exit 1; \
fi
@for pkg in $(PKGCONF_LIBS); do \
$(call shell_validate_dependency,$$pkg); \
done
# TODO: Simply-expanded, but lazily initialized shell/$(PKG_CONFIG) output variables
# I.e. don't require shell commands to run for targets that don't
# need them, but also don't evaluate them more times than necessary.
WAYLAND_SCANNER := $(shell $(PKG_CONFIG) --variable=wayland_scanner wayland-scanner)
WL_PROTOCOLS_DIR := $(shell $(PKG_CONFIG) --variable=pkgdatadir wayland-protocols)
WLR_PROTOCOLS_DIR := wayland-protocol-extensions/wlr-protocols
COSMIC_PROTOCOLS_DIR := wayland-protocol-extensions/cosmic-protocols
HYPRLAND_PROTOCOLS_DIR := wayland-protocol-extensions/hyprland-protocols
wl_protocols_required_xml_paths := \
$(WLR_PROTOCOLS_DIR)/unstable/wlr-layer-shell-unstable-v1.xml \
$(WLR_PROTOCOLS_DIR)/unstable/wlr-output-management-unstable-v1.xml \
$(COSMIC_PROTOCOLS_DIR)/unstable/cosmic-output-management-unstable-v1.xml \
$(HYPRLAND_PROTOCOLS_DIR)/hyprland-surface-v1.xml \
$(WL_PROTOCOLS_DIR)/stable/xdg-shell/xdg-shell.xml \
$(WL_PROTOCOLS_DIR)/stable/tablet/tablet-v2.xml \
$(WL_PROTOCOLS_DIR)/stable/presentation-time/presentation-time.xml \
$(WL_PROTOCOLS_DIR)/stable/viewporter/viewporter.xml \
$(WL_PROTOCOLS_DIR)/unstable/xdg-output/xdg-output-unstable-v1.xml \
$(WL_PROTOCOLS_DIR)/staging/cursor-shape/cursor-shape-v1.xml \
$(WL_PROTOCOLS_DIR)/staging/ext-image-capture-source/ext-image-capture-source-v1.xml \
$(WL_PROTOCOLS_DIR)/staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml \
$(WL_PROTOCOLS_DIR)/staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml \
$(WL_PROTOCOLS_DIR)/staging/ext-data-control/ext-data-control-v1.xml \
$(WL_PROTOCOLS_DIR)/staging/fractional-scale/fractional-scale-v1.xml
# $(1): Wayland protocol .xml path
# $(2): Output file extension
define create_protocol_output_path
$(WL_PROTOCOLS_DIR_LOCAL)/$(basename $(notdir $(1)))$(2)
endef
# $(1): Wayland protocol .xml path
define wl_protocol_rule
$(call create_protocol_output_path,$(1),.h) \
$(call create_protocol_output_path,$(1),.c) \
: $(1)
@mkdir -p $(WL_PROTOCOLS_DIR_LOCAL)
$(WAYLAND_SCANNER) client-header $(1) $(call create_protocol_output_path,$(1),.h)
$(WAYLAND_SCANNER) private-code $(1) $(call create_protocol_output_path,$(1),.c)
endef
$(foreach path, $(wl_protocols_required_xml_paths), $(eval $(call wl_protocol_rule,$(path))))
# XXX: These should probably inputs to wl_protocol_rule
wayland_protocols_srcs_c := $(foreach path, $(wl_protocols_required_xml_paths), $(call create_protocol_output_path,$(path),.c))
wayland_protocols_srcs_h := $(foreach path, $(wl_protocols_required_xml_paths), $(call create_protocol_output_path,$(path),.h))
wayland_protocols_srcs := $(wayland_protocols_srcs_c) $(wayland_protocols_srcs_h)
.PHONY: protocols_srcs
protocols_srcs: $(wayland_protocols_srcs)
build_dir_release := $(BUILD_DIR)/release
build_dir_debug := $(BUILD_DIR)/debug
$(build_dir_release)/%.o: %.c protocols_srcs
@mkdir -p $(dir $@)
$(CC) $(ALL_CFLAGS_REL) -c $< -o $@
$(build_dir_debug)/%.o: %.c protocols_srcs
@mkdir -p $(dir $@)
$(CC) $(ALL_CFLAGS_DBG) -c $< -o $@
# TODO: Separate Makefile for scranrot
# TODO: Handle changed header files
_srcdirs := src src/event-handlers src/init src/util scranrot/src
srcs := $(foreach dir,$(_srcdirs),$(wildcard $(dir)/*.c))
prog_release := $(build_dir_release)/$(PROG)
prog_debug := $(build_dir_debug)/$(PROG)
_objs := $(srcs:.c=.o) $(wayland_protocols_srcs_c:.c=.o)
objs_release := $(addprefix $(build_dir_release)/, $(_objs))
objs_debug := $(addprefix $(build_dir_debug)/, $(_objs))
$(prog_release): $(objs_release)
$(CC) $(ALL_CFLAGS_REL) $(LDFLAGS) $^ $(ALL_LDLIBS) -o $(prog_release)
$(prog_debug): $(objs_debug)
$(CC) $(ALL_CFLAGS_DBG) $(LDFLAGS) $^ $(ALL_LDLIBS) -o $(prog_debug)
.PHONY: all
all: release debug
.PHONY: release debug
release: validate_dependencies $(prog_release)
debug: validate_dependencies $(prog_debug)
.PHONY: protocols
_wayland_protocols_objs_debug := $(addprefix $(build_dir_debug)/, $(wayland_protocols_srcs_c:.c=.o))
protocols: $(wayland_protocols_srcs) $(_wayland_protocols_objs_debug)
.PHONY: clean clean-objs clean-generated-src
clean:
rm -rf $(BUILD_DIR)
clean-objs:
rm -f $(objs_release) $(objs_debug)
clean-generated-src:
rm -rf $(wayland_protocols_generated_source_dir)