progs.pl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/perl
  2. # Generate progs.h file by looking for command mains in list of C files
  3. # passed on the command line.
  4. use strict;
  5. use warnings;
  6. my %commands = ();
  7. my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
  8. foreach my $filename (@ARGV) {
  9. open F, $filename or die "Coudn't open $_: $!\n";
  10. foreach (grep /$cmdre/, <F>) {
  11. my @foo = /$cmdre/;
  12. $commands{$1} = 1;
  13. }
  14. close F;
  15. }
  16. @ARGV = sort keys %commands;
  17. print <<'EOF';
  18. /*
  19. * Automatically generated by progs.pl for openssl.c
  20. * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
  21. * See the openssl.c for copyright details.
  22. */
  23. typedef enum FUNC_TYPE {
  24. FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
  25. FT_md_alg, FT_cipher_alg
  26. } FUNC_TYPE;
  27. typedef struct function_st {
  28. FUNC_TYPE type;
  29. const char *name;
  30. int (*func)(int argc,char *argv[]);
  31. const OPTIONS *help;
  32. } FUNCTION;
  33. DEFINE_LHASH_OF(FUNCTION);
  34. EOF
  35. foreach (@ARGV) {
  36. printf "extern int %s_main(int argc, char *argv[]);\n", $_;
  37. }
  38. print "\n";
  39. foreach (@ARGV) {
  40. printf "extern OPTIONS %s_options[];\n", $_;
  41. }
  42. print "\n#ifdef INCLUDE_FUNCTION_TABLE\n";
  43. print "static FUNCTION functions[] = {\n";
  44. foreach (@ARGV) {
  45. my $str=" { FT_general, \"$_\", ${_}_main, ${_}_options },\n";
  46. if (/^s_/ || /^ciphers$/) {
  47. print "#if !defined(OPENSSL_NO_SOCK)\n${str}#endif\n";
  48. } elsif (/^engine$/) {
  49. print "#ifndef OPENSSL_NO_ENGINE\n${str}#endif\n";
  50. } elsif (/^rsa$/ || /^genrsa$/ || /^rsautl$/) {
  51. print "#ifndef OPENSSL_NO_RSA\n${str}#endif\n";
  52. } elsif (/^dsa$/ || /^gendsa$/ || /^dsaparam$/) {
  53. print "#ifndef OPENSSL_NO_DSA\n${str}#endif\n";
  54. } elsif (/^ec$/ || /^ecparam$/) {
  55. print "#ifndef OPENSSL_NO_EC\n${str}#endif\n";
  56. } elsif (/^dh$/ || /^gendh$/ || /^dhparam$/) {
  57. print "#ifndef OPENSSL_NO_DH\n${str}#endif\n";
  58. } elsif (/^pkcs12$/) {
  59. print "#if !defined(OPENSSL_NO_DES)\n${str}#endif\n";
  60. } elsif (/^cms$/) {
  61. print "#ifndef OPENSSL_NO_CMS\n${str}#endif\n";
  62. } elsif (/^ocsp$/) {
  63. print "#ifndef OPENSSL_NO_OCSP\n${str}#endif\n";
  64. } elsif (/^srp$/) {
  65. print "#ifndef OPENSSL_NO_SRP\n${str}#endif\n";
  66. } else {
  67. print $str;
  68. }
  69. }
  70. foreach (
  71. "md2", "md4", "md5",
  72. "md_ghost94",
  73. "sha1", "sha224", "sha256", "sha384", "sha512",
  74. "mdc2", "rmd160"
  75. ) {
  76. printf "#ifndef OPENSSL_NO_".uc($_)."\n" if ! /sha/;
  77. printf " { FT_md, \"".$_."\", dgst_main},\n";
  78. printf "#endif\n" if ! /sha/;
  79. }
  80. foreach (
  81. "aes-128-cbc", "aes-128-ecb",
  82. "aes-192-cbc", "aes-192-ecb",
  83. "aes-256-cbc", "aes-256-ecb",
  84. "camellia-128-cbc", "camellia-128-ecb",
  85. "camellia-192-cbc", "camellia-192-ecb",
  86. "camellia-256-cbc", "camellia-256-ecb",
  87. "base64", "zlib",
  88. "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
  89. "rc2", "bf", "cast", "rc5",
  90. "des-ecb", "des-ede", "des-ede3",
  91. "des-cbc", "des-ede-cbc","des-ede3-cbc",
  92. "des-cfb", "des-ede-cfb","des-ede3-cfb",
  93. "des-ofb", "des-ede-ofb","des-ede3-ofb",
  94. "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
  95. "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
  96. "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
  97. "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
  98. "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
  99. "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb"
  100. ) {
  101. my $str=" { FT_cipher, \"$_\", enc_main, enc_options },\n";
  102. if (/des/) {
  103. printf "#ifndef OPENSSL_NO_DES\n${str}#endif\n";
  104. } elsif (/aes/) {
  105. printf "#ifndef OPENSSL_NO_AES\n${str}#endif\n";
  106. } elsif (/camellia/) {
  107. printf "#ifndef OPENSSL_NO_CAMELLIA\n${str}#endif\n";
  108. } elsif (/idea/) {
  109. printf "#ifndef OPENSSL_NO_IDEA\n${str}#endif\n";
  110. } elsif (/seed/) {
  111. printf "#ifndef OPENSSL_NO_SEED\n${str}#endif\n";
  112. } elsif (/rc4/) {
  113. printf "#ifndef OPENSSL_NO_RC4\n${str}#endif\n";
  114. } elsif (/rc2/) {
  115. printf "#ifndef OPENSSL_NO_RC2\n${str}#endif\n";
  116. } elsif (/bf/) {
  117. printf "#ifndef OPENSSL_NO_BF\n${str}#endif\n";
  118. } elsif (/cast/) {
  119. printf "#ifndef OPENSSL_NO_CAST\n${str}#endif\n";
  120. } elsif (/rc5/) {
  121. printf "#ifndef OPENSSL_NO_RC5\n${str}#endif\n";
  122. } elsif (/zlib/) {
  123. printf "#ifdef ZLIB\n${str}#endif\n";
  124. } else {
  125. print $str;
  126. }
  127. }
  128. print " { 0, NULL, NULL}\n};\n";
  129. printf "#endif\n";