| 1 |
# Copyright (C) 2008-2026 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 != command -v bash || echo /bin/sh |
| 11 |
|
| 12 |
.PHONY: clean install tests tests-pytest tests-nsis 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 |
# Quoted form for calling Python. Windows CI passes a backslash path that bash |
| 25 |
# mangles unquoted, so use this instead of $(PYTHON). |
| 26 |
PYTHON_CMD := "$(PYTHON)" |
| 27 |
COVERAGE ?= $(PYTHON_CMD) |
| 28 |
|
| 29 |
# pytest runner used by `tests-pytest`. Extra arguments go in PYTEST_ARGS |
| 30 |
PYTEST ?= $(PYTHON_CMD) -m pytest |
| 31 |
PYTEST_ARGS ?= |
| 32 |
|
| 33 |
# Set PYTEST_COVERAGE to any value to measure coverage of the pytest runs |
| 34 |
ifdef PYTEST_COVERAGE |
| 35 |
PYTEST_COV := --cov=bleachbit --cov-report= |
| 36 |
PYTEST_COV_APPEND := --cov=bleachbit --cov-append --cov-report= |
| 37 |
endif |
| 38 |
|
| 39 |
# Arguments forwarded to scripts/install-deps.sh, such as --venv |
| 40 |
INSTALL_DEPS_ARGS ?= |
| 41 |
|
| 42 |
ifneq ($(COVERAGE),$(PYTHON_CMD)) |
| 43 |
BLEACHBIT_SUDO_COVERAGE_RUNNER := $(COVERAGE) --append |
| 44 |
BLEACHBIT_SUDO_COVERAGE_FILE := $(if $(COVERAGE_FILE),$(COVERAGE_FILE),.coverage) |
| 45 |
else |
| 46 |
BLEACHBIT_SUDO_COVERAGE_RUNNER := |
| 47 |
BLEACHBIT_SUDO_COVERAGE_FILE := |
| 48 |
endif |
| 49 |
|
| 50 |
build: |
| 51 |
echo Nothing to build |
| 52 |
|
| 53 |
install-deps: |
| 54 |
@./scripts/install-deps.sh $(INSTALL_DEPS_ARGS) |
| 55 |
|
| 56 |
install-deps-dev: |
| 57 |
@./scripts/install-deps.sh --dev $(INSTALL_DEPS_ARGS) |
| 58 |
|
| 59 |
clean: |
| 60 |
@rm -vf {.,bleachbit,tests,windows,bleachbit/markovify}/*{pyc,pyo,~} # files |
| 61 |
@rm -vrf {.,bleachbit,tests,windows,bleachbit/markovify}/__pycache__ # directories |
| 62 |
@rm -vrf build dist # created by py2exe |
| 63 |
@rm -rf BleachBit-Portable # created by windows/setup.bat |
| 64 |
@rm -rf BleachBit-*-portable.zip |
| 65 |
@rm -vf MANIFEST # created by setup.py |
| 66 |
$(MAKE) -C po clean |
| 67 |
@rm -vrf locale |
| 68 |
@rm -vrf {*/,./}*.{pylint,pyflakes,shellcheck}.log |
| 69 |
@rm -vrf windows/BleachBit-*-setup*.{exe,zip} |
| 70 |
@rm -vrf htmlcov .coverage # code coverage reports |
| 71 |
@rm -vrf *.egg-info # Python package metadata |
| 72 |
@rm -vrf docker-artifacts # Docker build outputs |
| 73 |
@rm -rf "$(APPIMAGE_APPDIR)" |
| 74 |
@rm -f $(LINUXDEPLOY) $(LINUXDEPLOY_GTK_PLUGIN) |
| 75 |
@rm -f BleachBit-*.AppImage |
| 76 |
|
| 77 |
install: |
| 78 |
# "binary" |
| 79 |
mkdir -p $(DESTDIR)$(bindir) |
| 80 |
$(INSTALL_SCRIPT) bleachbit.py $(DESTDIR)$(bindir)/bleachbit |
| 81 |
|
| 82 |
# application launcher |
| 83 |
mkdir -p $(DESTDIR)$(datadir)/applications |
| 84 |
$(INSTALL_DATA) org.bleachbit.BleachBit.desktop $(DESTDIR)$(datadir)/applications/ |
| 85 |
|
| 86 |
# AppStream metadata |
| 87 |
mkdir -p $(DESTDIR)$(datadir)/metainfo |
| 88 |
$(INSTALL_DATA) org.bleachbit.BleachBit.metainfo.xml $(DESTDIR)$(datadir)/metainfo/ |
| 89 |
|
| 90 |
# Python code |
| 91 |
mkdir -p $(DESTDIR)$(datadir)/bleachbit/markovify |
| 92 |
$(INSTALL_DATA) bleachbit/*.py $(DESTDIR)$(datadir)/bleachbit |
| 93 |
$(INSTALL_DATA) bleachbit/markovify/*.py $(DESTDIR)$(datadir)/bleachbit/markovify |
| 94 |
#note: compileall is recursive |
| 95 |
cd $(DESTDIR)$(datadir)/bleachbit && \ |
| 96 |
$(PYTHON_CMD) -O -c "import compileall; compileall.compile_dir('.')" && \ |
| 97 |
$(PYTHON_CMD) -c "import compileall; compileall.compile_dir('.')" |
| 98 |
|
| 99 |
# cleaners |
| 100 |
mkdir -p $(DESTDIR)$(datadir)/bleachbit/cleaners |
| 101 |
$(INSTALL_DATA) cleaners/*.xml $(DESTDIR)$(datadir)/bleachbit/cleaners |
| 102 |
|
| 103 |
# share files |
| 104 |
mkdir -p $(DESTDIR)$(datadir)/bleachbit/share |
| 105 |
$(INSTALL_DATA) share/app-menu.ui $(DESTDIR)$(datadir)/bleachbit/share |
| 106 |
$(INSTALL_DATA) share/protected_path.xml $(DESTDIR)$(datadir)/bleachbit/share |
| 107 |
|
| 108 |
# icon |
| 109 |
mkdir -p $(DESTDIR)$(datadir)/pixmaps |
| 110 |
$(INSTALL_DATA) bleachbit.png $(DESTDIR)$(datadir)/pixmaps/ |
| 111 |
|
| 112 |
# translations |
| 113 |
$(MAKE) -C po install DESTDIR=$(DESTDIR) |
| 114 |
|
| 115 |
# PolicyKit |
| 116 |
mkdir -p $(DESTDIR)$(datadir)/polkit-1/actions |
| 117 |
$(INSTALL_DATA) org.bleachbit.policy $(DESTDIR)$(datadir)/polkit-1/actions/ |
| 118 |
|
| 119 |
lint: |
| 120 |
command -v pyflakes3 >/dev/null 2>&1 || echo "WARNING: Missing pyflakes3. APT users, try: sudo apt install pyflakes3" |
| 121 |
command -v pylint >/dev/null 2>&1 || echo "WARNING: Missing pylint. APT users, try: sudo apt install pylint" |
| 122 |
@if command -v appstreamcli >/dev/null 2>&1; then \ |
| 123 |
appstreamcli validate org.bleachbit.BleachBit.metainfo.xml; \ |
| 124 |
else \ |
| 125 |
echo "WARNING: Missing appstreamcli. APT users, try: sudo apt install appstream"; \ |
| 126 |
fi |
| 127 |
@if command -v shellcheck >/dev/null 2>&1; then \ |
| 128 |
echo "Running shellcheck on .sh files"; \ |
| 129 |
for f in scripts/*.sh docker/*.sh; do \ |
| 130 |
[ -e "$$f" ] || continue; \ |
| 131 |
echo "$$f"; \ |
| 132 |
( shellcheck "$$f" > "$$f".shellcheck.log ); \ |
| 133 |
done; \ |
| 134 |
else \ |
| 135 |
echo "WARNING: Missing shellcheck. APT users, try: sudo apt install shellcheck"; \ |
| 136 |
fi |
| 137 |
@echo "Running pyflakes3 and pylint in parallel: see all.pyflakes.log and all.pylint.log" |
| 138 |
@pyflakes3 *py */*py > all.pyflakes.log 2>&1 & \ |
| 139 |
pylint -j 0 *py */*py > all.pylint.log 2>&1 & \ |
| 140 |
wait; \ |
| 141 |
exit 0 |
| 142 |
|
| 143 |
delete_windows_files: |
| 144 |
# This is used for building .deb and .rpm packages. |
| 145 |
# Remove Windows-specific cleaners. |
| 146 |
grep -l "cleaner id=\"\w*\" os=\"windows\"" cleaners/*xml | xargs rm -f |
| 147 |
# Remove Windows-specific code. |
| 148 |
rm -f bleachbit/{Winapp,Windows*}.py tests/TestWindows{,Wipe}.py |
| 149 |
# The windows/ directory is left in place because removing it breaks po/Makefile. |
| 150 |
|
| 151 |
tests: |
| 152 |
# Check translations but do not abort. |
| 153 |
$(MAKE) -C po tests |
| 154 |
# Catch Python warnings as errors. Also set in `tests/common.py`. |
| 155 |
$(MAKE) -C cleaners tests; cleaners_status=$$?; \ |
| 156 |
PYTHONWARNINGS=error $(COVERAGE) -m unittest discover -p Test*.py -v; py_status=$$?; \ |
| 157 |
$(MAKE) tests-nsis; nsis_status=$$?; \ |
| 158 |
exit $$(($$cleaners_status + $$py_status + $$nsis_status)) |
| 159 |
|
| 160 |
# The suite CI runs: the xdist pass, then the serial no_xdist pass. |
| 161 |
# The second pass is skipped if the first fails. |
| 162 |
tests-pytest: |
| 163 |
PYTHONWARNINGS=error PYTHONPATH=. $(PYTEST) -n logical --dist=loadgroup \ |
| 164 |
-m 'not no_xdist' $(PYTEST_COV) $(PYTEST_ARGS) |
| 165 |
PYTHONWARNINGS=error PYTHONPATH=. $(PYTEST) \ |
| 166 |
-m no_xdist $(PYTEST_COV_APPEND) $(PYTEST_ARGS) |
| 167 |
|
| 168 |
tests-nsis: |
| 169 |
$(PYTHON_CMD) windows/nsis_translations.py --unittest |
| 170 |
|
| 171 |
tests-with-sudo: |
| 172 |
# Run tests marked with @test_also_with_sudo using sudo |
| 173 |
PYTHONWARNINGS=error \ |
| 174 |
BLEACHBIT_COVERAGE_RUNNER="$(BLEACHBIT_SUDO_COVERAGE_RUNNER)" \ |
| 175 |
BLEACHBIT_COVERAGE_FILE="$(BLEACHBIT_SUDO_COVERAGE_FILE)" \ |
| 176 |
$(PYTHON_CMD) tests/test_with_sudo.py |
| 177 |
|
| 178 |
pretty: |
| 179 |
@if command -v autopep8 >/dev/null 2>&1; then \ |
| 180 |
echo "Running autopep* on .py files"; \ |
| 181 |
autopep8 -i {.,bleachbit,tests}/*py; \ |
| 182 |
else \ |
| 183 |
echo "WARNING: Missing autopep8. APT users, try: sudo apt install python3-autopep8"; \ |
| 184 |
fi |
| 185 |
@if command -v dos2unix >/dev/null 2>&1; then \ |
| 186 |
echo "Running dos2unix on .py files"; \ |
| 187 |
dos2unix {.,bleachbit,tests}/*py; \ |
| 188 |
else \ |
| 189 |
echo "WARNING: Missing dos2unix. APT users, try: sudo apt install dos2unix"; \ |
| 190 |
fi |
| 191 |
$(MAKE) -C cleaners pretty |
| 192 |
@if command -v xmllint >/dev/null 2>&1; then \ |
| 193 |
echo "Running xmllint on .xsd file"; \ |
| 194 |
xmllint --format doc/cleaner_markup_language.xsd > doc/cleaner_markup_language.xsd.tmp; \ |
| 195 |
mv doc/cleaner_markup_language.xsd.tmp doc/cleaner_markup_language.xsd; \ |
| 196 |
else \ |
| 197 |
echo "WARNING: Missing xmllint. APT users, try: sudo apt install libxml2-utils"; \ |
| 198 |
fi |
| 199 |
|
| 200 |
# AppImage build |
| 201 |
APPIMAGE_BUILD_DIR ?= appimage-build |
| 202 |
APPIMAGE_APPDIR := $(abspath $(APPIMAGE_BUILD_DIR)) |
| 203 |
APPIMAGE_OUTPUT ?= BleachBit-$(shell $(PYTHON_CMD) -c "import sys; sys.path.insert(0,'.'); from bleachbit import APP_VERSION; print(APP_VERSION)" 2>/dev/null || echo "latest")-x86_64.AppImage |
| 204 |
APPIMAGE_OUTPUT_PATH := $(abspath $(APPIMAGE_OUTPUT)) |
| 205 |
LINUXDEPLOY ?= linuxdeploy-x86_64.AppImage |
| 206 |
LINUXDEPLOY_GTK_PLUGIN ?= linuxdeploy-plugin-gtk.sh |
| 207 |
LINUXDEPLOY_URL ?= https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage |
| 208 |
LINUXDEPLOY_GTK_PLUGIN_URL ?= https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh |
| 209 |
|
| 210 |
$(LINUXDEPLOY): |
| 211 |
@echo "* Downloading linuxdeploy" |
| 212 |
wget -c "$(LINUXDEPLOY_URL)" -O $(LINUXDEPLOY) |
| 213 |
chmod +x $(LINUXDEPLOY) |
| 214 |
|
| 215 |
$(LINUXDEPLOY_GTK_PLUGIN): |
| 216 |
@echo "* Downloading linuxdeploy-plugin-gtk" |
| 217 |
wget -c "$(LINUXDEPLOY_GTK_PLUGIN_URL)" -O $(LINUXDEPLOY_GTK_PLUGIN) |
| 218 |
chmod +x $(LINUXDEPLOY_GTK_PLUGIN) |
| 219 |
|
| 220 |
appimage: $(LINUXDEPLOY) $(LINUXDEPLOY_GTK_PLUGIN) |
| 221 |
@echo "* Building AppImage: $(APPIMAGE_OUTPUT)" |
| 222 |
# Clean previous build |
| 223 |
rm -rf "$(APPIMAGE_APPDIR)" |
| 224 |
# Build translations (.mo files) |
| 225 |
$(MAKE) -C po |
| 226 |
# Install application into AppDir with prefix=/usr |
| 227 |
$(MAKE) install DESTDIR="$(APPIMAGE_APPDIR)" prefix=/usr |
| 228 |
# Copy icon to hicolor theme so linuxdeploy can find it |
| 229 |
mkdir -p "$(APPIMAGE_APPDIR)/usr/share/icons/hicolor/256x256/apps" |
| 230 |
cp bleachbit.png "$(APPIMAGE_APPDIR)/usr/share/icons/hicolor/256x256/apps/bleachbit.png" |
| 231 |
# Run GTK plugin first to set up AppDir (hooks, schemas, loaders, etc.) |
| 232 |
# DEPLOY_GTK_VERSION must be set because bleachbit is a Python script, |
| 233 |
# not a compiled binary, so auto-detection of GTK version fails. |
| 234 |
DEPLOY_GTK_VERSION=3 ./$(LINUXDEPLOY) \ |
| 235 |
--appdir "$(APPIMAGE_APPDIR)" \ |
| 236 |
--plugin gtk |
| 237 |
# Patch the hook file before packaging: |
| 238 |
# 1. Prepend bundled libraries to LD_LIBRARY_PATH so the AppImage's |
| 239 |
# GTK/gdk-pixbuf libraries are used instead of the host system's. |
| 240 |
# Without this, the host's gdk-pixbuf ignores GDK_PIXBUF_MODULEDIR |
| 241 |
# and cannot find the bundled pixbuf loaders. |
| 242 |
# 2. Export GDK_PIXBUF_MODULEDIR so gdk-pixbuf can resolve the |
| 243 |
# relative loader paths in loaders.cache. |
| 244 |
sed -i '1s|^|export LD_LIBRARY_PATH="$$APPDIR/usr/lib:$$LD_LIBRARY_PATH"\n|' \ |
| 245 |
"$(APPIMAGE_APPDIR)/apprun-hooks/linuxdeploy-plugin-gtk.sh" |
| 246 |
echo 'export GDK_PIXBUF_MODULEDIR="$$APPDIR/usr/lib/gdk-pixbuf-2.0/2.10.0/loaders"' \ |
| 247 |
>> "$(APPIMAGE_APPDIR)/apprun-hooks/linuxdeploy-plugin-gtk.sh" |
| 248 |
# Package the AppDir into an AppImage |
| 249 |
./$(LINUXDEPLOY) \ |
| 250 |
--appdir "$(APPIMAGE_APPDIR)" \ |
| 251 |
--output appimage |
| 252 |
# linuxdeploy names output after the desktop file; rename to our convention |
| 253 |
@if [ -f BleachBit-x86_64.AppImage ] && [ "$(abspath BleachBit-x86_64.AppImage)" != "$(APPIMAGE_OUTPUT_PATH)" ]; then \ |
| 254 |
mv BleachBit-x86_64.AppImage "$(APPIMAGE_OUTPUT_PATH)"; \ |
| 255 |
fi |
| 256 |
# Test the AppImage to check it doesn't crash |
| 257 |
@if [ -n "$${SKIP_APPIMAGE_TEST:-}" ]; then \ |
| 258 |
echo "SKIP_APPIMAGE_TEST is set, skipping AppImage test."; \ |
| 259 |
else \ |
| 260 |
"$(APPIMAGE_OUTPUT_PATH)" --sysinfo; \ |
| 261 |
fi |
| 262 |
|
| 263 |
@echo "* AppImage created: $(APPIMAGE_OUTPUT_PATH)" |