symbols.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2011 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. ###########################################################################
  23. #
  24. # Experience has shown that the symbols-in-versions file is very useful to
  25. # applications that want to build with a wide range of libcurl versions.
  26. # It is however easy to get it wrong and the source gets a bit messy with all
  27. # the fixed numerical comparisons.
  28. #
  29. # The point of this script is to provide an easy-to-use macro for libcurl-
  30. # using applications to do preprocessor checks for specific libcurl defines,
  31. # and yet make the code clearly show what the macro is used for.
  32. #
  33. # Run this script and generate libcurl-symbols.h and then use that header in
  34. # a fashion similar to:
  35. #
  36. # #include "libcurl-symbols.h"
  37. #
  38. # #if LIBCURL_HAS(CURLOPT_MUTE)
  39. # has mute
  40. # #else
  41. # no mute
  42. # #endif
  43. #
  44. #
  45. open F, "<symbols-in-versions";
  46. sub str2num {
  47. my ($str)=@_;
  48. if($str =~ /([0-9]*)\.([0-9]*)\.*([0-9]*)/) {
  49. return sprintf("0x%06x", $1<<16 | $2 << 8 | $3);
  50. }
  51. }
  52. print <<EOS
  53. #include <curl/curl.h>
  54. #define LIBCURL_HAS(x) \\
  55. (defined(x ## _FIRST) && (x ## _FIRST <= LIBCURL_VERSION_NUM) && \\
  56. (!defined(x ## _LAST) || ( x ## _LAST >= LIBCURL_VERSION_NUM)))
  57. EOS
  58. ;
  59. while(<F>) {
  60. if(/^(CURL[^ ]*)[ \t]*(.*)/) {
  61. my ($sym, $vers)=($1, $2);
  62. my $intr;
  63. my $rm;
  64. my $dep;
  65. # is there removed info?
  66. if($vers =~ /([\d.]+)[ \t-]+([\d.-]+)[ \t]+([\d.]+)/) {
  67. ($intr, $dep, $rm)=($1, $2, $3);
  68. }
  69. # is it a dep-only line?
  70. elsif($vers =~ /([\d.]+)[ \t-]+([\d.]+)/) {
  71. ($intr, $dep)=($1, $2);
  72. }
  73. else {
  74. $intr = $vers;
  75. }
  76. my $inum = str2num($intr);
  77. print <<EOS
  78. #define ${sym}_FIRST $inum /* Added in $intr */
  79. EOS
  80. ;
  81. my $irm = str2num($rm);
  82. if($rm) {
  83. print <<EOS
  84. #define ${sym}_LAST $irm /* Last featured in $rm */
  85. EOS
  86. ;
  87. }
  88. }
  89. }