#!/usr/bin/env bash usage () { echo "Usage: $0 [-h|options...]"; } help () { cat <config.rc conf() { echo "$1" >&3; } colour=auto while getopts B:C:L:P:W:c:defhovw opt; do qopt=${OPTARG@Q} case $opt in B) conf "LDLIBS+=($qopt)";; C) conf "CFLAGS+=($qopt)";; L) conf "LDFLAGS+=($qopt)";; P) conf "CPPFLAGS+=($qopt)";; W) warn="$OPTARG";; c) colour="$OPTARG";; d) conf "debug=1" >&3;; e) conf "werror=1" >&3;; f) conf "extra_targets+=(compile_commands.json)" ;; h) usage; help; exit;; o) conf "optimise=1" >&3;; v) conf "verbose=1" >&3;; w) warn=1;; ?) usage >&2; exit 1;; esac done case "$colour" in auto) [[ -t 1 ]] && conf "colour=1" || conf "colour=0";; always) conf "colour=1";; off) conf "colour=0";; *) usage >&2; exit 1;; esac case "$warn" in 1|clang|gcc) conf "warn=$warn";; ?*) usage >&2; exit 1;; esac if [[ $CC ]]; then conf "CC=${CC@Q}"; fi