]> ruderich.org/simon Gitweb - config/dotfiles.git/commitdiff
lib.sh: m4() define useful macros.
authorSimon Ruderich <simon@ruderich.org>
Sun, 1 Mar 2009 15:19:29 +0000 (16:19 +0100)
committerSimon Ruderich <simon@ruderich.org>
Sun, 1 Mar 2009 15:19:29 +0000 (16:19 +0100)
At the moment only IF and FI are defined which can be used for easy checking
of variables. They use the ifelse() macro.

lib.sh

diff --git a/lib.sh b/lib.sh
index ea61359e2e806be5b26aaff201930743d7214b5a..88b7b98a26f2ba84cf2c141191bc296dbac48ddc 100644 (file)
--- 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.
 # 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
 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 '$*'"
 
     # 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
 }
 
     unset file
 }