wined3d: Properly check if an attribute is used in state_normalize().
[wine] / tools / winemaker
index 5300e15..b2e58cc 100755 (executable)
@@ -20,7 +20,7 @@ use strict;
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 #
 
-my $version="0.7.0";
+my $version="0.7.3";
 
 use Cwd;
 use File::Basename;
@@ -64,6 +64,17 @@ my $OPT_ASK_YES=1;
 my $OPT_ASK_SKIP=-1;
 
 
+# The following constants define the architecture
+
+##
+# 32-Bit Target
+my $OPT_ARCH_32=32;
+
+##
+# 64-Bit Target
+my $OPT_ARCH_64=64;
+
+
 # General options
 
 ##
@@ -112,6 +123,10 @@ 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.
@@ -520,6 +535,7 @@ sub source_scan_project_file($$$)
     # 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;
@@ -647,10 +663,12 @@ sub source_scan_project_file($$$)
                         # Use Multithreaded Run-Time Library
                     } elsif (/^D\s*\"(.*)\"/) {
                         # Preprocessor Definitions
-                        $prj_target_cflags.="-D".$1." ";
-                    } elsif (/^I/) {
+                        $prj_target_defines.="-D".$1." ";
+                    } elsif (/^I\s*\"(.*)\"/) {
                         # Additional Include Directories
-                        #$prj_target_cflags.="-I" fixpath(option)
+                        $sfilet=$1;
+                        $sfilet=~s/\\/\//g;
+                        push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
                     } elsif (/^U\s*\"(.*)\"/) {
                         # Undefines a previously defined symbol
                         $prj_target_cflags.="-U".$1." ";
@@ -709,11 +727,9 @@ sub source_scan_project_file($$$)
                 @prj_target_options=split(" /", $prj_target_ldflags);
                 $prj_target_ldflags="";
                 $prj_target_libs=$prj_target_options[0];
-                #print "\n$prj_target_libs bevor\n";
                 $prj_target_libs=~s/\\/\//g;
                 $prj_target_libs=~s/\.lib//g;
                 $prj_target_libs=~s/\s+/ -l/g;
-                #print "\n$prj_target_libs after\n";
                 shift (@prj_target_options);
                 foreach ( @prj_target_options ) {
                     if ($_ eq "") {
@@ -826,76 +842,115 @@ sub source_scan_project_file($$$)
         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) {
-        # Import des Moduls XML::Simple
-        use XML::Simple;
-
-        my $project_xml = XMLin($filename, forcearray=>1);
+        # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
+        require XML::LibXML;
 
-        $targets{$project_xml->{'Name'}.".exe"}=1;
+        my $xmlparser = XML::LibXML->new();
+        my $project_xml = $xmlparser->parse_file($filename);
         my $sfilet;
-        for my $vc_files (@{$project_xml->{'Files'}}) {
-            for my $vc_filter (@{$vc_files->{'Filter'}}) {
-                for my $vc_file (@{$vc_filter->{'File'}}) {
-                    $sfilet=$vc_file->{'RelativePath'};
-                    $sfilet=~s/\\\\/\\/g; #remove double backslash
-                    $sfilet=~s/^\.\\//; #remove starting 'this directory'
-                    $sfilet=~s/\\/\//g; #make slashes out of backslashes
-                    if ($sfilet =~ /\.(exe|dll)$/i) {
-                        $targets{$sfilet}=1;
-                    } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
-                        push @sources_c,$sfilet;
-                    } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
-                        if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
+        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") {
+                    $targets{$vc_project_attr->getValue.".exe"}=1;
+                    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
+                        if ($sfilet =~ /\.(exe|dll)$/i) {
+                            $targets{$sfilet}=1;
+                        } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
+                            push @sources_c,$sfilet;
+                        } elsif ($sfilet =~ /\.(cpp|cxx)$/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 =~ /\.rc$/i) {
+                            push @sources_rc,$sfilet;
+                        } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
                             push @sources_misc,$sfilet;
-                            @$project_settings[$T_FLAGS]|=$TF_MFC;
-                        } else {
-                            push @sources_cxx,$sfilet;
-                        }
-                    } elsif ($sfilet =~ /\.rc$/i) {
-                        push @sources_rc,$sfilet;
-                    } 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;
+                            if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
+                                @$project_settings[$T_FLAGS]|=$TF_MFC;
+                            }
                         }
                     }
                 }
             }
         }
