-
Notifications
You must be signed in to change notification settings - Fork 94
/
Makefile
172 lines (142 loc) · 4.4 KB
/
Makefile
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
162
163
164
165
166
167
168
169
170
171
172
# if $CC is not set, guess default `cc'. It has to be in system
CC ?= cc
# compile options
CFLAGS ?= -Os -Wall -Wpedantic -Wextra
# link options
LDFLAGS ?= -s
# install path is: $(DESTDIR)$(PREFIX)/$(BINDIR)/$(BINARY)
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= bin
MANDIR ?= $(PREFIX)/share/man
# implemented backends: wayland x11 gdi
backends ?= wayland x11
# addons
with ?= libconfig
# needs rebuild on dependency change (object name, w/o obj/ prefix)
<<needs-rebuild>> = \
activate_linux.o \
options.o
IS_CLANG = $(shell $(CC) -v 2>&1 | grep -q clang && echo true)
ifeq ($(IS_CLANG),true)
CFLAGS += -Wno-gnu-zero-variadic-macro-arguments
CFLAGS += -Wno-empty-translation-unit
endif
# Echo function
<< := echo
ifneq ($(shell eval 'echo -e'),-e)
<< += -e
endif
# Mess with backends
<<backends>> = $(sort $(filter x11 wayland gdi,$(backends)))
# optional addons
<<with>> = $(sort $(filter libconfig,$(with)))
<<addons>> =
<<addon-srcs>> = src/config.c
ifeq ($(filter x11,$(<<backends>>)),x11)
PKGS += x11 xfixes xinerama xrandr xext x11
CFLAGS += -DX11
endif
ifeq ($(filter wayland,$(<<backends>>)),wayland)
PKGS += wayland-client
CFLAGS += -DWAYLAND
LDFLAGS += -lrt
endif
ifneq ($(filter wayland x11,$(<<backends>>)),)
PKGS += cairo
CFLAGS += -DCOLOR_HELP -DCAIRO
endif
ifeq ($(filter gdi,$(<<backends>>)),gdi)
# Current toolchain architecture variable from MSYS2 project
ifeq ($(MSYSTEM_CARCH),i686)
CFLAGS += -m32
endif
CFLAGS += -DGDI
LDFLAGS += -lgdi32
endif
# rebuild on optional deps change
ifneq ($(filter libconfig,$(<<with>>)),)
ifneq ($(shell pkg-config --exists libconfig && echo exists),)
PKGS += libconfig
CFLAGS += -DLIBCONFIG
<<addons>> += libconfig
endif
endif
ifneq ($(PKGS),)
CFLAGS += $(shell pkg-config --cflags $(PKGS))
LDFLAGS += $(shell pkg-config --libs $(PKGS))
endif
<<sources>> := \
$(filter-out $(<<addon-srcs>>), \
$(wildcard src/*.c) \
$(foreach <<backend>>,$(<<backends>>),$(wildcard src/$(<<backend>>)/*.c)))
<<generators>> := \
$(filter-out $(<<addon-srcs>>), \
$(wildcard src/*.cgen) \
$(foreach <<backend>>,$(<<backends>>),$(wildcard src/$(<<backend>>)/*.cgen)))
<<hgenerators>> := \
$(filter-out $(<<addon-srcs>>), \
$(wildcard src/*.hgen) \
$(foreach <<backend>>,$(<<backends>>),$(wildcard src/$(<<backend>>)/*.hgen)))
ifneq ($(filter libconfig,$(<<addons>>)),)
<<sources>> += src/config.c
endif
<<objects>> := $(<<sources>>:src/%.c=obj/%.o)
<<objects>> += $(<<generators>>:src/%.cgen=obj/%.o)
# Output file name
NAME := $(shell uname -s)
ifeq ($(NAME),Linux)
BINARY ?= activate-linux
endif
ifeq ($(NAME),Darwin)
BINARY ?= activate-macos
endif
ifneq (, filter($(shell uname -o),Msys Cygwin))
ifeq ($(MSYSTEM_CARCH),i686)
BINARY ?= activate-windows.exe
else
BINARY ?= activate-windows64.exe
endif
endif
# Use .$(BINARY).d file to track backend change
<<depends>> = $(sort $(<<backends>>) $(<<addons>>))
ifneq ($(sort $(file < .$(BINARY).d)),$(<<depends>>))
<<null>> := $(file > .$(BINARY).d,$(<<depends>>))
endif
undefine <<depends>> <<null>>
# using some makefile sorcery
all: $(BINARY)
obj/%.o: src/%.c
@$(<<) " CC\t" $(<:src/%=%)
@mkdir -p $(shell dirname $(@))
@$(CC) -c $(<) -o $(@) $(CFLAGS)
%.h: %.hgen
@$(<<) " GEN\t" $(@:src/%=%)
@sh -- $(<) $(@)
%.c: %.cgen
@$(<<) " GEN\t" $(@:src/%=%)
@sh -- $(<) $(@)
$(BINARY): $(<<objects>>)
@if test -n "$(<<addons>>)"; then $(<<) "WITH\t" $(<<addons>>);fi
@$(<<) "LINK\t" "$(BINARY)$(^:obj/%=\\n\\t + %)"
@$(CC) $(^) -o $(@) $(LDFLAGS)
install: $(BINARY)
install -Dm0755 $(BINARY) $(DESTDIR)$(PREFIX)/$(BINDIR)/$(BINARY)
install -Dm0644 activate-linux.1 $(MANDIR)/man1/activate-linux.1
uninstall:
sudo $(RM) -f $(DESTDIR)$(PREFIX)/$(BINDIR)/$(BINARY)
sudo $(RM) -f $(MANDIR)/man1/activate-linux.1
sudo mandb -q
appimage: $(BINARY)
curl -#L -O https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage
./linuxdeploy-x86_64.AppImage --appdir AppDir --executable ./$(BINARY) --desktop-file res/activate-linux.desktop --icon-file res/icon.png --output appimage
clean:
@$(<<) " RM\t" "$(BINARY)$(<<objects>>:obj/%=\\n\\t + %)"
@$(RM) -f $(<<objects>>) $(BINARY) .$(BINARY).d
test: $(BINARY)
./$(BINARY)
$(<<needs-rebuild>>:%=obj/%): .$(BINARY).d
obj/wayland/wayland.o: src/wayland/wlr-layer-shell-unstable-v1.h
.PHONY: all clean install uninstall test
.INTERMEDIATE: $(<<hgenerators>>:%.hgen=%.h) $(<<generators>>:%.cgen=%.c)