7
use File::Temp 'tempfile';
10
#########################################################
11
# HACK HERE HACK HERE HACK HERE HACK HERE HACK HERE #
12
#########################################################
14
use constant DEBUG => 0;
16
### CLAMAV-CONFIG.H MACROES ###
17
# - Set to the proper win32 value or -1 to undef - #
19
'AC_APPLE_UNIVERSAL_BUILD' => -1,
20
'ANONYMOUS_MAP' => -1,
21
'BIND_8_COMPAT' => -1,
23
'CLAMAVGROUP' => '"clamav"',
24
'CLAMAVUSER' => '"clamav"',
27
'CL_BCUNSIGNED' => -1,
28
'CL_EXPERIMENTAL' => -1,
29
'CL_THREAD_SAFE' => '1',
30
'CONFDIR' => '"C:\\\\ClamAV"',
31
'CURSES_INCLUDE' => -1,
41
'C_KFREEBSD_GNU' => -1,
47
'DATADIR' => '"C:\\\\ClamAV\\\\db"',
48
'DEFAULT_FD_SETSIZE' => '1024',
49
'FDPASS_NEED_XOPEN' => -1,
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,
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',
74
'HAVE_DLFCN_H' => '1',
78
'HAVE_FD_PASSING' => -1,
80
'HAVE_GETADDRINFO' => '1',
81
'HAVE_GETPAGESIZE' => '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,
91
'HAVE_LIBDLLOADER' => '1',
92
'HAVE_LIBMILTER_MFAPI_H' => -1,
93
'HAVE_LIBNCURSES' => -1,
94
'HAVE_LIBPDCURSES' => -1,
96
'HAVE_LIMITS_H' => '1',
98
'HAVE_MACH_O_DYLD_H' => -1,
100
'HAVE_MALLINFO' => -1,
101
'HAVE_MALLOC_H' => '1',
102
'HAVE_MEMCPY' => '1',
103
'HAVE_MEMORY_H' => '1',
104
'HAVE_MKSTEMP' => '1',
107
'HAVE_OPENDIR' => '1',
110
'HAVE_PRAGMA_PACK' => '1',
111
'HAVE_PRAGMA_PACK_HPPA' => -1,
112
'HAVE_PRELOADED_SYMBOLS' => -1,
113
'HAVE_PTHREAD_YIELD' => '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',
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"',
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',
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,
182
'VERSION_SUFFIX' => '""',
183
'WORDS_BIGENDIAN' => '0',
184
'_LARGEFILE_SOURCE' => -1,
185
'_POSIX_PII_SOCKET' => -1,
187
'_THREAD_SAFE' => -1,
188
'__error_t_defined' => -1,
191
'inline' => '_inline',
195
'HAVE_UNAME_SYSCALL' => -1,
196
'HAVE__INTERNAL__SHA_COLLECT' => -1
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)
209
{makefile => 'libclamav', sections => ['libclamav', 'libclamav_internal_utils'], output => 'win32/libclamav.vcxproj', vcxproj_only => '(3rdparty\\\\|compat\\\\|getopt\\.c|misc\\.c)'},
211
# LIBCLAMUNRAR_IFACE #
212
{makefile => 'libclamav', sections => ['libclamunrar_iface'], output => 'win32/libclamunrar_iface.vcxproj', vcxproj_only => 'compat\\\\'},
215
{makefile => 'libclamav', sections => ['libclamunrar'], output => 'win32/libclamunrar.vcxproj'},
218
{makefile => 'libclamav/c++', sections => ['libclamavcxx'], output => 'win32/libclamavcxx.vcxproj'},
221
{makefile => 'clamscan', sections => ['clamscan'], output => 'win32/clamscan.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
224
{makefile => 'clamdscan', sections => ['clamdscan'], output => 'win32/clamdscan.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
227
{makefile => 'clamd', sections => ['clamd'], output => 'win32/clamd.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c|(daz|clam)uko.*)$'},
230
{makefile => 'freshclam', sections => ['freshclam'], output => 'win32/freshclam.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$', vcxproj_only => 'compat\\\\'},
233
{makefile => 'clamconf', sections => ['clamconf'], output => 'win32/clamconf.vcxproj', makefile_only => '(optparser\\.c$|getopt\\.c)$'},
236
{makefile => 'clambc', sections => ['clambc'], output => 'win32/clambc.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
239
{makefile => 'libclamav/c++', sections => ['libllvmsystem'], output => 'win32/LLVMsystem.vcxproj'},
242
{makefile => 'libclamav/c++', sections => ['libllvmcodegen'], output => 'win32/LLVMcodegen.vcxproj'},
245
{makefile => 'libclamav/c++', sections => ['libllvmx86codegen'], output => 'win32/LLVMx86codegen.vcxproj'},
248
{makefile => 'libclamav/c++', sections => ['libllvmjit'], output => 'win32/LLVMjit.vcxproj'},
251
{makefile => 'sigtool', sections => ['sigtool'], output => 'win32/sigtool.vcxproj', makefile_only => '(optparser\\.c|getopt\\.c)$'},
255
###########################################################
256
# STOP HACKING HERE STOP HACKING HERE STOP HACKING HERE #
257
###########################################################
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};
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`;
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`;
284
die "Cannot determine git version via git-describe\n" unless $VER && !$?;
288
print "Processing clamav-config.h...\n";
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";
294
if(!/^#\s*undef (.*)/) {
295
$do_patch and print OUT $_;
298
if($1 eq 'VERSION') {
299
$do_patch and print OUT "#define VERSION \"$VER\"\n";
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";
308
if($CONF{$1} eq -1) {
309
$do_patch and print OUT "/* #undef $1 */\n";
311
$do_patch and print OUT "#define $1 $CONF{$1}\n";
317
print "clamav-config.h generated ($w warnings)\n";
319
print "clamav-config.h.in parsed ($w warnings)\n";
321
foreach (@PROJECTS) {
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";
332
next unless /^(.*?)(?:_la)?_SOURCES\s*\+?=\s*(.*?)\s*(\\)?\s*$/;
333
next unless grep {$_ eq $1} (@{$proj{'sections'}});
338
/^\s*(.*?)(\s*\\)?$/;
342
if($fname =~ /\.c(pp)?$/) {
343
if($fname =~ s/^(\$\(top_srcdir\)|\.\.)\///) {
344
$fname = "../$fname";
346
$fname = "../$proj{'makefile'}/$fname";
349
$ref_files{$fname} = 1 unless defined($proj{'makefile_only'}) && $fname =~ /$proj{'makefile_only'}/;
351
$got = 0 unless $trail;
355
my $xml = XML::Twig->new( keep_encoding => 1, twig_handlers => { 'ItemGroup/ClCompile' => \&file }, pretty_print => 'record' );
356
$xml->parsefile("$BASE_DIR/$proj{'output'}");
358
my @missing_in_vcxproj = grep ! exists $files{$_}, keys %ref_files;
359
my @missing_in_makefile = grep ! exists $ref_files{$_}, keys %files;
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');
367
if(!defined($group)) {
368
$group = $xml->root('ItemGroup');
369
$group->paste($xml->root);
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;
378
warn "Warning: File $_ not in $proj{'makefile'}/Makefile.am: deleted!\n" foreach @missing_in_makefile;
379
my ($fh, $filename) = tempfile();
382
move($filename, "$proj{'output'}");
383
print "Regenerated $proj{'output'} (".($#missing_in_vcxproj + $#missing_in_makefile + 2)." changes)\n";
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";