Generate progs.h from a bunch of files instead of internal knowledge
[openssl.git] / apps / progs.pl
index 40053a73063b66cab38d0d8e24cc4af8631d1da8..b87aef610e5d0ac80387c812398d4337e49ffc5c 100644 (file)
@@ -1,5 +1,23 @@
-#!/usr/local/bin/perl
-# Generate progs.h file from list of "programs" passed on the command line.
+#!/usr/bin/perl
+# Generate progs.h file by looking for command mains in list of C files
+# passed on the command line.
+
+use strict;
+use warnings;
+
+my %commands = ();
+my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
+
+foreach my $filename (@ARGV) {
+       open F, $filename or die "Coudn't open $_: $!\n";
+       foreach (grep /$cmdre/, <F>) {
+               my @foo = /$cmdre/;
+               $commands{$1} = 1;
+       }
+       close F;
+}
+
+@ARGV = sort keys %commands;
 
 print <<'EOF';
 /*
@@ -24,13 +42,6 @@ DEFINE_LHASH_OF(FUNCTION);
 
 EOF
 
-grep(s/\.o//, @ARGV);
-grep(s/^asn1pars$/asn1parse/, @ARGV);
-grep(s/^crl2p7$/crl2pkcs7/, @ARGV);
-push @ARGV, 'list';
-push @ARGV, 'help';
-push @ARGV, 'exit';
-
 foreach (@ARGV) {
        printf "extern int %s_main(int argc, char *argv[]);\n", $_;
 }
@@ -43,7 +54,7 @@ foreach (@ARGV) {
 print "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
 print "static FUNCTION functions[] = {\n";
 foreach (@ARGV) {
-       $str="    { FT_general, \"$_\", ${_}_main, ${_}_options },\n";
+       my $str="    { FT_general, \"$_\", ${_}_main, ${_}_options },\n";
        if (/^s_/ || /^ciphers$/) {
                print "#if !defined(OPENSSL_NO_SOCK)\n${str}#endif\n";
        } elsif (/^engine$/) {
@@ -101,7 +112,7 @@ foreach (
        "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
        "cast-cbc", "rc5-cbc",   "rc5-ecb",  "rc5-cfb",  "rc5-ofb"
 ) {
-       $str="    { FT_cipher, \"$_\", enc_main, enc_options },\n";
+       my $str="    { FT_cipher, \"$_\", enc_main, enc_options },\n";
        if (/des/) {
                printf "#ifndef OPENSSL_NO_DES\n${str}#endif\n";
        } elsif (/aes/) {