wined3d: Remove the special case for loop and rep in shader_get_registers_used().
[wine/multimedia.git] / tools / winemaker
blobbc8452c33a4a804665ce47981d7298e008afe043
1 #!/usr/bin/perl -w
2 use strict;
4 # Copyright 2000-2004 Francois Gouget for CodeWeavers
5 # Copyright 2004 Dimitrie O. Paun
6 # Copyright 2009-2011 André Hentschel
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 my $version="0.8.0";
25 use Cwd;
26 use File::Basename;
27 use File::Copy;
31 #####
33 # Options
35 #####
37 # The following constants define what we do with the case of filenames
40 # Never rename a file to lowercase
41 my $OPT_LOWER_NONE=0;
44 # Rename all files to lowercase
45 my $OPT_LOWER_ALL=1;
48 # Rename only files that are all uppercase to lowercase
49 my $OPT_LOWER_UPPERCASE=2;
52 # The following constants define whether to ask questions or not
55 # No (synonym of never)
56 my $OPT_ASK_NO=0;
59 # Yes (always)
60 my $OPT_ASK_YES=1;
63 # Skip the questions till the end of this scope
64 my $OPT_ASK_SKIP=-1;
67 # The following constants define the architecture
70 # Default Architecture will be chosen
71 my $OPT_ARCH_DEFAULT=0;
74 # 32-Bit Target
75 my $OPT_ARCH_32=32;
78 # 64-Bit Target
79 my $OPT_ARCH_64=64;
82 # General options
85 # This is the directory in which winemaker will operate.
86 my $opt_work_dir;
89 # This is the file in which winemaker will operate if a project file is specified.
90 my $opt_work_file;
93 # Make a backup of the files
94 my $opt_backup;
97 # Defines which files to rename
98 my $opt_lower;
101 # If we don't find the file referenced by an include, lower it
102 my $opt_lower_include;
105 # If true then winemaker should not attempt to fix the source. This is
106 # useful if the source is known to be already in a suitable form and is
107 # readonly
108 my $opt_no_source_fix;
110 # Options for the 'Source' method
113 # Specifies that we have only one target so that all sources relate
114 # to this target. By default this variable is left undefined which
115 # means winemaker should try to find out by itself what the targets
116 # are. If not undefined then this contains the name of the default
117 # target (without the extension).
118 my $opt_single_target;
121 # If '$opt_single_target' has been specified then this is the type of
122 # that target. Otherwise it specifies whether the default target type
123 # is guiexe or cuiexe.
124 my $opt_target_type;
127 # Contains the default set of flags to be used when creating a new target.
128 my $opt_flags;
131 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
132 my $opt_arch;
135 # If true then winemaker should ask questions to the user as it goes
136 # along.
137 my $opt_is_interactive;
138 my $opt_ask_project_options;
139 my $opt_ask_target_options;
142 # If false then winemaker should not generate the makefiles.
143 my $opt_no_generated_files;
146 # Specifies not to print the banner if set.
147 my $opt_no_banner;
151 #####
153 # Target modelization
155 #####
157 # The description of a target is stored in an array. The constants
158 # below identify what is stored at each index of the array.
161 # This is the name of the target.
162 my $T_NAME=0;
165 # Defines the type of target we want to build. See the TT_xxx
166 # constants below
167 my $T_TYPE=1;
170 # This is a bitfield containing flags refining the way the target
171 # should be handled. See the TF_xxx constants below
172 my $T_FLAGS=2;
175 # This is a reference to an array containing the list of the
176 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
177 my $T_SOURCES_C=3;
178 my $T_SOURCES_CXX=4;
179 my $T_SOURCES_RC=5;
180 my $T_SOURCES_MISC=6;
183 # This is a reference to an array containing the list of
184 # C compiler options
185 my $T_CEXTRA=7;
188 # This is a reference to an array containing the list of
189 # C++ compiler options
190 my $T_CXXEXTRA=8;
193 # This is a reference to an array containing the list of
194 # RC compiler options
195 my $T_RCEXTRA=9;
198 # This is a reference to an array containing the list of macro
199 # definitions
200 my $T_DEFINES=10;
203 # This is a reference to an array containing the list of directory
204 # names that constitute the include path
205 my $T_INCLUDE_PATH=11;
208 # Flags for the linker
209 my $T_LDFLAGS=12;
212 # Flags for the archiver
213 my $T_ARFLAGS=13;
216 # Same as T_INCLUDE_PATH but for the dll search path
217 my $T_DLL_PATH=14;
220 # The list of Windows dlls to import
221 my $T_DLLS=15;
224 # Same as T_INCLUDE_PATH but for the library search path
225 my $T_LIBRARY_PATH=16;
228 # The list of Unix libraries to link with
229 my $T_LIBRARIES=17;
232 # The following constants define the recognized types of target
235 # This is not a real target. This type of target is used to collect
236 # the sources that don't seem to belong to any other target. Thus no
237 # real target is generated for them, we just put the sources of the
238 # fake target in the global source list.
239 my $TT_SETTINGS=0;
242 # For executables in the windows subsystem
243 my $TT_GUIEXE=1;
246 # For executables in the console subsystem
247 my $TT_CUIEXE=2;
250 # For dynamically linked libraries
251 my $TT_DLL=3;
254 # For static libraries
255 my $TT_LIB=4;
258 # The following constants further refine how the target should be handled
261 # This target is an MFC-based target
262 my $TF_MFC=4;
265 # User has specified --nomfc option for this target or globally
266 my $TF_NOMFC=8;
269 # --nodlls option: Do not use standard DLL set
270 my $TF_NODLLS=16;
273 # --nomsvcrt option: Do not link with msvcrt
274 my $TF_NOMSVCRT=32;
277 # This target has a def file (only use it with TT_DLL)
278 my $TF_HASDEF=64;
281 # Initialize a target:
282 # - set the target type to TT_SETTINGS, i.e. no real target will
283 # be generated.
284 sub target_init($)
286 my $target=$_[0];
288 @$target[$T_TYPE]=$TT_SETTINGS;
289 @$target[$T_FLAGS]=$opt_flags;
290 @$target[$T_SOURCES_C]=[];
291 @$target[$T_SOURCES_CXX]=[];
292 @$target[$T_SOURCES_RC]=[];
293 @$target[$T_SOURCES_MISC]=[];
294 @$target[$T_CEXTRA]=[];
295 @$target[$T_CXXEXTRA]=[];
296 @$target[$T_RCEXTRA]=[];
297 @$target[$T_DEFINES]=[];
298 @$target[$T_INCLUDE_PATH]=[];
299 @$target[$T_LDFLAGS]=[];
300 @$target[$T_ARFLAGS]=[];
301 @$target[$T_DLL_PATH]=[];
302 @$target[$T_DLLS]=[];
303 @$target[$T_LIBRARY_PATH]=[];
304 @$target[$T_LIBRARIES]=[];
309 #####
311 # Project modelization
313 #####
315 # First we have the notion of project. A project is described by an
316 # array (since we don't have structs in perl). The constants below
317 # identify what is stored at each index of the array.
320 # This is the path in which this project is located. In other
321 # words, this is the path to the Makefile.
322 my $P_PATH=0;
325 # This index contains a reference to an array containing the project-wide
326 # settings. The structure of that arrray is actually identical to that of
327 # a regular target since it can also contain extra sources.
328 my $P_SETTINGS=1;
331 # This index contains a reference to an array of targets for this
332 # project. Each target describes how an executable or library is to
333 # be built. For each target this description takes the same form as
334 # that of the project: an array. So this entry is an array of arrays.
335 my $P_TARGETS=2;
338 # Initialize a project:
339 # - set the project's path
340 # - initialize the target list
341 # - create a default target (will be removed later if unnecessary)
342 sub project_init($$$)
344 my ($project, $path, $global_settings)=@_;
346 my $project_settings=[];
347 target_init($project_settings);
348 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
349 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
350 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
351 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
352 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
353 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
355 @$project[$P_PATH]=$path;
356 @$project[$P_SETTINGS]=$project_settings;
357 @$project[$P_TARGETS]=[];
362 #####
364 # Global variables
366 #####
368 my %warnings;
370 my %templates;
373 # This maps a directory name to a reference to an array listing
374 # its contents (files and directories)
375 my %directories;
378 # Contains the list of all projects. This list tells us what are
379 # the subprojects of the main Makefile and where we have to generate
380 # Makefiles.
381 my @projects=();
384 # This is the main project, i.e. the one in the "." directory.
385 # It may well be empty in which case the main Makefile will only
386 # call out subprojects.
387 my @main_project;
390 # Contains the defaults for the include path, etc.
391 # We store the defaults as if this were a target except that we only
392 # exploit the defines, include path, library path, library list and misc
393 # sources fields.
394 my @global_settings;
398 #####
400 # Utility functions
402 #####
405 # Cleans up a name to make it an acceptable Makefile
406 # variable name.
407 sub canonize($)
409 my $name=$_[0];
411 $name =~ tr/a-zA-Z0-9_/_/c;
412 return $name;
416 # Returns true is the specified pathname is absolute.
417 # Note: pathnames that start with a variable '$' or
418 # '~' are considered absolute.
419 sub is_absolute($)
421 my $path=$_[0];
423 return ($path =~ /^[\/~\$]/);
427 # Retrieves the contents of the specified directory.
428 # We either get it from the directories hashtable which acts as a
429 # cache, or use opendir, readdir, closedir and store the result
430 # in the hashtable.
431 sub get_directory_contents($)
433 my $dirname=$_[0];
434 my $directory;
436 #print "getting the contents of $dirname\n";
438 # check for a cached version
439 $dirname =~ s+/$++;
440 if ($dirname eq "") {
441 $dirname=cwd;
443 $directory=$directories{$dirname};
444 if (defined $directory) {
445 #print "->@$directory\n";
446 return $directory;
449 # Read this directory
450 if (opendir(DIRECTORY, "$dirname")) {
451 my @files=readdir DIRECTORY;
452 closedir(DIRECTORY);
453 $directory=\@files;
454 } else {
455 # Return an empty list
456 #print "error: cannot open $dirname\n";
457 my @files;
458 $directory=\@files;
460 #print "->@$directory\n";
461 $directories{$dirname}=$directory;
462 return $directory;
466 # Removes a directory from the cache.
467 # This is needed if one of its files or subdirectory has been renamed.
468 sub clear_directory_cache($)
470 my ($dirname)=@_;
471 delete $directories{$dirname};
475 #####
477 # 'Source'-based Project analysis
479 #####
482 # Allows the user to specify makefile and target specific options
483 # - target: the structure in which to store the results
484 # - options: the string containing the options
485 sub source_set_options($$)
487 my $target=$_[0];
488 my $options=$_[1];
490 #FIXME: we must deal with escaping of stuff and all
491 foreach my $option (split / /,$options) {
492 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
493 push @{@$target[$T_DEFINES]},$option;
494 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
495 push @{@$target[$T_INCLUDE_PATH]},$option;
496 } elsif ($option =~ /^-P/) {
497 push @{@$target[$T_DLL_PATH]},"-L$'";
498 } elsif ($option =~ /^-i/) {
499 push @{@$target[$T_DLLS]},"$'";
500 } elsif ($option =~ /^-L/) {
501 push @{@$target[$T_LIBRARY_PATH]},$option;
502 } elsif ($option =~ /^-l/) {
503 push @{@$target[$T_LIBRARIES]},"$'";
504 } elsif ($option =~ /^--mfc/) {
505 @$target[$T_FLAGS]|=$TF_MFC;
506 @$target[$T_FLAGS]&=~$TF_NOMFC;
507 } elsif ($option =~ /^--nomfc/) {
508 @$target[$T_FLAGS]&=~$TF_MFC;
509 @$target[$T_FLAGS]|=$TF_NOMFC;
510 } elsif ($option =~ /^--nodlls/) {
511 @$target[$T_FLAGS]|=$TF_NODLLS;
512 } elsif ($option =~ /^--nomsvcrt/) {
513 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
514 } else {
515 print STDERR "error: unknown option \"$option\"\n";
516 return 0;
519 return 1;
523 # Scans the specified project file to:
524 # - get a list of targets for this project
525 # - get some settings
526 # - get the list of source files
527 sub source_scan_project_file($$$);
528 sub source_scan_project_file($$$)
530 # a reference to the parent's project
531 my $parent_project=$_[0];
532 # 0 if it is a single project, 1 if it is part of a workspace
533 my $is_sub_project=$_[1];
534 # the name of the project file, with complete path, or without if in
535 # the same directory
536 my $filename=$_[2];
538 # reference to the project for this file. May not be used
539 my $project;
540 # list of sources found in the current file
541 my @sources_c=();
542 my @sources_cxx=();
543 my @sources_rc=();
544 my @sources_misc=();
545 # some more settings
546 my $path=dirname($filename);
547 my $prj_target_cflags;
548 my $prj_target_defines;
549 my $prj_target_ldflags;
550 my $prj_target_libs;
551 my $prj_name;
552 my $found_cfg=0;
553 my $prj_cfg;
554 my $prj_target_type=$TT_GUIEXE;
555 my @prj_target_options;
557 if (!($path=~/\/$/)) {
558 $path.="/";
561 if (defined $opt_single_target or $is_sub_project == 0) {
562 # Either there is a single target and thus a single project,
563 # or we are a single project-file for which a project
564 # already exists
565 $project=$parent_project;
566 } else {
567 $project=[];
568 project_init($project, $path, \@global_settings);
570 my $project_settings=@$project[$P_SETTINGS];
572 if ($filename =~ /.dsp$/i) {
573 # First find out what this project file contains:
574 # collect all sources, find targets and settings
575 if (!open(FILEI,$filename)) {
576 print STDERR "error: unable to open $filename for reading:\n";
577 print STDERR " $!\n";
578 return;
580 my $sfilet;
581 while (<FILEI>) {
582 # Remove any trailing CtrlZ, which isn't strictly in the file
583 if (/\x1A/) {
584 s/\x1A//;
585 last if (/^$/)
588 # Remove any trailing CrLf
589 s/\r\n$/\n/;
590 if (!/\n$/) {
591 # Make sure all lines are '\n' terminated
592 $_ .= "\n";
595 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
596 $prj_name="$1";
597 $prj_name=~s/\s+/_/g;
598 #print $prj_name;
599 next;
600 } elsif (/^# TARGTYPE/) {
601 if (/[[:space:]]0+x0*101$/) {
602 # Application
603 $prj_target_type=$TT_GUIEXE;
604 }elsif (/[[:space:]]0+x0*102$/) {
605 # Dynamic-Link Library
606 $prj_target_type=$TT_DLL;
607 }elsif (/[[:space:]]0+x0*103$/) {
608 # Console Application
609 $prj_target_type=$TT_CUIEXE;
610 }elsif (/[[:space:]]0+x0*104$/) {
611 # Static Library
612 $prj_target_type=$TT_LIB;
614 next;
615 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
616 $prj_target_cflags=$1;
617 @prj_target_options=split(/\s+\//, $prj_target_cflags);
618 $prj_target_cflags="";
619 foreach ( @prj_target_options ) {
620 if ($_ eq "") {
621 # empty
622 } elsif (/nologo/) {
623 # Suppress Startup Banner and Information Messages
624 } elsif (/^W0$/) {
625 # Turns off all warning messages
626 $prj_target_cflags.="-w ";
627 } elsif (/^W[123]$/) {
628 # Warning Level
629 $prj_target_cflags.="-W ";
630 } elsif (/^W4$/) {
631 # Warning Level
632 $prj_target_cflags.="-Wall ";
633 } elsif (/^WX$/) {
634 # Warnings As Errors
635 $prj_target_cflags.="-Werror ";
636 } elsif (/^Gm$/) {
637 # Enable Minimal Rebuild
638 } elsif (/^GX$/) {
639 # Enable Exception Handling
640 $prj_target_cflags.="-fexceptions ";
641 } elsif (/^Gd$/) {
642 # use cdecl calling convention (default)
643 } elsif (/^Gr$/) {
644 # use fastcall calling convention
645 } elsif (/^Gz$/) {
646 # use stdcall calling convention
647 $prj_target_cflags.="-mrtd ";
648 } elsif (/^Z[d7iI]$/) {
649 # Debug Info
650 $prj_target_cflags.="-g ";
651 } elsif (/^Od$/) {
652 # Disable Optimizations
653 $prj_target_cflags.="-O0 ";
654 } elsif (/^O1$/) {
655 # Minimize Size
656 $prj_target_cflags.="-Os ";
657 } elsif (/^O2$/) {
658 # Maximize Speed
659 $prj_target_cflags.="-O2 ";
660 } elsif (/^Ob0$/) {
661 # Disables inline Expansion
662 $prj_target_cflags.="-fno-inline ";
663 } elsif (/^Ob1$/) {
664 #In-line Function Expansion
665 $prj_target_cflags.="-finline-functions ";
666 } elsif (/^Ob2$/) {
667 # auto In-line Function Expansion
668 $prj_target_cflags.="-finline-functions ";
669 } elsif (/^Ox$/) {
670 # Use maximum optimization
671 $prj_target_cflags.="-O3 ";
672 } elsif (/^Oy$/) {
673 # Frame-Pointer Omission
674 $prj_target_cflags.="-fomit-frame-pointer ";
675 } elsif (/^Oy-$/) {
676 # Frame-Pointer Omission
677 $prj_target_cflags.="-fno-omit-frame-pointer ";
678 } elsif (/^GZ$/) {
679 # Catch Release-Build Errors in Debug Build
680 } elsif (/^M[DLT]d?$/) {
681 # Use Multithreaded Run-Time Library
682 } elsif (/^D\s*\"(.*)\"/) {
683 # Preprocessor Definitions
684 $prj_target_defines.="-D".$1." ";
685 } elsif (/^I\s*\"(.*)\"/) {
686 # Additional Include Directories
687 $sfilet=$1;
688 $sfilet=~s/\\/\//g;
689 if ($sfilet=~/^\w:/) {
690 print STDERR "warning: Can't fix path $sfilet\n"
691 } else {
692 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
694 } elsif (/^U\s*\"(.*)\"/) {
695 # Undefines a previously defined symbol
696 $prj_target_cflags.="-U".$1." ";
697 } elsif (/^Fp/) {
698 # Name .PCH File
699 } elsif (/^F[Rr]/) {
700 # Create .SBR File
701 } elsif (/^YX$/) {
702 # Automatic Use of Precompiled Headers
703 } elsif (/^FD$/) {
704 # Generate File Dependencies
705 } elsif (/^c$/) {
706 # Compile Without Linking
707 # this option is always present and is already specified in the suffix rules
708 } elsif (/^GB$/) {
709 # Blend Optimization
710 $prj_target_cflags.="-D_M_IX86=500 ";
711 } elsif (/^G6$/) {
712 # Pentium Pro Optimization
713 $prj_target_cflags.="-D_M_IX86=600 ";
714 } elsif (/^G5$/) {
715 # Pentium Optimization
716 $prj_target_cflags.="-D_M_IX86=500 ";
717 } elsif (/^G3$/) {
718 # 80386 Optimization
719 $prj_target_cflags.="-D_M_IX86=300 ";
720 } elsif (/^G4$/) {
721 # 80486 Optimization
722 $prj_target_cflags.="-D_M_IX86=400 ";
723 } elsif (/^Yc/) {
724 # Create Precompiled Header
725 } elsif (/^Yu/) {
726 # Use Precompiled Header
727 } elsif (/^Za$/) {
728 # Disable Language Extensions
729 $prj_target_cflags.="-ansi ";
730 } elsif (/^Ze$/) {
731 # Enable Microsoft Extensions
732 } elsif (/^Zm[[:digit:]]+$/) {
733 # Specify Memory Allocation Limit
734 } elsif (/^Zp1?$/) {
735 # Packs structures on 1-byte boundaries
736 $prj_target_cflags.="-fpack-struct ";
737 } elsif (/^Zp(2|4|8|16)$/) {
738 # Struct Member Alignment
739 $prj_target_cflags.="-fpack-struct=".$1;
740 } else {
741 print "C compiler option $_ not implemented\n";
745 #print "\nOptions: $prj_target_cflags\n";
746 next;
747 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
748 $prj_target_ldflags=$1;
749 @prj_target_options=split(/\s+\//, $prj_target_ldflags);
750 $prj_target_ldflags="";
751 $prj_target_libs=$prj_target_options[0];
752 $prj_target_libs=~s/\\/\//g;
753 $prj_target_libs=~s/\.lib//g;
754 $prj_target_libs=~s/\s+/ -l/g;
755 shift (@prj_target_options);
756 foreach ( @prj_target_options ) {
757 if ($_ eq "") {
758 # empty
759 } elsif (/^base:(.*)/) {
760 # Base Address
761 $prj_target_ldflags.="--image-base ".$1." ";
762 } elsif (/^debug$/) {
763 # Generate Debug Info
764 } elsif (/^dll$/) {
765 # Build a DLL
766 $prj_target_type=$TT_DLL;
767 } elsif (/^incremental:[[:alpha:]]+$/) {
768 # Link Incrmentally
769 } elsif (/^implib:/) {
770 # Name import library
771 } elsif (/^libpath:\"(.*)\"/) {
772 # Additional Libpath
773 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
774 } elsif (/^machine:[[:alnum:]]+$/) {
775 # Specify Target Platform
776 } elsif (/^map/) {
777 # Generate Mapfile
778 if (/^map:(.*)/) {
779 $prj_target_ldflags.="-Map ".$1." ";
780 } else {
781 $prj_target_ldflags.="-Map ".$prj_name.".map ";
783 } elsif (/^nologo$/) {
784 # Suppress Startup Banner and Information Messages
785 } elsif (/^out:/) {
786 # Output File Name
787 # may use it as Target?
788 } elsif (/^pdbtype:/) {
789 # Program Database Storage
790 } elsif (/^subsystem:/) {
791 # Specify Subsystem
792 } elsif (/^version:[[:digit:].]+$/) {
793 # Version Information
794 } else {
795 print "Linker option $_ not implemented\n";
798 next;
799 } elsif (/^LIB32=/ && $found_cfg==1) {
800 #$libflag = 1;
801 next;
802 } elsif (/^SOURCE=(.*)$/) {
803 my @components=split /[\/\\]+/, $1;
804 $sfilet=search_from($path, \@components);
805 if (!defined $sfilet) { next; }
806 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
807 push @sources_c,$sfilet;
808 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
809 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
810 push @sources_misc,$sfilet;
811 @$project_settings[$T_FLAGS]|=$TF_MFC;
812 } else {
813 push @sources_cxx,$sfilet;
815 } elsif ($sfilet =~ /\.rc$/i) {
816 push @sources_rc,$sfilet;
817 } elsif ($sfilet =~ /\.def$/i) {
818 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
819 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
820 push @sources_misc,$sfilet;
821 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
822 @$project_settings[$T_FLAGS]|=$TF_MFC;
825 next;
827 } elsif (/^# (Begin|End) Source File/) {
828 # Source-Files already handled
829 next;
830 } elsif (/^# (Begin|End) Group/) {
831 # Groups are ignored
832 next;
833 } elsif (/^# (Begin|End) Custom Build/) {
834 # Custom Builds are ignored
835 next;
836 } elsif (/^# ADD LIB32 /) {
837 #"ARFLAGS=rus"
838 next;
839 } elsif (/^# Begin Target$/) {
840 # Targets are ignored
841 next;
842 } elsif (/^# End Target$/) {
843 # Targets are ignored
844 next;
845 } elsif (/^!/) {
846 if ($found_cfg == 1) {
847 $found_cfg=0;
849 if (/if (.*)\(CFG\)" == "(.*)"/i) {
850 if ($2 eq $prj_cfg) {
851 $found_cfg=1;
854 next;
855 } elsif (/^CFG=(.*)/i) {
856 $prj_cfg=$1;
857 next;
859 else { # Line recognized
860 # print "|\n";
863 close(FILEI);
865 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
866 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
867 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
868 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
869 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
870 } elsif ($filename =~ /.vcproj$/i) {
871 # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
872 require XML::LibXML;
874 my $xmlparser = XML::LibXML->new();
875 my $project_xml = $xmlparser->parse_file($filename);
876 my $sfilet;
877 my $configt;
879 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
880 foreach my $vc_project_attr ($vc_project->attributes) {
881 if ($vc_project_attr->getName eq "Name") {
882 $prj_name=$vc_project_attr->getValue;
883 $prj_name=~s/\s+/_/g;
884 last;
889 for (my $flevel = 0; $flevel <= 5; $flevel++) {
890 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
891 foreach my $vc_file_attr ($vc_file->attributes) {
892 if ($vc_file_attr->getName eq "RelativePath") {
893 $sfilet = $vc_file_attr->getValue;
894 $sfilet=~s/\\\\/\\/g; #remove double backslash
895 $sfilet=~s/^\.\\//; #remove starting 'this directory'
896 $sfilet=~s/\\/\//g; #make slashes out of backslashes
897 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
898 push @sources_c,$sfilet;
899 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
900 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
901 push @sources_misc,$sfilet;
902 @$project_settings[$T_FLAGS]|=$TF_MFC;
903 } else {
904 push @sources_cxx,$sfilet;
906 } elsif ($sfilet =~ /\.rc$/i) {
907 push @sources_rc,$sfilet;
908 } elsif ($sfilet =~ /\.def$/i) {
909 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
910 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
911 push @sources_misc,$sfilet;
912 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
913 @$project_settings[$T_FLAGS]|=$TF_MFC;
921 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
922 my $vc_configuration = $vc_configurations[0];
923 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
924 if ($vc_configuration_attr->getName eq "ConfigurationType") {
925 if ($vc_configuration_attr->getValue==1) {
926 $prj_target_type=$TT_GUIEXE; # Application
927 } elsif ($vc_configuration_attr->getValue==2) {
928 $prj_target_type=$TT_DLL; # Dynamic-Link Library
929 } elsif ($vc_configuration_attr->getValue==4) {
930 $prj_target_type=$TT_LIB; # Static Library
935 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
936 my @find_tool = $vc_configuration_tools->attributes;
937 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
938 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
939 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
940 if ($vc_compiler_tool->getName eq "WarningLevel") {
941 if ($vc_compiler_tool->getValue==0) {
942 $prj_target_cflags.="-w ";
943 } elsif ($vc_compiler_tool->getValue<4) {
944 $prj_target_cflags.="-W ";
945 } elsif ($vc_compiler_tool->getValue==4) {
946 $prj_target_cflags.="-Wall ";
947 } elsif ($vc_compiler_tool->getValue eq "X") {
948 $prj_target_cflags.="-Werror ";
951 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
952 $configt=$vc_compiler_tool->getValue;
953 $configt=~s/;\s*/ -D/g;
954 $prj_target_defines.="-D".$configt." ";
956 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
957 $configt=$vc_compiler_tool->getValue;
958 $configt=~s/\\/\//g;
959 $configt=~s/;/ -I/g;
960 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
964 if ($find_tool[0]->getValue eq "VCLinkerTool") {
965 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
966 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
967 $prj_target_libs=" ".$vc_linker_tool->getValue;
968 $prj_target_libs=~s/\\/\//g;
969 $prj_target_libs=~s/\.lib//g;
970 $prj_target_libs=~s/\s+/ -l/g;
976 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
977 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
978 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
979 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
982 # Add this project to the project list, except for
983 # the main project which is already in the list.
984 if ($is_sub_project == 1) {
985 push @projects,$project;
988 # Ask for project-wide options
989 if ($opt_ask_project_options == $OPT_ASK_YES) {
990 my $flag_desc="";
991 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
992 $flag_desc="mfc";
994 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
995 if (defined $flag_desc) {
996 print "* (currently $flag_desc)\n";
998 print "* or 'skip' to skip the target specific options,\n";
999 print "* or 'never' to not be asked this question again:\n";
1000 while (1) {
1001 my $options=<STDIN>;
1002 chomp $options;
1003 if ($options eq "skip") {
1004 $opt_ask_target_options=$OPT_ASK_SKIP;
1005 last;
1006 } elsif ($options eq "never") {
1007 $opt_ask_project_options=$OPT_ASK_NO;
1008 last;
1009 } elsif (source_set_options($project_settings,$options)) {
1010 last;
1012 print "Please re-enter the options:\n";
1016 # Create the target...
1017 my $target=[];
1018 target_init($target);
1020 if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
1021 $prj_name=lc($prj_name.".exe");
1022 @$target[$T_TYPE]=$opt_target_type;
1023 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1024 } elsif ($prj_target_type==$TT_LIB) {
1025 $prj_name=lc("lib".$prj_name.".a");
1026 @$target[$T_TYPE]=$TT_LIB;
1027 push @{@$target[$T_ARFLAGS]},("rc");
1028 } else {
1029 $prj_name=lc($prj_name.".dll");
1030 @$target[$T_TYPE]=$TT_DLL;
1031 my $canon=canonize($prj_name);
1032 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1033 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1034 } else {
1035 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1039 @$target[$T_NAME]=$prj_name;
1040 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1042 # This is the default link list of Visual Studio
1043 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1044 my @std_libraries=qw(uuid);
1045 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1046 @$target[$T_DLLS]=\@std_imports;
1047 @$target[$T_LIBRARIES]=\@std_libraries;
1048 } else {
1049 @$target[$T_DLLS]=[];
1050 @$target[$T_LIBRARIES]=[];
1052 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1053 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1054 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1055 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1058 push @{@$project[$P_TARGETS]},$target;
1060 # Ask for target-specific options
1061 if ($opt_ask_target_options == $OPT_ASK_YES) {
1062 my $flag_desc="";
1063 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1064 $flag_desc=" (mfc";
1066 if ($flag_desc ne "") {
1067 $flag_desc.=")";
1069 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1070 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1071 while (1) {
1072 my $options=<STDIN>;
1073 chomp $options;
1074 if ($options eq "never") {
1075 $opt_ask_target_options=$OPT_ASK_NO;
1076 last;
1077 } elsif (source_set_options($target,$options)) {
1078 last;
1080 print "Please re-enter the options:\n";
1083 if (@$target[$T_FLAGS] & $TF_MFC) {
1084 @$project_settings[$T_FLAGS]|=$TF_MFC;
1085 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1086 push @{@$target[$T_DLLS]},"mfc.dll";
1087 # FIXME: Link with the MFC in the Unix sense, until we
1088 # start exporting the functions properly.
1089 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1090 push @{@$target[$T_LIBRARIES]},"mfc";
1093 # Match sources...
1094 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1095 @$project_settings[$T_SOURCES_C]=[];
1096 @sources_c=();
1097 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1098 @$project_settings[$T_SOURCES_CXX]=[];
1099 @sources_cxx=();
1100 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1101 @$project_settings[$T_SOURCES_RC]=[];
1102 @sources_rc=();
1103 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1104 @$project_settings[$T_SOURCES_MISC]=[];
1105 @sources_misc=();
1107 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1108 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1109 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1110 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1112 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1113 $opt_ask_target_options=$OPT_ASK_YES;
1116 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1117 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1118 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1119 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1120 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1121 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1125 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1126 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1128 # The sources that did not match, if any, go to the extra
1129 # source list of the project settings
1130 foreach my $source (@sources_c) {
1131 if ($source ne "") {
1132 push @{@$project_settings[$T_SOURCES_C]},$source;
1135 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1136 foreach my $source (@sources_cxx) {
1137 if ($source ne "") {
1138 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1141 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1142 foreach my $source (@sources_rc) {
1143 if ($source ne "") {
1144 push @{@$project_settings[$T_SOURCES_RC]},$source;
1147 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1148 foreach my $source (@sources_misc) {
1149 if ($source ne "") {
1150 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1153 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1157 # Scans the specified workspace file to find the project files
1158 sub source_scan_workspace_file($);
1159 sub source_scan_workspace_file($)
1161 my $filename=$_[0];
1162 my $path=dirname($filename);
1163 my @components;
1165 if (! -e $filename) {
1166 return;
1169 if (!open(FILEIWS,$filename)) {
1170 print STDERR "error: unable to open $filename for reading:\n";
1171 print STDERR " $!\n";
1172 return;
1175 my $prj_name;
1176 my $prj_path;
1178 if ($filename =~ /.dsw$/i) {
1179 while (<FILEIWS>) {
1180 # Remove any trailing CrLf
1181 s/\r\n$/\n/;
1183 # catch a project definition
1184 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1185 $prj_name=$1;
1186 $prj_path=$2;
1187 @components=split /[\/\\]+/, $prj_path;
1188 $prj_path=search_from($path, \@components);
1189 print "Name: $prj_name\nPath: $prj_path\n";
1190 source_scan_project_file(\@main_project,1,$prj_path);
1191 next;
1192 } elsif (/^#/) {
1193 # ignore Comments
1194 } elsif (/^Global:/) {
1195 # ignore the Global section
1196 } elsif (/\w:/) {
1197 print STDERR "unknown section $_\n";
1198 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1199 print "\nFileversion: $3\n";
1202 close(FILEIWS);
1203 } elsif ($filename =~ /.sln$/i) {
1204 while (<FILEIWS>) {
1205 # Remove any trailing CrLf
1206 s/\r\n$/\n/;
1208 # catch a project definition
1209 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1210 $prj_name=$2;
1211 $prj_path=$3;
1212 if ($prj_path eq "Solution Items") { next; }
1213 @components=split /[\/\\]+/, $3;
1214 $prj_path=search_from($path, \@components);
1215 print "Name: $prj_name\nPath: $prj_path\n";
1216 source_scan_project_file(\@main_project,1,$prj_path);
1217 next;
1218 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1219 print "\nFileversion: $3\n";
1222 close(FILEIWS);
1225 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1229 # Scans the specified directory to:
1230 # - see if we should create a Makefile in this directory. We normally do
1231 # so if we find a project file and sources
1232 # - get a list of targets for this directory
1233 # - get the list of source files
1234 sub source_scan_directory($$$$);
1235 sub source_scan_directory($$$$)
1237 # a reference to the parent's project
1238 my $parent_project=$_[0];
1239 # the full relative path to the current directory, including a
1240 # trailing '/', or an empty string if this is the top level directory
1241 my $path=$_[1];
1242 # the name of this directory, including a trailing '/', or an empty
1243 # string if this is the top level directory
1244 my $dirname=$_[2];
1245 # if set then no targets will be looked for and the sources will all
1246 # end up in the parent_project's 'misc' bucket
1247 my $no_target=$_[3];
1249 # reference to the project for this directory. May not be used
1250 my $project;
1251 # list of targets found in the 'current' directory
1252 my %targets;
1253 # list of sources found in the current directory
1254 my @sources_c=();
1255 my @sources_cxx=();
1256 my @sources_rc=();
1257 my @sources_misc=();
1258 # true if this directory contains a Windows project
1259 my $has_win_project=0;
1260 # true if this directory contains headers
1261 my $has_headers=0;
1262 # If we don't find any executable/library then we might make up targets
1263 # from the list of .dsp/.mak files we find since they usually have the
1264 # same name as their target.
1265 my @prj_files=();
1266 my @mak_files=();
1268 if (defined $opt_single_target or $dirname eq "") {
1269 # Either there is a single target and thus a single project,
1270 # or we are in the top level directory for which a project
1271 # already exists
1272 $project=$parent_project;
1273 } else {
1274 $project=[];
1275 project_init($project, $path, \@global_settings);
1277 my $project_settings=@$project[$P_SETTINGS];
1279 # First find out what this directory contains:
1280 # collect all sources, targets and subdirectories
1281 my $directory=get_directory_contents($path);
1282 foreach my $dentry (@$directory) {
1283 if ($dentry =~ /^\./) {
1284 next;
1286 my $fullentry="$path$dentry";
1287 if (-d "$fullentry") {
1288 if ($dentry =~ /^(Release|Debug)/i) {
1289 # These directories are often used to store the object files and the
1290 # resulting executable/library. They should not contain anything else.
1291 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1292 foreach my $candidate (@candidates) {
1293 $targets{$candidate}=1;
1295 } elsif ($dentry =~ /^include/i) {
1296 # This directory must contain headers we're going to need
1297 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1298 source_scan_directory($project,"$fullentry/","$dentry/",1);
1299 } else {
1300 # Recursively scan this directory. Any source file that cannot be
1301 # attributed to a project in one of the subdirectories will be
1302 # attributed to this project.
1303 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1305 } elsif (-f "$fullentry") {
1306 if ($dentry =~ /\.(exe|dll)$/i) {
1307 $targets{$dentry}=1;
1308 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1309 push @sources_c,"$dentry";
1310 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1311 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1312 push @sources_misc,"$dentry";
1313 @$project_settings[$T_FLAGS]|=$TF_MFC;
1314 } else {
1315 push @sources_cxx,"$dentry";
1317 } elsif ($dentry =~ /\.rc$/i) {
1318 push @sources_rc,"$dentry";
1319 } elsif ($dentry =~ /\.def$/i) {
1320 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
1321 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1322 $has_headers=1;
1323 push @sources_misc,"$dentry";
1324 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1325 @$project_settings[$T_FLAGS]|=$TF_MFC;
1327 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1328 push @prj_files,"$dentry";
1329 $has_win_project=1;
1330 } elsif ($dentry =~ /\.mak$/i) {
1331 push @mak_files,"$dentry";
1332 $has_win_project=1;
1333 } elsif ($dentry =~ /^makefile/i) {
1334 $has_win_project=1;
1339 if ($has_headers) {
1340 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1342 # If we have a single target then all we have to do is assign
1343 # all the sources to it and we're done
1344 # FIXME: does this play well with the --interactive mode?
1345 if ($opt_single_target) {
1346 my $target=@{@$project[$P_TARGETS]}[0];
1347 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1348 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1349 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1350 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1351 return;
1353 if ($no_target) {
1354 my $parent_settings=@$parent_project[$P_SETTINGS];
1355 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1356 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1357 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1358 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1359 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1360 return;
1363 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1364 @{@$project_settings[$T_SOURCES_C]}+
1365 @{@$project_settings[$T_SOURCES_CXX]}+
1366 @{@$project_settings[$T_SOURCES_RC]};
1367 if ($source_count == 0) {
1368 # A project without real sources is not a project, get out!
1369 if ($project!=$parent_project) {
1370 my $parent_settings=@$parent_project[$P_SETTINGS];
1371 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1372 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1374 return;
1376 #print "targets=",%targets,"\n";
1377 #print "target_count=$target_count\n";
1378 #print "has_win_project=$has_win_project\n";
1379 #print "dirname=$dirname\n";
1381 my $target_count;
1382 if (($has_win_project != 0) or ($dirname eq "")) {
1383 # Deal with cases where we could not find any executable/library, and
1384 # thus have no target, although we did find some sort of windows project.
1385 $target_count=keys %targets;
1386 if ($target_count == 0) {
1387 # Try to come up with a target list based on .dsp/.mak files
1388 my $prj_list;
1389 if (@prj_files > 0) {
1390 print "Projectfile found! You might want to try using it directly.\n";
1391 $prj_list=\@prj_files;
1392 } else {
1393 $prj_list=\@mak_files;
1395 foreach my $filename (@$prj_list) {
1396 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1397 if ($opt_target_type == $TT_DLL) {
1398 $filename = "$filename.dll";
1400 $targets{$filename}=1;
1402 $target_count=keys %targets;
1403 if ($target_count == 0) {
1404 # Still nothing, try the name of the directory
1405 my $name;
1406 if ($dirname eq "") {
1407 # Bad luck, this is the top level directory!
1408 $name=(split /\//, cwd)[-1];
1409 } else {
1410 $name=$dirname;
1411 # Remove the trailing '/'. Also eliminate whatever is after the last
1412 # '.' as it is likely to be meaningless (.orig, .new, ...)
1413 $name =~ s+(/|\.[^.]*)$++;
1414 if ($name eq "src") {
1415 # 'src' is probably a subdirectory of the real project directory.
1416 # Try again with the parent (if any).
1417 my $parent=$path;
1418 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1419 $name=$parent;
1420 } else {
1421 $name=(split /\//, cwd)[-1];
1425 $name =~ s+(/|\.[^.]*)$++;
1426 if ($opt_target_type == $TT_DLL) {
1427 $name = canonize($name).".dll";
1428 } else {
1429 $name = canonize($name).".exe";
1431 $targets{$name}=1;
1435 # Ask confirmation to the user if he wishes so
1436 if ($opt_is_interactive == $OPT_ASK_YES) {
1437 my $target_list=join " ",keys %targets;
1438 print "\n*** In ",($path?$path:"./"),"\n";
1439 print "* winemaker found the following list of (potential) targets\n";
1440 print "* $target_list\n";
1441 print "* Type enter to use it as is, your own comma-separated list of\n";
1442 print "* targets, 'none' to assign the source files to a parent directory,\n";
1443 print "* or 'ignore' to ignore everything in this directory tree.\n";
1444 print "* Target list:\n";
1445 $target_list=<STDIN>;
1446 chomp $target_list;
1447 if ($target_list eq "") {
1448 # Keep the target list as is, i.e. do nothing
1449 } elsif ($target_list eq "none") {
1450 # Empty the target list
1451 undef %targets;
1452 } elsif ($target_list eq "ignore") {
1453 # Ignore this subtree altogether
1454 return;
1455 } else {
1456 undef %targets;
1457 foreach my $target (split /,/,$target_list) {
1458 $target =~ s+^\s*++;
1459 $target =~ s+\s*$++;
1460 $targets{$target}=1;
1466 # If we have no project at this level, then transfer all
1467 # the sources to the parent project
1468 $target_count=keys %targets;
1469 if ($target_count == 0) {
1470 if ($project!=$parent_project) {
1471 my $parent_settings=@$parent_project[$P_SETTINGS];
1472 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1473 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1474 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1475 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1476 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1478 return;
1481 # Otherwise add this project to the project list, except for
1482 # the main project which is already in the list.
1483 if ($dirname ne "") {
1484 push @projects,$project;
1487 # Ask for project-wide options
1488 if ($opt_ask_project_options == $OPT_ASK_YES) {
1489 my $flag_desc="";
1490 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1491 $flag_desc="mfc";
1493 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1494 if (defined $flag_desc) {
1495 print "* (currently $flag_desc)\n";
1497 print "* or 'skip' to skip the target specific options,\n";
1498 print "* or 'never' to not be asked this question again:\n";
1499 while (1) {
1500 my $options=<STDIN>;
1501 chomp $options;
1502 if ($options eq "skip") {
1503 $opt_ask_target_options=$OPT_ASK_SKIP;
1504 last;
1505 } elsif ($options eq "never") {
1506 $opt_ask_project_options=$OPT_ASK_NO;
1507 last;
1508 } elsif (source_set_options($project_settings,$options)) {
1509 last;
1511 print "Please re-enter the options:\n";
1515 # - Create the targets
1516 # - Check if we have both libraries and programs
1517 # - Match each target with source files (sort in reverse
1518 # alphabetical order to get the longest matches first)
1519 my @local_dlls=();
1520 my @local_depends=();
1521 my @exe_list=();
1522 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1523 # Create the target...
1524 my $target=[];
1525 target_init($target);
1526 @$target[$T_NAME]=$target_name;
1527 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1528 if ($target_name =~ /\.dll$/) {
1529 @$target[$T_TYPE]=$TT_DLL;
1530 push @local_depends,"$target_name.so";
1531 push @local_dlls,$target_name;
1532 my $canon=canonize($target_name);
1533 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1534 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1535 } else {
1536 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1538 } else {
1539 @$target[$T_TYPE]=$opt_target_type;
1540 push @exe_list,$target;
1541 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1543 my $basename=$target_name;
1544 $basename=~ s/\.(dll|exe)$//i;
1545 # This is the default link list of Visual Studio
1546 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1547 my @std_libraries=qw(uuid);
1548 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1549 @$target[$T_DLLS]=\@std_imports;
1550 @$target[$T_LIBRARIES]=\@std_libraries;
1551 } else {
1552 @$target[$T_DLLS]=[];
1553 @$target[$T_LIBRARIES]=[];
1555 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1556 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1557 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1558 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1561 push @{@$project[$P_TARGETS]},$target;
1563 # Ask for target-specific options
1564 if ($opt_ask_target_options == $OPT_ASK_YES) {
1565 my $flag_desc="";
1566 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1567 $flag_desc=" (mfc";
1569 if ($flag_desc ne "") {
1570 $flag_desc.=")";
1572 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1573 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1574 while (1) {
1575 my $options=<STDIN>;
1576 chomp $options;
1577 if ($options eq "never") {
1578 $opt_ask_target_options=$OPT_ASK_NO;
1579 last;
1580 } elsif (source_set_options($target,$options)) {
1581 last;
1583 print "Please re-enter the options:\n";
1586 if (@$target[$T_FLAGS] & $TF_MFC) {
1587 @$project_settings[$T_FLAGS]|=$TF_MFC;
1588 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1589 push @{@$target[$T_DLLS]},"mfc.dll";
1590 # FIXME: Link with the MFC in the Unix sense, until we
1591 # start exporting the functions properly.
1592 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1593 push @{@$target[$T_LIBRARIES]},"mfc";
1596 # Match sources...
1597 if ($target_count == 1) {
1598 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1599 @$project_settings[$T_SOURCES_C]=[];
1600 @sources_c=();
1602 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1603 @$project_settings[$T_SOURCES_CXX]=[];
1604 @sources_cxx=();
1606 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1607 @$project_settings[$T_SOURCES_RC]=[];
1608 @sources_rc=();
1610 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1611 # No need for sorting these sources
1612 @$project_settings[$T_SOURCES_MISC]=[];
1613 @sources_misc=();
1614 } else {
1615 foreach my $source (@sources_c) {
1616 if ($source =~ /^$basename/i) {
1617 push @{@$target[$T_SOURCES_C]},$source;
1618 $source="";
1621 foreach my $source (@sources_cxx) {
1622 if ($source =~ /^$basename/i) {
1623 push @{@$target[$T_SOURCES_CXX]},$source;
1624 $source="";
1627 foreach my $source (@sources_rc) {
1628 if ($source =~ /^$basename/i) {
1629 push @{@$target[$T_SOURCES_RC]},$source;
1630 $source="";
1633 foreach my $source (@sources_misc) {
1634 if ($source =~ /^$basename/i) {
1635 push @{@$target[$T_SOURCES_MISC]},$source;
1636 $source="";
1640 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1641 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1642 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1643 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1645 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1646 $opt_ask_target_options=$OPT_ASK_YES;
1649 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1650 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1651 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1652 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1653 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1654 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1658 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1659 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1661 # The sources that did not match, if any, go to the extra
1662 # source list of the project settings
1663 foreach my $source (@sources_c) {
1664 if ($source ne "") {
1665 push @{@$project_settings[$T_SOURCES_C]},$source;
1668 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1669 foreach my $source (@sources_cxx) {
1670 if ($source ne "") {
1671 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1674 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1675 foreach my $source (@sources_rc) {
1676 if ($source ne "") {
1677 push @{@$project_settings[$T_SOURCES_RC]},$source;
1680 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1681 foreach my $source (@sources_misc) {
1682 if ($source ne "") {
1683 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1686 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1688 # Finally if we are building both libraries and programs in
1689 # this directory, then the programs should be linked with all
1690 # the libraries
1691 if (@local_dlls > 0 and @exe_list > 0) {
1692 foreach my $target (@exe_list) {
1693 push @{@$target[$T_DLL_PATH]},"-L.";
1694 push @{@$target[$T_DLLS]},@local_dlls;
1700 # Scan the source directories in search of things to build
1701 sub source_scan()
1703 # If there's a single target then this is going to be the default target
1704 if (defined $opt_single_target) {
1705 # Create the main target
1706 my $main_target=[];
1707 target_init($main_target);
1708 @$main_target[$T_NAME]=$opt_single_target;
1709 @$main_target[$T_TYPE]=$opt_target_type;
1711 # Add it to the list
1712 push @{$main_project[$P_TARGETS]},$main_target;
1715 # The main directory is always going to be there
1716 push @projects,\@main_project;
1718 if (defined $opt_work_dir) {
1719 # Now scan the directory tree looking for source files and, maybe, targets
1720 print "Scanning the source directories...\n";
1721 source_scan_directory(\@main_project,"","",0);
1722 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1723 } elsif (defined $opt_work_file) {
1724 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1725 source_scan_project_file(\@main_project,0,$opt_work_file);
1726 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1727 source_scan_workspace_file($opt_work_file);
1732 #####
1734 # Source search
1736 #####
1739 # Performs a directory traversal and renames the files so that:
1740 # - they have the case desired by the user
1741 # - their extension is of the appropriate case
1742 # - they don't contain annoying characters like ' ', '$', '#', ...
1743 # But only perform these changes for source files and directories.
1744 sub fix_file_and_directory_names($);
1745 sub fix_file_and_directory_names($)
1747 my $dirname=$_[0];
1749 my $directory=get_directory_contents($dirname);
1750 foreach my $dentry (@$directory)
1752 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1753 next;
1755 # Set $warn to 1 if the user should be warned of the renaming
1756 my $warn;
1757 my $new_name=$dentry;
1759 if (-f "$dirname/$dentry")
1761 # Don't rename Winemaker's makefiles
1762 next if ($dentry eq "Makefile" and
1763 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1765 # Leave non-source files alone
1766 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
1768 # Only all lowercase extensions are supported (because of
1769 # rules like '.c.o:').
1770 $new_name =~ s/\.C$/.c/;
1771 $new_name =~ s/\.cpp$/.cpp/i;
1772 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1773 $new_name =~ s/\.rc$/.rc/i;
1774 # And this last one is to avoid confusion when running make
1775 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1778 # Adjust the case to the user's preferences
1779 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1780 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1782 $new_name=lc $new_name;
1785 # make doesn't support these characters well
1786 $new_name =~ s/[ \$]/_/g;
1788 # And finally, perform the renaming
1789 if ($new_name ne $dentry)
1791 if ($warn) {
1792 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1794 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1795 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1796 print STDERR " $!\n";
1797 $new_name=$dentry;
1799 else
1801 clear_directory_cache($dirname);
1804 if (-d "$dirname/$new_name") {
1805 fix_file_and_directory_names("$dirname/$new_name");
1812 #####
1814 # Source fixup
1816 #####
1819 # Try to find a file for the specified filename. The attempt is
1820 # case-insensitive which is why it's not trivial. If a match is
1821 # found then we return the pathname with the correct case.
1822 sub search_from($$)
1824 my $dirname=$_[0];
1825 my $path=$_[1];
1826 my $real_path="";
1828 $dirname =~ s/(\.\/)+//;
1829 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1830 $dirname=cwd;
1831 } elsif ($dirname !~ m+^/+) {
1832 $dirname=cwd . "/" . $dirname;
1834 if ($dirname !~ m+/$+) {
1835 $dirname.="/";
1838 foreach my $component (@$path) {
1839 $component=~s/^\"//;
1840 $component=~s/\"$//;
1841 #print " looking for $component in \"$dirname\"\n";
1842 if ($component eq ".") {
1843 # Pass it as is
1844 $real_path.="./";
1845 } elsif ($component eq "..") {
1846 # Go up one level
1847 if ($dirname =~ /\.\.\/$/) {
1848 $dirname.="../";
1849 } else {
1850 $dirname=dirname($dirname) . "/";
1852 $real_path.="../";
1853 } else {
1854 # The file/directory may have been renamed before. Also try to
1855 # match the renamed file.
1856 my $renamed=$component;
1857 $renamed =~ s/[ \$]/_/g;
1858 if ($renamed eq $component) {
1859 undef $renamed;
1862 my $directory=get_directory_contents $dirname;
1863 my $found;
1864 foreach my $dentry (@$directory) {
1865 if ($dentry =~ /^\Q$component\E$/i or
1866 (defined $renamed and $dentry =~ /^$renamed$/i)
1868 $dirname.="$dentry/";
1869 $real_path.="$dentry/";
1870 $found=1;
1871 last;
1874 if (!defined $found) {
1875 # Give up
1876 #print " could not find $component in $dirname\n";
1877 return;
1881 $real_path=~ s+/$++;
1882 #print " -> found $real_path\n";
1883 return $real_path;
1887 # Performs a case-insensitive search for the specified file in the
1888 # include path.
1889 # $line is the line number that should be referenced when an error occurs
1890 # $filename is the file we are looking for
1891 # $dirname is the directory of the file containing the '#include' directive
1892 # if '"' was used, it is an empty string otherwise
1893 # $project and $target specify part of the include path
1894 sub get_real_include_name($$$$$)
1896 my $line=$_[0];
1897 my $filename=$_[1];
1898 my $dirname=$_[2];
1899 my $project=$_[3];
1900 my $target=$_[4];
1902 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a-zA-Z]:[\/\\]?/) {
1903 # This is not a relative path, we cannot make any check
1904 my $warning="path:$filename";
1905 if (!defined $warnings{$warning}) {
1906 $warnings{$warning}="1";
1907 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1908 print STDERR "$line: $filename\n";
1910 } else {
1911 # Here's how we proceed:
1912 # - split the filename we look for into its components
1913 # - then for each directory in the include path
1914 # - trace the directory components starting from that directory
1915 # - if we fail to find a match at any point then continue with
1916 # the next directory in the include path
1917 # - otherwise, rejoice, our quest is over.
1918 my @file_components=split /[\/\\]+/, $filename;
1919 #print " Searching for $filename from @$project[$P_PATH]\n";
1921 my $real_filename;
1922 if ($dirname ne "") {
1923 # This is an 'include ""' -> look in dirname first.
1924 #print " in $dirname (include \"\")\n";
1925 $real_filename=search_from($dirname,\@file_components);
1926 if (defined $real_filename) {
1927 return $real_filename;
1930 my $project_settings=@$project[$P_SETTINGS];
1931 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1932 my $dirname=$include;
1933 $dirname=~ s+^-I++;
1934 $dirname=~ s+\s$++;
1935 if (!is_absolute($dirname)) {
1936 $dirname="@$project[$P_PATH]$dirname";
1937 } else {
1938 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1939 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1941 #print " in $dirname\n";
1942 $real_filename=search_from("$dirname",\@file_components);
1943 if (defined $real_filename) {
1944 return $real_filename;
1947 my $dotdotpath=@$project[$P_PATH];
1948 $dotdotpath =~ s/[^\/]+/../g;
1949 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1950 my $dirname=$include;
1951 $dirname=~ s+^-I++;
1952 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1953 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1954 #print " in $dirname (global setting)\n";
1955 $real_filename=search_from("$dirname",\@file_components);
1956 if (defined $real_filename) {
1957 return $real_filename;
1961 $filename =~ s+\\\\+/+g; # in include ""
1962 $filename =~ s+\\+/+g; # in include <> !
1963 if ($opt_lower_include) {
1964 return lc "$filename";
1966 return $filename;
1969 sub print_pack($$$)
1971 my $indent=$_[0];
1972 my $size=$_[1];
1973 my $trailer=$_[2];
1975 if ($size =~ /^(1|2|4|8)$/) {
1976 print FILEO "$indent#include <pshpack$size.h>$trailer";
1977 } else {
1978 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1979 print FILEO "$indent#include <pshpack4.h>$trailer";
1984 # 'Parses' a source file and fixes constructs that would not work with
1985 # Winelib. The parsing is rather simple and not all non-portable features
1986 # are corrected. The most important feature that is corrected is the case
1987 # and path separator of '#include' directives. This requires that each
1988 # source file be associated to a project & target so that the proper
1989 # include path is used.
1990 # Also note that the include path is relative to the directory in which the
1991 # compiler is run, i.e. that of the project, not to that of the file.
1992 sub fix_file($$$)
1994 my $filename=$_[0];
1995 my $project=$_[1];
1996 my $target=$_[2];
1997 $filename="@$project[$P_PATH]$filename";
1998 if (! -e $filename) {
1999 return;
2002 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
2003 my $dirname=dirname($filename);
2004 my $is_mfc=0;
2005 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
2006 $is_mfc=1;
2009 print " $filename\n";
2010 if (! -e "$filename.bak") {
2011 if (!copy("$filename","$filename.bak")) {
2012 print STDERR "error: unable to make a backup of $filename:\n";
2013 print STDERR " $!\n";
2014 return;
2017 if (!open(FILEI,"$filename.bak")) {
2018 print STDERR "error: unable to open $filename.bak for reading:\n";
2019 print STDERR " $!\n";
2020 return;
2022 if (!open(FILEO,">$filename")) {
2023 print STDERR "error: unable to open $filename for writing:\n";
2024 print STDERR " $!\n";
2025 return;
2027 my $line=0;
2028 my $modified=0;
2029 my $rc_block_depth=0;
2030 my $rc_textinclude_state=0;
2031 my @pack_stack;
2032 while (<FILEI>) {
2033 # Remove any trailing CtrlZ, which isn't strictly in the file
2034 if (/\x1A/) {
2035 s/\x1A//;
2036 last if (/^$/)
2038 $line++;
2039 s/\r\n$/\n/;
2040 if (!/\n$/) {
2041 # Make sure all files are '\n' terminated
2042 $_ .= "\n";
2044 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2045 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2046 # the RC files it generates (even in non-MFC projects). So we replace
2047 # it with 'winresrc.h' its very close standard cousin so that non MFC
2048 # projects can compile in Wine without the MFC sources.
2049 my $warning="mfc:afxres.h";
2050 if (!defined $warnings{$warning}) {
2051 $warnings{$warning}="1";
2052 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2053 print STDERR "warning: the above warning is issued only once\n";
2055 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2056 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2057 print FILEO "$1$2\"winresrc.h\"$'";
2058 $modified=1;
2060 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2061 my $from_file=($2 eq "<"?"":$dirname);
2062 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2063 print FILEO "$1$2$real_include_name$4$'";
2064 $modified|=($real_include_name ne $3);
2066 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2067 # Pragma pack handling
2069 # pack_stack is an array of references describing the stack of
2070 # pack directives currently in effect. Each directive if described
2071 # by a reference to an array containing:
2072 # - "push" for pack(push,...) directives, "" otherwise
2073 # - the directive's identifier at index 1
2074 # - the directive's alignment value at index 2
2076 # Don't believe a word of what the documentation says: it's all wrong.
2077 # The code below is based on the actual behavior of Visual C/C++ 6.
2078 my $pack_indent=$1;
2079 my $pack_header=$2;
2080 if (/^(\))/) {
2081 # pragma pack()
2082 # Pushes the default stack alignment
2083 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2084 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2085 print_pack($pack_indent,4,$');
2086 push @pack_stack, [ "", "", 4 ];
2088 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2089 # pragma pack(pop)
2090 # pragma pack(pop,n)
2091 # Goes up the stack until it finds a pack(push,...), and pops it
2092 # Ignores any pack(n) entry
2093 # Issues a warning if the pack is of the form pack(push,label)
2094 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2095 my $pack_comment=$';
2096 $pack_comment =~ s/^\s*//;
2097 if ($pack_comment ne "") {
2098 print FILEO "$pack_indent$pack_comment";
2100 while (1) {
2101 my $alignment=pop @pack_stack;
2102 if (!defined $alignment) {
2103 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2104 last;
2106 if (@$alignment[1]) {
2107 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2109 print FILEO "$pack_indent#include <poppack.h>\n";
2110 if (@$alignment[0]) {
2111 last;
2115 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2116 # pragma pack(pop,label[,n])
2117 # Goes up the stack until finding a pack(push,...) and pops it.
2118 # 'n', if specified, is ignored.
2119 # Ignores any pack(n) entry
2120 # Issues a warning if the label of the pack does not match,
2121 # or if it is in fact a pack(push,n)
2122 my $label=$2;
2123 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2124 my $pack_comment=$';
2125 $pack_comment =~ s/^\s*//;
2126 if ($pack_comment ne "") {
2127 print FILEO "$pack_indent$pack_comment";
2129 while (1) {
2130 my $alignment=pop @pack_stack;
2131 if (!defined $alignment) {
2132 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2133 last;
2135 if (@$alignment[1] and @$alignment[1] ne $label) {
2136 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2138 print FILEO "$pack_indent#include <poppack.h>\n";
2139 if (@$alignment[0]) {
2140 last;
2144 } elsif (/^(push\s*\))/) {
2145 # pragma pack(push)
2146 # Push the current alignment
2147 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2148 if (@pack_stack > 0) {
2149 my $alignment=$pack_stack[$#pack_stack];
2150 print_pack($pack_indent,@$alignment[2],$');
2151 push @pack_stack, [ "push", "", @$alignment[2] ];
2152 } else {
2153 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2154 print_pack($pack_indent,4,$');
2155 push @pack_stack, [ "push", "", 4 ];
2158 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2159 # pragma pack([push,]n)
2160 # Push new alignment n
2161 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2162 print_pack($pack_indent,$3,"$'");
2163 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2165 } elsif (/^((\w+)\s*\))/) {
2166 # pragma pack(label)
2167 # label must in fact be a macro that resolves to an integer
2168 # Then behaves like 'pragma pack(n)'
2169 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2170 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2171 print_pack($pack_indent,4,$');
2172 push @pack_stack, [ "", "", 4 ];
2174 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2175 # pragma pack(push,label[,n])
2176 # Pushes a new label on the stack. It is possible to push the same
2177 # label multiple times. If 'n' is omitted then the alignment is
2178 # unchanged. Otherwise it becomes 'n'.
2179 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2180 my $size;
2181 if (defined $4) {
2182 $size=$4;
2183 } elsif (@pack_stack > 0) {
2184 my $alignment=$pack_stack[$#pack_stack];
2185 $size=@$alignment[2];
2186 } else {
2187 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2188 $size=4;
2190 print_pack($pack_indent,$size,$');
2191 push @pack_stack, [ "push", $2, $size ];
2193 } else {
2194 # pragma pack(??? -> What's that?
2195 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2196 print FILEO "$pack_indent$pack_header$_";
2199 $modified=1;
2201 } elsif ($is_rc) {
2202 if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT|RTF)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2203 my $from_file=($5 eq "<"?"":$dirname);
2204 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2205 print FILEO "$1$5$real_include_name$7$'";
2206 $modified|=($real_include_name ne $6);
2208 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2209 my $from_file=($2 eq "<"?"":$dirname);
2210 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2211 print FILEO "$1$2$real_include_name$4$'";
2212 $modified|=($real_include_name ne $3);
2214 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2215 $rc_textinclude_state=1;
2216 print FILEO;
2218 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2219 print FILEO "$1winresrc.h$2$'";
2220 $modified=1;
2222 } elsif (/^\s*BEGIN(\W.*)?$/) {
2223 $rc_textinclude_state|=2;
2224 $rc_block_depth++;
2225 print FILEO;
2227 } elsif (/^\s*END(\W.*)?$/) {
2228 $rc_textinclude_state=0;
2229 if ($rc_block_depth>0) {
2230 $rc_block_depth--;
2232 print FILEO;
2234 } else {
2235 print FILEO;
2238 } else {
2239 print FILEO;
2243 close(FILEI);
2244 close(FILEO);
2245 if ($opt_backup == 0 or $modified == 0) {
2246 if (!unlink("$filename.bak")) {
2247 print STDERR "error: unable to delete $filename.bak:\n";
2248 print STDERR " $!\n";
2254 # Analyzes each source file in turn to find and correct issues
2255 # that would cause it not to compile.
2256 sub fix_source()
2258 print "Fixing the source files...\n";
2259 foreach my $project (@projects) {
2260 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2261 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2262 fix_file($source,$project,$target);
2270 #####
2272 # File generation
2274 #####
2277 # A convenience function to generate all the lists (defines,
2278 # C sources, C++ source, etc.) in the Makefile
2279 sub generate_list($$$;$)
2281 my $name=$_[0];
2282 my $last=$_[1];
2283 my $list=$_[2];
2284 my $data=$_[3];
2285 my $first=$name;
2287 if ($name) {
2288 printf FILEO "%-22s=",$name;
2290 if (defined $list) {
2291 foreach my $item (@$list) {
2292 my $value;
2293 if (defined $data) {
2294 $value=&$data($item);
2295 } else {
2296 if (defined $item) {
2297 $value=$item;
2298 } else {
2299 $value="";
2302 if ($value ne "") {
2303 if ($first) {
2304 print FILEO " $value";
2305 $first=0;
2306 } else {
2307 print FILEO " \\\n\t\t\t$value";
2312 if ($last) {
2313 print FILEO "\n";
2318 # Generates a project's Makefile and all the target files
2319 sub generate_project_files($)
2321 my $project=$_[0];
2322 my $project_settings=@$project[$P_SETTINGS];
2323 my @dll_list=();
2324 my @lib_list=();
2325 my @exe_list=();
2327 # Then sort the targets and separate the libraries from the programs
2328 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2329 if (@$target[$T_TYPE] == $TT_DLL) {
2330 push @dll_list,$target;
2331 } elsif (@$target[$T_TYPE] == $TT_LIB) {
2332 push @lib_list,$target;
2333 } else {
2334 push @exe_list,$target;
2337 @$project[$P_TARGETS]=[];
2338 push @{@$project[$P_TARGETS]}, @dll_list;
2339 push @{@$project[$P_TARGETS]}, @lib_list;
2340 push @{@$project[$P_TARGETS]}, @exe_list;
2342 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2343 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2344 print STDERR " $!\n";
2345 return;
2348 print FILEO "### Generated by Winemaker $version\n";
2349 print FILEO "\n\n";
2351 generate_list("SRCDIR",1,[ "." ]);
2352 if (@$project[$P_PATH] eq "") {
2353 # This is the main project. It is also responsible for recursively
2354 # calling the other projects
2355 generate_list("SUBDIRS",1,\@projects,sub
2357 if ($_[0] != \@main_project) {
2358 my $subdir=@{$_[0]}[$P_PATH];
2359 $subdir =~ s+/$++;
2360 return $subdir;
2362 # Eliminating the main project by returning undefined!
2365 if (@{@$project[$P_TARGETS]} > 0) {
2366 generate_list("DLLS",1,\@dll_list,sub
2368 return @{$_[0]}[$T_NAME];
2370 generate_list("LIBS",1,\@lib_list,sub
2372 return @{$_[0]}[$T_NAME];
2374 generate_list("EXES",1,\@exe_list,sub
2376 return "@{$_[0]}[$T_NAME]";
2378 print FILEO "\n\n\n";
2380 print FILEO "### Common settings\n\n";
2381 # Make it so that the project-wide settings override the global settings
2382 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2383 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2384 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2385 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2386 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2387 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2388 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2389 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2390 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2391 print FILEO "\n\n";
2393 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2394 @{@$project_settings[$T_SOURCES_CXX]}+
2395 @{@$project_settings[$T_SOURCES_RC]};
2396 my $no_extra=($extra_source_count == 0);
2397 if (!$no_extra) {
2398 print FILEO "### Extra source lists\n\n";
2399 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2400 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2401 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2402 print FILEO "\n";
2403 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2404 print FILEO "\n\n\n";
2407 # Iterate over all the targets...
2408 foreach my $target (@{@$project[$P_TARGETS]}) {
2409 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2410 my $canon=canonize("@$target[$T_NAME]");
2411 $canon =~ s+_so$++;
2413 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2414 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2415 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2416 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2417 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2418 generate_list("${canon}_ARFLAGS",1,@$target[$T_ARFLAGS]);
2419 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2420 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2421 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2422 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2423 print FILEO "\n";
2424 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2425 print FILEO "\n\n\n";
2427 print FILEO "### Global source lists\n\n";
2428 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2430 my $canon=canonize(@{$_[0]}[$T_NAME]);
2431 $canon =~ s+_so$++;
2432 return "\$(${canon}_C_SRCS)";
2434 if (!$no_extra) {
2435 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2437 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2439 my $canon=canonize(@{$_[0]}[$T_NAME]);
2440 $canon =~ s+_so$++;
2441 return "\$(${canon}_CXX_SRCS)";
2443 if (!$no_extra) {
2444 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2446 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2448 my $canon=canonize(@{$_[0]}[$T_NAME]);
2449 $canon =~ s+_so$++;
2450 return "\$(${canon}_RC_SRCS)";
2452 if (!$no_extra) {
2453 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2456 print FILEO "\n\n";
2457 print FILEO "### Tools\n\n";
2458 print FILEO "CC = winegcc\n";
2459 print FILEO "CXX = wineg++\n";
2460 print FILEO "RC = wrc\n";
2461 print FILEO "AR = ar\n";
2462 print FILEO "\n\n";
2464 print FILEO "### Generic targets\n\n";
2465 print FILEO "all:";
2466 if (@$project[$P_PATH] eq "") {
2467 print FILEO " \$(SUBDIRS)";
2469 if (@{@$project[$P_TARGETS]} > 0) {
2470 print FILEO " \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2472 print FILEO "\n\n";
2473 print FILEO "### Build rules\n";
2474 print FILEO "\n";
2475 print FILEO ".PHONY: all clean dummy\n";
2476 print FILEO "\n";
2477 print FILEO "\$(SUBDIRS): dummy\n";
2478 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2479 print FILEO "\n";
2480 print FILEO "# Implicit rules\n";
2481 print FILEO "\n";
2482 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2483 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2484 print FILEO "\n";
2485 print FILEO ".c.o:\n";
2486 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2487 print FILEO "\n";
2488 print FILEO ".cpp.o:\n";
2489 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2490 print FILEO "\n";
2491 print FILEO ".cxx.o:\n";
2492 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2493 print FILEO "\n";
2494 print FILEO ".rc.res:\n";
2495 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2496 print FILEO "\n";
2497 print FILEO "# Rules for cleaning\n";
2498 print FILEO "\n";
2499 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2500 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2501 print FILEO "\n";
2502 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2503 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2504 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2505 print FILEO "\n";
2506 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2507 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2508 print FILEO "\n";
2509 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2510 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2511 print FILEO "\n";
2513 if (@{@$project[$P_TARGETS]} > 0) {
2514 print FILEO "### Target specific build rules\n";
2515 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2516 foreach my $target (@{@$project[$P_TARGETS]}) {
2517 my $canon=canonize("@$target[$T_NAME]");
2518 $canon =~ s/_so$//;
2520 if (@$target[$T_TYPE] == $TT_DLL && (@$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2521 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2522 } elsif (@$target[$T_TYPE] == $TT_DLL) {
2523 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2524 } else {
2525 print FILEO "\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2528 if (@$target[$T_TYPE] == $TT_LIB) {
2529 print FILEO "\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2530 } else {
2531 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2532 print FILEO "\t\$(CXX)";
2533 } else {
2534 print FILEO "\t\$(CC)";
2536 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2538 print FILEO "\n\n";
2541 close(FILEO);
2547 # This is where we finally generate files. In fact this method does not
2548 # do anything itself but calls the methods that do the actual work.
2549 sub generate()
2551 print "Generating project files...\n";
2553 foreach my $project (@projects) {
2554 my $path=@$project[$P_PATH];
2555 if ($path eq "") {
2556 $path=".";
2557 } else {
2558 $path =~ s+/$++;
2560 print " $path\n";
2561 generate_project_files($project);
2567 #####
2569 # Option defaults
2571 #####
2573 $opt_backup=1;
2574 $opt_lower=$OPT_LOWER_UPPERCASE;
2575 $opt_lower_include=1;
2577 $opt_work_dir=undef;
2578 $opt_single_target=undef;
2579 $opt_target_type=$TT_GUIEXE;
2580 $opt_flags=0;
2581 $opt_arch=$OPT_ARCH_DEFAULT;
2582 $opt_is_interactive=$OPT_ASK_NO;
2583 $opt_ask_project_options=$OPT_ASK_NO;
2584 $opt_ask_target_options=$OPT_ASK_NO;
2585 $opt_no_generated_files=0;
2586 $opt_no_source_fix=0;
2587 $opt_no_banner=0;
2591 #####
2593 # Main
2595 #####
2597 sub print_banner()
2599 print "Winemaker $version\n";
2600 print "Copyright 2000-2004 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2601 print "Copyright 2004 Dimitrie O. Paun\n";
2602 print "Copyright 2009-2011 André Hentschel\n";
2605 sub usage()
2607 print_banner();
2608 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2609 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2610 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2611 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2612 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2613 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2614 print STDERR " [--generated-files|--nogenerated-files]\n";
2615 print STDERR " [--wine32]\n";
2616 print STDERR " work_directory|project_file|workspace_file\n";
2617 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2618 print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
2619 print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2620 print STDERR "\tPlease read the manual page before use.\n";
2621 exit (2);
2624 target_init(\@global_settings);
2626 while (@ARGV>0) {
2627 my $arg=shift @ARGV;
2628 # General options
2629 if ($arg eq "--nobanner") {
2630 $opt_no_banner=1;
2631 } elsif ($arg eq "--backup") {
2632 $opt_backup=1;
2633 } elsif ($arg eq "--nobackup") {
2634 $opt_backup=0;
2635 } elsif ($arg eq "--single-target") {
2636 $opt_single_target=shift @ARGV;
2637 } elsif ($arg eq "--lower-none") {
2638 $opt_lower=$OPT_LOWER_NONE;
2639 } elsif ($arg eq "--lower-all") {
2640 $opt_lower=$OPT_LOWER_ALL;
2641 } elsif ($arg eq "--lower-uppercase") {
2642 $opt_lower=$OPT_LOWER_UPPERCASE;
2643 } elsif ($arg eq "--lower-include") {
2644 $opt_lower_include=1;
2645 } elsif ($arg eq "--nolower-include") {
2646 $opt_lower_include=0;
2647 } elsif ($arg eq "--nosource-fix") {
2648 $opt_no_source_fix=1;
2649 } elsif ($arg eq "--generated-files") {
2650 $opt_no_generated_files=0;
2651 } elsif ($arg eq "--nogenerated-files") {
2652 $opt_no_generated_files=1;
2653 } elsif ($arg eq "--wine32") {
2654 $opt_arch=$OPT_ARCH_32;
2655 } elsif ($arg =~ /^-D/) {
2656 push @{$global_settings[$T_DEFINES]},$arg;
2657 } elsif ($arg =~ /^-I/) {
2658 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2659 } elsif ($arg =~ /^-P/) {
2660 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2661 } elsif ($arg =~ /^-i/) {
2662 push @{$global_settings[$T_DLLS]},$';
2663 } elsif ($arg =~ /^-L/) {
2664 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2665 } elsif ($arg =~ /^-l/) {
2666 push @{$global_settings[$T_LIBRARIES]},$arg;
2668 # 'Source'-based method options
2669 } elsif ($arg eq "--dll") {
2670 $opt_target_type=$TT_DLL;
2671 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2672 $opt_target_type=$TT_GUIEXE;
2673 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2674 $opt_target_type=$TT_CUIEXE;
2675 } elsif ($arg eq "--interactive") {
2676 $opt_is_interactive=$OPT_ASK_YES;
2677 $opt_ask_project_options=$OPT_ASK_YES;
2678 $opt_ask_target_options=$OPT_ASK_YES;
2679 } elsif ($arg eq "--mfc") {
2680 $opt_flags|=$TF_MFC;
2681 } elsif ($arg eq "--nomfc") {
2682 $opt_flags&=~$TF_MFC;
2683 $opt_flags|=$TF_NOMFC;
2684 } elsif ($arg eq "--nodlls") {
2685 $opt_flags|=$TF_NODLLS;
2686 } elsif ($arg eq "--nomsvcrt") {
2687 $opt_flags|=$TF_NOMSVCRT;
2689 # Catch errors
2690 } else {
2691 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2692 if (!defined $opt_work_dir and !defined $opt_work_file) {
2693 if (-f $arg) {
2694 $opt_work_file=$arg;
2696 else {
2697 $opt_work_dir=$arg;
2699 } else {
2700 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2701 usage();
2703 } else {
2704 usage();
2709 if (!defined $opt_work_dir and !defined $opt_work_file) {
2710 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2711 usage();
2712 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2713 print STDERR "error: could not chdir to the work directory\n";
2714 print STDERR " $!\n";
2715 usage();
2718 if ($opt_no_banner == 0) {
2719 print_banner();
2722 project_init(\@main_project, "", \@global_settings);
2724 # Fix the file and directory names
2725 fix_file_and_directory_names(".");
2727 # Scan the sources to identify the projects and targets
2728 source_scan();
2730 # Fix the source files
2731 if (! $opt_no_source_fix) {
2732 fix_source();
2735 # Generate the Makefile and the spec file
2736 if (! $opt_no_generated_files) {
2737 generate();