Use a perl script to create error2.h
authorAndre Noll <maan@systemlinux.org>
Sun, 4 Jul 2010 09:23:28 +0000 (11:23 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 Jul 2010 23:12:34 +0000 (01:12 +0200)
This is *much* faster than the shell code in configure. Perl is
required anyway for help2man, so this patch does not introduce
additional requirements on the build system.

configure.ac
error2.pl [new file with mode: 0755]

index d8f55ce..f0c2787 100644 (file)
@@ -652,53 +652,14 @@ AC_DEFUN([add_dot_o],[$(for i in $@; do printf "$i.o "; done)])
 AC_DEFUN([add_para],[$(for i in $@; do printf "para_$i "; done)])
 AC_DEFUN([objlist_to_errlist],[$(for i in $@; do printf "DEFINE_ERRLIST($(echo $i| tr 'a-z' 'A-Z'));"; done) [const char **para_errlist[[]]] = {$(for i in $@; do printf "PARA_ERRLIST($(echo $i | tr 'a-z' 'A-Z')), "; done) }])
 ############################################################# error2.h
-AC_DEFUN([define_safe_error_enums],
-[
-       exe=""
-       for i in $executables; do
-#              eval echo checking if $1 is linked into $i
-               for j in $(eval echo \$${i}_errlist_objs); do
-                       if test $j = $1; then
-                               exe="$exe $i"
-                               break;
-                       fi
-               done
-       done
-       #echo "$1 gets linked into $exe"
-       safe_errlists=""
-       for i in $all_errlist_objs; do
-               for j in $exe; do
-                       found=0
-                       for k in $(eval echo \$${j}_errlist_objs); do
-                               if test $k = $i; then
-                                       found=1
-                                       break;
-                               fi
-                       done
-                       if test $found -eq 0; then
-                               break;
-                       fi
-               done
-               if test $found -eq 1; then
-                       safe_errlists="$safe_errlists $i"
-               fi
-       done
-       #echo "safe errlists for $1: $safe_errlists"
-       ss_defs=""
-       for i in $safe_errlists; do
-               echo "SS_ENUM($(echo $i | tr 'a-z' 'A-Z'));"
-       done
-]
-)
-
-
 AC_MSG_NOTICE(creating error2.h)
+for i in $executables; do
+       echo "$i: "
+       eval echo \$${i}_errlist_objs
+done | ./error2.pl > error2.h
 for obj in $all_errlist_objs; do
        SS="$SS SS_$(echo $obj | tr 'a-z' 'A-Z'),"
-       echo "#ifdef MAIN_INPUT_FILE_IS_$obj"
-       define_safe_error_enums($obj)
-       echo "#endif"
-done > error2.h
+done
 AC_DEFINE_UNQUOTED(DEFINE_ERRLIST_OBJECT_ENUM,
        [enum {$SS NUM_SS}],
        [list of all objects that use paraslash's error facility]
diff --git a/error2.pl b/error2.pl
new file mode 100755 (executable)
index 0000000..78ff2c5
--- /dev/null
+++ b/error2.pl
@@ -0,0 +1,58 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+my %matrix;
+my @executables;
+my %objects;
+
+sub make_matrix
+{
+       my ($line, $e, @fields, $field);
+
+       while (defined($line = <>)) {
+               chomp($line);
+               if ($line =~ "^ *\$") {
+                       next;
+               }
+               @fields = split(" ", $line);
+               while (defined(($field = shift(@fields)))) {
+                       if ($field =~ ":\$") {
+                               $field =~ s/://;
+                               $e = $field;
+                               push(@executables, $e);
+                               next;
+                       }
+                       $matrix{$e . ">" . $field} = 1;
+                       $objects{$field} = 1;
+               }
+       }
+}
+
+sub print_safe_objects
+{
+       my @objs = keys(%objects);
+       my ($o1, $o2, $e);
+
+       foreach $o1 (@objs) {
+               print("#ifdef MAIN_INPUT_FILE_IS_$o1\n");
+               O2: foreach $o2 (@objs) {
+                       foreach $e (@executables) {
+                               if (!defined($matrix{$e . ">" . $o1})) {
+                                       next;
+                               }
+                               if (defined($matrix{$e . ">" . $o2})) {
+                                       next;
+                               }
+                               next O2;
+                       }
+                       $_ = $o2;
+                       tr/a-z/A-Z/;
+                       printf("SS_ENUM(%s);\n", $_);
+               }
+               print("#endif\n");
+       }
+}
+make_matrix;
+print_safe_objects;