From 436187efa55385c2bec80981d255566d5083c9e8 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 4 May 2020 11:10:26 +0200 Subject: copy speedymalloc's build system Thanks to Florian Schmaus for most of the work. --- .clang-format | 5 +++++ .clang-tidy | 2 ++ Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/check-format | 26 +++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 Makefile create mode 100755 tools/check-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9b8d6a4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +BasedOnStyle: LLVM +ColumnLimit: 100 +TabWidth: 2 +UseTab: Always diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..36ac2ed --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,2 @@ +Checks: bugprone-*, cert-*, linuxkernel-*, modernize-*, performance-*, portability-*, readability-*,-readability-isolate-declaration +WarningsAsErrors: clang-*, readability-*, performance-* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1def4c2 --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +SHELL=bash + +# https://stackoverflow.com/a/39124162/194894 +word-dot = $(word $2,$(subst ., ,$1)) + +MESON_VERSION=$(shell meson --version) +MESON_MAJOR_VERSION=$(call word-dot, $(MESON_VERSION), 1) +MESON_MINOR_VERSION=$(call word-dot, $(MESON_VERSION), 2) + +.PHONY: all build builddir check check-format clean debug format release + +all: release + +BUILDTYPE ?= debugoptimized +BUILDDIR := build-$(BUILDTYPE) + +release: + $(MAKE) build BUILDTYPE=$@ + +debug: + $(MAKE) build BUILDTYPE=$@ + +build: builddir + ninja -C $(BUILDDIR) + +builddir: + [[ -d $(BUILDDIR) ]] || mkdir $(BUILDDIR) + [[ -d build && $(shell realpath $(BUILDDIR)) == $(shell realpath build) ]] || ( \ + rm -f build && \ + ln -rs $(BUILDDIR) build && \ + meson --buildtype=$(BUILDTYPE) $(BUILDDIR) \ + ) + + +CHECK_NINJA_TARGETS += test + +# Meson >= 0.52 will automatically generate a clang-tidy target if a +# .clang-tidy file is found. +# Source version check: https://stackoverflow.com/a/3732456/194894 +ifeq ($(shell [ $(MESON_MINOR_VERSION) -ge 52 ] && echo true), true) +CHECK_NINJA_TARGETS += clang-tidy +else +$(warning old mesion version $(MESON_VERSION) detected, meson >= 0.52 required for clang-tidy) +endif + +check: all check-format + ninja -C build $(CHECK_NINJA_TARGETS) + +format: all + ninja -C build clang-format + +check-format: + ./tools/check-format + +clean: + rm -rf build + rm -rf build-* diff --git a/tools/check-format b/tools/check-format new file mode 100755 index 0000000..414ddc4 --- /dev/null +++ b/tools/check-format @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Pretty fancy method to get reliable the absolute path of a shell +# script, *even if it is sourced*. Credits go to GreenFox on +# stackoverflow: http://stackoverflow.com/a/12197518/194894 +pushd . > /dev/null +SCRIPTDIR="${BASH_SOURCE[0]}"; +while([ -h "${SCRIPTDIR}" ]); do + cd "`dirname "${SCRIPTDIR}"`" + SCRIPTDIR="$(readlink "`basename "${SCRIPTDIR}"`")"; +done +cd "`dirname "${SCRIPTDIR}"`" > /dev/null +SCRIPTDIR="`pwd`"; +popd > /dev/null + +ROOTDIR=$(readlink -f "${SCRIPTDIR}/..") + +MAX_PROCS=$(nproc) + +# Note that the --dry-run and --Werror clang-format arguments require +# clang-format 10 or higher. See https://reviews.llvm.org/D68554 +find "${ROOTDIR}" -path "${ROOTDIR}/build*" -prune -o \ + -type f -name '*.[c|h|cpp]' -print0 |\ + xargs --null --max-args=3 --max-procs="${MAX_PROCS}" \ + clang-format --style=file --dry-run -Werror -- cgit v1.2.3