Debian Codegraph @

Makefile

raw symbols SCIP
1 # Copyright (C) 2008-2025 Andrew Ziem. All rights reserved.
2 # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3 # This is free software: You are free to change and redistribute it.
4 # There is NO WARRANTY, to the extent permitted by law.
5 #
6 # Makefile edited by https://github.com/Tobias-B-Besemer
7 # Done on 2019-03-13
8
9 # On some systems if not explicitly given, make uses /bin/sh
10 SHELL := /bin/bash
11
12 .PHONY: clean install tests build tests-with-sudo lint delete_windows_files pretty appimage clean-appimage install-deps install-deps-dev
13
14 prefix ?= /usr/local
15 bindir ?= $(prefix)/bin
16 datadir ?= $(prefix)/share
17
18 INSTALL = install
19 INSTALL_DATA = $(INSTALL) -m 644
20 INSTALL_SCRIPT = $(INSTALL) -m 755
21
22 # if not specified, do not check coverage
23 PYTHON ?= python3
24 COVERAGE ?= $(PYTHON)
25
26 ifneq ($(COVERAGE),$(PYTHON))
27 BLEACHBIT_SUDO_COVERAGE_RUNNER := $(COVERAGE) --append
28 BLEACHBIT_SUDO_COVERAGE_FILE := $(if $(COVERAGE_FILE),$(COVERAGE_FILE),.coverage)
29 else
30 BLEACHBIT_SUDO_COVERAGE_RUNNER :=
31 BLEACHBIT_SUDO_COVERAGE_FILE :=
32 endif
33
34 build:
35 echo Nothing to build
36
37 install-deps:
38 @./scripts/install-deps.sh
39
40 install-deps-dev:
41 @./scripts/install-deps.sh --dev
42
43 clean:
44 @rm -vf {.,bleachbit,tests,windows,bleachbit/markovify}/*{pyc,pyo,~} # files
45 @rm -vrf {.,bleachbit,tests,windows,bleachbit/markovify}/__pycache__ # directories
46 @rm -vrf build dist # created by py2exe
47 @rm -rf BleachBit-Portable # created by windows/setup.bat
48 @rm -rf BleachBit-*-portable.zip
49 @rm -vf MANIFEST # created by setup.py
50 $(MAKE) -C po clean
51 @rm -vrf locale
52 @rm -vrf {*/,./}*.{pylint,pyflakes,shellcheck}.log
53 @rm -vrf windows/BleachBit-*-setup*.{exe,zip}
54 @rm -vrf htmlcov .coverage # code coverage reports
55 @rm -vrf *.egg-info # Python package metadata
56 @rm -vrf docker-artifacts # Docker build outputs
57 @rm -rf "$(APPIMAGE_APPDIR)"
58 @rm -f $(LINUXDEPLOY) $(LINUXDEPLOY_GTK_PLUGIN)
59 @rm -f BleachBit-*.AppImage
60
61 install:
62 # "binary"
63 mkdir -p $(DESTDIR)$(bindir)
64 $(INSTALL_SCRIPT) bleachbit.py $(DESTDIR)$(bindir)/bleachbit
65
66 # application launcher
67 mkdir -p $(DESTDIR)$(datadir)/applications
68 $(INSTALL_DATA) org.bleachbit.BleachBit.desktop $(DESTDIR)$(datadir)/applications/
69
70 # AppStream metadata
71 mkdir -p $(DESTDIR)$(datadir)/metainfo
72 $(INSTALL_DATA) org.bleachbit.BleachBit.metainfo.xml $(DESTDIR)$(datadir)/metainfo/
73
74 # Python code
75 mkdir -p $(DESTDIR)$(datadir)/bleachbit/markovify
76 $(INSTALL_DATA) bleachbit/*.py $(DESTDIR)$(datadir)/bleachbit
77 $(INSTALL_DATA) bleachbit/markovify/*.py $(DESTDIR)$(datadir)/bleachbit/markovify
78 #note: compileall is recursive
79 cd $(DESTDIR)$(datadir)/bleachbit && \
80 $(PYTHON) -O -c "import compileall; compileall.compile_dir('.')" && \
81 $(PYTHON) -c "import compileall; compileall.compile_dir('.')"
82
83 # cleaners
84 mkdir -p $(DESTDIR)$(datadir)/bleachbit/cleaners
85 $(INSTALL_DATA) cleaners/*.xml $(DESTDIR)$(datadir)/bleachbit/cleaners
86
87 # share files
88 mkdir -p $(DESTDIR)$(datadir)/bleachbit/share
89 $(INSTALL_DATA) share/app-menu.ui $(DESTDIR)$(datadir)/bleachbit/share
90 $(INSTALL_DATA) share/protected_path.xml $(DESTDIR)$(datadir)/bleachbit/share
91
92 # icon
93 mkdir -p $(DESTDIR)$(datadir)/pixmaps
94 $(INSTALL_DATA) bleachbit.png $(DESTDIR)$(datadir)/pixmaps/
95
96 # translations
97 $(MAKE) -C po install DESTDIR=$(DESTDIR)
98
99 # PolicyKit
100 mkdir -p $(DESTDIR)$(datadir)/polkit-1/actions
101 $(INSTALL_DATA) org.bleachbit.policy $(DESTDIR)$(datadir)/polkit-1/actions/
102
103 lint:
104 command -v pyflakes3 >/dev/null 2>&1 || echo "WARNING: Missing pyflakes3. APT users, try: sudo apt install pyflakes3"
105 command -v pylint >/dev/null 2>&1 || echo "WARNING: Missing pylint. APT users, try: sudo apt install pylint"
106 @if command -v appstreamcli >/dev/null 2>&1; then \
107 appstreamcli validate org.bleachbit.BleachBit.metainfo.xml; \
108 else \
109 echo "WARNING: Missing appstreamcli. APT users, try: sudo apt install appstream"; \
110 fi
111 @if command -v shellcheck >/dev/null 2>&1; then \
112 echo "Running shellcheck on .sh files"; \
113 for f in scripts/*.sh docker/*.sh; do \
114 [ -e "$$f" ] || continue; \
115 echo "$$f"; \
116 ( shellcheck "$$f" > "$$f".shellcheck.log ); \
117 done; \
118 else \
119 echo "WARNING: Missing shellcheck. APT users, try: sudo apt install shellcheck"; \
120 fi
121 for f in *py */*py; \
122 do \
123 echo "$$f"; \
124 ( pyflakes3 "$$f" > "$$f".pyflakes.log ); \
125 ( pylint "$$f" > "$$f".pylint.log ); \
126 done; \
127 exit 0
128
129 delete_windows_files:
130 # This is used for building .deb and .rpm packages.
131 # Remove Windows-specific cleaners.
132 grep -l "cleaner id=\"\w*\" os=\"windows\"" cleaners/*xml | xargs rm -f
133 # Remove Windows-specific code.
134 rm -f bleachbit/{Winapp,Windows*}.py tests/TestWindows{,Wipe}.py
135 # Remove the whole directory after verifying it's the Windows build directory.
136 # This is disabled because it break po/Makefile
137 #@if [ -f windows/bleachbit.nsi ]; then \
138 # rm -rf windows; \
139 #else \
140 # echo "WARNING: windows/bleachbit.nsi not found, skipping windows directory removal"; \
141 #fi
142
143 tests:
144 # Catch warnings as errors. Also set in `tests/common.py`.
145 $(MAKE) -C cleaners tests; cleaners_status=$$?; \
146 PYTHONWARNINGS=error $(COVERAGE) -m unittest discover -p Test*.py -v; py_status=$$?; \
147 $(PYTHON) windows/nsis_translations.py --unittest; nsis_status=$$?; \
148 exit $$(($$cleaners_status + $$py_status + $$nsis_status))
149
150 tests-with-sudo:
151 # Run tests marked with @test_also_with_sudo using sudo
152 PYTHONWARNINGS=error \
153 BLEACHBIT_COVERAGE_RUNNER="$(BLEACHBIT_SUDO_COVERAGE_RUNNER)" \
154 BLEACHBIT_COVERAGE_FILE="$(BLEACHBIT_SUDO_COVERAGE_FILE)" \
155 $(PYTHON) tests/test_with_sudo.py
156
157 pretty:
158 @if command -v autopep8 >/dev/null 2>&1; then \
159 echo "Running autopep* on .py files"; \
160 autopep8 -i {.,bleachbit,tests}/*py; \
161 else \
162 echo "WARNING: Missing autopep8. APT users, try: sudo apt install python3-autopep8"; \
163 fi
164 @if command -v dos2unix >/dev/null 2>&1; then \
165 echo "Running dos2unix on .py files"; \
166 dos2unix {.,bleachbit,tests}/*py; \
167 else \
168 echo "WARNING: Missing dos2unix. APT users, try: sudo apt install dos2unix"; \
169 fi
170 $(MAKE) -C cleaners pretty
171 @if command -v xmllint >/dev/null 2>&1; then \
172 echo "Running xmllint on .xsd file"; \
173 xmllint --format doc/cleaner_markup_language.xsd > doc/cleaner_markup_language.xsd.tmp; \
174 mv doc/cleaner_markup_language.xsd.tmp doc/cleaner_markup_language.xsd; \
175 else \
176 echo "WARNING: Missing xmllint. APT users, try: sudo apt install libxml2-utils"; \
177 fi
178
179 # AppImage build
180 APPIMAGE_BUILD_DIR ?= appimage-build
181 APPIMAGE_APPDIR := $(abspath $(APPIMAGE_BUILD_DIR))
182 APPIMAGE_OUTPUT ?= BleachBit-$(shell $(PYTHON) -c "import sys; sys.path.insert(0,'.'); from bleachbit import APP_VERSION; print(APP_VERSION)" 2>/dev/null || echo "latest")-x86_64.AppImage
183 APPIMAGE_OUTPUT_PATH := $(abspath $(APPIMAGE_OUTPUT))
184 LINUXDEPLOY ?= linuxdeploy-x86_64.AppImage
185 LINUXDEPLOY_GTK_PLUGIN ?= linuxdeploy-plugin-gtk.sh
186 LINUXDEPLOY_URL ?= https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
187 LINUXDEPLOY_GTK_PLUGIN_URL ?= https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh
188
189 $(LINUXDEPLOY):
190 @echo "* Downloading linuxdeploy"
191 wget -c "$(LINUXDEPLOY_URL)" -O $(LINUXDEPLOY)
192 chmod +x $(LINUXDEPLOY)
193
194 $(LINUXDEPLOY_GTK_PLUGIN):
195 @echo "* Downloading linuxdeploy-plugin-gtk"
196 wget -c "$(LINUXDEPLOY_GTK_PLUGIN_URL)" -O $(LINUXDEPLOY_GTK_PLUGIN)
197 chmod +x $(LINUXDEPLOY_GTK_PLUGIN)
198
199 appimage: $(LINUXDEPLOY) $(LINUXDEPLOY_GTK_PLUGIN)
200 @echo "* Building AppImage: $(APPIMAGE_OUTPUT)"
201 # Clean previous build
202 rm -rf "$(APPIMAGE_APPDIR)"
203 # Build translations (.mo files)
204 $(MAKE) -C po
205 # Install application into AppDir with prefix=/usr
206 $(MAKE) install DESTDIR="$(APPIMAGE_APPDIR)" prefix=/usr
207 # Copy icon to hicolor theme so linuxdeploy can find it
208 mkdir -p "$(APPIMAGE_APPDIR)/usr/share/icons/hicolor/256x256/apps"
209 cp bleachbit.png "$(APPIMAGE_APPDIR)/usr/share/icons/hicolor/256x256/apps/bleachbit.png"
210 # Run GTK plugin first to set up AppDir (hooks, schemas, loaders, etc.)
211 # DEPLOY_GTK_VERSION must be set because bleachbit is a Python script,
212 # not a compiled binary, so auto-detection of GTK version fails.
213 DEPLOY_GTK_VERSION=3 ./$(LINUXDEPLOY) \
214 --appdir "$(APPIMAGE_APPDIR)" \
215 --plugin gtk
216 # Patch the hook file before packaging:
217 # 1. Prepend bundled libraries to LD_LIBRARY_PATH so the AppImage's
218 # GTK/gdk-pixbuf libraries are used instead of the host system's.
219 # Without this, the host's gdk-pixbuf ignores GDK_PIXBUF_MODULEDIR
220 # and cannot find the bundled pixbuf loaders.
221 # 2. Export GDK_PIXBUF_MODULEDIR so gdk-pixbuf can resolve the
222 # relative loader paths in loaders.cache.
223 sed -i '1s|^|export LD_LIBRARY_PATH="$$APPDIR/usr/lib:$$LD_LIBRARY_PATH"\n|' \
224 "$(APPIMAGE_APPDIR)/apprun-hooks/linuxdeploy-plugin-gtk.sh"
225 echo 'export GDK_PIXBUF_MODULEDIR="$$APPDIR/usr/lib/gdk-pixbuf-2.0/2.10.0/loaders"' \
226 >> "$(APPIMAGE_APPDIR)/apprun-hooks/linuxdeploy-plugin-gtk.sh"
227 # Package the AppDir into an AppImage
228 ./$(LINUXDEPLOY) \
229 --appdir "$(APPIMAGE_APPDIR)" \
230 --output appimage
231 # linuxdeploy names output after the desktop file; rename to our convention
232 @if [ -f BleachBit-x86_64.AppImage ] && [ "$(abspath BleachBit-x86_64.AppImage)" != "$(APPIMAGE_OUTPUT_PATH)" ]; then \
233 mv BleachBit-x86_64.AppImage "$(APPIMAGE_OUTPUT_PATH)"; \
234 fi
235 # Test the AppImage to check it doesn't crash
236 @if [ -n "$${SKIP_APPIMAGE_TEST:-}" ]; then \
237 echo "SKIP_APPIMAGE_TEST is set, skipping AppImage test."; \
238 else \
239 "$(APPIMAGE_OUTPUT_PATH)" --sysinfo; \
240 fi
241
242 @echo "* AppImage created: $(APPIMAGE_OUTPUT_PATH)"