forked from nih-at/libzip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-cmake-config.h.in.pl
executable file
·77 lines (59 loc) · 1.36 KB
/
create-cmake-config.h.in.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env perl
# Haiku OS: we don't care!
use strict;
my $in = 'cmake-config.h.in';
my $out = "$in.$$";
my ($fin, $fout);
open $fin, "< $in" or die "can't open $in: $!";
open $fout, "> $out" or die "can't create $out: $!";
my $zipconf_defines = read_zipconf_defines();
my $in_defines = 0;
while (my $line = <$fin>) {
if ($in_defines) {
if ($line =~ m,/* END DEFINES,) {
$in_defines = 0;
}
else {
next;
}
}
print $fout $line;
if ($line =~ m,/\* BEGIN DEFINES,) {
$in_defines = 1;
add_defines($fout, $zipconf_defines);
}
}
close $fin;
close $fout;
rename($out, $in);
sub add_defines {
my ($fout, $zipconf_defines) = @_;
my $fin;
open $fin, "< CMakeLists.txt" or die "can't open CMakeLists.txt: $!";
while (my $line = <$fin>) {
my ($key, $value);
if ($line =~ m/CHECK_TYPE_SIZE\(.* (\S*)\)/) {
$key = $1;
$value = "\${$1}";
}
elsif ($line =~ m/CHECK_\S*\(.* (\S*)\)/) {
$key = $1;
}
if (defined($key) && !defined($zipconf_defines->{$key})) {
print $fout "#cmakedefine $key" . ($value ? " $value" : "") . "\n";
}
}
close $fin;
}
sub read_zipconf_defines {
my %zipconf_defines = ();
my $fin;
open $fin, "< cmake-zipconf.h.in" or die "can't open cmake-zipconf.h.in: $!";
while (my $line = <$fin>) {
if ($line =~ m/#cmakedefine\s+(\S+)/) {
$zipconf_defines{$1} = 1;
}
}
close $fin;
return \%zipconf_defines;
}