[FFmpeg-cvslog] configure: rewrite print_config() function using awk

Mans Rullgard git at videolan.org
Tue Oct 30 17:52:52 CET 2012


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Sat Oct 27 16:43:12 2012 +0100| [f454e879238ce317c6d905d187e7608c461a7087] | committer: Mans Rullgard

configure: rewrite print_config() function using awk

This is much faster with slow shells and noticeably faster even
with bash on a fast Linux system.

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f454e879238ce317c6d905d187e7608c461a7087
---

 configure |   40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/configure b/configure
index 2abc465..f215c76 100755
--- a/configure
+++ b/configure
@@ -566,31 +566,29 @@ check_deps(){
     done
 }
 
-print_config_h(){
-    enabled $1 && v=1 || v=0
-    echo "#define $2 $v"
-}
-
-print_config_mak(){
-    enabled $1 && v= || v=!
-    echo "$v$2=yes"
-}
-
-print_config_asm(){
-    enabled $1 && v=1 || v=0
-    echo "%define $2 $v"
-}
-
 print_config(){
     pfx=$1
     files=$2
     shift 2
-    for cfg; do
-        ucname="$(toupper $cfg)"
-        for f in $files; do
-            "print_config_${f##*.}" $cfg ${pfx}${ucname} >>$f
-        done
-    done
+    map 'eval echo "$v \${$v:-no}"' "$@" |
+    awk "BEGIN { split(\"$files\", files) }
+        {
+            c = \"$pfx\" toupper(\$1);
+            v = \$2;
+            sub(/yes/, 1, v);
+            sub(/no/,  0, v);
+            for (f in files) {
+                file = files[f];
+                if (file ~ /\\.h\$/) {
+                    printf(\"#define %s %d\\n\", c, v) >>file;
+                } else if (file ~ /\\.asm\$/) {
+                    printf(\"%%define %s %d\\n\", c, v) >>file;
+                } else if (file ~ /\\.mak\$/) {
+                    n = +v ? \"\" : \"!\";
+                    printf(\"%s%s=yes\\n\", n, c) >>file;
+                }
+            }
+        }"
 }
 
 print_enabled(){



More information about the ffmpeg-cvslog mailing list