#!/usr/bin/env bash name='configure' # Luke's configuration script #version='1.0' # Copyright (C) 2009, 2016 Luke Shumaker # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. # If not, see . srcdir="$(dirname -- "$0")" outdir="." error() { echo "$name: $1" >&2 exit 1 } if [ "${srcdir:0:1}" = / ]; then topsrcdir=$srcdir else topsrcdir="&/$srcdir" fi topsrcdir="${topsrcdir%/.}" edit=(sed -E -e "s|^topsrcdir := .*|$topsrcdir|") setvar() { edit+=(-e "s@^(\s*$1\s*:?=).*@\1 $2@") } vars=($(<"$srcdir/config.mk.in" sed -n 's/^\([ a-z_-]*\)=.*/\1/p')) printf -v lopt '%s:,' "${vars[@]}" lopt+='enable-autodeps,disable-autodeps' sopt='' args=$(getopt -n "$name" -o "${sopt}" -l "${lopt}" -- "$@") || exit $? eval set -- "$args" while [ $# -gt 0 ]; do case "$1" in --) shift; break;; --enable-autodeps) setvar AUTODEPS t; shift;; --disable-autodeps) setvar AUTODEPS ''; shift;; --*) setvar "${1#--}" "$2"; shift 2;; *) error "unrecognized option \`$1'"; esac done "${edit[@]}" < "$srcdir/config.mk.in" > "$outdir/config.mk" Makefiles=($(find "$srcdir/" -name 'Makefile') "$srcdir"/modules/module.mk "$srcdir"/modules/*/Makefile.inc.mk) for src in "${Makefiles[@]}"; do out="$outdir/${src#$srcdir/}" mkdir -p -- $(dirname -- "$out") if ! test "$src" -ef "$out"; then cp -fT -- "$src" "$out" fi done