X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib.sh;h=9e2308d6adf988de977116d7b28713e52c077fce;hb=f30437901deddf4e539294eaddcd2f19af1d778b;hp=ea61359e2e806be5b26aaff201930743d7214b5a;hpb=144b79caff995d7c5773e3efb66813bf131de0e2;p=config%2Fdotfiles.git diff --git a/lib.sh b/lib.sh index ea61359..9e2308d 100644 --- a/lib.sh +++ b/lib.sh @@ -17,11 +17,14 @@ installed() { which $1 | grep -E '^/' > /dev/null } -# Prints the current OS. Supported are Debian (debian) and Mac OS X (darwin) -# at the moment. If an unsupported OS is used an error is printed. +# Prints the current OS. Supported are Debian (debian), Gentoo (gentoo) and +# Mac OS X (darwin) at the moment. If an unsupported OS is used an error is +# printed. os() { if [ -f /etc/debian_version ]; then echo debian + elif [ -f /etc/gentoo-release ]; then + echo gentoo elif [ x`uname` = xDarwin ]; then echo darwin else @@ -73,6 +76,11 @@ link() { # to $1 with a warning at the beginning to not edit the generated file. # # All arguments (except the first which is the filename) are passed to m4. +# +# The following macros are defined: IF and FI. Example: +# IF(OS, debian) +# ... +# FI m4() { # First argument is file name. file=$1 @@ -88,7 +96,11 @@ m4() { # Process $1.m4 with m4 using the given options. echo "m4(): generating '$file' from '$file.m4' with options '$*'" - $m4 $* $file.m4 >> $file + # Add useful macros. + (echo "define(\`IF', \`ifelse(\`\$1', \`\$2',dnl')dnl +define(\`FI', \`)dnl')dnl"; + # Run the file (and the default macros) through m4. + cat $file.m4) | $m4 "$@" >> $file unset file }