1#!/usr/bin/env make 2# prefix=<path> specifies the installation prefix (ex: /usr/local) 3# DESTDIR=<path> specifies the temporary staging directory (ex: /tmp/stage) 4# V=1 or VERBOSE=1 enables verbose builds 5# NO_NINJA=1 disables autodetection and use of ninja 6# PRMAN_15_COMPATIBLE_PTEX=1 enables compatibility with PRman 15 7# FLAVOR={opt,debug,profile} sets CMAKE_BUILD_TYPE using short aliases 8# BUILD_TYPE={Release,Debug,RelWithDebInfo} sets CMAKE_BUILD_TYPE directly 9 10FLAGS = 11FLAVOR ?= optimize 12uname_S := $(shell sh -c 'uname -s || echo kernel') 13uname_R := $(shell sh -c '(uname -r || echo release) | cut -d- -f1') 14uname_M := $(shell sh -c 'uname -m || echo machine') 15platform ?= $(uname_S)-$(uname_R)-$(uname_M)-$(FLAVOR) 16build = build/$(platform) 17# Installation prefix 18prefix = $(CURDIR)/$(platform) 19CMAKE_FLAGS = -DCMAKE_INSTALL_PREFIX=$(prefix) 20 21ifdef V 22 VERBOSE = 1 23endif 24ifndef VERBOSE 25 QUIET = @ 26endif 27 28# Ninja auto-detection 29NO_NINJA := $(shell sh -c '(type ninja >/dev/null && echo 0) || echo 1') 30ifeq ($(NO_NINJA),1) 31 CMAKE_FLAGS += -G "Unix Makefiles" 32 FLAGS += -- --no-print-directory 33else 34 CMAKE_FLAGS += -G Ninja 35 FLAGS += $(shell sh -c '\ 36 VERBOSE=$(VERBOSE) ./src/build/ninja-flags.sh $(MAKEFLAGS)') 37endif 38ifdef PRMAN_15_COMPATIBLE_PTEX 39 CMAKE_FLAGS += -DPRMAN_15_COMPATIBLE_PTEX:BOOL=TRUE 40endif 41ifdef TOOLCHAIN 42 CMAKE_FLAGS += -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) 43endif 44ifdef BUILD_TYPE 45 CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) 46endif 47 48# Targets 49default:: test 50 51test:: all 52 53clean:: uninstall 54 55configure = $(build)/cmake.conf 56$(configure): 57 $(QUIET)mkdir -p $(build) 58 $(QUIET)cd $(build) && cmake $(CMAKE_FLAGS) $(CURDIR) 59 $(QUIET)touch $@ 60 61cmake: 62 $(QUIET)mkdir -p $(build) 63 $(QUIET)cd $(build) && cmake $(CMAKE_FLAGS) $(CURDIR) 64 65all clean doc install test:: $(configure) 66 +$(QUIET)cmake --build $(build) --target $@ $(FLAGS) 67 68install:: 69 $(QUIET)cp $(build)/install_manifest.txt $(build).manifest.txt 70 71uninstall: $(configure) 72 $(QUIET)touch $(build).manifest.txt 73 $(QUIET)xargs rm -f <$(build).manifest.txt 74 $(QUIET)xargs dirname <$(build).manifest.txt 2>/dev/null | \ 75 sort -u -r | xargs rmdir -p >/dev/null 2>&1 || true 76