symbols.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 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. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. #
  26. # Experience has shown that the symbols-in-versions file is useful to
  27. # applications that want to build with a wide range of libcurl versions. It
  28. # is however easy to get it wrong and the source gets a bit messy with all the
  29. # fixed numerical comparisons.
  30. #
  31. # The point of this script is to provide an easy-to-use macro for libcurl-
  32. # using applications to do preprocessor checks for specific libcurl defines,
  33. # and yet make the code clearly show what the macro is used for.
  34. #
  35. # Run this script and generate libcurl-symbols.h and then use that header in
  36. # a fashion similar to:
  37. #
  38. # #include "libcurl-symbols.h"
  39. #
  40. # #if LIBCURL_HAS(CURLOPT_MUTE)
  41. # has mute
  42. # #else
  43. # no mute
  44. # #endif
  45. #
  46. #
  47. open F, "<symbols-in-versions";
  48. sub str2num {
  49. my ($str)=@_;
  50. if($str =~ /([0-9]*)\.([0-9]*)\.*([0-9]*)/) {
  51. return sprintf("0x%06x", $1<<16 | $2 << 8 | $3);
  52. }
  53. }
  54. print <<EOS
  55. #include <curl/curl.h>
  56. #define LIBCURL_HAS(x) \\
  57. (defined(x ## _FIRST) && (x ## _FIRST <= LIBCURL_VERSION_NUM) && \\
  58. (!defined(x ## _LAST) || ( x ## _LAST >= LIBCURL_VERSION_NUM)))
  59. EOS
  60. ;
  61. while(<F>) {
  62. if(/^(CURL[^ ]*)[ \t]*(.*)/) {
  63. my ($sym, $vers)=($1, $2);
  64. my $intr;
  65. my $rm;
  66. my $dep;
  67. # is there removed info?
  68. if($vers =~ /([\d.]+)[ \t-]+([\d.-]+)[ \t]+([\d.]+)/) {
  69. ($intr, $dep, $rm)=($1, $2, $3);
  70. }
  71. # is it a dep-only line?
  72. elsif($vers =~ /([\d.]+)[ \t-]+([\d.]+)/) {
  73. ($intr, $dep)=($1, $2);
  74. }
  75. else {
  76. $intr = $vers;
  77. }
  78. my $inum = str2num($intr);
  79. print <<EOS
  80. #define ${sym}_FIRST $inum /* Added in $intr */
  81. EOS
  82. ;
  83. my $irm = str2num($rm);
  84. if($rm) {
  85. print <<EOS
  86. #define ${sym}_LAST $irm /* Last featured in $rm */
  87. EOS
  88. ;
  89. }
  90. }
  91. }