#!/usr/bin/env sh # simple and flexible configure script for people who don't like to waste time # licensed to the public domain set -e mkf=config.mk objs='esvapi.o util.o initial.o' srcs='esvapi.d util.d initial.d' # utility functions present () { command -v "$1" 1>/dev/null 2>/dev/null } throw () { >&2 printf "%s: %s\n" "$(basename "$0")" "$1" exit 1 } using () { >&2 printf "using %s\n" "$1" } # generators ## D compiler gen_DC () { if [ -n "$dc" ]; then using "$dc" return 0 fi if present ldc2; then dc=ldc2 elif present dmd; then dc=dmd else throw "D compiler not found; install LDC or DMD" fi using "$dc" } ## flags used in the compilation step gen_CFLAGS () { if [ -z "$debug" ]; then case "$dc" in ldc2) cflags="-Oz";; dmd) cflags="-O";; esac else cflags="-g" case "$dc" in ldc2) cflags="$cflags -O0 -d-debug";; dmd) cflags="$cflags -debug";; esac fi for flag in $cflags; do using "$flag" done } ## flags used in the linking step gen_LDFLAGS () { if [ "$dc" = ldc2 ]; then if present ld.lld; then ldflags="-linker=lld" elif present ld.gold; then ldflags="-linker=gold" fi fi if [ -z "$debug" ]; then if [ -n "$ldflags" ]; then ldflags="$ldflags "; fi ldflags="$ldflags-L--gc-sections" fi for flag in $ldflags; do using "$flag" done } # command line interface while getopts c:dhr ch; do case "$ch" in c) case "$OPTARG" in ldc2) dc="ldc2" ;; dmd) dc="dmd" ;; *) throw "unknown D compiler '$OPTARG' specified (valid options: ldc2, dmd)" ;; esac ;; d) debug=1 ;; r) unset debug ;; h) cat <&2 "$dc" -o- -makedeps "$src" i="$((i + 1))" done unset i printf '# end generated dependencies\n' } >>"$mkf"