forked from MrGlockenspiel/activate-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
150 lines (122 loc) · 3.72 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
# 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
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
CFLAGS += -Isrc
# Echo function
<< := @echo
ifneq ($(shell eval 'echo -e'),-e)
<< += -e
endif
# Mess with backends
<<backends>> = $(sort $(filter x11 wayland gdi,$(backends)))
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
ifeq ($(shell pkg-config --exists libconfig && echo exists),exists)
PKGS += libconfig
CFLAGS += -DLIBCONFIG
endif
ifneq ($(PKGS),)
CFLAGS += $(shell pkg-config --cflags $(PKGS))
LDFLAGS += $(shell pkg-config --libs $(PKGS))
endif
<<sources>> := \
$(wildcard src/*.c) \
$(foreach <<backend>>,$(<<backends>>),$(wildcard src/$(<<backend>>)/*.c))
<<generators>> := \
$(wildcard src/*.cgen) \
$(foreach <<backend>>,$(<<backends>>),$(wildcard src/$(<<backend>>)/*.cgen))
<<hgenerators>> := \
$(wildcard src/*.hgen) \
$(foreach <<backend>>,$(<<backends>>),$(wildcard src/$(<<backend>>)/*.hgen))
<<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
ifneq ($(sort $(file < .$(BINARY).d)),$(<<backends>>))
<<null>> := $(file > .$(BINARY).d,$(<<backends>>))
endif
undefine <<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>>)
$(<<) "LINK\t" $(^:obj/%=%)
@$(CC) $(^) -o $(@) $(LDFLAGS)
install: $(BINARY)
sudo install -Dm0755 $(BINARY) $(DESTDIR)$(PREFIX)/$(BINDIR)/$(BINARY)
sudo install -Dm0644 activate-linux.1 $(MANDIR)/man1/activate-linux.1
sudo mandb -q
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" $(<<objects>>:obj/%=%) $(BINARY)
@$(RM) -f $(<<objects>>) $(BINARY) .$(BINARY).d
test: $(BINARY)
./$(BINARY)
obj/activate_linux.o: .$(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)