Skip to content

Commit 8cde19d

Browse files
committed
Improve makefile rebuild caching
1 parent e00fc50 commit 8cde19d

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

Makefile

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,66 @@
1-
VENV=.venv
2-
.PHONY: all install clean distclean deps
1+
# Use bash for shell
2+
SHELL := /bin/bash
33

4-
all: deps
5-
$(VENV)/bin/meson setup libvmaf/build libvmaf --buildtype release -Denable_float=true && \
6-
$(VENV)/bin/ninja -vC libvmaf/build && \
7-
cd python && \
8-
../$(VENV)/bin/python setup.py build_ext --build-lib .
4+
# Path and environment setup
5+
VENV := .venv
6+
VIRTUAL_ENV_PATH := $(VENV)/bin
97

10-
install: deps
11-
$(VENV)/bin/meson setup libvmaf/build libvmaf --buildtype release && \
12-
$(VENV)/bin/ninja -vC libvmaf/build install
8+
# Build tools configured in the virtual environment
9+
PYTHON_INTERPRETER := python3.10
10+
VENV_PIP := $(VIRTUAL_ENV_PATH)/pip
11+
VENV_PYTHON := $(VIRTUAL_ENV_PATH)/python
12+
MESON_SETUP := $(VIRTUAL_ENV_PATH)/meson setup
13+
NINJA := $(VIRTUAL_ENV_PATH)/ninja
14+
15+
# Build types and options
16+
BUILDTYPE_RELEASE := --buildtype release
17+
BUILDTYPE_DEBUG := --buildtype debug
18+
ENABLE_FLOAT := -Denable_float=true
19+
20+
# Directories
21+
LIBVMAF_DIR := libvmaf
22+
BUILD_DIR := $(LIBVMAF_DIR)/build
23+
DEBUG_DIR := $(LIBVMAF_DIR)/debug
24+
25+
.PHONY: default all debug build install cythonize clean distclean
26+
27+
default: build
28+
29+
all: build debug install test cythonize
30+
31+
$(BUILD_DIR): $(VENV)
32+
PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(BUILD_DIR) $(LIBVMAF_DIR) $(BUILDTYPE_RELEASE) $(ENABLE_FLOAT)
33+
34+
$(DEBUG_DIR): $(VENV)
35+
PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(DEBUG_DIR) $(LIBVMAF_DIR) $(BUILDTYPE_DEBUG) $(ENABLE_FLOAT)
36+
37+
cythonize: $(VENV)
38+
pushd python && ../$(VENV_PYTHON) setup.py build_ext --build-lib . && popd || exit 1
39+
40+
build: $(BUILD_DIR) $(VENV)
41+
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(BUILD_DIR)
42+
43+
test: build $(VENV)
44+
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(BUILD_DIR) test
45+
46+
debug: $(DEBUG_DIR) $(VENV)
47+
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(DEBUG_DIR)
48+
49+
install: $(BUILD_DIR) $(VENV)
50+
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(BUILD_DIR) install
1351

1452
clean:
15-
rm -rf libvmaf/build
53+
rm -rf $(BUILD_DIR) $(DEBUG_DIR)
1654
rm -f python/vmaf/core/adm_dwt2_cy.c*
1755

1856
distclean: clean
1957
rm -rf $(VENV)
2058

21-
deps:
22-
test -d $(VENV) || python3 -mvenv $(VENV)
23-
$(VENV)/bin/pip install meson ninja cython numpy
59+
# Set up or rebuild virtual environment
60+
$(VENV):
61+
@echo "Setting up the virtual environment..."
62+
@set -e; \
63+
$(PYTHON_INTERPRETER) -m venv $(VENV) || { echo "Failed to create virtual environment"; exit 1; }; \
64+
$(VENV_PIP) install --upgrade pip || { echo "Failed to upgrade pip"; exit 1; }; \
65+
$(VENV_PIP) install meson ninja cython numpy || { echo "Failed to install dependencies"; exit 1; }
66+
@echo "Virtual environment setup complete."

0 commit comments

Comments
 (0)