xref: /curl/docs/libcurl/symbols.pl (revision 945db0d9)
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#
47open F, "<symbols-in-versions";
48
49sub str2num {
50    my ($str)=@_;
51    if($str =~ /([0-9]*)\.([0-9]*)\.*([0-9]*)/) {
52        return sprintf("0x%06x", $1<<16 | $2 << 8 | $3);
53    }
54}
55
56print <<EOS
57
58#include <curl/curl.h>
59
60#define LIBCURL_HAS(x) \\
61  (defined(x ## _FIRST) && (x ## _FIRST <= LIBCURL_VERSION_NUM) && \\
62   (!defined(x ## _LAST) || ( x ## _LAST >= LIBCURL_VERSION_NUM)))
63
64EOS
65    ;
66
67while(<F>) {
68    if(/^(CURL[^ ]*)[ \t]*(.*)/) {
69        my ($sym, $vers)=($1, $2);
70
71        my $intr;
72        my $rm;
73        my $dep;
74
75        # is there removed info?
76        if($vers =~ /([\d.]+)[ \t-]+([\d.-]+)[ \t]+([\d.]+)/) {
77            ($intr, $dep, $rm)=($1, $2, $3);
78        }
79        # is it a dep-only line?
80        elsif($vers =~ /([\d.]+)[ \t-]+([\d.]+)/) {
81            ($intr, $dep)=($1, $2);
82        }
83        else {
84            $intr = $vers;
85        }
86
87        my $inum = str2num($intr);
88
89        print <<EOS
90#define ${sym}_FIRST $inum /* Added in $intr */
91EOS
92;
93        my $irm = str2num($rm);
94        if($rm) {
95        print <<EOS
96#define ${sym}_LAST $irm /* Last featured in $rm */
97EOS
98;
99        }
100
101    }
102}
103