PYTHON ?= $(shell command -v python3 2> /dev/null || echo python)
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CORES ?= $(shell ${ROOT_DIR}/scripts/cpu_cores.sh || echo 4)
MEDIASOUP_OUT_DIR ?= $(shell pwd)/out
MEDIASOUP_BUILDTYPE ?= Release
GULP = ./scripts/node_modules/.bin/gulp
LCOV = ./deps/lcov/bin/lcov
DOCKER ?= docker
PIP_DIR = $(MEDIASOUP_OUT_DIR)/pip
INSTALL_DIR ?= $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)
BUILD_DIR ?= $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)/build
MESON ?= $(PIP_DIR)/bin/meson
MESON_VERSION ?= 0.61.5
MESON_ARGS ?= ""
PIP_BUILD_BINARIES = $(shell [ -f /etc/NIXOS -o -d /etc/guix ] && echo "--no-binary :all:")
NINJA_VERSION ?= 1.10.2.4
export PYTHONDONTWRITEBYTECODE = 1
ifeq ($(OS),Windows_NT)
export NINJA = $(PIP_DIR)/bin/ninja.exe
else
export NINJA = $(PIP_DIR)/bin/ninja
endif
ifeq ($(OS),Windows_NT)
export PYTHONPATH := $(PIP_DIR)
else
export PYTHONPATH := $(PIP_DIR):${PYTHONPATH}
endif
ifeq ($(OS),Windows_NT)
ifeq ($(MESON_ARGS),"")
MESON_ARGS = $(subst $\",,"--vsenv")
endif
endif
.PHONY: \
default \
meson-ninja \
setup \
clean \
clean-build \
clean-pip \
clean-subprojects \
clean-all \
update-wrap-file \
mediasoup-worker \
libmediasoup-worker \
xcode \
lint \
format \
test \
tidy \
fuzzer \
fuzzer-run-all \
docker \
docker-run
default: mediasoup-worker
meson-ninja:
ifeq ($(wildcard $(PIP_DIR)),)
$(PYTHON) -m pip install --system --target=$(PIP_DIR) pip setuptools || \
$(PYTHON) -m pip install --target=$(PIP_DIR) pip setuptools || \
echo "Installation failed, likely because PIP is unavailable, if you are on Debian/Ubuntu or derivative please install the python3-pip package"
$(PYTHON) -m pip install --upgrade --target=$(PIP_DIR) $(PIP_BUILD_BINARIES) meson==$(MESON_VERSION) ninja==$(NINJA_VERSION)
endif
setup: meson-ninja
ifeq ($(MEDIASOUP_BUILDTYPE),Release)
$(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype release \
-Db_ndebug=true \
-Db_pie=true \
-Db_staticpic=true \
--reconfigure \
$(MESON_ARGS) \
$(BUILD_DIR) || \
$(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype release \
-Db_ndebug=true \
-Db_pie=true \
-Db_staticpic=true \
$(MESON_ARGS) \
$(BUILD_DIR)
else
ifeq ($(MEDIASOUP_BUILDTYPE),Debug)
$(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype debug \
-Db_pie=true \
-Db_staticpic=true \
--reconfigure \
$(MESON_ARGS) \
$(BUILD_DIR) || \
$(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype debug \
-Db_pie=true \
-Db_staticpic=true \
$(MESON_ARGS) \
$(BUILD_DIR)
else
$(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype $(MEDIASOUP_BUILDTYPE) \
-Db_ndebug=if-release \
-Db_pie=true \
-Db_staticpic=true \
--reconfigure \
$(MESON_ARGS) \
$(BUILD_DIR) || \
$(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype $(MEDIASOUP_BUILDTYPE) \
-Db_ndebug=if-release \
-Db_pie=true \
-Db_staticpic=true \
$(MESON_ARGS) \
$(BUILD_DIR)
endif
endif
clean:
$(RM) -rf $(INSTALL_DIR)
clean-build:
$(RM) -rf $(BUILD_DIR)
clean-pip:
$(RM) -rf $(PIP_DIR)
clean-subprojects: meson-ninja
$(MESON) subprojects purge --include-cache --confirm
clean-all: clean-subprojects
$(RM) -rf $(MEDIASOUP_OUT_DIR)
update-wrap-file: meson-ninja
$(MESON) subprojects update --reset $(SUBPROJECT)
mediasoup-worker: setup
ifeq ($(MEDIASOUP_WORKER_BIN),)
$(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker
endif
libmediasoup-worker: setup
$(MESON) compile -C $(BUILD_DIR) -j $(CORES) libmediasoup-worker
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags libmediasoup-worker
xcode: setup
$(MESON) setup --buildtype debug --backend xcode $(MEDIASOUP_OUT_DIR)/xcode
lint:
$(GULP) --gulpfile ./scripts/gulpfile.js lint:worker
format:
$(GULP) --gulpfile ./scripts/gulpfile.js format:worker
test: setup
$(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-test
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker-test
ifeq ($(OS),Windows_NT)
$(BUILD_DIR)/mediasoup-worker-test.exe --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS)
else
$(LCOV) --directory ./ --zerocounters
$(BUILD_DIR)/mediasoup-worker-test --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS)
endif
tidy:
$(PYTHON) ./scripts/clang-tidy.py \
-clang-tidy-binary=./scripts/node_modules/.bin/clang-tidy \
-clang-apply-replacements-binary=./scripts/node_modules/.bin/clang-apply-replacements \
-header-filter='(Channel/**/*.hpp|DepLibSRTP.hpp|DepLibUV.hpp|DepLibWebRTC.hpp|DepOpenSSL.hpp|DepUsrSCTP.hpp|LogLevel.hpp|Logger.hpp|MediaSoupError.hpp|RTC/**/*.hpp|Settings.hpp|Utils.hpp|Worker.hpp|common.hpp|handles/**/*.hpp)' \
-p=$(BUILD_DIR) \
-j=$(CORES) \
-checks=$(MEDIASOUP_TIDY_CHECKS) \
-quiet
fuzzer: setup
$(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-fuzzer
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker-fuzzer
fuzzer-run-all:
LSAN_OPTIONS=verbosity=1:log_threads=1 $(BUILD_DIR)/mediasoup-worker-fuzzer -artifact_prefix=fuzzer/reports/ -max_len=1400 fuzzer/new-corpus deps/webrtc-fuzzer-corpora/corpora/stun-corpus deps/webrtc-fuzzer-corpora/corpora/rtp-corpus deps/webrtc-fuzzer-corpora/corpora/rtcp-corpus
docker:
ifeq ($(DOCKER_NO_CACHE),true)
$(DOCKER) build -f Dockerfile --no-cache --tag mediasoup/docker:latest .
else
$(DOCKER) build -f Dockerfile --tag mediasoup/docker:latest .
endif
docker-run:
$(DOCKER) run \
--name=mediasoupDocker -it --rm \
--privileged \
--cap-add SYS_PTRACE \
-v $(shell pwd)/../:/mediasoup \
mediasoup/docker:latest