2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 # SPDX-License-Identifier: curl
24 ###########################################################################
26 # This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
27 # a late evening in the #curl IRC channel.
32 use vars qw($Cpreprocessor);
35 # configurehelp perl module is generated by configure script
38 require configurehelp;
39 configurehelp->import(qw(
44 # Set default values if configure has not generated a configurehelp.pm file.
45 # This is the case with cmake.
47 $Cpreprocessor = 'cpp';
50 # we may get the dir root pointed out
51 my $root=$ARGV[0] || ".";
53 # need an include directory when building out-of-tree
54 my $i = ($ARGV[1]) ? "-I$ARGV[1] " : '';
65 # scanenum runs the preprocessor on curl.h so it will process all enums
66 # included by it, which *should* be all headers
69 open my $h_in, "-|", "$Cpreprocessor $i$file" || die "Cannot preprocess $file";
71 if ( /enum\s+(\S+\s+)?{/ .. /}/ ) {
79 close $h_in || die "Error preprocessing $file";
84 open my $h, "<", "$f";
86 if (/^#define ((LIB|)CURL[A-Za-z0-9_]*)/) {
94 my $d = "$root/include/curl";
95 opendir(my $dh, $d) ||
96 die "Can't opendir: $!";
97 my @headers = grep { /.h\z/ } readdir($dh);
99 foreach my $h (@headers) {
108 open(my $mh, "<", "$m");
111 # strip off formatting
113 # detect global-looking 'CURL[BLABLA]_*' symbols
114 while(s/\W(CURL(AUTH|E|H|MOPT|OPT|SHOPT|UE|M|SSH|SSLBACKEND|HEADER|FORM|FTP|PIPE|MIMEOPT|GSSAPI|ALTSVC|PROTO|PROXY|UPART|USESSL|_READFUNC|_WRITEFUNC|_CSELECT|_FORMADD|_IPRESOLVE|_REDIR|_RTSPREQ|_TIMECOND|_VERSION)_[a-zA-Z0-9_]+)//) {
116 # skip two "special" ones
117 if($s !~ /^(CURLE_OBSOLETE|CURLOPT_TEMPLATE)/) {
118 push @manrefs, "$1:$m:$line";
128 opendir(my $dh, $d) ||
129 die "Can't opendir: $!";
130 my @mans = grep { /.3\z/ } readdir($dh);
133 checkmanpage("$d/$m");
139 scanman3dir("$root/docs/libcurl");
140 scanman3dir("$root/docs/libcurl/opts");
142 open my $s, "<", "$root/docs/libcurl/symbols-in-versions";
144 if(/(^[^ \n]+) +(.*)/) {
145 my ($sym, $rest)=($1, $2);
147 print "Detected duplicate symbol: $sym\n";
152 my @a=split(/ +/, $rest);
154 # this symbol is documented to have been present the last time
163 for my $e (sort @syms) {
164 # OBSOLETE - names that are just placeholders for a position where we
165 # previously had a name, that is now removed. The OBSOLETE names should
166 # never be used for anything.
168 # CURL_EXTERN - is a define used for libcurl functions that are external,
169 # public. No app or other code should ever use it.
171 # CURLINC_ - defines for header dual-include prevention, ignore those.
173 # CURL_TEMP_ - are defined and *undefined* again within the file
175 # *_LAST and *_LASTENTRY are just prefix for the placeholders used for the
176 # last entry in many enum series.
179 if($e =~ /(OBSOLETE|^CURL_EXTERN|^CURLINC_|_LAST\z|_LASTENTRY\z|^CURL_TEMP_)/) {
197 # now scan through all symbols that were present in the symbols-in-versions
198 # but not in the headers
200 # If the symbols were marked 'removed' in symbols-in-versions we don't output
201 # anything about it since that is perfectly fine.
206 for my $e (sort keys %doc) {
207 if(($doc{$e} ne "used") && !$rem{$e}) {
210 print "Missing symbols mentioned in symbols-in-versions\n";
211 print "Add them to a header, or mark them as removed.\n";
220 for my $r (@manrefs) {
221 if($r =~ /^([^:]+):(.*)/) {
222 my ($sym, $file)=($1, $2);
223 if(!$doc{$sym} && !$warned{$sym, $file}) {
224 print "$file: $sym is not a public symbol\n";
225 $warned{$sym, $file} = 1;
232 printf "%d symbols in headers (out of which %d are ignored)\n", scalar(@syms),
234 printf "%d symbols in headers are interesting\n",
235 scalar(@syms)- $ignored;
236 printf "%d symbols are listed in symbols-in-versions\n (out of which %d are listed as removed)\n", scalar(keys %doc), scalar(keys %rem);
237 printf "%d symbols in symbols-in-versions should match the ones in headers\n", scalar(keys %doc) - scalar(keys %rem);
241 exit 0; # there are stuff to attend to!