summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/build-scripts/fnsince.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/build-scripts/fnsince.pl')
-rwxr-xr-xsrc/contrib/SDL-3.2.20/build-scripts/fnsince.pl169
1 files changed, 169 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/build-scripts/fnsince.pl b/src/contrib/SDL-3.2.20/build-scripts/fnsince.pl
new file mode 100755
index 0000000..9d987fc
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/build-scripts/fnsince.pl
@@ -0,0 +1,169 @@
1#!/usr/bin/perl -w
2
3use warnings;
4use strict;
5use File::Basename;
6use Cwd qw(abs_path);
7
8my $wikipath = undef;
9foreach (@ARGV) {
10 $wikipath = abs_path($_), next if not defined $wikipath;
11}
12
13chdir(dirname(__FILE__));
14chdir('..');
15
16my %fulltags = ();
17my @unsorted_releases = ();
18open(PIPEFH, '-|', 'git tag -l') or die "Failed to read git release tags: $!\n";
19
20while (<PIPEFH>) {
21 chomp;
22 my $fulltag = $_;
23 if ($fulltag =~ /\A(prerelease|preview|release)\-(\d+)\.(\d+)\.(\d+)\Z/) {
24 # Ignore anything that isn't a x.y.0 release.
25 # Make sure new APIs are assigned to the next minor version and ignore the patch versions, but we'll make an except for the prereleases.
26 my $release_type = $1;
27 my $major = int($2);
28 my $minor = int($3);
29 my $patch = int($4);
30 next if ($major != 3); # Ignore anything that isn't an SDL3 release.
31 next if ($patch != 0) && ($minor >= 2); # Ignore anything that is a patch release (unless it was between the preview release and the official release).
32
33 # Consider this release version.
34 my $ver = "${major}.${minor}.${patch}";
35 push @unsorted_releases, $ver;
36 $fulltags{$ver} = $fulltag;
37 }
38}
39close(PIPEFH);
40
41#print("\n\nUNSORTED\n");
42#foreach (@unsorted_releases) {
43# print "$_\n";
44#}
45
46my @releases = sort {
47 my @asplit = split /\./, $a;
48 my @bsplit = split /\./, $b;
49 my $rc;
50 for (my $i = 0; $i < scalar(@asplit); $i++) {
51 return 1 if (scalar(@bsplit) <= $i); # a is "2.0.1" and b is "2.0", or whatever.
52 my $aseg = $asplit[$i];
53 my $bseg = $bsplit[$i];
54 $rc = int($aseg) <=> int($bseg);
55 return $rc if ($rc != 0); # found the difference.
56 }
57 return 0; # still here? They matched completely?!
58} @unsorted_releases;
59
60my $current_release = $releases[-1];
61my $next_release;
62
63if (scalar(@releases) > 0) {
64 # this happens to work for how SDL versions things at the moment.
65 $current_release = $releases[-1];
66
67 my @current_release_segments = split /\./, $current_release;
68 # if we're still in the 3.1.x prereleases, call the "next release" 3.2.0 even if we do more prereleases.
69 if (($current_release_segments[0] == '3') && ($current_release_segments[1] == '1')) {
70 $next_release = '3.2.0';
71 } else {
72 @current_release_segments[1] = '' . (int($current_release_segments[1]) + 2);
73 $next_release = join('.', @current_release_segments);
74 }
75}
76
77#print("\n\nSORTED\n");
78#foreach (@releases) {
79# print "$_\n";
80#}
81#print("\nCURRENT RELEASE: $current_release\n");
82#print("NEXT RELEASE: $next_release\n\n");
83
84push @releases, 'HEAD';
85$fulltags{'HEAD'} = 'HEAD';
86
87my %funcs = ();
88foreach my $release (@releases) {
89 #print("Checking $release...\n");
90 my $tag = $fulltags{$release};
91 my $blobname = "$tag:src/dynapi/SDL_dynapi_overrides.h";
92
93 if ($release =~ /\A3\.[01]\.\d+\Z/) { # make everything up to the first SDL3 official release look like 3.2.0.
94 $release = '3.2.0';
95 }
96
97 open(PIPEFH, '-|', "git show '$blobname'") or die "Failed to read git blob '$blobname': $!\n";
98 while (<PIPEFH>) {
99 chomp;
100 if (/\A\#define\s+(SDL_.*?)\s+SDL_.*?_REAL\Z/) {
101 my $fn = $1;
102 $funcs{$fn} = $release if not defined $funcs{$fn};
103 }
104 }
105 close(PIPEFH);
106}
107
108if (not defined $wikipath) {
109 foreach my $release (@releases) {
110 foreach my $fn (sort keys %funcs) {
111 print("$fn: $funcs{$fn}\n") if $funcs{$fn} eq $release;
112 }
113 }
114} else {
115 if (defined $wikipath) {
116 chdir($wikipath);
117 foreach my $fn (keys %funcs) {
118 next if $fn eq 'SDL_ThreadID'; # this was a function early on (it's now called SDL_GetThreadID), but now it's a datatype (which originally had a different capitalization).
119 my $revision = $funcs{$fn};
120 $revision = $next_release if $revision eq 'HEAD';
121 my $fname = "$fn.md";
122 if ( ! -f $fname ) {
123 #print STDERR "No such file: $fname\n";
124 next;
125 }
126
127 my @lines = ();
128 open(FH, '<', $fname) or die("Can't open $fname for read: $!\n");
129 my $added = 0;
130 while (<FH>) {
131 chomp;
132 if ((/\A\-\-\-\-/) && (!$added)) {
133 push @lines, "## Version";
134 push @lines, "";
135 push @lines, "This function is available since SDL $revision.";
136 push @lines, "";
137 $added = 1;
138 }
139 push @lines, $_;
140 next if not /\A\#\#\s+Version/;
141 $added = 1;
142 push @lines, "";
143 push @lines, "This function is available since SDL $revision.";
144 push @lines, "";
145 while (<FH>) {
146 chomp;
147 next if not (/\A\#\#\s+/ || /\A\-\-\-\-/);
148 push @lines, $_;
149 last;
150 }
151 }
152 close(FH);
153
154 if (!$added) {
155 push @lines, "## Version";
156 push @lines, "";
157 push @lines, "This function is available since SDL $revision.";
158 push @lines, "";
159 }
160
161 open(FH, '>', $fname) or die("Can't open $fname for write: $!\n");
162 foreach (@lines) {
163 print FH "$_\n";
164 }
165 close(FH);
166 }
167 }
168}
169