~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to win32/update-win32.pl

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
 
3
 
use strict;
4
 
use warnings;
5
 
use XML::Twig;
6
 
use File::Copy;
7
 
use File::Temp 'tempfile';
8
 
 
9
 
 
10
 
#########################################################
11
 
# HACK HERE  HACK HERE  HACK HERE  HACK HERE  HACK HERE # 
12
 
#########################################################
13
 
 
14
 
use constant DEBUG => 0;
15
 
 
16
 
### CLAMAV-CONFIG.H MACROES ###
17
 
# - Set to the proper win32 value or -1 to undef - #
18
 
my %CONF = (
19
 
    'AC_APPLE_UNIVERSAL_BUILD' => -1,
20
 
    'ANONYMOUS_MAP' => -1,
21
 
    'BIND_8_COMPAT' => -1,
22
 
    'BUILD_CLAMD' => '1',
23
 
    'CLAMAVGROUP' => '"clamav"',
24
 
    'CLAMAVUSER' => '"clamav"',
25
 
    'CLAMUKO' => -1,
26
 
    'CL_DEBUG' => -1,
27
 
    'CL_BCUNSIGNED' => -1,
28
 
    'CL_EXPERIMENTAL' => -1,
29
 
    'CL_THREAD_SAFE' => '1',
30
 
    'CONFDIR' => '"C:\\\\ClamAV"',
31
 
    'CURSES_INCLUDE' => -1,
32
 
    'C_AIX' => -1,
33
 
    'C_BEOS' => -1,
34
 
    'C_BIGSTACK' => -1,
35
 
    'C_BSD' => -1,
36
 
    'C_DARWIN' => -1,
37
 
    'C_GNU_HURD' => -1,
38
 
    'C_HPUX' => -1,
39
 
    'C_INTERIX' => -1,
40
 
    'C_IRIX' => -1,
41
 
    'C_KFREEBSD_GNU' => -1,
42
 
    'C_LINUX' => -1,
43
 
    'C_OS2' => -1,
44
 
    'C_OSF' => -1,
45
 
    'C_QNX6' => -1,
46
 
    'C_SOLARIS' => -1,
47
 
    'DATADIR' => '"C:\\\\ClamAV\\\\db"',
48
 
    'DEFAULT_FD_SETSIZE' => '1024',
49
 
    'FDPASS_NEED_XOPEN' => -1,
50
 
    'FILEBUFF' => '8192',
51
 
    'FPU_WORDS_BIGENDIAN' => '0',
52
 
    'FRESHCLAM_DNS_FIX' => -1,
53
 
    'FRESHCLAM_NO_CACHE' => -1,
54
 
    'HAVE_ARGZ_ADD' => -1,
55
 
    'HAVE_ARGZ_APPEND' => -1,
56
 
    'HAVE_ARGZ_COUNT' => -1,
57
 
    'HAVE_ARGZ_CREATE_SEP' => -1,
58
 
    'HAVE_ARGZ_H' => -1,
59
 
    'HAVE_ARGZ_INSERT' => -1,
60
 
    'HAVE_ARGZ_NEXT' => -1,
61
 
    'HAVE_ARGZ_STRINGIFY' => -1,
62
 
    'HAVE_ATTRIB_ALIGNED' => -1,
63
 
    'HAVE_ATTRIB_PACKED' => -1,
64
 
    'HAVE_BZLIB_H' => '1',
65
 
    'HAVE_CLOSEDIR' => '1',
66
 
    'HAVE_CTIME_R' => '1',
67
 
    'HAVE_CTIME_R_2' => '1',
68
 
    'HAVE_CTIME_R_3' => -1,
69
 
    'HAVE_DECL_CYGWIN_CONV_PATH' => -1,
70
 
    'HAVE_DIRENT_H' => '1',
71
 
    'HAVE_DLD' => -1,
72
 
    'HAVE_DLD_H' => -1,
73
 
    'HAVE_DLERROR' => -1,
74
 
    'HAVE_DLFCN_H' => '1',
75
 
    'HAVE_DL_H' => -1,
76
 
    'HAVE_DYLD' => -1,
77
 
    'HAVE_ERROR_T' => -1,
78
 
    'HAVE_FD_PASSING' => -1,
79
 
    'HAVE_FSEEKO' => '1',
80
 
    'HAVE_GETADDRINFO' => '1',
81
 
    'HAVE_GETPAGESIZE' => '1',
82
 
    'HAVE_GRP_H' => -1,
83
 
    'HAVE_ICONV' => -1,
84
 
    'HAVE_INET_NTOP' => '1',
85
 
    'HAVE_INITGROUPS' => -1,
86
 
    'HAVE_INTTYPES_H' => -1,
87
 
    'HAVE_IN_ADDR_T' => -1,
88
 
    'HAVE_IN_PORT_T' => '1',
89
 
    'HAVE_LIBCHECK' => -1,
90
 
    'HAVE_LIBDL' => '1',
91
 
    'HAVE_LIBDLLOADER' => '1',
92
 
    'HAVE_LIBMILTER_MFAPI_H' => -1,
93
 
    'HAVE_LIBNCURSES' => -1,
94
 
    'HAVE_LIBPDCURSES' => -1,
95
 
    'HAVE_LIBZ' => '1',
96
 
    'HAVE_LIMITS_H' => '1',
97
 
    'HAVE_LTDL' => '1',
98
 
    'HAVE_MACH_O_DYLD_H' => -1,
99
 
    'HAVE_MADVISE' => -1,
100
 
    'HAVE_MALLINFO' => -1,
101
 
    'HAVE_MALLOC_H' => '1',
102
 
    'HAVE_MEMCPY' => '1',
103
 
    'HAVE_MEMORY_H' => '1',
104
 
    'HAVE_MKSTEMP' => '1',
105
 
    'HAVE_MMAP' => -1,
106
 
    'HAVE_NDIR_H' => -1,
107
 
    'HAVE_OPENDIR' => '1',
108
 
    'HAVE_POLL' => '1',
109
 
    'HAVE_POLL_H' => -1,
110
 
    'HAVE_PRAGMA_PACK' => '1',
111
 
    'HAVE_PRAGMA_PACK_HPPA' => -1,
112
 
    'HAVE_PRELOADED_SYMBOLS' => -1,
113
 
    'HAVE_PTHREAD_YIELD' => '1',
114
 
    'HAVE_PWD_H' => -1,
115
 
    'HAVE_READDIR' => '1',
116
 
    'HAVE_READDIR_R_2' => -1,
117
 
    'HAVE_READDIR_R_3' => -1,
118
 
    'HAVE_RECVMSG' => '1',
119
 
    'HAVE_RESOLV_H' => '1',
120
 
    'HAVE_SAR' => '1',
121
 
    'HAVE_SCHED_YIELD' => -1,
122
 
    'HAVE_SENDMSG' => '1',
123
 
    'HAVE_SETGROUPS' => -1,
124
 
    'HAVE_SETSID' => '1',
125
 
    'HAVE_SHL_LOAD' => -1,
126
 
    'HAVE_SNPRINTF' => '1',
127
 
    'HAVE_STDBOOL_H' => -1,
128
 
    'HAVE_STDINT_H' => -1,
129
 
    'HAVE_STDLIB_H' => '1',
130
 
    'HAVE_STRCASESTR' => -1,
131
 
    'HAVE_STRERROR_R' => '1',
132
 
    'HAVE_STRINGS_H' => -1,
133
 
    'HAVE_STRING_H' => '1',
134
 
    'HAVE_STRLCAT' => -1,
135
 
    'HAVE_STRLCPY' => -1,
136
 
    'HAVE_SYSCONF_SC_PAGESIZE' => -1,
137
 
    'HAVE_SYSTEM_TOMMATH' => -1,
138
 
    'HAVE_SYS_DL_H' => -1,
139
 
    'HAVE_SYS_FILIO_H' => -1,
140
 
    'HAVE_SYS_INTTYPES_H' => -1,
141
 
    'HAVE_SYS_INT_TYPES_H' => -1,
142
 
    'HAVE_SYS_MMAN_H' => -1,
143
 
    'HAVE_SYS_PARAM_H' => -1,
144
 
    'HAVE_SYS_SELECT_H' => -1,
145
 
    'HAVE_SYS_STAT_H' => '1',
146
 
    'HAVE_SYS_TYPES_H' => '1',
147
 
    'HAVE_SYS_UIO_H' => -1,
148
 
    'HAVE_TERMIOS_H' => -1,
149
 
    'HAVE_UNISTD_H' => -1,
150
 
    'HAVE_VSNPRINTF' => '1',
151
 
    'HAVE_WORKING_ARGZ' => -1,
152
 
    'LIBCLAMAV_FULLVER' => '"6.0.4"',
153
 
    'LIBCLAMAV_MAJORVER' => '6',
154
 
    'LTDL_DLOPEN_DEPLIBS' => -1,
155
 
    'LT_DLSEARCH_PATH' => '""',
156
 
    'LT_LIBEXT' => '"dll"',
157
 
    'LT_MODULE_EXT' => '".dll"',
158
 
    'LT_MODULE_PATH_VAR' => '"LD_LIBRARY_PATH"',
159
 
    'LT_OBJDIR' => '""',
160
 
    'NDEBUG' => '1',
161
 
    'NEED_USCORE' => -1,
162
 
    'NOBZ2PREFIX' => -1,
163
 
    'NO_FD_SET' => -1,
164
 
    'PACKAGE' => 'PACKAGE_NAME',
165
 
    'PACKAGE_BUGREPORT' => '"http://bugs.clamav.net/"',
166
 
    'PACKAGE_NAME' => '"ClamAV"',
167
 
    'PACKAGE_STRING' => '"ClamAV devel"',
168
 
    'PACKAGE_TARNAME' => '"clamav"',
169
 
    'PACKAGE_URL' => '"http://www.clamav.net/"',
170
 
    'PACKAGE_VERSION' => '"devel"',
171
 
    'SCANBUFF' => '131072',
172
 
    'SETPGRP_VOID' => '1',
173
 
    'SIZEOF_INT' => '4',
174
 
    'SIZEOF_LONG' => '4',
175
 
    'SIZEOF_LONG_LONG' => '8',
176
 
    'SIZEOF_SHORT' => '2',
177
 
    'SIZEOF_VOID_P' => -1,
178
 
    'STDC_HEADERS' => '1',
179
 
    'SUPPORT_IPv6' => -1,
180
 
    'USE_MPOOL' => 1,
181
 
    'USE_SYSLOG' => -1,
182
 
    'VERSION_SUFFIX' => '""',
183
 
    'WORDS_BIGENDIAN' => '0',
184
 
    '_LARGEFILE_SOURCE' => -1,
185
 
    '_POSIX_PII_SOCKET' => -1,
186
 
    '_REENTRANT' => '1',
187
 
    '_THREAD_SAFE' => -1,
188
 
    '__error_t_defined' => -1,
189
 
    'const' => -1,
190
 
    'error_t' => -1,
191
 
    'inline' => '_inline',
192
 
    'off_t' => -1,
193
 
    'restrict' => -1,
194
 
    'socklen_t' => -1,
195
 
    'HAVE_UNAME_SYSCALL' => -1,
196
 
    'HAVE__INTERNAL__SHA_COLLECT' => -1
197
 
    );
