nativeapi.pm 5.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Copyright 1999, 2000, 2001 Patrik Stridvall
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18
#

19 20 21 22
package nativeapi;

use strict;

23 24 25 26 27 28 29 30 31
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;

@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw($nativeapi);

use vars qw($nativeapi);

32
use config qw(file_type $current_dir $wine_dir $winapi_dir);
33 34 35 36 37
use options qw($options);
use output qw($output);

$nativeapi = 'nativeapi'->new;

38
sub new($) {
39 40 41 42 43 44
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = {};
    bless ($self, $class);

    my $functions = \%{$self->{FUNCTIONS}};
45 46
    my $conditionals = \%{$self->{CONDITIONALS}};
    my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
47
    my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
48

49
    my $api_file = "$winapi_dir/nativeapi.dat";
Patrik Stridvall's avatar
Patrik Stridvall committed
50
    my $configure_ac_file = "$wine_dir/configure.ac";
51
    my $config_h_in_file = "$wine_dir/include/config.h.in";
52

53
    $api_file =~ s/^\.\///;
Patrik Stridvall's avatar
Patrik Stridvall committed
54
    $configure_ac_file =~ s/^\.\///;
55 56
    $config_h_in_file =~ s/^\.\///;

Patrik Stridvall's avatar
Patrik Stridvall committed
57 58 59

    $$conditional_headers{"config.h"}++;

60
    $output->progress("$api_file");
61

62
    open(IN, "< $api_file") || die "Error: Can't open $api_file: $!\n";
Patrik Stridvall's avatar
Patrik Stridvall committed
63
    local $/ = "\n";
64
    while(<IN>) {
65 66
	s/^\s*(.*?)\s*$/$1/; # remove whitespace at begin and end of line
	s/^(.*?)\s*#.*$/$1/; # remove comments
67
	/^$/ && next;        # skip empty lines
68

69 70 71 72
	$$functions{$_}++;
    }
    close(IN);

Patrik Stridvall's avatar
Patrik Stridvall committed
73
    $output->progress("$configure_ac_file");
74

75
    my $again = 0;
76
    open(IN, "< $configure_ac_file") || die "Error: Can't open $configure_ac_file: $!\n";
77 78 79 80
    local $/ = "\n";
    while($again || (defined($_ = <IN>))) {
	$again = 0;
	chomp;
81 82 83 84 85 86 87 88 89 90 91 92
	if(/^(.*?)\\$/) {
	    my $current = $1;
	    my $next = <IN>;
	    if(defined($next)) {
		# remove trailing whitespace
		$current =~ s/\s+$//;

		# remove leading whitespace
		$next =~ s/^\s+//;

		$_ = $current . " " . $next;

93 94 95 96
		$again = 1;
		next;
	    }
	}
97

98 99 100
	# remove leading and trailing whitespace
	s/^\s*(.*?)\s*$/$1/;

101 102 103 104 105 106
	# skip emty lines
	if(/^$/) { next; }

	# skip comments
	if(/^dnl/) { next; }

Patrik Stridvall's avatar
Patrik Stridvall committed
107 108 109 110
	if(/AC_CHECK_HEADERS\(\s*([^,\)]*)(?:,|\))?/) {
	    my $headers = $1;
	    $headers =~ s/^\s*\[\s*(.*?)\s*\]\s*$/$1/;
	    foreach my $name (split(/\s+/, $headers)) {
111 112
		$$conditional_headers{$name}++;
	    }
113 114 115 116 117 118 119 120
	} elsif(/AC_HEADER_STAT\(\)/) {
            # This checks for a bunch of standard headers
            # There's stdlib.h, string.h and sys/types.h too but we don't
            # want to force ifdefs for those at this point.
	    foreach my $name ("sys/stat.h", "memory.h", "strings.h",
                              "inttypes.h", "stdint.h", "unistd.h") {
		$$conditional_headers{$name}++;
	    }
Patrik Stridvall's avatar
Patrik Stridvall committed
121 122 123 124
	} elsif(/AC_CHECK_FUNCS\(\s*([^,\)]*)(?:,|\))?/) {
	    my $funcs = $1;
	    $funcs =~ s/^\s*\[\s*(.*?)\s*\]\s*$/$1/;
	    foreach my $name (split(/\s+/, $funcs)) {
125
		$$conditional_functions{$name}++;
126
	    }
Patrik Stridvall's avatar
Patrik Stridvall committed
127
	} elsif(/AC_FUNC_ALLOCA/) {
128
	    $$conditional_headers{"alloca.h"}++;
Patrik Stridvall's avatar
Patrik Stridvall committed
129 130 131 132 133 134 135 136
        } elsif (/AC_DEFINE\(\s*HAVE_(.*?)_H/) {
	    my $name = lc($1);
	    $name =~ s/_/\//;
	    $name .= ".h";

	    next if $name =~ m%correct/%;

	    $$conditional_headers{$name}++;
137 138 139 140 141
	}

    }
    close(IN);

142
    $output->progress("$config_h_in_file");
143

144
    open(IN, "< $config_h_in_file") || die "Error: Can't open $config_h_in_file: $!\n";
145 146
    local $/ = "\n";
    while(<IN>) {
147 148 149 150 151 152 153
	# remove leading and trailing whitespace
	s/^\s*(.*?)\s*$/$1/;

	# skip emty lines
	if(/^$/) { next; }

	if(/^\#undef\s+(\S+)$/) {
154 155
	    $$conditionals{$1}++;
	}
156 157 158
    }
    close(IN);

159 160
    $nativeapi = $self;

161 162 163
    return $self;
}

164
sub is_function($$) {
165 166 167 168 169
    my $self = shift;
    my $functions = \%{$self->{FUNCTIONS}};

    my $name = shift;

170
    return ($$functions{$name} || 0);
171 172
}

173
sub is_conditional($$) {
174 175 176 177 178
    my $self = shift;
    my $conditionals = \%{$self->{CONDITIONALS}};

    my $name = shift;

179
    return ($$conditionals{$name} || 0);
180 181
}

182
sub found_conditional($$) {
183 184 185 186 187 188 189 190
    my $self = shift;
    my $conditional_found = \%{$self->{CONDITIONAL_FOUND}};

    my $name = shift;

    $$conditional_found{$name}++;
}

191
sub is_conditional_header($$) {
192 193 194 195 196
    my $self = shift;
    my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};

    my $name = shift;

197
    return ($$conditional_headers{$name} || 0);
198 199
}

200
sub is_conditional_function($$) {
201 202 203 204 205
    my $self = shift;
    my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};

    my $name = shift;

206
    return ($$conditional_functions{$name} || 0);
207 208
}

209
sub global_report($) {
210 211 212 213 214 215 216 217
    my $self = shift;

    my $output = \${$self->{OUTPUT}};
    my $conditional_found = \%{$self->{CONDITIONAL_FOUND}};
    my $conditionals = \%{$self->{CONDITIONALS}};

    my @messages;
    foreach my $name (sort(keys(%$conditionals))) {
218
	if($name =~ /^(?:const|inline|size_t)$/) { next; }
219 220 221 222 223 224 225

	if(0 && !$$conditional_found{$name}) {
	    push @messages, "config.h.in: conditional $name not used\n";
	}
    }

    foreach my $message (sort(@messages)) {
226
	$output->write($message);
227 228 229
    }
}

230
1;