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