198
 
 
199
 
 
200
 
### PROJECT FILES ###
201
 
# - makefile: path to Makefile.am from the root of the repo
202
 
# - sections: section of Makefile.am to parse (without _SOURCES or _la_SOURCES)
203
 
# - output: path to the output vcxproj file
204
 
# - makefile_only: *optional* regex to allow exclusion of certain files from the vcxproj (use double escapes)
205
 
# - vcxproj_only: *optional* regex to allow inclusion of certain files into the vcxproj (use double escapes)
206
 
 
207
 
my @PROJECTS = (
208
 
    # LIBCLAMAV #
209
 
    {makefile => 'libclamav', sections => ['libclamav', 'libclamav_internal_utils'], output => 'win32/libclamav.vcxproj', vcxproj_only => '(3rdparty\\\\|compat\\\\|getopt\\.c|misc\\.c)'},
210
 
 
211
 
    # LIBCLAMUNRAR_IFACE #
212
 
    {makefile => 'libclamav', sections => ['libclamunrar_iface'], output => 'win32/libclamunrar_iface.vcxproj', vcxproj_only => 'compat\\\\'},
213
 
 
214
 
    # LIBCLAMUNRAR #
215
 
    {makefile => 'libclamav', sections => ['libclamunrar'], output => 'win32/libclamunrar.vcxproj'},
216
 
 
217
 
    # LIBCLAMAVCXX #
218
 
    {makefile => 'libclamav/c++', sections => ['libclamavcxx'], output => 'win32/libclamavcxx.vcxproj'},
219
 
 
220
 
    # CLAMSCAN #
221
 
    {makefile => 'clamscan', sections => ['clamscan'], output => 'win32/clamscan.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
222
 
 
223
 
    # CLAMDSCAN #
224
 
    {makefile => 'clamdscan', sections => ['clamdscan'], output => 'win32/clamdscan.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
225
 
 
226
 
    # CLAMD #
227
 
    {makefile => 'clamd', sections => ['clamd'], output => 'win32/clamd.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c|(daz|clam)uko.*)$'},
228
 
 
229
 
    # FRESHCLAM #
230
 
    {makefile => 'freshclam', sections => ['freshclam'], output => 'win32/freshclam.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcxproj_only => 'compat\\\\'},
231
 
 
232
 
    # CLAMCONF #
233
 
    {makefile => 'clamconf', sections => ['clamconf'], output => 'win32/clamconf.vcxproj', makefile_only => '(optparser\\.c$|getopt\\.c)$'},
234
 
 
235
 
    # CLAMBC #
236
 
    {makefile => 'clambc', sections => ['clambc'], output => 'win32/clambc.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
237
 
 
238
 
    # LLVMsystem #
239
 
    {makefile => 'libclamav/c++', sections => ['libllvmsystem'], output => 'win32/LLVMsystem.vcxproj'},
240
 
 
241
 
    # LLVMcodgen #
242
 
    {makefile => 'libclamav/c++', sections => ['libllvmcodegen'], output => 'win32/LLVMcodegen.vcxproj'},
243
 
 
244
 
    # LLVMx86codgen #
245
 
    {makefile => 'libclamav/c++', sections => ['libllvmx86codegen'], output => 'win32/LLVMx86codegen.vcxproj'},
246
 
 
247
 
    # LLVMjit #
248
 
    {makefile => 'libclamav/c++', sections => ['libllvmjit'], output => 'win32/LLVMjit.vcxproj'},
249
 
 
250
 
    # sigtool #
251
 
    {makefile => 'sigtool', sections => ['sigtool'], output => 'win32/sigtool.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
252
 
 
253
 
    );
254
 
 
255
 
###########################################################
256
 
# STOP HACKING HERE  STOP HACKING HERE  STOP HACKING HERE # 
257
 
###########################################################
258
 
 
259
 
 
260
 
 
261
 
 
262
 
my %ref_files;
263
 
my %files;
264
 
my $exclude;
265
 
my $do_patch = 0;
266
 
 
267
 
sub file {
268
 
    my ($twig, $file) = @_;
269
 
    my $fname = $file->{'att'}->{'Include'};
270
 
    return unless $fname =~ /^.*\.c(pp)?$/;
271
 
    return if defined($exclude) && $fname =~ /$exclude/;
272
 
    $file->delete unless !$do_patch || exists $ref_files{$fname};
273
 
    $files{$fname} = 1;
274
 
}
275
 
 
276
 
$do_patch = $#ARGV == 0 && $ARGV[0] eq '--regen';
277
 
die("Usage:\nupdate-win32.pl [--regen]\n\nChecks the win32 build system and regenerates it if --regen is given\n\n") if $#ARGV == 0 && $ARGV[0] eq '--help';
278
 
my $BASE_DIR = `git rev-parse --git-dir`;
279
 
chomp($BASE_DIR);
280
 
die "This script only works in a GIT repository\n" unless $BASE_DIR;
281
 
$BASE_DIR = "$BASE_DIR/..";
282
 
my $VER = `git describe --always`;
283
 
chomp($VER);
284
 
die "Cannot determine git version via git-describe\n" unless $VER && !$?;
285
 
$VER = "devel-$VER";
286
 
my $w = 0;
287
 
 
288
 
print "Processing clamav-config.h...\n";
289
 
 
290
 
open IN, "< $BASE_DIR/clamav-config.h.in" || die "Cannot find clamav-config.h.in: $!\n";
291
 
$do_patch and open OUT, "> $BASE_DIR/win32/clamav-config.h" || die "Cannot open clamav-config.h: $!\n";
292
 
$do_patch and  print OUT "/* clamav-config.h.  Generated from clamav-config.h.in by update-win32.  */\n\n";
293
 
while(<IN>) {
294
 
    if(!/^#\s*undef (.*)/) {
295
 
        $do_patch and print OUT $_;
296
 
        next;
297
 
    }
298
 
    if($1 eq 'VERSION') {
299
 
        $do_patch and print OUT "#define VERSION \"$VER\"\n";
300
 
        next;
301
 
    }
302
 
    if(!exists($CONF{$1})) {
303
 
        warn "Warning: clamav-config.h option '$1' is unknown. Please take a second to update this script.\n";
304
 
        $do_patch and print OUT "/* #undef $1 */\n";
305
 
        $w++;
306
 
        next;
307
 
    }
308
 
    if($CONF{$1} eq -1) {
309
 
        $do_patch and print OUT "/* #undef $1 */\n";
310
 
    } else {
311
 
        $do_patch and print OUT "#define $1 $CONF{$1}\n";
312
 
    }
313
 
}
314
 
close IN;
315
 
if($do_patch) {
316
 
    close OUT;
317
 
    print "clamav-config.h generated ($w warnings)\n";
318
 
} else {
319
 
    print "clamav-config.h.in parsed ($w warnings)\n";
320
 
}
321
 
foreach (@PROJECTS) {
322
 
    my %proj = %$_;
323
 
    %files = ();
324
 
    %ref_files = ();
325
 
    my $got = 0;
326
 
    $exclude = $proj{'vcxproj_only'};
327
 
    print "Parsing $proj{'output'}...\n";
328
 
    open IN, "$proj{'makefile'}/Makefile.am" or die "Cannot open $proj{'makefile'}/Makefile.am\n";
329
 
    while(<IN>) {
330
 
        my ($trail, $fname);
331
 
        if($got == 0) {
332
 
            next unless /^(.*?)(?:_la)?_SOURCES\s*\+?=\s*(.*?)\s*(\\)?\s*$/;
333
 
            next unless grep {$_ eq $1} (@{$proj{'sections'}});
334
 
            $got = 1;
335
 
            $trail = $3;
336
 
            $fname = $2;
337
 
        } else {
338
 
            /^\s*(.*?)(\s*\\)?$/;
339
 
            $trail = $2;
340
 
            $fname = $1;
341
 
        }
342
 
        if($fname =~ /\.c(pp)?$/) {
343
 
            if($fname =~ s/^(\$\(top_srcdir\)|\.\.)\///) {
344
 
                $fname = "../$fname";
345
 
            } else {
346
 
                $fname = "../$proj{'makefile'}/$fname";
347
 
            }
348
 
            $fname =~ y/\//\\/;
349
 
            $ref_files{$fname} = 1 unless defined($proj{'makefile_only'}) && $fname =~ /$proj{'makefile_only'}/;
350
 
        }
351
 
        $got = 0 unless $trail;
352
 
    }
353
 
    close IN;
354
 
 
355
 
    my $xml = XML::Twig->new( keep_encoding => 1, twig_handlers => { 'ItemGroup/ClCompile' => \&file }, pretty_print => 'record' );
356
 
    $xml->parsefile("$BASE_DIR/$proj{'output'}");
357
 
 
358
 
    my @missing_in_vcxproj = grep ! exists $files{$_}, keys %ref_files;
359
 
    my @missing_in_makefile = grep ! exists $ref_files{$_}, keys %files;
360
 
 
361
 
    if($do_patch) {
362
 
        if($#missing_in_vcxproj >=0) {
363
 
            my $group = $xml->root;
364
 
            while($group = $group->next_elt('ItemGroup')) {
365
 
                last if $group->has_child('ClCompile');
366
 
            }
367
 
            if(!defined($group)) {
368
 
                $group = $xml->root('ItemGroup');
369
 
                $group->paste($xml->root);
370
 
            }
371
 
            foreach (@missing_in_vcxproj) {
372
 
                my $addfile = $xml->root->new('ClCompile');
373
 
                $addfile->set_att('Include' => $_);
374
 
                $addfile->paste($group);
375
 
                warn "Warning: File $_ not in $proj{'output'}: added!\n" foreach @missing_in_vcxproj;
376
 
            }
377
 
        }
378
 
        warn "Warning: File $_ not in $proj{'makefile'}/Makefile.am: deleted!\n" foreach @missing_in_makefile;
379
 
        my ($fh, $filename) = tempfile();
380
 
        $xml->print($fh);
381
 
        close $fh;
382
 
        move($filename, "$proj{'output'}");
383
 
        print "Regenerated $proj{'output'} (".($#missing_in_vcxproj + $#missing_in_makefile + 2)." changes)\n";
384
 
    } else {
385
 
        warn "Warning: File $_ not in $proj{'output'}\n" foreach @missing_in_vcxproj;
386
 
        warn "Warning: File $_ not in $proj{'makefile'}/Makefile.am\n" foreach @missing_in_makefile;
387
 
        print "Parsed $proj{'output'} (".($#missing_in_vcxproj + $#missing_in_makefile + 2)." warnings)\n";
388
 
    }
389
 
}