Copyright consolidation: perl files
[openssl.git] / apps / progs.pl
1 #! /usr/bin/env perl
2 # Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 # Generate progs.h file by looking for command mains in list of C files
10 # passed on the command line.
11
12 use strict;
13 use warnings;
14 use configdata qw/@disablables/;
15
16 my %commands = ();
17 my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
18
19 foreach my $filename (@ARGV) {
20         open F, $filename or die "Coudn't open $_: $!\n";
21         foreach (grep /$cmdre/, <F>) {
22                 my @foo = /$cmdre/;
23                 $commands{$1} = 1;
24         }
25         close F;
26 }
27
28 @ARGV = sort keys %commands;
29
30 print <<'EOF';
31 /*
32  * WARNING: do not edit!
33  * Generated by apps/progs.pl
34  *
35  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
36  *
37  * Licensed under the OpenSSL license (the "License").  You may not use
38  * this file except in compliance with the License.  You can obtain a copy
39  * in the file LICENSE in the source distribution or at
40  * https://www.openssl.org/source/license.html
41  */
42
43 typedef enum FUNC_TYPE {
44     FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
45     FT_md_alg, FT_cipher_alg
46 } FUNC_TYPE;
47
48 typedef struct function_st {
49     FUNC_TYPE type;
50     const char *name;
51     int (*func)(int argc,char *argv[]);
52     const OPTIONS *help;
53 } FUNCTION;
54
55 DEFINE_LHASH_OF(FUNCTION);
56
57 EOF
58
59 foreach (@ARGV) {
60         printf "extern int %s_main(int argc, char *argv[]);\n", $_;
61 }
62
63 print "\n";
64
65 foreach (@ARGV) {
66         printf "extern OPTIONS %s_options[];\n", $_;
67 }
68
69 print "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
70 print "static FUNCTION functions[] = {\n";
71 my %cmd_disabler = (
72     ciphers  => "sock",
73     genrsa   => "rsa",
74     rsautl   => "rsa",
75     gendsa   => "dsa",
76     dsaparam => "dsa",
77     gendh    => "dh",
78     dhparam  => "dh",
79     ecparam  => "ec",
80     pkcs12   => "des",
81     );
82 foreach my $cmd (@ARGV) {
83         my $str="    { FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options },\n";
84         if ($cmd =~ /^s_/) {
85                 print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
86         } elsif (grep { $cmd eq $_ } @disablables) {
87                 print "#ifndef OPENSSL_NO_".uc($cmd)."\n${str}#endif\n";
88         } elsif (my $disabler = $cmd_disabler{$cmd}) {
89                 print "#ifndef OPENSSL_NO_".uc($disabler)."\n${str}#endif\n";
90         } else {
91                 print $str;
92         }
93 }
94
95 my %md_disabler = (
96     sha1       => "sha",
97     sha224     => "sha",
98     sha256     => "sha",
99     sha384     => "sha",
100     sha512     => "sha",
101     blake2b512 => "blake2",
102     blake2s256 => "blake2",
103     );
104 foreach my $cmd (
105         "md2", "md4", "md5",
106         "gost",
107         "sha1", "sha224", "sha256", "sha384", "sha512",
108         "mdc2", "rmd160", "blake2b512", "blake2s256"
109 ) {
110         my $str = "    { FT_md, \"".$cmd."\", dgst_main},\n";
111         if (grep { $cmd eq $_ } @disablables) {
112                 print "#ifndef OPENSSL_NO_".uc($cmd)."\n${str}#endif\n";
113         } elsif (my $disabler = $md_disabler{$cmd}) {
114                 print "#ifndef OPENSSL_NO_".uc($disabler)."\n${str}#endif\n";
115         } else {
116                 print "#ifndef OPENSSL_NO_".uc($cmd)."\n${str}#endif\n";
117         }
118 }
119
120 my %cipher_disabler = (
121     des3  => "des",
122     desx  => "des",
123     cast5 => "cast",
124     );
125 foreach my $cmd (
126         "aes-128-cbc", "aes-128-ecb",
127         "aes-192-cbc", "aes-192-ecb",
128         "aes-256-cbc", "aes-256-ecb",
129         "camellia-128-cbc", "camellia-128-ecb",
130         "camellia-192-cbc", "camellia-192-ecb",
131         "camellia-256-cbc", "camellia-256-ecb",
132         "base64", "zlib",
133         "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
134         "rc2", "bf", "cast", "rc5",
135         "des-ecb", "des-ede",    "des-ede3",
136         "des-cbc", "des-ede-cbc","des-ede3-cbc",
137         "des-cfb", "des-ede-cfb","des-ede3-cfb",
138         "des-ofb", "des-ede-ofb","des-ede3-ofb",
139         "idea-cbc","idea-ecb",    "idea-cfb", "idea-ofb",
140         "seed-cbc","seed-ecb",    "seed-cfb", "seed-ofb",
141         "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
142         "bf-cbc",  "bf-ecb",     "bf-cfb",   "bf-ofb",
143         "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
144         "cast-cbc", "rc5-cbc",   "rc5-ecb",  "rc5-cfb",  "rc5-ofb"
145 ) {
146         my $str="    { FT_cipher, \"$cmd\", enc_main, enc_options },\n";
147         (my $algo= $cmd) =~ s/-.*//g;
148         if ($cmd eq "zlib") {
149                 print "#ifdef ZLIB\n${str}#endif\n";
150         } elsif (grep { $algo eq $_ } @disablables) {
151                 print "#ifndef OPENSSL_NO_".uc($algo)."\n${str}#endif\n";
152         } elsif (my $disabler = $cipher_disabler{$algo}) {
153                 print "#ifndef OPENSSL_NO_".uc($disabler)."\n${str}#endif\n";
154         } else {
155                 print $str;
156         }
157 }
158
159 print "    { 0, NULL, NULL}\n};\n";
160 print "#endif\n";