50b6cee53f2c2d08548f251d8cd9c7137499f3bc
[openssl.git] / apps / progs.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
4 #
5 # Licensed under the OpenSSL licenses, (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 # https://www.openssl.org/source/license.html
9 # or in the file LICENSE in the source distribution.
10
11 # Generate progs.h file by looking for command mains in list of C files
12 # passed on the command line.
13
14 use strict;
15 use warnings;
16 use configdata qw/@disablables/;
17
18 my %commands = ();
19 my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
20
21 foreach my $filename (@ARGV) {
22         open F, $filename or die "Coudn't open $_: $!\n";
23         foreach (grep /$cmdre/, <F>) {
24                 my @foo = /$cmdre/;
25                 $commands{$1} = 1;
26         }
27         close F;
28 }
29
30 @ARGV = sort keys %commands;
31
32 print <<'EOF';
33 /*
34  * Automatically generated by progs.pl for openssl.c
35  * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
36  *
37  * Licensed under the OpenSSL licenses, (the "License");
38  * you may not use this file except in compliance with the License.
39  * You may obtain a copy of the License at
40  * https://www.openssl.org/source/license.html
41  * or in the file LICENSE in the source distribution.
42  */
43
44 typedef enum FUNC_TYPE {
45     FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
46     FT_md_alg, FT_cipher_alg
47 } FUNC_TYPE;
48
49 typedef struct function_st {
50     FUNC_TYPE type;
51     const char *name;
52     int (*func)(int argc,char *argv[]);
53     const OPTIONS *help;
54 } FUNCTION;
55
56 DEFINE_LHASH_OF(FUNCTION);
57
58 EOF
59
60 foreach (@ARGV) {
61         printf "extern int %s_main(int argc, char *argv[]);\n", $_;
62 }
63
64 print "\n";
65
66 foreach (@ARGV) {
67         printf "extern OPTIONS %s_options[];\n", $_;
68 }
69
70 my %cmd_disabler = (
71     ciphers  => "sock",
72     genrsa   => "rsa",
73     rsautl   => "rsa",
74     gendsa   => "dsa",
75     dsaparam => "dsa",
76     gendh    => "dh",
77     dhparam  => "dh",
78     ecparam  => "ec",
79     pkcs12   => "des",
80     );
81 print "\nstatic FUNCTION functions[] = {\n";
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         "md_ghost94",
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";