Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve makefile rebuild caching #1396

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 57 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,66 @@
VENV=.venv
.PHONY: all install clean distclean deps
# Use bash for shell
SHELL := /bin/bash

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

install: deps
$(VENV)/bin/meson setup libvmaf/build libvmaf --buildtype release && \
$(VENV)/bin/ninja -vC libvmaf/build install
# Build tools configured in the virtual environment
PYTHON_INTERPRETER := python3.10
VENV_PIP := $(VIRTUAL_ENV_PATH)/pip
VENV_PYTHON := $(VIRTUAL_ENV_PATH)/python
MESON_SETUP := $(VIRTUAL_ENV_PATH)/meson setup
NINJA := $(VIRTUAL_ENV_PATH)/ninja

# Build types and options
BUILDTYPE_RELEASE := --buildtype release
BUILDTYPE_DEBUG := --buildtype debug
ENABLE_FLOAT := -Denable_float=true

# Directories
LIBVMAF_DIR := libvmaf
BUILD_DIR := $(LIBVMAF_DIR)/build
DEBUG_DIR := $(LIBVMAF_DIR)/debug

.PHONY: default all debug build install cythonize clean distclean

default: build

all: build debug install test cythonize

$(BUILD_DIR): $(VENV)
PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(BUILD_DIR) $(LIBVMAF_DIR) $(BUILDTYPE_RELEASE) $(ENABLE_FLOAT)

$(DEBUG_DIR): $(VENV)
PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(DEBUG_DIR) $(LIBVMAF_DIR) $(BUILDTYPE_DEBUG) $(ENABLE_FLOAT)

cythonize: $(VENV)
pushd python && ../$(VENV_PYTHON) setup.py build_ext --build-lib . && popd || exit 1

build: $(BUILD_DIR) $(VENV)
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(BUILD_DIR)

test: build $(VENV)
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(BUILD_DIR) test

debug: $(DEBUG_DIR) $(VENV)
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(DEBUG_DIR)

install: $(BUILD_DIR) $(VENV)
PATH="$(VENV)/bin:$$PATH" $(NINJA) -vC $(BUILD_DIR) install

clean:
rm -rf libvmaf/build
rm -rf $(BUILD_DIR) $(DEBUG_DIR)
rm -f python/vmaf/core/adm_dwt2_cy.c*

distclean: clean
rm -rf $(VENV)

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