procwatch/justfile
Thorsten Schubert 01ff781d92
All checks were successful
/ build-x86 (push) Successful in 58s
/ build (push) Successful in 1m13s
Remove distribution-specific build files
2024-10-24 19:03:17 +02:00

150 lines
3.9 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
dist:
@mkdir -p dist
# Remove all untracked files
[no-exit-message]
wipe: clean
@git clean -fxd
alias mrproper := wipe
# vi: set ft=just ts=4 sw=4 sts=-1 nosr et si tw=0 fdm=manual: