199 lines
5.1 KiB
Makefile
199 lines
5.1 KiB
Makefile
#!/usr/bin/env -S just --justfile
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
# Copyright © 2023 Thorsten Schubert <tschubert@bafh.org>
|
|
|
|
set positional-arguments := true
|
|
|
|
project := 'procwatch'
|
|
arch := 'x86-64-v3'
|
|
pie := 'false'
|
|
proot := justfile_directory()
|
|
|
|
[private]
|
|
default:
|
|
@just help
|
|
|
|
# Display this help
|
|
help:
|
|
@just --list
|
|
|
|
# Watch for file modificatons and rebuild
|
|
watch:
|
|
#!/usr/bin/env bash
|
|
while :; do
|
|
inotifywait -q -e create,modify,delete --exclude '\.git' --recursive {{ proot }} \
|
|
| while read -r directory events filename; do
|
|
if [[ $events =~ "ISDIR" ]]; then
|
|
break
|
|
elif [[ $filename =~ \.(c|cpp|cxx|h|hpp|hxx)$ ]]; then
|
|
printf "[%s]: %s%s\n" "$events" "$directory" "$filename"
|
|
tput bold
|
|
if time just build; then
|
|
tput setaf 2
|
|
printf "\n>>> Build finished <<<\n\n"
|
|
else
|
|
tput setaf 1
|
|
printf "\n>>> Build failed <<<\n\n"
|
|
fi
|
|
tput sgr0
|
|
fi
|
|
done
|
|
done
|
|
|
|
# Setup pre-condition
|
|
[private]
|
|
setup-pre-debug:
|
|
@{{ if path_exists("build") == "false" { "just setup" } else { "" } }}
|
|
|
|
[private]
|
|
setup-pre-release:
|
|
@{{ if path_exists("release") == "false" { "just setup-release" } else { "" } }}
|
|
|
|
# Setup debug build environment
|
|
setup *args:
|
|
@meson setup build \
|
|
-Db_sanitize=address,undefined \
|
|
-Db_lundef=false \
|
|
-Dbench=true \
|
|
-Dndebug=false \
|
|
{{ args }}
|
|
|
|
# Enable debug allocation output
|
|
enable-print-allocs: setup-pre-debug
|
|
@meson configure build -Dcpp_args=-DPRINT_ALLOC
|
|
|
|
# Disable debug allocation output
|
|
disable-print-allocs: setup-pre-debug
|
|
@meson configure build -Dcpp_args=
|
|
|
|
# Enable leak sanitizer
|
|
enable-leak-sanitizer: setup-pre-debug
|
|
@meson configure build -Db_sanitize=leak
|
|
|
|
# Enable address sanitizer
|
|
enable-address-sanitizer: setup-pre-debug
|
|
@meson configure build -Db_sanitize=address,undefined
|
|
|
|
# Build debug
|
|
build: setup-pre-debug
|
|
@ninja -v -C build all
|
|
|
|
# Run all tests if any
|
|
test: setup-pre-debug
|
|
@ninja -v -C build test
|
|
|
|
# Clean debug object files
|
|
[no-exit-message]
|
|
clean:
|
|
@-ninja -v -C build clean
|
|
@-ninja -v -C release clean
|
|
@-ccache -C || true
|
|
@-rm -rf ./dist
|
|
|
|
# Run debug build with arguments
|
|
run *args: build
|
|
@./build/{{ project }} "$@"
|
|
|
|
# Run debug build with fixed parameters for testing
|
|
debug-run:
|
|
just run -t0.1 -i2s -g10s '.'
|
|
|
|
# Setup release environment
|
|
setup-release march=arch $CCACHE_DISABLE="1":
|
|
@meson setup release
|
|
@meson configure release \
|
|
-Dbuildtype=release \
|
|
-Dcpp_args="-march={{ march }}" \
|
|
-Db_pie={{ pie }} \
|
|
-Ddebug=true \
|
|
{{ if pie == 'false' { "-Dcpp_link_args=-no-pie" } else { "" } }}
|
|
|
|
# Create release, default to native march
|
|
release $CCACHE_DISABLE="1": dist setup-pre-release
|
|
#!/usr/bin/env bash
|
|
march=$(meson introspect release --buildoptions | \
|
|
jq -r '.[] | select(.name == "build.cpp_args").value[] | select(startswith("-march=")) | sub("^-march="; "")')
|
|
if [[ -z march ]]; then
|
|
echo "march not set" >&2
|
|
exit 1
|
|
fi
|
|
ninja -v -C release
|
|
set -x
|
|
cp -f "release/{{ project }}" "dist/{{ project }}-${march}"
|
|
readelf -p .GCC.command.line "dist/{{ project }}-${march}" || true
|
|
|
|
# Invoke setup and build, creating a complete debug build
|
|
debug: setup build
|
|
|
|
# Try building debug and release variants
|
|
build-all: build release
|
|
|
|
# Update version information
|
|
update-version:
|
|
@echo {{ replace_regex(```git describe --tags --abbrev=0 --always```, '^' + project + '-(.+)-\d+$', '$1') }} | \
|
|
tee meson.version
|
|
|
|
# Show version information
|
|
version:
|
|
@cat meson.version
|
|
|
|
# Tag release, will force-sign existing tag
|
|
tag-release version release:
|
|
#!/usr/bin/env bash
|
|
if [[ -n $(git status --porcelain=v1 2>/dev/null) ]]; then
|
|
echo "Uncommitted changes, cannot prepare release." >&2
|
|
exit 1
|
|
fi
|
|
|
|
tag="{{ project }}-{{ version }}-{{ release }}"
|
|
if [[ ! $(git tag -l "$tag") ]]; then
|
|
printf "Creating tag: %s\n" "$tag" >&2
|
|
rpkg tag --version {{ version }} --release {{ release }}
|
|
fi
|
|
|
|
if [[ $(git config user.signingkey) ]]; then
|
|
echo "Replacing rpkg tag with signed one" >&2
|
|
git tag --force --sign --no-edit "$tag"
|
|
fi
|
|
|
|
# Show NVR
|
|
nvr:
|
|
@cat dist/nvr
|
|
|
|
dist:
|
|
@mkdir -p dist
|
|
|
|
# Build spec file
|
|
spec: dist
|
|
@rpkg spec --outdir=dist --sources
|
|
@rpkg nvr > dist/nvr
|
|
|
|
# Build locally
|
|
rpkg: dist
|
|
@rpkg local --outdir={{ proot }}/dist
|
|
|
|
# Create srpm in mock container
|
|
mock-srpm:
|
|
@mock --resultdir dist --buildsrpm --spec dist/procwatch.spec --sources dist/procwatch-$(git rev-parse --short HEAD)*.tar.gz
|
|
|
|
# Build the rpm package in mock container
|
|
mock-rpm:
|
|
@mock --resultdir dist dist/$(< dist/nvr).src.rpm
|
|
|
|
# Build with mock
|
|
mock: mock-srpm mock-rpm
|
|
|
|
# Build rpm
|
|
rpm: spec mock-srpm mock-rpm
|
|
|
|
# Remove all untracked files
|
|
[no-exit-message]
|
|
[private]
|
|
mrproper: wipe
|
|
|
|
# Remove all untracked files
|
|
[no-exit-message]
|
|
wipe: clean
|
|
@git clean -fxd
|
|
|
|
# vi: set ft=just ts=4 sw=4 sts=-1 nosr et si tw=0 fdm=manual:
|