forked from pop-os/firmware-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (134 loc) · 4.77 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
173
174
175
prefix ?= /usr/local
bindir = $(prefix)/bin
includedir = $(prefix)/include
libdir = $(prefix)/lib
sharedir = $(prefix)/share
export CARGO_C_PREFIX = $(prefix)
export CARGO_C_LIBDIR = $(libdir)
TARGET = debug
DEBUG ?= 0
S76_DEV ?= 0
ARGS = --no-default-features
ifeq ($(DEBUG),0)
TARGET = release
ARGS += --release
endif
VENDOR ?= 0
ifneq ($(VENDOR),0)
ARGS += --frozen
DESKTOP_ARGS += --frozen
endif
APPID = com.system76.FirmwareManager
NOTIFY_APPID = $(APPID).Notify
NOTIFY_SERVICE = $(NOTIFY_APPID).service
NOTIFY_TIMER = $(NOTIFY_APPID).timer
GTKPROJ = gtk/Cargo.toml
GTKFFIPROJ = gtk/ffi/Cargo.toml
NOTPROJ = notify/Cargo.toml
PACKAGE = firmware_manager
DESKTOP = target/$(APPID).desktop
STARTUP_DESKTOP = target/$(APPID).Notify.desktop
GTKBINARY = target/$(TARGET)/firmware-manager-gtk
NOTBINARY = target/$(TARGET)/firmware-manager-notify
LIBRARY = target/$(TARGET)/lib$(PACKAGE).so
PKGCONFIG = target/$(PACKAGE).pc
HEADER = gtk/ffi/$(PACKAGE).h
VERSION = $(shell grep version Cargo.toml | head -1 | awk '{print $$3}' | tail -c +2 | head -c -2)
SOURCES = $(shell find src -type f -name '*.rs') Cargo.toml Cargo.lock \
$(shell find tools/src -type f -name '*.rs') tools/Cargo.toml
FFI_SOURCES = $(shell find gtk/ffi/src -type f -name '*.rs') \
gtk/ffi/Cargo.toml gtk/ffi/build.rs gtk/ffi/$(PACKAGE).h
all: $(GTKBINARY) $(NOTBINARY) $(LIBRARY) $(PKGCONFIG)
clean:
cargo clean
distclean: clean
rm -rf .cargo vendor vendor.tar
## Developer tools
clippy:
cargo clippy --manifest-path $(GTKPROJ) $(ARGS)'
cargo clippy --manifest-path $(NOTPROJ) $(ARGS)'
## Building the binaries
bin $(GTKBINARY): $(DESKTOP) vendor-extract
cargo build --manifest-path $(GTKPROJ) $(ARGS)
bin-notify $(NOTBINARY): $(STARTUP_DESKTOP) vendor-extract
env APPID=$(NOTIFY_APPID) prefix=$(prefix) \
cargo build --manifest-path $(NOTPROJ) $(ARGS)
## Builds the desktop entry in the target directory.
desktop $(DESKTOP): vendor-extract
cargo run -p tools --bin desktop-entry $(DESKTOP_ARGS) -- \
--appid $(APPID) \
--name "Firmware Manager" \
--icon firmware-manager \
--comment "Manage system and device firmware" \
--keywords firmware \
--keywords system76 \
--keywords fwupd \
--keywords lvfs \
--categories System \
--categories GTK \
--binary $(APPID) \
--prefix $(prefix) \
--startup-notify
notify-desktop $(STARTUP_DESKTOP): vendor-extract
cargo run -p tools --bin desktop-entry $(DESKTOP_ARGS) -- \
--appid $(NOTIFY_APPID) \
--name "Firmware Manager Check" \
--icon firmware-manager \
--comment "Check for firmware updates, and display notification if found" \
--categories System \
--binary $(NOTIFY_APPID) \
--prefix $(prefix) \
## Building the library
ffi: $(LIBRARY) $(PKGCONFIG)
$(LIBRARY): $(SOURCES) $(FFI_SOURCES) vendor-extract
cargo build --manifest-path $(GTKFFIPROJ) $(ARGS)
## Builds the pkg-config file necessary to locate the library.
$(PKGCONFIG): tools/src/pkgconfig.rs
cargo run -p tools --bin pkgconfig $(DESKTOP_ARGS) -- \
$(PACKAGE) $(libdir) $(includedir)
## Install commands
install: install-bin install-ffi install-notify install-icons
install-bin:
install -Dm0755 "$(GTKBINARY)" "$(DESTDIR)$(bindir)/$(APPID)"
install -Dm0644 "$(DESKTOP)" "$(DESTDIR)$(prefix)/share/applications/$(APPID).desktop"
install -Dm0644 "assets/$(APPID).appdata.xml" "$(DESTDIR)$(sharedir)/metainfo/$(APPID).appdata.xml"
install-ffi:
install -Dm0644 "$(HEADER)" "$(DESTDIR)$(includedir)/$(PACKAGE).h"
install -Dm0644 "$(LIBRARY)" "$(DESTDIR)$(libdir)/lib$(PACKAGE).so"
install -Dm0644 "$(PKGCONFIG)" "$(DESTDIR)$(libdir)/pkgconfig/$(PACKAGE).pc"
install-notify:
install -Dm0755 "$(NOTBINARY)" "$(DESTDIR)$(bindir)/$(NOTIFY_APPID)"
install -Dm0644 "$(STARTUP_DESKTOP)" "$(DESTDIR)/etc/xdg/autostart/$(NOTIFY_APPID).desktop"
install -Dm0644 "target/$(NOTIFY_SERVICE)" "$(DESTDIR)$(libdir)/systemd/user/$(NOTIFY_SERVICE)"
install -Dm0644 "target/$(NOTIFY_TIMER)" "$(DESTDIR)$(libdir)/systemd/user/$(NOTIFY_TIMER)"
install-icons:
for icon in $(shell find assets/icons -name *.png -or -name *.svg); do \
dest=$(DESTDIR)$(sharedir)/icons/hicolor/$$(echo "$$icon" | cut -c 13-); \
mkdir -p $$(dirname $$dest); \
cp -v $$icon $$dest; \
done
## Uninstall Commands
uninstall: uninstall-bin uninstall-ffi
uninstall-bin:
rm "$(DESTDIR)$(bindir)/$(APPID)"
uninstall-ffi:
rm "$(DESTDIR)$(includedir)/$(PACKAGE).h"
rm "$(DESTDIR)$(libdir)/lib$(PACKAGE).so"
rm "$(DESTDIR)$(libdir)/pkgconfig/$(PACKAGE).pc"
## Cargo Vendoring
vendor: vendor.tar
vendor.tar:
mkdir -p .cargo
cargo vendor \
--sync gtk/Cargo.toml \
--sync gtk/ffi/Cargo.toml \
--sync notify/Cargo.toml \
--sync tools/Cargo.toml \
| head -n -1 > .cargo/config
echo 'directory = "vendor"' >> .cargo/config
tar pcf vendor.tar vendor
rm -rf vendor
vendor-extract:
ifeq ($(VENDOR),1)
tar pxf vendor.tar
endif