-        $prj_target_cflags="";
-        for my $vc_configurations (@{$project_xml->{'Configurations'}}) {
-            for my $vc_configuration (@{$vc_configurations->{'Configuration'}}) {
-                for my $vc_tool (@{$vc_configuration->{'Tool'}}) {
-                    if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
-                    if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
-                    if (defined $vc_tool->{'WarningLevel'}) {
-                        if ($vc_tool->{'WarningLevel'}==0) {
+
+        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=1; # Win32 (x86) Application
+                } elsif ($vc_configuration_attr->getValue==2) {
+                    $prj_target_type=3; # Win32 (x86) Dynamic-Link 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_tool->{'WarningLevel'}<4) {
+                        } elsif ($vc_compiler_tool->getValue<4) {
                             $prj_target_cflags.="-W ";
-                        } elsif ($vc_tool->{'WarningLevel'}==4) {
+                        } elsif ($vc_compiler_tool->getValue==4) {
                             $prj_target_cflags.="-Wall ";
-                        } elsif ($vc_tool->{'WarningLevel'} eq "X") {
+                        } elsif ($vc_compiler_tool->getValue eq "X") {
                             $prj_target_cflags.="-Werror ";
                         }
                     }
-                    if (defined $vc_tool->{'PreprocessorDefinitions'}) {
-                        $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
-                        $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
+                    if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
+                        $configt=$vc_compiler_tool->getValue;
+                        $configt=~s/;/ -D/g;
+                        $prj_target_defines.="-D".$configt." ";
                     }
-                    if (defined $vc_tool->{'AdditionalIncludeDirectories'}) {
-                        $vc_tool->{'AdditionalIncludeDirectories'}=~s/\\/\//g;
-                        $vc_tool->{'AdditionalIncludeDirectories'}=~s/;/ -I/g;
-                        push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$vc_tool->{'AdditionalIncludeDirectories'};
+                    if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
+                        $configt=$vc_compiler_tool->getValue;
+                        $configt=~s/\\/\//g;
+                        $configt=~s/;/ -I/g;
+                        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;
                     }
                 }
-                last;
             }
         }
+
+        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;
     }
 
     my $target_count;
@@ -974,7 +1029,7 @@ sub source_scan_project_file($$$)
         }
         if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
             push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
-            push @{@$target[$T_LDFLAGS]},"-m32";
+            push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
         }
         push @{@$project[$P_TARGETS]},$target;
 
@@ -1103,10 +1158,9 @@ sub source_scan_workspace_file($)
             s/\r\n$/\n/;
 
             # catch a project definition
-            if (/^Project:\s\"(.*)\"=\"?(.*)\s-/) {
+            if (/^Project:\s\"(.*)\"=(.*)\s-/) {
                 $prj_name=$1;
                 $prj_path=$2;
-                $prj_path=~s/\"$//;
                 @components=split /[\/\\]+/, $prj_path;
                 $prj_path=search_from($path, \@components);
                 print "Name: $prj_name\nPath: $prj_path\n";
@@ -1467,7 +1521,7 @@ sub source_scan_directory($$$$)
     }
     if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
       push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
-      push @{@$target[$T_LDFLAGS]},"-m32";
+      push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
     }
     push @{@$project[$P_TARGETS]},$target;
 
@@ -1833,6 +1887,7 @@ sub get_real_include_name($$$$$)
     foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
       my $dirname=$include;
       $dirname=~ s+^-I++;
+      $dirname=~ s+\s$++;
       if (!is_absolute($dirname)) {
        $dirname="@$project[$P_PATH]$dirname";
       } else {
@@ -2456,6 +2511,7 @@ $opt_work_dir=undef;
 $opt_single_target=undef;
 $opt_target_type=$TT_GUIEXE;
 $opt_flags=0;
+$opt_arch=$OPT_ARCH_32;
 $opt_is_interactive=$OPT_ASK_NO;
 $opt_ask_project_options=$OPT_ASK_NO;
 $opt_ask_target_options=$OPT_ASK_NO;
@@ -2489,6 +2545,7 @@ sub usage()
   print STDERR "                 [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
   print STDERR "                 [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
   print STDERR "                 [--generated-files|--nogenerated-files]\n";
+  print STDERR "                 [--wine64]\n";
   print STDERR "                 work_directory|project_file|workspace_file\n";
   print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
   print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
@@ -2526,6 +2583,8 @@ while (@ARGV>0) {
     $opt_no_generated_files=0;
   } elsif ($arg eq "--nogenerated-files") {
     $opt_no_generated_files=1;
+  } elsif ($arg eq "--wine64") {
+    $opt_arch=$OPT_ARCH_64;
   } elsif ($arg =~ /^-D/) {
     push @{$global_settings[$T_DEFINES]},$arg;
   } elsif ($arg =~ /^-I/) {