Debian Codegraph @

Makefile

raw
1 #
2 # Entra ID SSO via Microsoft Identity Broker on Linux
3 #
4 # SPDX-License-Identifier: MPL-2.0
5 # SPDX-FileCopyrightText: Copyright (c) Jan Kiszka, 2020-2024
6 # SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2024
7 #
8 # Authors:
9 # Jan Kiszka <[email protected]>
10 # Felix Moessbauer <[email protected]>
11 #
12 # This Source Code Form is subject to the terms of the Mozilla Public
13 # License, v. 2.0. If a copy of the MPL was not distributed with this
14 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 #
16
17 prefix ?= /usr/local
18 exec_prefix ?= $(prefix)
19 libexecdir ?= $(exec_prefix)/libexec
20 # do not prefix with $(prefix) as these dirs are defined by the browsers
21 firefox_nm_dir ?= /usr/lib/mozilla/native-messaging-hosts
22 chrome_nm_dir ?= /etc/opt/chrome/native-messaging-hosts
23 chrome_ext_dir ?= /usr/share/google-chrome/extensions
24 chromium_nm_dir ?= /etc/chromium/native-messaging-hosts
25 # local install path
26 brave_lconfig_dir ?= $(HOME)/.config/BraveSoftware/Brave-Browser
27 firefox_lconfig_dir ?= $(HOME)/.mozilla
28 chrome_lconfig_dir ?= $(HOME)/.config/google-chrome
29 chromium_lconfig_dir ?= $(HOME)/.config/chromium
30 vivaldi_lconfig_dir ?= $(HOME)/.config/vivaldi
31 # python3 system interpreter for global installs
32 python3_bin ?= $(shell which python3)
33
34 ifeq ($(V),1)
35 Q =
36 else
37 Q = @
38 endif
39
40 PACKAGE_NAME=Linux-Entra-SSO
41
42 RELEASE_TAG ?= $(shell git describe --match "v[0-9].[0-9]*" --dirty)
43 WEBEXT_VERSION=$(RELEASE_TAG:v%=%)
44 ARCHIVE_NAME=$(PACKAGE_NAME)-$(RELEASE_TAG)
45
46 COMMON_INPUT_FILES= \
47 LICENSES/MPL-2.0.txt \
48 src/account.js \
49 src/background.js \
50 src/broker.js \
51 src/device.js \
52 src/platform.js \
53 src/policy.js \
54 src/utils.js \
55 icons/profile-outline_48.png \
56 icons/profile-outline_48.png.license \
57 popup/menu.css \
58 popup/menu.js \
59 popup/menu.html
60
61 CHROME_INPUT_FILES= \
62 $(COMMON_INPUT_FILES) \
63 platform/chrome/manifest.json \
64 platform/chrome/manifest.json.license \
65 platform/chrome/js/platform-chrome.js \
66 platform/chrome/js/platform-factory.js \
67 platform/chrome/storage-schema.json \
68 platform/chrome/storage-schema.json.license \
69 icons/linux-entra-sso_48.png \
70 icons/linux-entra-sso_48.png.license \
71 icons/linux-entra-sso_128.png \
72 icons/linux-entra-sso_128.png.license
73
74 FIREFOX_INPUT_FILES= \
75 $(COMMON_INPUT_FILES) \
76 platform/firefox/manifest.json \
77 platform/firefox/manifest.json.license \
78 platform/firefox/js/platform-firefox.js \
79 platform/firefox/js/platform-factory.js \
80 icons/linux-entra-sso.svg \
81 icons/profile-outline.svg
82
83 THUNDERBIRD_INPUT_FILES= \
84 $(COMMON_INPUT_FILES) \
85 platform/thunderbird/manifest.json \
86 platform/thunderbird/manifest.json.license \
87 platform/thunderbird/js/platform-thunderbird.js \
88 platform/thunderbird/js/platform-factory.js \
89 icons/linux-entra-sso.svg \
90 icons/profile-outline.svg
91
92 # common files for all platforms (relative to build directory)
93 CHROME_PACKAGE_FILES= \
94 $(COMMON_INPUT_FILES) \
95 src/platform-chrome.js \
96 src/platform-factory.js \
97 manifest.json \
98 manifest.json.license \
99 storage-schema.json \
100 storage-schema.json.license \
101 icons/linux-entra-sso_48.png \
102 icons/linux-entra-sso_48.png.license \
103 icons/linux-entra-sso_128.png \
104 icons/linux-entra-sso_128.png.license \
105 popup/profile-outline.svg
106
107 FIREFOX_PACKAGE_FILES= \
108 $(COMMON_INPUT_FILES) \
109 src/platform-firefox.js \
110 src/platform-factory.js \
111 manifest.json \
112 manifest.json.license \
113 icons/linux-entra-sso.svg \
114 popup/profile-outline.svg
115
116 THUNDERBIRD_PACKAGE_FILES= \
117 $(FIREFOX_PACKAGE_FILES) \
118 src/platform-thunderbird.js
119
120 UPDATE_VERSION='s|"version":.*|"version": "$(VERSION)",|'
121 UPDATE_VERSION_PY='s|0.0.0-dev|$(WEBEXT_VERSION)|g'
122 UPDATE_PYTHON_INTERPRETER='1,1s:^\#!.*:\#!$(python3_bin):'
123
124 CHROME_EXT_ID=$(shell $(CURDIR)/platform/chrome/get-ext-id.py $(CURDIR)/build/chrome/)
125 CHROME_EXT_ID_SIGNED=jlnfnnolkbjieggibinobhkjdfbpcohn
126
127 # debian package related vars
128 DEBIAN_PV = $(RELEASE_TAG:v%=%)
129 DEBIAN_PN = linux-entra-sso
130 DEBIAN_DESCRIPTION = Entra ID SSO via Microsoft Identity Broker on Linux
131 DEBIAN_DESTDIR := $(CURDIR)/debuild.d
132 DEBIAN_ARCH = all
133 DEBIAN_PKG_DIR = $(CURDIR)/pkgs
134 DEBIAN_PKG_FILE = $(DEBIAN_PKG_DIR)/$(DEBIAN_PN)_$(DEBIAN_PV)_$(DEBIAN_ARCH).deb
135
136 all package: clean $(CHROME_INPUT_FILES) $(FIREFOX_INPUT_FILES) $(THUNDERBIRD_INPUT_FILES)
137 for P in firefox thunderbird chrome; do \
138 mkdir -p build/$$P/icons build/$$P/popup; \
139 cp platform/$$P/manifest* build/$$P; \
140 cp -rf LICENSES src build/$$P/; \
141 cp platform/$$P/js/* build/$$P/src; \
142 done
143 cp -r build/firefox/icons build/firefox/popup build/thunderbird/
144 cp platform/chrome/storage* build/chrome/
145 cp icons/*.svg icons/profile-outline_48.* build/firefox/icons/
146 cp icons/*.png* icons/profile-outline.svg build/chrome/icons/
147 cp popup/menu.* icons/linux-entra-sso.svg icons/profile-outline.svg build/firefox/popup/
148 cp popup/menu.* icons/linux-entra-sso.svg icons/profile-outline.svg build/chrome/popup/
149 # thunderbird is almost identical to Firefox
150 cp -r build/firefox/icons build/firefox/popup build/thunderbird/
151 cp build/firefox/src/platform-firefox.js build/thunderbird/src/
152 cd build/firefox && zip -r ../$(ARCHIVE_NAME).firefox.xpi $(FIREFOX_PACKAGE_FILES)
153 cd build/thunderbird && zip -r ../$(ARCHIVE_NAME).thunderbird.xpi $(THUNDERBIRD_PACKAGE_FILES)
154 cd build/chrome && zip -r ../$(ARCHIVE_NAME).chrome.zip $(CHROME_PACKAGE_FILES)
155
156 deb:
157 install --mode 00755 --directory $(DEBIAN_DESTDIR)
158 $(MAKE) install DESTDIR=$(DEBIAN_DESTDIR) python3_bin=/usr/bin/python3 prefix=/usr
159 install --mode 644 -D --target-directory=$(DEBIAN_DESTDIR)/usr/share/doc/$(DEBIAN_PN) README.md CONTRIBUTING.md MAINTAINERS.md PRIVACY.md LICENSES/MPL-2.0.txt
160 install --mode 00755 --directory $(DEBIAN_DESTDIR)/DEBIAN
161 { \
162 echo Package: $(DEBIAN_PN); \
163 echo Architecture: $(DEBIAN_ARCH); \
164 echo Section: admin; \
165 echo Priority: optional; \
166 echo 'Maintainer: Dr. Johann Pfefferl <[email protected]>'; \
167 echo Installed-Size: `du --summarize $(DEBIAN_DESTDIR) | cut --fields=1`; \
168 echo 'Depends: python3-pydbus, python3-gi'; \
169 echo Version: $(DEBIAN_PV); \
170 echo Description: $(DEBIAN_DESCRIPTION); \
171 } > $(DEBIAN_DESTDIR)/DEBIAN/control
172 install --mode 775 --directory $(DEBIAN_PKG_DIR)
173 dpkg-deb --deb-format=2.0 --root-owner-group --build $(DEBIAN_DESTDIR) $(DEBIAN_PKG_DIR)
174 @echo Package can be found here: $(DEBIAN_PKG_FILE)
175
176 deb_clean:
177 rm -rf $(DEBIAN_PKG_DIR) $(DEBIAN_DESTDIR)
178
179 clean: deb_clean
180 rm -rf build
181
182 release:
183 ${Q}if [ -z "$(VERSION)" ]; then \
184 echo "VERSION is not set"; \
185 exit 1; \
186 fi
187 ${Q}if [ -n "`git status -s -uno`" ]; then \
188 echo "Working directory is dirty!"; \
189 exit 1; \
190 fi
191 ${Q}sed -i $(UPDATE_VERSION) platform/*/manifest.json
192 git commit -s platform/firefox/manifest.json platform/thunderbird/manifest.json platform/chrome/manifest.json -m "Bump version number"
193 git tag -as v$(VERSION) -m "Release v$(VERSION)"
194
195 #######################
196 # local install targets
197 #######################
198
199 local-install-firefox:
200 install -d $(firefox_lconfig_dir)/native-messaging-hosts
201 install -m 0644 platform/firefox/linux_entra_sso.json $(firefox_lconfig_dir)/native-messaging-hosts
202 ${Q}sed -i 's|/usr/local/lib/linux-entra-sso/|'$(firefox_lconfig_dir)'/|' $(firefox_lconfig_dir)/native-messaging-hosts/linux_entra_sso.json
203 install -m 0755 linux-entra-sso.py $(firefox_lconfig_dir)
204 ${Q}sed -i $(UPDATE_VERSION_PY) $(firefox_lconfig_dir)/linux-entra-sso.py
205
206 # Helper target for installing Chromium-based browsers
207 # Usage: make local-install-chromium-based BROWSER_CONFIG_PATH=~/.config/chromium
208 local-install-chromium-based:
209 install -d $(BROWSER_CONFIG_PATH)/NativeMessagingHosts
210 install -m 0644 platform/chrome/linux_entra_sso.json $(BROWSER_CONFIG_PATH)/NativeMessagingHosts
211 ${Q}sed -i 's|/usr/local/lib/linux-entra-sso/|'$(BROWSER_CONFIG_PATH)'/|' $(BROWSER_CONFIG_PATH)/NativeMessagingHosts/linux_entra_sso.json
212 # compute extension id and and grant permission
213 ${Q}sed -i 's|{extension_id}|$(CHROME_EXT_ID)|' $(BROWSER_CONFIG_PATH)/NativeMessagingHosts/linux_entra_sso.json
214 install -m 0755 linux-entra-sso.py $(BROWSER_CONFIG_PATH)
215 ${Q}sed -i $(UPDATE_VERSION_PY) $(BROWSER_CONFIG_PATH)/linux-entra-sso.py
216
217 local-install-brave:
218 $(MAKE) local-install-chromium-based BROWSER_CONFIG_PATH=$(brave_lconfig_dir)
219
220 local-install-chrome:
221 $(MAKE) local-install-chromium-based BROWSER_CONFIG_PATH=$(chrome_lconfig_dir)
222
223 local-install-chromium:
224 $(MAKE) local-install-chromium-based BROWSER_CONFIG_PATH=$(chromium_lconfig_dir)
225
226 local-install-vivaldi:
227 $(MAKE) local-install-chromium-based BROWSER_CONFIG_PATH=$(vivaldi_lconfig_dir)
228
229 local-install: local-install-brave local-install-chrome local-install-chromium local-install-firefox local-install-vivaldi
230
231 # For testing, we provide a mock implementation of the broker communication
232 local-install-mock: local-install
233 install -m 0755 tests/linux_entra_sso_mock.py $(brave_lconfig_dir)/linux_entra_sso.py
234 install -m 0755 tests/linux_entra_sso_mock.py $(chrome_lconfig_dir)/linux_entra_sso.py
235 install -m 0755 tests/linux_entra_sso_mock.py $(chromium_lconfig_dir)/linux_entra_sso.py
236 install -m 0755 tests/linux_entra_sso_mock.py $(firefox_lconfig_dir)/linux_entra_sso.py
237 install -m 0755 tests/linux_entra_sso_mock.py $(vivaldi_lconfig_dir)/linux_entra_sso.py
238
239 ####################################
240 # system install / uninstall targets
241 ####################################
242
243 install:
244 ${Q}[ -z "$(python3_bin)" ] && { echo "python3 not found. Please set 'python3_bin'."; exit 1; } || true
245 # Host application
246 install -d $(DESTDIR)/$(libexecdir)/linux-entra-sso
247 install -m 0755 linux-entra-sso.py $(DESTDIR)/$(libexecdir)/linux-entra-sso
248 ${Q}sed -i $(UPDATE_VERSION_PY) $(DESTDIR)/$(libexecdir)/linux-entra-sso/linux-entra-sso.py
249 ${Q}sed -i $(UPDATE_PYTHON_INTERPRETER) $(DESTDIR)/$(libexecdir)/linux-entra-sso/linux-entra-sso.py
250 # Firefox
251 install -d $(DESTDIR)/$(firefox_nm_dir)
252 install -m 0644 platform/firefox/linux_entra_sso.json $(DESTDIR)/$(firefox_nm_dir)
253 ${Q}sed -i 's|/usr/local/lib/|'$(libexecdir)/'|' $(DESTDIR)/$(firefox_nm_dir)/linux_entra_sso.json
254 # Chrome
255 install -d $(DESTDIR)/$(chrome_nm_dir)
256 install -m 0644 platform/chrome/linux_entra_sso.json $(DESTDIR)/$(chrome_nm_dir)
257 ${Q}sed -i 's|/usr/local/lib/|'$(libexecdir)/'|' $(DESTDIR)/$(chrome_nm_dir)/linux_entra_sso.json
258 ${Q}sed -i '/{extension_id}/d' $(DESTDIR)/$(chrome_nm_dir)/linux_entra_sso.json
259 install -d $(DESTDIR)/$(chrome_ext_dir)
260 install -m 0644 platform/chrome/extension.json $(DESTDIR)/$(chrome_ext_dir)/$(CHROME_EXT_ID_SIGNED).json
261 # Chromium
262 install -d $(DESTDIR)/$(chromium_nm_dir)
263 install -m 0644 platform/chrome/linux_entra_sso.json $(DESTDIR)/$(chromium_nm_dir)
264 ${Q}sed -i 's|/usr/local/lib/|'$(libexecdir)/'|' $(DESTDIR)/$(chromium_nm_dir)/linux_entra_sso.json
265 ${Q}sed -i '/{extension_id}/d' $(DESTDIR)/$(chromium_nm_dir)/linux_entra_sso.json
266
267 uninstall:
268 rm -rf $(DESTDIR)/$(libexecdir)/linux-entra-sso
269 rm -f $(DESTDIR)/$(firefox_nm_dir)/linux_entra_sso.json
270 rm -f $(DESTDIR)/$(chrome_nm_dir)/linux_entra_sso.json
271 rm -f $(DESTDIR)/$(chromium_nm_dir)/linux_entra_sso.json
272 rm -f $(DESTDIR)/$(chrome_ext_dir)/$(CHROME_EXT_ID_SIGNED).json
273
274 #########################
275 # local uninstall targets
276 #########################
277
278 local-uninstall-brave:
279 rm -f $(brave_lconfig_dir)/NativeMessagingHosts/linux_entra_sso.json
280 rm -f $(brave_lconfig_dir)/linux-entra-sso.py
281
282 local-uninstall-chrome:
283 rm -f $(chrome_lconfig_dir)/NativeMessagingHosts/linux_entra_sso.json
284 rm -f $(chrome_lconfig_dir)/linux-entra-sso.py
285
286 local-uninstall-chromium:
287 rm -f $(chromium_lconfig_dir)/NativeMessagingHosts/linux_entra_sso.json
288 rm -f $(chromium_lconfig_dir)/linux-entra-sso.py
289
290 local-uninstall-firefox:
291 rm -f $(firefox_lconfig_dir)/native-messaging-hosts/linux_entra_sso.json
292 rm -f $(firefox_lconfig_dir)/linux-entra-sso.py
293
294 local-uninstall-vivaldi:
295 rm -f $(vivaldi_lconfig_dir)/NativeMessagingHosts/linux_entra_sso.json
296 rm -f $(vivaldi_lconfig_dir)/linux-entra-sso.py
297
298 local-uninstall: local-uninstall-brave local-uninstall-chrome local-uninstall-chromium local-uninstall-firefox local-uninstall-vivaldi
299
300 .PHONY: clean release deb deb_clean
301 .PHONY: local-install-firefox local-install-chrome local-install-brave local-install-chromium-based local-install-vivaldi local-install
302 .PHONY: local-uninstall-firefox local-uninstall-chromium-based local-uninstall-chrome local-uninstall-brave local-uninstall-vivaldi local-uninstall
303 .PHONY: local-install-mock
304 .PHONY: install uninstall