summaryrefslogtreecommitdiff
path: root/source4/heimdal/cf/make-proto.pl
diff options
context:
space:
mode:
Diffstat (limited to 'source4/heimdal/cf/make-proto.pl')
-rw-r--r--source4/heimdal/cf/make-proto.pl211
1 files changed, 168 insertions, 43 deletions
diff --git a/source4/heimdal/cf/make-proto.pl b/source4/heimdal/cf/make-proto.pl
index 07b53f9a8cd..36a040ce6c0 100644
--- a/source4/heimdal/cf/make-proto.pl
+++ b/source4/heimdal/cf/make-proto.pl
@@ -2,17 +2,33 @@
# $Id$
use Getopt::Std;
+use File::Compare;
+
+use JSON;
my $comment = 0;
+my $doxygen = 0;
+my $funcdoc = 0;
my $if_0 = 0;
my $brace = 0;
my $line = "";
my $debug = 0;
my $oproto = 1;
my $private_func_re = "^_";
-my %depfunction = ();
+my %depfunction;
+my %exported;
+my %deprecated;
+my $apple = 0;
+my %documentation;
getopts('x:m:o:p:dqE:R:P:') || die "foo";
+if($opt_a) {
+ $apple = 1;
+}
+
+if($opt_a) {
+ $apple = 1;
+}
if($opt_d) {
$debug = 1;
@@ -51,18 +67,20 @@ if($opt_m) {
}
if($opt_x) {
- open(EXP, $opt_x);
- while(<EXP>) {
- chomp;
- s/\#.*//g;
- s/\s+/ /g;
- if(/^([a-zA-Z0-9_]+)\s?(.*)$/) {
- $exported{$1} = $2;
- } else {
- print $_, "\n";
+ my $EXP;
+ local $/;
+ open(EXP, '<', $opt_x) || die "open ${opt_x}";
+ my $obj = JSON->new->utf8->decode(<EXP>);
+ close $EXP;
+
+ foreach my $x (keys %$obj) {
+ if (defined $obj->{$x}->{"export"}) {
+ $exported{$x} = $obj->{$x};
+ }
+ if (defined $obj->{$x}->{"deprecated"}) {
+ $deprecated{$x} = $obj->{$x}->{"deprecated"};
}
}
- close EXP;
}
while(<>) {
@@ -71,10 +89,19 @@ while(<>) {
# Handle C comments
s@/\*.*\*/@@;
s@//.*/@@;
- if ( s@/\*.*@@) { $comment = 1;
- } elsif ($comment && s@.*\*/@@) { $comment = 0;
+ if ( s@/\*\*(.*)@@) { $comment = 1; $doxygen = 1; $funcdoc = $1;
+ } elsif ( s@/\*.*@@) { $comment = 1;
+ } elsif ($comment && s@.*\*/@@) { $comment = 0; $doxygen = 0;
+ } elsif ($doxygen) { $funcdoc .= $_; next;
} elsif ($comment) { next; }
+ # Handle CPP #define's
+ $define = 1 if /^\s*\#\s*define/;
+ if ($define) {
+ $define = 0 if ! /\\$/;
+ next;
+ }
+
if(/^\#if 0/) {
$if_0 = 1;
}
@@ -116,6 +143,10 @@ while(<>) {
$attr .= " $2";
$_ = "$1 $3";
}
+ if(m/(.*)\s(HEIMDAL_\w+_ATTRIBUTE)\s?(\(.*\))?(.*)/) {
+ $attr .= " $2$3";
+ $_ = "$1 $4";
+ }
# remove outer ()
s/\s*\(/</;
s/\)\s?$/>/;
@@ -164,6 +195,22 @@ while(<>) {
if($attr ne "") {
$_ .= "\n $attr";
}
+ if ($funcdoc) {
+ $documentation{$f} = $funcdoc;
+ }
+ $funcdoc = undef;
+ if ($apple && exists $exported{$f}) {
+ $ios = $exported{$f}{ios};
+ $ios = "NA" if (!defined $ios);
+ $mac = $exported{$f}{macos};
+ $mac = "NA" if (!defined $mac);
+ die "$f neither" if ($mac eq "NA" and $ios eq "NA");
+ $_ = $_ . " __OSX_AVAILABLE_STARTING(__MAC_${mac}, __IPHONE_${ios})";
+ }
+ if (exists $deprecated{$f}) {
+ $_ = $_ . " GSSAPI_DEPRECATED_FUNCTION(\"$deprecated{$f}\")";
+ $depfunction{GSSAPI_DEPRECATED_FUNCTION} = 1;
+ }
$_ = $_ . ";";
$funcs{$f} = $_;
}
@@ -181,6 +228,9 @@ while(<>) {
}
}
+die "reached end of code and still in doxygen comment" if ($doxygen);
+die "reached end of code and still in comment" if ($comment);
+
sub foo {
local ($arg) = @_;
$_ = $arg;
@@ -191,14 +241,14 @@ sub foo {
}
if($opt_o) {
- open(OUT, ">$opt_o");
+ open(OUT, ">${opt_o}.new");
$block = &foo($opt_o);
} else {
$block = "__public_h__";
}
if($opt_p) {
- open(PRIV, ">$opt_p");
+ open(PRIV, ">${opt_p}.new");
$private = &foo($opt_p);
} else {
$private = "__private_h__";
@@ -210,6 +260,7 @@ $private_h = "";
$public_h_header .= "/* This is a generated file */
#ifndef $block
#define $block
+#ifndef DOXY
";
if ($oproto) {
@@ -257,20 +308,32 @@ if($oproto) {
}
$private_h_trailer = "";
+
foreach(sort keys %funcs){
- if(/^(main)$/) { next }
+ if(/^(DllMain|main)$/) { next }
if ($funcs{$_} =~ /\^/) {
$beginblock = "#ifdef __BLOCKS__\n";
$endblock = "#endif /* __BLOCKS__ */\n";
} else {
$beginblock = $endblock = "";
}
- if(!defined($exported{$_}) && /$private_func_re/) {
- $private_h .= $beginblock . $funcs{$_} . "\n" . $endblock . "\n";
+ # if we have an export table and doesn't have content, or matches private RE
+ if((scalar(keys(%exported)) ne 0 && !exists $exported{$_} ) || /$private_func_re/) {
+ $private_h .= $beginblock;
+# if ($apple and not /$private_func_re/) {
+# $private_h .= "#define $_ __ApplePrivate_${_}\n";
+# }
+ $private_h .= $funcs{$_} . "\n" ;
+ $private_h .= $endblock . "\n";
if($funcs{$_} =~ /__attribute__/) {
$private_attribute_seen = 1;
}
} else {
+ if($documentation{$_}) {
+ $public_h .= "/**\n";
+ $public_h .= "$documentation{$_}";
+ $public_h .= " */\n\n";
+ }
if($flags{"function-blocking"}) {
$fupper = uc $_;
if($exported{$_} =~ /proto/) {
@@ -312,12 +375,22 @@ my $depstr = "";
my $undepstr = "";
foreach (keys %depfunction) {
$depstr .= "#ifndef $_
-#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
+#ifndef __has_extension
+#define __has_extension(x) 0
+#define ${_}has_extension 1
+#endif
+#if __has_extension(attribute_deprecated_with_message)
+#define $_(x) __attribute__((__deprecated__(x)))
+#elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
#define $_(X) __attribute__((__deprecated__))
#else
#define $_(X)
#endif
+#ifdef ${_}has_extension
+#undef __has_extension
+#undef ${_}has_extension
#endif
+#endif /* $_ */
";
@@ -349,34 +422,67 @@ extern \"C\" {
}
if ($opt_E) {
$public_h_header .= "#ifndef $opt_E
-#ifndef ${opt_E}_FUNCTION
-#if defined(_WIN32)
-#define ${opt_E}_FUNCTION __declspec(dllimport)
-#define ${opt_E}_CALL __stdcall
-#define ${opt_E}_VARIABLE __declspec(dllimport)
-#else
-#define ${opt_E}_FUNCTION
-#define ${opt_E}_CALL
-#define ${opt_E}_VARIABLE
-#endif
-#endif
+ #ifndef ${opt_E}_FUNCTION
+ #if defined(_WIN32)
+ #define ${opt_E}_FUNCTION __declspec(dllimport)
+ #else
+ #define ${opt_E}_FUNCTION
+ #endif
+ #endif
+ #ifndef ${opt_E}_NORETURN_FUNCTION
+ #if defined(_WIN32)
+ #define ${opt_E}_NORETURN_FUNCTION __declspec(dllimport noreturn)
+ #else
+ #define ${opt_E}_NORETURN_FUNCTION
+ #endif
+ #endif
+ #ifndef ${opt_E}_CALL
+ #if defined(_WIN32)
+ #define ${opt_E}_CALL __stdcall
+ #else
+ #define ${opt_E}_CALL
+ #endif
+ #endif
+ #ifndef ${opt_E}_VARIABLE
+ #if defined(_WIN32)
+ #define ${opt_E}_VARIABLE __declspec(dllimport)
+ #else
+ #define ${opt_E}_VARIABLE
+ #endif
+ #endif
#endif
";
$private_h_header .= "#ifndef $opt_E
-#ifndef ${opt_E}_FUNCTION
-#if defined(_WIN32)
-#define ${opt_E}_FUNCTION __declspec(dllimport)
-#define ${opt_E}_CALL __stdcall
-#define ${opt_E}_VARIABLE __declspec(dllimport)
-#else
-#define ${opt_E}_FUNCTION
-#define ${opt_E}_CALL
-#define ${opt_E}_VARIABLE
-#endif
+ #ifndef ${opt_E}_FUNCTION
+ #if defined(_WIN32)
+ #define ${opt_E}_FUNCTION __declspec(dllimport)
+ #else
+ #define ${opt_E}_FUNCTION
+ #endif
+ #endif
+ #ifndef ${opt_E}_NORETURN_FUNCTION
+ #if defined(_WIN32)
+ #define ${opt_E}_NORETURN_FUNCTION __declspec(dllimport noreturn)
+ #else
+ #define ${opt_E}_NORETURN_FUNCTION
+ #endif
+ #endif
+ #ifndef ${opt_E}_CALL
+ #if defined(_WIN32)
+ #define ${opt_E}_CALL __stdcall
+ #else
+ #define ${opt_E}_CALL
+ #endif
+ #endif
+ #ifndef ${opt_E}_VARIABLE
+ #if defined(_WIN32)
+ #define ${opt_E}_VARIABLE __declspec(dllimport)
+ #else
+ #define ${opt_E}_VARIABLE
+ #endif
+ #endif
#endif
-#endif
-
";
}
@@ -385,7 +491,7 @@ $private_h_trailer .= $undepstr;
if ($public_h ne "" && $flags{"header"}) {
$public_h = $public_h_header . $public_h .
- $public_h_trailer . "#endif /* $block */\n";
+ $public_h_trailer . "#endif /* DOXY */\n#endif /* $block */\n";
}
if ($private_h ne "" && $flags{"header"}) {
$private_h = $private_h_header . $private_h .
@@ -401,3 +507,22 @@ if($opt_p) {
close OUT;
close PRIV;
+
+if ($opt_o) {
+
+ if (compare("${opt_o}.new", ${opt_o}) != 0) {
+ printf("updating ${opt_o}\n");
+ rename("${opt_o}.new", ${opt_o});
+ } else {
+ unlink("${opt_o}.new");
+ }
+}
+
+if ($opt_p) {
+ if (compare("${opt_p}.new", ${opt_p}) != 0) {
+ printf("updating ${opt_p}\n");
+ rename("${opt_p}.new", ${opt_p});
+ } else {
+ unlink("${opt_p}.new");
+ }
+}