-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinemaker.pl
More file actions
2818 lines (2562 loc) · 92.8 KB
/
Copy pathwinemaker.pl
File metadata and controls
2818 lines (2562 loc) · 92.8 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
use utf8;
use strict;
# Copyright 2000-2004 François Gouget for CodeWeavers
# Copyright 2004 Dimitrie O. Paun
# Copyright 2009-2012 André Hentschel
#
# 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
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
my $version="0.8.4";
use Cwd;
use File::Basename;
use File::Copy;
#####
#
# Options
#
#####
# The following constants define what we do with the case of filenames
##
# Never rename a file to lowercase
my $OPT_LOWER_NONE=0;
##
# Rename all files to lowercase
my $OPT_LOWER_ALL=1;
##
# Rename only files that are all uppercase to lowercase
my $OPT_LOWER_UPPERCASE=2;
# The following constants define whether to ask questions or not
##
# No (synonym of never)
my $OPT_ASK_NO=0;
##
# Yes (always)
my $OPT_ASK_YES=1;
##
# Skip the questions till the end of this scope
my $OPT_ASK_SKIP=-1;
# The following constants define the architecture
##
# Default Architecture will be chosen
my $OPT_ARCH_DEFAULT=0;
##
# 32-Bit Target
my $OPT_ARCH_32=32;
##
# 64-Bit Target
my $OPT_ARCH_64=64;
# General options
##
# This is the directory in which winemaker will operate.
my $opt_work_dir;
##
# This is the file in which winemaker will operate if a project file is specified.
my $opt_work_file;
##
# Make a backup of the files
my $opt_backup;
##
# Defines which files to rename
my $opt_lower;
##
# If we don't find the file referenced by an include, lower it
my $opt_lower_include;
##
# If true then winemaker should not attempt to fix the source. This is
# useful if the source is known to be already in a suitable form and is
# readonly
my $opt_no_source_fix;
# Options for the 'Source' method
##
# Specifies that we have only one target so that all sources relate
# to this target. By default this variable is left undefined which
# means winemaker should try to find out by itself what the targets
# are. If not undefined then this contains the name of the default
# target (without the extension).
my $opt_single_target;
##
# If '$opt_single_target' has been specified then this is the type of
# that target. Otherwise it specifies whether the default target type
# is guiexe or cuiexe.
my $opt_target_type;
##
# Contains the default set of flags to be used when creating a new target.
my $opt_flags;
##
# Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
my $opt_arch;
##
# If true then winemaker should ask questions to the user as it goes
# along.
my $opt_is_interactive;
my $opt_ask_project_options;
my $opt_ask_target_options;
##
# If false then winemaker should not generate the makefiles.
my $opt_no_generated_files;
##
# Specifies not to print the banner if set.
my $opt_no_banner;
#####
#
# Target modelization
#
#####
# The description of a target is stored in an array. The constants
# below identify what is stored at each index of the array.
##
# This is the name of the target.
my $T_NAME=0;
##
# Defines the type of target we want to build. See the TT_xxx
# constants below
my $T_TYPE=1;
##
# This is a bitfield containing flags refining the way the target
# should be handled. See the TF_xxx constants below
my $T_FLAGS=2;
##
# This is a reference to an array containing the list of the
# resp. C, C++, RC, other (.h, .hxx, etc.) source files.
my $T_SOURCES_C=3;
my $T_SOURCES_CXX=4;
my $T_SOURCES_RC=5;
my $T_SOURCES_MISC=6;
##
# This is a reference to an array containing the list of
# C compiler options
my $T_CEXTRA=7;
##
# This is a reference to an array containing the list of
# C++ compiler options
my $T_CXXEXTRA=8;
##
# This is a reference to an array containing the list of
# RC compiler options
my $T_RCEXTRA=9;
##
# This is a reference to an array containing the list of macro
# definitions
my $T_DEFINES=10;
##
# This is a reference to an array containing the list of directory
# names that constitute the include path
my $T_INCLUDE_PATH=11;
##
# Flags for the linker
my $T_LDFLAGS=12;
##
# Flags for the archiver
my $T_ARFLAGS=13;
##
# Same as T_INCLUDE_PATH but for the dll search path
my $T_DLL_PATH=14;
##
# The list of Windows dlls to import
my $T_DLLS=15;
##
# Same as T_INCLUDE_PATH but for the library search path
my $T_LIBRARY_PATH=16;
##
# The list of Unix libraries to link with
my $T_LIBRARIES=17;
# The following constants define the recognized types of target
##
# This is not a real target. This type of target is used to collect
# the sources that don't seem to belong to any other target. Thus no
# real target is generated for them, we just put the sources of the
# fake target in the global source list.
my $TT_SETTINGS=0;
##
# For executables in the windows subsystem
my $TT_GUIEXE=1;
##
# For executables in the console subsystem
my $TT_CUIEXE=2;
##
# For dynamically linked libraries
my $TT_DLL=3;
##
# For static libraries
my $TT_LIB=4;
# The following constants further refine how the target should be handled
##
# This target is an MFC-based target
my $TF_MFC=4;
##
# User has specified --nomfc option for this target or globally
my $TF_NOMFC=8;
##
# --nodlls option: Do not use standard DLL set
my $TF_NODLLS=16;
##
# --nomsvcrt option: Do not link with msvcrt
my $TF_NOMSVCRT=32;
##
# This target has a def file (only use it with TT_DLL)
my $TF_HASDEF=64;
##
# This target has C++ files named *.cxx (instead of *.cpp)
my $TF_HASCXX=128;
##
# Initialize a target:
# - set the target type to TT_SETTINGS, i.e. no real target will
# be generated.
sub target_init($)
{
my $target=$_[0];
@$target[$T_TYPE]=$TT_SETTINGS;
@$target[$T_FLAGS]=$opt_flags;
@$target[$T_SOURCES_C]=[];
@$target[$T_SOURCES_CXX]=[];
@$target[$T_SOURCES_RC]=[];
@$target[$T_SOURCES_MISC]=[];
@$target[$T_CEXTRA]=[];
@$target[$T_CXXEXTRA]=[];
@$target[$T_RCEXTRA]=[];
@$target[$T_DEFINES]=[];
@$target[$T_INCLUDE_PATH]=[];
@$target[$T_LDFLAGS]=[];
@$target[$T_ARFLAGS]=[];
@$target[$T_DLL_PATH]=[];
@$target[$T_DLLS]=[];
@$target[$T_LIBRARY_PATH]=[];
@$target[$T_LIBRARIES]=[];
}
#####
#
# Project modelization
#
#####
# First we have the notion of project. A project is described by an
# array (since we don't have structs in perl). The constants below
# identify what is stored at each index of the array.
##
# This is the path in which this project is located. In other
# words, this is the path to the Makefile.
my $P_PATH=0;
##
# This index contains a reference to an array containing the project-wide
# settings. The structure of that arrray is actually identical to that of
# a regular target since it can also contain extra sources.
my $P_SETTINGS=1;
##
# This index contains a reference to an array of targets for this
# project. Each target describes how an executable or library is to
# be built. For each target this description takes the same form as
# that of the project: an array. So this entry is an array of arrays.
my $P_TARGETS=2;
##
# Initialize a project:
# - set the project's path
# - initialize the target list
# - create a default target (will be removed later if unnecessary)
sub project_init($$$)
{
my ($project, $path, $global_settings)=@_;
my $project_settings=[];
target_init($project_settings);
@$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
@$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
@$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
@$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
@$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
@$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
@$project[$P_PATH]=$path;
@$project[$P_SETTINGS]=$project_settings;
@$project[$P_TARGETS]=[];
}
#####
#
# Global variables
#
#####
my %warnings;
my %templates;
##
# This maps a directory name to a reference to an array listing
# its contents (files and directories)
my %directories;
##
# Contains the list of all projects. This list tells us what are
# the subprojects of the main Makefile and where we have to generate
# Makefiles.
my @projects=();
##
# This is the main project, i.e. the one in the "." directory.
# It may well be empty in which case the main Makefile will only
# call out subprojects.
my @main_project;
##
# Contains the defaults for the include path, etc.
# We store the defaults as if this were a target except that we only
# exploit the defines, include path, library path, library list and misc
# sources fields.
my @global_settings;
#####
#
# Utility functions
#
#####
##
# Cleans up a name to make it an acceptable Makefile
# variable name.
sub canonize($)
{
my $name=$_[0];
$name =~ tr/a-zA-Z0-9_/_/c;
return $name;
}
##
# Returns true is the specified pathname is absolute.
# Note: pathnames that start with a variable '$' or
# '~' are considered absolute.
sub is_absolute($)
{
my $path=$_[0];
return ($path =~ /^[\/~\$]/);
}
##
# Retrieves the contents of the specified directory.
# We either get it from the directories hashtable which acts as a
# cache, or use opendir, readdir, closedir and store the result
# in the hashtable.
sub get_directory_contents($)
{
my $dirname=$_[0];
my $directory;
#print "getting the contents of $dirname\n";
# check for a cached version
$dirname =~ s+/$++;
if ($dirname eq "") {
$dirname=cwd;
}
$directory=$directories{$dirname};
if (defined $directory) {
#print "->@$directory\n";
return $directory;
}
# Read this directory
if (opendir(DIRECTORY, "$dirname")) {
my @files=readdir DIRECTORY;
closedir(DIRECTORY);
$directory=\@files;
} else {
# Return an empty list
#print "error: cannot open $dirname\n";
my @files;
$directory=\@files;
}
#print "->@$directory\n";
$directories{$dirname}=$directory;
return $directory;
}
##
# Removes a directory from the cache.
# This is needed if one of its files or subdirectory has been renamed.
sub clear_directory_cache($)
{
my ($dirname)=@_;
delete $directories{$dirname};
}
#####
#
# 'Source'-based Project analysis
#
#####
##
# Allows the user to specify makefile and target specific options
# - target: the structure in which to store the results
# - options: the string containing the options
sub source_set_options($$)
{
my $target=$_[0];
my $options=$_[1];
#FIXME: we must deal with escaping of stuff and all
foreach my $option (split / /,$options) {
if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
push @{@$target[$T_DEFINES]},$option;
} elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
push @{@$target[$T_INCLUDE_PATH]},$option;
} elsif ($option =~ /^-P/) {
push @{@$target[$T_DLL_PATH]},"-L$'";
} elsif ($option =~ /^-i/) {
push @{@$target[$T_DLLS]},"$'";
} elsif ($option =~ /^-L/) {
push @{@$target[$T_LIBRARY_PATH]},$option;
} elsif ($option =~ /^-l/) {
push @{@$target[$T_LIBRARIES]},"$'";
} elsif ($option =~ /^--mfc/) {
@$target[$T_FLAGS]|=$TF_MFC;
@$target[$T_FLAGS]&=~$TF_NOMFC;
} elsif ($option =~ /^--nomfc/) {
@$target[$T_FLAGS]&=~$TF_MFC;
@$target[$T_FLAGS]|=$TF_NOMFC;
} elsif ($option =~ /^--nodlls/) {
@$target[$T_FLAGS]|=$TF_NODLLS;
} elsif ($option =~ /^--nomsvcrt/) {
@$target[$T_FLAGS]|=$TF_NOMSVCRT;
} else {
print STDERR "error: unknown option \"$option\"\n";
return 0;
}
}
return 1;
}
##
# Scans the specified project file to:
# - get a list of targets for this project
# - get some settings
# - get the list of source files
sub source_scan_project_file($$$);
sub source_scan_project_file($$$)
{
# a reference to the parent's project
my $parent_project=$_[0];
# 0 if it is a single project, 1 if it is part of a workspace
my $is_sub_project=$_[1];
# the name of the project file, with complete path, or without if in
# the same directory
my $filename=$_[2];
# reference to the project for this file. May not be used
my $project;
# list of sources found in the current file
my @sources_c=();
my @sources_cxx=();
my @sources_rc=();
my @sources_misc=();
# some more settings
my $path=dirname($filename);
my $prj_target_cflags;
my $prj_target_defines;
my $prj_target_ldflags;
my $prj_target_libs;
my $prj_name;
my $found_cfg=0;
my $prj_cfg;
my $prj_target_type=$TT_GUIEXE;
my @prj_target_options;
if (!($path=~/\/$/)) {
$path.="/";
}
$project=$parent_project;
my $project_settings=@$project[$P_SETTINGS];
if ($filename =~ /.dsp$/i) {
# First find out what this project file contains:
# collect all sources, find targets and settings
if (!open(FILEI,$filename)) {
print STDERR "error: unable to open $filename for reading:\n";
print STDERR " $!\n";
return;
}
my $sfilet;
while (<FILEI>) {
# Remove any trailing CtrlZ, which isn't strictly in the file
if (/\x1A/) {
s/\x1A//;
last if (/^$/)
}
# Remove any trailing CrLf
s/\r\n$/\n/;
if (!/\n$/) {
# Make sure all lines are '\n' terminated
$_ .= "\n";
}
if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
$prj_name="$1";
$prj_name=~s/\s+/_/g;
#print $prj_name;
next;
} elsif (/^# TARGTYPE/) {
if (/[[:space:]]0+x0*101$/) {
# Application
$prj_target_type=$TT_GUIEXE;
}elsif (/[[:space:]]0+x0*102$/) {
# Dynamic-Link Library
$prj_target_type=$TT_DLL;
}elsif (/[[:space:]]0+x0*103$/) {
# Console Application
$prj_target_type=$TT_CUIEXE;
}elsif (/[[:space:]]0+x0*104$/) {
# Static Library
$prj_target_type=$TT_LIB;
}
next;
} elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
$prj_target_cflags=$1;
@prj_target_options=split(/\s+\//, $prj_target_cflags);
$prj_target_cflags="";
foreach ( @prj_target_options ) {
if ($_ eq "") {
# empty
} elsif (/nologo/) {
# Suppress Startup Banner and Information Messages
} elsif (/^W0$/) {
# Turns off all warning messages
$prj_target_cflags.="-w ";
} elsif (/^W[123]$/) {
# Warning Level
$prj_target_cflags.="-W ";
} elsif (/^W4$/) {
# Warning Level
$prj_target_cflags.="-Wall ";
} elsif (/^WX$/) {
# Warnings As Errors
$prj_target_cflags.="-Werror ";
} elsif (/^Gm$/) {
# Enable Minimal Rebuild
} elsif (/^GX$/) {
# Enable Exception Handling
$prj_target_cflags.="-fexceptions ";
} elsif (/^Gd$/) {
# use cdecl calling convention (default)
} elsif (/^Gr$/) {
# use fastcall calling convention
} elsif (/^Gz$/) {
# use stdcall calling convention
$prj_target_cflags.="-mrtd ";
} elsif (/^Z[d7iI]$/) {
# Debug Info
$prj_target_cflags.="-g ";
} elsif (/^Od$/) {
# Disable Optimizations
$prj_target_cflags.="-O0 ";
} elsif (/^O1$/) {
# Minimize Size
$prj_target_cflags.="-Os ";
} elsif (/^O2$/) {
# Maximize Speed
$prj_target_cflags.="-O2 ";
} elsif (/^Ob0$/) {
# Disables inline Expansion
$prj_target_cflags.="-fno-inline ";
} elsif (/^Ob1$/) {
#In-line Function Expansion
$prj_target_cflags.="-finline-functions ";
} elsif (/^Ob2$/) {
# auto In-line Function Expansion
$prj_target_cflags.="-finline-functions ";
} elsif (/^Ox$/) {
# Use maximum optimization
$prj_target_cflags.="-O3 ";
} elsif (/^Oy$/) {
# Frame-Pointer Omission
$prj_target_cflags.="-fomit-frame-pointer ";
} elsif (/^Oy-$/) {
# Frame-Pointer Omission
$prj_target_cflags.="-fno-omit-frame-pointer ";
} elsif (/^GZ$/) {
# Catch Release-Build Errors in Debug Build
} elsif (/^M[DLT]d?$/) {
# Use Multithreaded Run-Time Library
} elsif (/^D\s*\"(.*)\"/) {
# Preprocessor Definitions
$prj_target_defines.="-D".$1." ";
} elsif (/^I\s*\"(.*)\"/) {
# Additional Include Directories
$sfilet=$1;
$sfilet=~s/\\/\//g;
my @compinc=split /\/+/, $sfilet;
my $realinc=search_from($path, \@compinc);
if (defined $realinc) {
$sfilet=$realinc;
}
if ($sfilet=~/^\w:/) {
print STDERR "warning: Can't fix path $sfilet\n"
} else {
push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
}
} elsif (/^U\s*\"(.*)\"/) {
# Undefines a previously defined symbol
$prj_target_cflags.="-U".$1." ";
} elsif (/^Fp/) {
# Name .PCH File
} elsif (/^F[Rr]/) {
# Create .SBR File
} elsif (/^YX$/) {
# Automatic Use of Precompiled Headers
} elsif (/^FD$/) {
# Generate File Dependencies
} elsif (/^c$/) {
# Compile Without Linking
# this option is always present and is already specified in the suffix rules
} elsif (/^GB$/) {
# Blend Optimization
$prj_target_cflags.="-D_M_IX86=500 ";
} elsif (/^G6$/) {
# Pentium Pro Optimization
$prj_target_cflags.="-D_M_IX86=600 ";
} elsif (/^G5$/) {
# Pentium Optimization
$prj_target_cflags.="-D_M_IX86=500 ";
} elsif (/^G3$/) {
# 80386 Optimization
$prj_target_cflags.="-D_M_IX86=300 ";
} elsif (/^G4$/) {
# 80486 Optimization
$prj_target_cflags.="-D_M_IX86=400 ";
} elsif (/^Yc/) {
# Create Precompiled Header
} elsif (/^Yu/) {
# Use Precompiled Header
} elsif (/^Za$/) {
# Disable Language Extensions
$prj_target_cflags.="-ansi ";
} elsif (/^Ze$/) {
# Enable Microsoft Extensions
} elsif (/^Zm[[:digit:]]+$/) {
# Specify Memory Allocation Limit
} elsif (/^Zp1?$/) {
# Packs structures on 1-byte boundaries
$prj_target_cflags.="-fpack-struct ";
} elsif (/^Zp(2|4|8|16)$/) {
# Struct Member Alignment
$prj_target_cflags.="-fpack-struct=".$1;
} else {
print "C compiler option $_ not implemented\n";
}
}
#print "\nOptions: $prj_target_cflags\n";
next;
} elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
$prj_target_ldflags=$1;
@prj_target_options=split(/\s+\//, $prj_target_ldflags);
$prj_target_ldflags="";
$prj_target_libs=$prj_target_options[0];
$prj_target_libs=~s/\\/\//g;
$prj_target_libs=~s/\.lib//g;
$prj_target_libs=~s/\s+/ -l/g;
shift (@prj_target_options);
foreach ( @prj_target_options ) {
if ($_ eq "") {
# empty
} elsif (/^base:(.*)/) {
# Base Address
$prj_target_ldflags.="--image-base ".$1." ";
} elsif (/^debug$/) {
# Generate Debug Info
} elsif (/^dll$/) {
# Build a DLL
$prj_target_type=$TT_DLL;
} elsif (/^incremental:[[:alpha:]]+$/) {
# Link Incrmentally
} elsif (/^implib:/) {
# Name import library
} elsif (/^libpath:\"(.*)\"/) {
# Additional Libpath
push @{@$project_settings[$T_DLL_PATH]},"-L$1";
} elsif (/^machine:[[:alnum:]]+$/) {
# Specify Target Platform
} elsif (/^map/) {
# Generate Mapfile
if (/^map:(.*)/) {
$prj_target_ldflags.="-Map ".$1." ";
} else {
$prj_target_ldflags.="-Map ".$prj_name.".map ";
}
} elsif (/^nologo$/) {
# Suppress Startup Banner and Information Messages
} elsif (/^out:/) {
# Output File Name
# may use it as Target?
} elsif (/^pdbtype:/) {
# Program Database Storage
} elsif (/^subsystem:/) {
# Specify Subsystem
} elsif (/^version:[[:digit:].]+$/) {
# Version Information
} else {
print "Linker option $_ not implemented\n";
}
}
next;
} elsif (/^LIB32=/ && $found_cfg==1) {
#$libflag = 1;
next;
} elsif (/^SOURCE=(.*)$/) {
my @components=split /[\/\\]+/, $1;
$sfilet=search_from($path, \@components);
if (!defined $sfilet) { next; }
if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
push @sources_c,$sfilet;
} elsif ($sfilet =~ /\.cpp$/i) {
if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
push @sources_misc,$sfilet;
@$project_settings[$T_FLAGS]|=$TF_MFC;
} else {
push @sources_cxx,$sfilet;
}
} elsif ($sfilet =~ /\.cxx$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASCXX;
push @sources_cxx,$sfilet;
} elsif ($sfilet =~ /\.rc$/i) {
push @sources_rc,$sfilet;
} elsif ($sfilet =~ /\.def$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASDEF;
} elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
push @sources_misc,$sfilet;
if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
@$project_settings[$T_FLAGS]|=$TF_MFC;
}
}
next;
} elsif (/^# (Begin|End) Source File/) {
# Source-Files already handled
next;
} elsif (/^# (Begin|End) Group/) {
# Groups are ignored
next;
} elsif (/^# (Begin|End) Custom Build/) {
# Custom Builds are ignored
next;
} elsif (/^# ADD LIB32 /) {
#"ARFLAGS=rus"
next;
} elsif (/^# Begin Target$/) {
# Targets are ignored
next;
} elsif (/^# End Target$/) {
# Targets are ignored
next;
} elsif (/^!/) {
if ($found_cfg == 1) {
$found_cfg=0;
}
if (/if (.*)\(CFG\)" == "(.*)"/i) {
if ($2 eq $prj_cfg) {
$found_cfg=1;
}
}
next;
} elsif (/^CFG=(.*)/i) {
$prj_cfg=$1;
next;
}
else { # Line recognized
# print "|\n";
}
}
close(FILEI);
push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
} elsif ($filename =~ /.vcproj$/i) {
eval {
require XML::LibXML;
};
if ($@) {
die "Error: You need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)";
}
my $xmlparser = XML::LibXML->new();
my $project_xml = $xmlparser->parse_file($filename);
my $sfilet;
my $configt;
foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
foreach my $vc_project_attr ($vc_project->attributes) {
if ($vc_project_attr->getName eq "Name") {
$prj_name=$vc_project_attr->getValue;
$prj_name=~s/\s+/_/g;
last;
}
}
}
for (my $flevel = 0; $flevel <= 5; $flevel++) {
foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
foreach my $vc_file_attr ($vc_file->attributes) {
if ($vc_file_attr->getName eq "RelativePath") {
$sfilet = $vc_file_attr->getValue;
$sfilet=~s/\\\\/\\/g; #remove double backslash
$sfilet=~s/^\.\\//; #remove starting 'this directory'
$sfilet=~s/\\/\//g; #make slashes out of backslashes
my @compsrc=split(/\/+/, $sfilet);
my $realsrc=search_from($path, \@compsrc);
if (defined $realsrc) {
$sfilet=$realsrc;
}
if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
push @sources_c,$sfilet;
} elsif ($sfilet =~ /\.cpp$/i) {
if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
push @sources_misc,$sfilet;
@$project_settings[$T_FLAGS]|=$TF_MFC;
} else {
push @sources_cxx,$sfilet;
}
} elsif ($sfilet =~ /\.cxx$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASCXX;
push @sources_cxx,$sfilet;
} elsif ($sfilet =~ /\.rc$/i) {
push @sources_rc,$sfilet;
} elsif ($sfilet =~ /\.def$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASDEF;
} elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
push @sources_misc,$sfilet;
if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
@$project_settings[$T_FLAGS]|=$TF_MFC;
}
}
}
}
}
}
my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
my $vc_configuration = $vc_configurations[0];
foreach my $vc_configuration_attr ($vc_configuration->attributes) {
if ($vc_configuration_attr->getName eq "ConfigurationType") {
if ($vc_configuration_attr->getValue==1) {
$prj_target_type=$TT_GUIEXE; # Application
} elsif ($vc_configuration_attr->getValue==2) {
$prj_target_type=$TT_DLL; # Dynamic-Link Library
} elsif ($vc_configuration_attr->getValue==4) {
$prj_target_type=$TT_LIB; # Static Library
}
}
}
foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
my @find_tool = $vc_configuration_tools->attributes;
if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
if ($vc_compiler_tool->getName eq "WarningLevel") {
if ($vc_compiler_tool->getValue==0) {
$prj_target_cflags.="-w ";
} elsif ($vc_compiler_tool->getValue<4) {
$prj_target_cflags.="-W ";
} elsif ($vc_compiler_tool->getValue==4) {
$prj_target_cflags.="-Wall ";
} elsif ($vc_compiler_tool->getValue eq "X") {
$prj_target_cflags.="-Werror ";
}
}
if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
$configt=$vc_compiler_tool->getValue;
$configt=~s/;\s*/ -D/g;
$prj_target_defines.="-D".$configt." ";
}
if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
$configt=$vc_compiler_tool->getValue;
$configt=~s/\\/\//g;
my @addincl = split(/\s*;\s*/, $configt);
foreach $configt (@addincl) {
my @compinc=split(/\/+/, $configt);
my $realinc=search_from($path, \@compinc);
if (defined $realinc) {
$configt=$realinc;
}
push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
}
}
}
}
if ($find_tool[0]->getValue eq "VCLinkerTool") {
foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
if ($vc_linker_tool->getName eq "AdditionalDependencies") {
$prj_target_libs=" ".$vc_linker_tool->getValue;
$prj_target_libs=~s/\\/\//g;
$prj_target_libs=~s/\.lib//g;
$prj_target_libs=~s/\s+/ -l/g;
}
}
}
}
push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;