From: Simon Ruderich Date: Sun, 1 Mar 2009 15:19:29 +0000 (+0100) Subject: lib.sh: m4() define useful macros. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=8c731331a353d82adc61a81bd3cb92e79f3c2dc8;p=config%2Fdotfiles.git lib.sh: m4() define useful macros. At the moment only IF and FI are defined which can be used for easy checking of variables. They use the ifelse() macro. --- diff --git a/lib.sh b/lib.sh index ea61359..88b7b98 100644 --- a/lib.sh +++ b/lib.sh @@ -73,6 +73,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 +93,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 }