d3d10core: Create wined3d queries for queries.
[wine/multimedia.git] / tools / winemaker
blobaf2624320d0e5a3eb5f6da428e0f3f1181aff7d6
1 #!/usr/bin/perl -w
2 use utf8;
3 use strict;
5 # Copyright 2000-2004 François Gouget for CodeWeavers
6 # Copyright 2004 Dimitrie O. Paun
7 # Copyright 2009-2012 André Hentschel
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 my $version="0.8.4";
26 use Cwd;
27 use File::Basename;
28 use File::Copy;
32 #####
34 # Options
36 #####
38 # The following constants define what we do with the case of filenames
41 # Never rename a file to lowercase
42 my $OPT_LOWER_NONE=0;
45 # Rename all files to lowercase
46 my $OPT_LOWER_ALL=1;
49 # Rename only files that are all uppercase to lowercase
50 my $OPT_LOWER_UPPERCASE=2;
53 # The following constants define whether to ask questions or not
56 # No (synonym of never)
57 my $OPT_ASK_NO=0;
60 # Yes (always)
61 my $OPT_ASK_YES=1;
64 # Skip the questions till the end of this scope
65 my $OPT_ASK_SKIP=-1;
68 # The following constants define the architecture
71 # Default Architecture will be chosen
72 my $OPT_ARCH_DEFAULT=0;
75 # 32-Bit Target
76 my $OPT_ARCH_32=32;
79 # 64-Bit Target
80 my $OPT_ARCH_64=64;
83 # General options
86 # This is the directory in which winemaker will operate.
87 my $opt_work_dir;
90 # This is the file in which winemaker will operate if a project file is specified.
91 my $opt_work_file;
94 # Make a backup of the files
95 my $opt_backup;
98 # Defines which files to rename
99 my $opt_lower;
102 # If we don't find the file referenced by an include, lower it
103 my $opt_lower_include;
106 # If true then winemaker should not attempt to fix the source. This is
107 # useful if the source is known to be already in a suitable form and is
108 # readonly
109 my $opt_no_source_fix;
111 # Options for the 'Source' method
114 # Specifies that we have only one target so that all sources relate
115 # to this target. By default this variable is left undefined which
116 # means winemaker should try to find out by itself what the targets
117 # are. If not undefined then this contains the name of the default
118 # target (without the extension).
119 my $opt_single_target;
122 # If '$opt_single_target' has been specified then this is the type of
123 # that target. Otherwise it specifies whether the default target type
124 # is guiexe or cuiexe.
125 my $opt_target_type;
128 # Contains the default set of flags to be used when creating a new target.
129 my $opt_flags;
132 # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
133 my $opt_arch;
136 # If true then winemaker should ask questions to the user as it goes
137 # along.
138 my $opt_is_interactive;
139 my $opt_ask_project_options;
140 my $opt_ask_target_options;
143 # If false then winemaker should not generate the makefiles.
144 my $opt_no_generated_files;
147 # Specifies not to print the banner if set.
148 my $opt_no_banner;
152 #####
154 # Target modelization
156 #####
158 # The description of a target is stored in an array. The constants
159 # below identify what is stored at each index of the array.
162 # This is the name of the target.
163 my $T_NAME=0;
166 # Defines the type of target we want to build. See the TT_xxx
167 # constants below
168 my $T_TYPE=1;
171 # This is a bitfield containing flags refining the way the target
172 # should be handled. See the TF_xxx constants below
173 my $T_FLAGS=2;
176 # This is a reference to an array containing the list of the
177 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
178 my $T_SOURCES_C=3;
179 my $T_SOURCES_CXX=4;
180 my $T_SOURCES_RC=5;
181 my $T_SOURCES_MISC=6;
184 # This is a reference to an array containing the list of
185 # C compiler options
186 my $T_CEXTRA=7;
189 # This is a reference to an array containing the list of
190 # C++ compiler options
191 my $T_CXXEXTRA=8;
194 # This is a reference to an array containing the list of
195 # RC compiler options
196 my $T_RCEXTRA=9;
199 # This is a reference to an array containing the list of macro
200 # definitions
201 my $T_DEFINES=10;
204 # This is a reference to an array containing the list of directory
205 # names that constitute the include path
206 my $T_INCLUDE_PATH=11;
209 # Flags for the linker
210 my $T_LDFLAGS=12;
213 # Flags for the archiver
214 my $T_ARFLAGS=13;
217 # Same as T_INCLUDE_PATH but for the dll search path
218 my $T_DLL_PATH=14;
221 # The list of Windows dlls to import
222 my $T_DLLS=15;
225 # Same as T_INCLUDE_PATH but for the library search path
226 my $T_LIBRARY_PATH=16;
229 # The list of Unix libraries to link with
230 my $T_LIBRARIES=17;
233 # The following constants define the recognized types of target
236 # This is not a real target. This type of target is used to collect
237 # the sources that don't seem to belong to any other target. Thus no
238 # real target is generated for them, we just put the sources of the
239 # fake target in the global source list.
240 my $TT_SETTINGS=0;
243 # For executables in the windows subsystem
244 my $TT_GUIEXE=1;
247 # For executables in the console subsystem
248 my $TT_CUIEXE=2;
251 # For dynamically linked libraries
252 my $TT_DLL=3;
255 # For static libraries
256 my $TT_LIB=4;
259 # The following constants further refine how the target should be handled
262 # This target is an MFC-based target
263 my $TF_MFC=4;
266 # User has specified --nomfc option for this target or globally
267 my $TF_NOMFC=8;
270 # --nodlls option: Do not use standard DLL set
271 my $TF_NODLLS=16;
274 # --nomsvcrt option: Do not link with msvcrt
275 my $TF_NOMSVCRT=32;
278 # This target has a def file (only use it with TT_DLL)
279 my $TF_HASDEF=64;
282 # This target has C++ files named *.cxx (instead of *.cpp)
283 my $TF_HASCXX=128;
286 # Initialize a target:
287 # - set the target type to TT_SETTINGS, i.e. no real target will
288 # be generated.
289 sub target_init($)
291 my $target=$_[0];
293 @$target[$T_TYPE]=$TT_SETTINGS;
294 @$target[$T_FLAGS]=$opt_flags;
295 @$target[$T_SOURCES_C]=[];
296 @$target[$T_SOURCES_CXX]=[];
297 @$target[$T_SOURCES_RC]=[];
298 @$target[$T_SOURCES_MISC]=[];
299 @$target[$T_CEXTRA]=[];
300 @$target[$T_CXXEXTRA]=[];
301 @$target[$T_RCEXTRA]=[];
302 @$target[$T_DEFINES]=[];
303 @$target[$T_INCLUDE_PATH]=[];
304 @$target[$T_LDFLAGS]=[];
305 @$target[$T_ARFLAGS]=[];
306 @$target[$T_DLL_PATH]=[];
307 @$target[$T_DLLS]=[];
308 @$target[$T_LIBRARY_PATH]=[];
309 @$target[$T_LIBRARIES]=[];
314 #####
316 # Project modelization
318 #####
320 # First we have the notion of project. A project is described by an
321 # array (since we don't have structs in perl). The constants below
322 # identify what is stored at each index of the array.
325 # This is the path in which this project is located. In other
326 # words, this is the path to the Makefile.
327 my $P_PATH=0;
330 # This index contains a reference to an array containing the project-wide
331 # settings. The structure of that arrray is actually identical to that of
332 # a regular target since it can also contain extra sources.
333 my $P_SETTINGS=1;
336 # This index contains a reference to an array of targets for this
337 # project. Each target describes how an executable or library is to
338 # be built. For each target this description takes the same form as
339 # that of the project: an array. So this entry is an array of arrays.
340 my $P_TARGETS=2;
343 # Initialize a project:
344 # - set the project's path
345 # - initialize the target list
346 # - create a default target (will be removed later if unnecessary)
347 sub project_init($$$)
349 my ($project, $path, $global_settings)=@_;
351 my $project_settings=[];
352 target_init($project_settings);
353 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
354 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
355 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
356 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
357 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
358 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
360 @$project[$P_PATH]=$path;
361 @$project[$P_SETTINGS]=$project_settings;
362 @$project[$P_TARGETS]=[];
367 #####
369 # Global variables
371 #####
373 my %warnings;
375 my %templates;
378 # This maps a directory name to a reference to an array listing
379 # its contents (files and directories)
380 my %directories;
383 # Contains the list of all projects. This list tells us what are
384 # the subprojects of the main Makefile and where we have to generate
385 # Makefiles.
386 my @projects=();
389 # This is the main project, i.e. the one in the "." directory.
390 # It may well be empty in which case the main Makefile will only
391 # call out subprojects.
392 my @main_project;
395 # Contains the defaults for the include path, etc.
396 # We store the defaults as if this were a target except that we only
397 # exploit the defines, include path, library path, library list and misc
398 # sources fields.
399 my @global_settings;
403 #####
405 # Utility functions
407 #####
410 # Cleans up a name to make it an acceptable Makefile
411 # variable name.
412 sub canonize($)
414 my $name=$_[0];
416 $name =~ tr/a-zA-Z0-9_/_/c;
417 return $name;
421 # Returns true is the specified pathname is absolute.
422 # Note: pathnames that start with a variable '$' or
423 # '~' are considered absolute.
424 sub is_absolute($)
426 my $path=$_[0];
428 return ($path =~ /^[\/~\$]/);
432 # Retrieves the contents of the specified directory.
433 # We either get it from the directories hashtable which acts as a
434 # cache, or use opendir, readdir, closedir and store the result
435 # in the hashtable.
436 sub get_directory_contents($)
438 my $dirname=$_[0];
439 my $directory;
441 #print "getting the contents of $dirname\n";
443 # check for a cached version
444 $dirname =~ s+/$++;
445 if ($dirname eq "") {
446 $dirname=cwd;
448 $directory=$directories{$dirname};
449 if (defined $directory) {
450 #print "->@$directory\n";
451 return $directory;
454 # Read this directory
455 if (opendir(DIRECTORY, "$dirname")) {
456 my @files=readdir DIRECTORY;
457 closedir(DIRECTORY);
458 $directory=\@files;
459 } else {
460 # Return an empty list
461 #print "error: cannot open $dirname\n";
462 my @files;
463 $directory=\@files;
465 #print "->@$directory\n";
466 $directories{$dirname}=$directory;
467 return $directory;
471 # Removes a directory from the cache.
472 # This is needed if one of its files or subdirectory has been renamed.
473 sub clear_directory_cache($)
475 my ($dirname)=@_;
476 delete $directories{$dirname};
480 #####
482 # 'Source'-based Project analysis
484 #####
487 # Allows the user to specify makefile and target specific options
488 # - target: the structure in which to store the results
489 # - options: the string containing the options
490 sub source_set_options($$)
492 my $target=$_[0];
493 my $options=$_[1];
495 #FIXME: we must deal with escaping of stuff and all
496 foreach my $option (split / /,$options) {
497 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
498 push @{@$target[$T_DEFINES]},$option;
499 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
500 push @{@$target[$T_INCLUDE_PATH]},$option;
501 } elsif ($option =~ /^-P/) {
502 push @{@$target[$T_DLL_PATH]},"-L$'";
503 } elsif ($option =~ /^-i/) {
504 push @{@$target[$T_DLLS]},"$'";
505 } elsif ($option =~ /^-L/) {
506 push @{@$target[$T_LIBRARY_PATH]},$option;
507 } elsif ($option =~ /^-l/) {
508 push @{@$target[$T_LIBRARIES]},"$'";
509 } elsif ($option =~ /^--mfc/) {
510 @$target[$T_FLAGS]|=$TF_MFC;
511 @$target[$T_FLAGS]&=~$TF_NOMFC;
512 } elsif ($option =~ /^--nomfc/) {
513 @$target[$T_FLAGS]&=~$TF_MFC;
514 @$target[$T_FLAGS]|=$TF_NOMFC;
515 } elsif ($option =~ /^--nodlls/) {
516 @$target[$T_FLAGS]|=$TF_NODLLS;
517 } elsif ($option =~ /^--nomsvcrt/) {
518 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
519 } else {
520 print STDERR "error: unknown option \"$option\"\n";
521 return 0;
524 return 1;
528 # Scans the specified project file to:
529 # - get a list of targets for this project
530 # - get some settings
531 # - get the list of source files
532 sub source_scan_project_file($$$);
533 sub source_scan_project_file($$$)
535 # a reference to the parent's project
536 my $parent_project=$_[0];
537 # 0 if it is a single project, 1 if it is part of a workspace
538 my $is_sub_project=$_[1];
539 # the name of the project file, with complete path, or without if in
540 # the same directory
541 my $filename=$_[2];
543 # reference to the project for this file. May not be used
544 my $project;
545 # list of sources found in the current file
546 my @sources_c=();
547 my @sources_cxx=();
548 my @sources_rc=();
549 my @sources_misc=();
550 # some more settings
551 my $path=dirname($filename);
552 my $prj_target_cflags;
553 my $prj_target_defines;
554 my $prj_target_ldflags;
555 my $prj_target_libs;
556 my $prj_name;
557 my $found_cfg=0;
558 my $prj_cfg;
559 my $prj_target_type=$TT_GUIEXE;
560 my @prj_target_options;
562 if (!($path=~/\/$/)) {
563 $path.="/";
566 $project=$parent_project;
567 my $project_settings=@$project[$P_SETTINGS];
569 if ($filename =~ /.dsp$/i) {
570 # First find out what this project file contains:
571 # collect all sources, find targets and settings
572 if (!open(FILEI,$filename)) {
573 print STDERR "error: unable to open $filename for reading:\n";
574 print STDERR " $!\n";
575 return;
577 my $sfilet;
578 while (<FILEI>) {
579 # Remove any trailing CtrlZ, which isn't strictly in the file
580 if (/\x1A/) {
581 s/\x1A//;
582 last if (/^$/)
585 # Remove any trailing CrLf
586 s/\r\n$/\n/;
587 if (!/\n$/) {
588 # Make sure all lines are '\n' terminated
589 $_ .= "\n";
592 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
593 $prj_name="$1";
594 $prj_name=~s/\s+/_/g;
595 #print $prj_name;
596 next;
597 } elsif (/^# TARGTYPE/) {
598 if (/[[:space:]]0+x0*101$/) {
599 # Application
600 $prj_target_type=$TT_GUIEXE;
601 }elsif (/[[:space:]]0+x0*102$/) {
602 # Dynamic-Link Library
603 $prj_target_type=$TT_DLL;
604 }elsif (/[[:space:]]0+x0*103$/) {
605 # Console Application
606 $prj_target_type=$TT_CUIEXE;
607 }elsif (/[[:space:]]0+x0*104$/) {
608 # Static Library
609 $prj_target_type=$TT_LIB;
611 next;
612 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
613 $prj_target_cflags=$1;
614 @prj_target_options=split(/\s+\//, $prj_target_cflags);
615 $prj_target_cflags="";
616 foreach ( @prj_target_options ) {
617 if ($_ eq "") {
618 # empty
619 } elsif (/nologo/) {
620 # Suppress Startup Banner and Information Messages
621 } elsif (/^W0$/) {
622 # Turns off all warning messages
623 $prj_target_cflags.="-w ";
624 } elsif (/^W[123]$/) {
625 # Warning Level
626 $prj_target_cflags.="-W ";
627 } elsif (/^W4$/) {
628 # Warning Level
629 $prj_target_cflags.="-Wall ";
630 } elsif (/^WX$/) {
631 # Warnings As Errors
632 $prj_target_cflags.="-Werror ";
633 } elsif (/^Gm$/) {
634 # Enable Minimal Rebuild
635 } elsif (/^GX$/) {
636 # Enable Exception Handling
637 $prj_target_cflags.="-fexceptions ";
638 } elsif (/^Gd$/) {
639 # use cdecl calling convention (default)
640 } elsif (/^Gr$/) {
641 # use fastcall calling convention
642 } elsif (/^Gz$/) {
643 # use stdcall calling convention
644 $prj_target_cflags.="-mrtd ";
645 } elsif (/^Z[d7iI]$/) {
646 # Debug Info
647 $prj_target_cflags.="-g ";
648 } elsif (/^Od$/) {
649 # Disable Optimizations
650 $prj_target_cflags.="-O0 ";
651 } elsif (/^O1$/) {
652 # Minimize Size
653 $prj_target_cflags.="-Os ";
654 } elsif (/^O2$/) {
655 # Maximize Speed
656 $prj_target_cflags.="-O2 ";
657 } elsif (/^Ob0$/) {
658 # Disables inline Expansion
659 $prj_target_cflags.="-fno-inline ";
660 } elsif (/^Ob1$/) {
661 #In-line Function Expansion
662 $prj_target_cflags.="-finline-functions ";
663 } elsif (/^Ob2$/) {
664 # auto In-line Function Expansion
665 $prj_target_cflags.="-finline-functions ";
666 } elsif (/^Ox$/) {
667 # Use maximum optimization
668 $prj_target_cflags.="-O3 ";
669 } elsif (/^Oy$/) {
670 # Frame-Pointer Omission
671 $prj_target_cflags.="-fomit-frame-pointer ";
672 } elsif (/^Oy-$/) {
673 # Frame-Pointer Omission
674 $prj_target_cflags.="-fno-omit-frame-pointer ";
675 } elsif (/^GZ$/) {
676 # Catch Release-Build Errors in Debug Build
677 } elsif (/^M[DLT]d?$/) {
678 # Use Multithreaded Run-Time Library
679 } elsif (/^D\s*\"(.*)\"/) {
680 # Preprocessor Definitions
681 $prj_target_defines.="-D".$1." ";
682 } elsif (/^I\s*\"(.*)\"/) {
683 # Additional Include Directories
684 $sfilet=$1;
685 $sfilet=~s/\\/\//g;
686 my @compinc=split /\/+/, $sfilet;
687 my $realinc=search_from($path, \@compinc);
688 if (defined $realinc) {
689 $sfilet=$realinc;
691 if ($sfilet=~/^\w:/) {
692 print STDERR "warning: Can't fix path $sfilet\n"
693 } else {
694 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
696 } elsif (/^U\s*\"(.*)\"/) {
697 # Undefines a previously defined symbol
698 $prj_target_cflags.="-U".$1." ";
699 } elsif (/^Fp/) {
700 # Name .PCH File
701 } elsif (/^F[Rr]/) {
702 # Create .SBR File
703 } elsif (/^YX$/) {
704 # Automatic Use of Precompiled Headers
705 } elsif (/^FD$/) {
706 # Generate File Dependencies
707 } elsif (/^c$/) {
708 # Compile Without Linking
709 # this option is always present and is already specified in the suffix rules
710 } elsif (/^GB$/) {
711 # Blend Optimization
712 $prj_target_cflags.="-D_M_IX86=500 ";
713 } elsif (/^G6$/) {
714 # Pentium Pro Optimization
715 $prj_target_cflags.="-D_M_IX86=600 ";
716 } elsif (/^G5$/) {
717 # Pentium Optimization
718 $prj_target_cflags.="-D_M_IX86=500 ";
719 } elsif (/^G3$/) {
720 # 80386 Optimization
721 $prj_target_cflags.="-D_M_IX86=300 ";
722 } elsif (/^G4$/) {
723 # 80486 Optimization
724 $prj_target_cflags.="-D_M_IX86=400 ";
725 } elsif (/^Yc/) {
726 # Create Precompiled Header
727 } elsif (/^Yu/) {
728 # Use Precompiled Header
729 } elsif (/^Za$/) {
730 # Disable Language Extensions
731 $prj_target_cflags.="-ansi ";
732 } elsif (/^Ze$/) {
733 # Enable Microsoft Extensions
734 } elsif (/^Zm[[:digit:]]+$/) {
735 # Specify Memory Allocation Limit
736 } elsif (/^Zp1?$/) {
737 # Packs structures on 1-byte boundaries
738 $prj_target_cflags.="-fpack-struct ";
739 } elsif (/^Zp(2|4|8|16)$/) {
740 # Struct Member Alignment
741 $prj_target_cflags.="-fpack-struct=".$1;
742 } else {
743 print "C compiler option $_ not implemented\n";
747 #print "\nOptions: $prj_target_cflags\n";
748 next;
749 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
750 $prj_target_ldflags=$1;
751 @prj_target_options=split(/\s+\//, $prj_target_ldflags);
752 $prj_target_ldflags="";
753 $prj_target_libs=$prj_target_options[0];
754 $prj_target_libs=~s/\\/\//g;
755 $prj_target_libs=~s/\.lib//g;
756 $prj_target_libs=~s/\s+/ -l/g;
757 shift (@prj_target_options);
758 foreach ( @prj_target_options ) {
759 if ($_ eq "") {
760 # empty
761 } elsif (/^base:(.*)/) {
762 # Base Address
763 $prj_target_ldflags.="--image-base ".$1." ";
764 } elsif (/^debug$/) {
765 # Generate Debug Info
766 } elsif (/^dll$/) {
767 # Build a DLL
768 $prj_target_type=$TT_DLL;
769 } elsif (/^incremental:[[:alpha:]]+$/) {
770 # Link Incrmentally
771 } elsif (/^implib:/) {
772 # Name import library
773 } elsif (/^libpath:\"(.*)\"/) {
774 # Additional Libpath
775 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
776 } elsif (/^machine:[[:alnum:]]+$/) {
777 # Specify Target Platform
778 } elsif (/^map/) {
779 # Generate Mapfile
780 if (/^map:(.*)/) {
781 $prj_target_ldflags.="-Map ".$1." ";
782 } else {
783 $prj_target_ldflags.="-Map ".$prj_name.".map ";
785 } elsif (/^nologo$/) {
786 # Suppress Startup Banner and Information Messages
787 } elsif (/^out:/) {
788 # Output File Name
789 # may use it as Target?
790 } elsif (/^pdbtype:/) {
791 # Program Database Storage
792 } elsif (/^subsystem:/) {
793 # Specify Subsystem
794 } elsif (/^version:[[:digit:].]+$/) {
795 # Version Information
796 } else {
797 print "Linker option $_ not implemented\n";
800 next;
801 } elsif (/^LIB32=/ && $found_cfg==1) {
802 #$libflag = 1;
803 next;
804 } elsif (/^SOURCE=(.*)$/) {
805 my @components=split /[\/\\]+/, $1;
806 $sfilet=search_from($path, \@components);
807 if (!defined $sfilet) { next; }
808 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
809 push @sources_c,$sfilet;
810 } elsif ($sfilet =~ /\.cpp$/i) {
811 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
812 push @sources_misc,$sfilet;
813 @$project_settings[$T_FLAGS]|=$TF_MFC;
814 } else {
815 push @sources_cxx,$sfilet;
817 } elsif ($sfilet =~ /\.cxx$/i) {
818 @$project_settings[$T_FLAGS]|=$TF_HASCXX;
819 push @sources_cxx,$sfilet;
820 } elsif ($sfilet =~ /\.rc$/i) {
821 push @sources_rc,$sfilet;
822 } elsif ($sfilet =~ /\.def$/i) {
823 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
824 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
825 push @sources_misc,$sfilet;
826 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
827 @$project_settings[$T_FLAGS]|=$TF_MFC;
830 next;
832 } elsif (/^# (Begin|End) Source File/) {
833 # Source-Files already handled
834 next;
835 } elsif (/^# (Begin|End) Group/) {
836 # Groups are ignored
837 next;
838 } elsif (/^# (Begin|End) Custom Build/) {
839 # Custom Builds are ignored
840 next;
841 } elsif (/^# ADD LIB32 /) {
842 #"ARFLAGS=rus"
843 next;
844 } elsif (/^# Begin Target$/) {
845 # Targets are ignored
846 next;
847 } elsif (/^# End Target$/) {
848 # Targets are ignored
849 next;
850 } elsif (/^!/) {
851 if ($found_cfg == 1) {
852 $found_cfg=0;
854 if (/if (.*)\(CFG\)" == "(.*)"/i) {
855 if ($2 eq $prj_cfg) {
856 $found_cfg=1;
859 next;
860 } elsif (/^CFG=(.*)/i) {
861 $prj_cfg=$1;
862 next;
864 else { # Line recognized
865 # print "|\n";
868 close(FILEI);
870 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
871 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
872 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
873 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
874 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
875 } elsif ($filename =~ /.vcproj$/i) {
876 eval {
877 require XML::LibXML;
879 if ($@) {
880 die "Error: You need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)";
883 my $xmlparser = XML::LibXML->new();
884 my $project_xml = $xmlparser->parse_file($filename);
885 my $sfilet;
886 my $configt;
888 foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
889 foreach my $vc_project_attr ($vc_project->attributes) {
890 if ($vc_project_attr->getName eq "Name") {
891 $prj_name=$vc_project_attr->getValue;
892 $prj_name=~s/\s+/_/g;
893 last;
898 for (my $flevel = 0; $flevel <= 5; $flevel++) {
899 foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
900 foreach my $vc_file_attr ($vc_file->attributes) {
901 if ($vc_file_attr->getName eq "RelativePath") {
902 $sfilet = $vc_file_attr->getValue;
903 $sfilet=~s/\\\\/\\/g; #remove double backslash
904 $sfilet=~s/^\.\\//; #remove starting 'this directory'
905 $sfilet=~s/\\/\//g; #make slashes out of backslashes
906 my @compsrc=split(/\/+/, $sfilet);
907 my $realsrc=search_from($path, \@compsrc);
908 if (defined $realsrc) {
909 $sfilet=$realsrc;
911 if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
912 push @sources_c,$sfilet;
913 } elsif ($sfilet =~ /\.cpp$/i) {
914 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
915 push @sources_misc,$sfilet;
916 @$project_settings[$T_FLAGS]|=$TF_MFC;
917 } else {
918 push @sources_cxx,$sfilet;
920 } elsif ($sfilet =~ /\.cxx$/i) {
921 @$project_settings[$T_FLAGS]|=$TF_HASCXX;
922 push @sources_cxx,$sfilet;
923 } elsif ($sfilet =~ /\.rc$/i) {
924 push @sources_rc,$sfilet;
925 } elsif ($sfilet =~ /\.def$/i) {
926 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
927 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
928 push @sources_misc,$sfilet;
929 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
930 @$project_settings[$T_FLAGS]|=$TF_MFC;
938 my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
939 my $vc_configuration = $vc_configurations[0];
940 foreach my $vc_configuration_attr ($vc_configuration->attributes) {
941 if ($vc_configuration_attr->getName eq "ConfigurationType") {
942 if ($vc_configuration_attr->getValue==1) {
943 $prj_target_type=$TT_GUIEXE; # Application
944 } elsif ($vc_configuration_attr->getValue==2) {
945 $prj_target_type=$TT_DLL; # Dynamic-Link Library
946 } elsif ($vc_configuration_attr->getValue==4) {
947 $prj_target_type=$TT_LIB; # Static Library
952 foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
953 my @find_tool = $vc_configuration_tools->attributes;
954 if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
955 foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
956 if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
957 if ($vc_compiler_tool->getName eq "WarningLevel") {
958 if ($vc_compiler_tool->getValue==0) {
959 $prj_target_cflags.="-w ";
960 } elsif ($vc_compiler_tool->getValue<4) {
961 $prj_target_cflags.="-W ";
962 } elsif ($vc_compiler_tool->getValue==4) {
963 $prj_target_cflags.="-Wall ";
964 } elsif ($vc_compiler_tool->getValue eq "X") {
965 $prj_target_cflags.="-Werror ";
968 if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
969 $configt=$vc_compiler_tool->getValue;
970 $configt=~s/;\s*/ -D/g;
971 $prj_target_defines.="-D".$configt." ";
973 if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
974 $configt=$vc_compiler_tool->getValue;
975 $configt=~s/\\/\//g;
976 my @addincl = split(/\s*;\s*/, $configt);
977 foreach $configt (@addincl) {
978 my @compinc=split(/\/+/, $configt);
979 my $realinc=search_from($path, \@compinc);
980 if (defined $realinc) {
981 $configt=$realinc;
983 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
988 if ($find_tool[0]->getValue eq "VCLinkerTool") {
989 foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
990 if ($vc_linker_tool->getName eq "AdditionalDependencies") {
991 $prj_target_libs=" ".$vc_linker_tool->getValue;
992 $prj_target_libs=~s/\\/\//g;
993 $prj_target_libs=~s/\.lib//g;
994 $prj_target_libs=~s/\s+/ -l/g;
1000 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
1001 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
1002 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
1003 push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
1004 } else {
1005 print STDERR "File format not supported for file: $filename\n";
1006 return;
1009 # Add this project to the project list, except for
1010 # the main project which is already in the list.
1011 if ($is_sub_project == 1) {
1012 push @projects,$project;
1015 # Ask for project-wide options
1016 if ($opt_ask_project_options == $OPT_ASK_YES) {
1017 my $flag_desc="";
1018 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1019 $flag_desc="mfc";
1021 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1022 if (defined $flag_desc) {
1023 print "* (currently $flag_desc)\n";
1025 print "* or 'skip' to skip the target specific options,\n";
1026 print "* or 'never' to not be asked this question again:\n";
1027 while (1) {
1028 my $options=<STDIN>;
1029 chomp $options;
1030 if ($options eq "skip") {
1031 $opt_ask_target_options=$OPT_ASK_SKIP;
1032 last;
1033 } elsif ($options eq "never") {
1034 $opt_ask_project_options=$OPT_ASK_NO;
1035 last;
1036 } elsif (source_set_options($project_settings,$options)) {
1037 last;
1039 print "Please re-enter the options:\n";
1043 # Create the target...
1044 my $target=[];
1045 target_init($target);
1047 if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
1048 $prj_name=lc($prj_name.".exe");
1049 @$target[$T_TYPE]=$opt_target_type;
1050 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1051 } elsif ($prj_target_type==$TT_LIB) {
1052 $prj_name=lc("lib".$prj_name.".a");
1053 @$target[$T_TYPE]=$TT_LIB;
1054 push @{@$target[$T_ARFLAGS]},("rc");
1055 } else {
1056 $prj_name=lc($prj_name.".dll");
1057 @$target[$T_TYPE]=$TT_DLL;
1058 my $canon=canonize($prj_name);
1059 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1060 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1061 } else {
1062 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1066 @$target[$T_NAME]=$prj_name;
1067 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1069 # This is the default link list of Visual Studio
1070 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1071 my @std_libraries=qw(uuid);
1072 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1073 @$target[$T_DLLS]=\@std_imports;
1074 @$target[$T_LIBRARIES]=\@std_libraries;
1075 } else {
1076 @$target[$T_DLLS]=[];
1077 @$target[$T_LIBRARIES]=[];
1079 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1080 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1081 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1082 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1085 push @{@$project[$P_TARGETS]},$target;
1087 # Ask for target-specific options
1088 if ($opt_ask_target_options == $OPT_ASK_YES) {
1089 my $flag_desc="";
1090 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1091 $flag_desc=" (mfc";
1093 if ($flag_desc ne "") {
1094 $flag_desc.=")";
1096 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1097 print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
1098 while (1) {
1099 my $options=<STDIN>;
1100 chomp $options;
1101 if ($options eq "never") {
1102 $opt_ask_target_options=$OPT_ASK_NO;
1103 last;
1104 } elsif (source_set_options($target,$options)) {
1105 last;
1107 print "Please re-enter the options:\n";
1110 if (@$target[$T_FLAGS] & $TF_MFC) {
1111 @$project_settings[$T_FLAGS]|=$TF_MFC;
1112 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1113 push @{@$target[$T_DLLS]},"mfc.dll";
1114 # FIXME: Link with the MFC in the Unix sense, until we
1115 # start exporting the functions properly.
1116 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1117 push @{@$target[$T_LIBRARIES]},"mfc";
1120 # Match sources...
1121 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1122 @$project_settings[$T_SOURCES_C]=[];
1123 @sources_c=();
1124 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1125 @$project_settings[$T_SOURCES_CXX]=[];
1126 @sources_cxx=();
1127 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1128 @$project_settings[$T_SOURCES_RC]=[];
1129 @sources_rc=();
1130 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1131 @$project_settings[$T_SOURCES_MISC]=[];
1132 @sources_misc=();
1134 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1135 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1136 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1137 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1139 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1140 $opt_ask_target_options=$OPT_ASK_YES;
1143 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1144 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1145 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1146 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1147 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1151 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1152 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1154 # The sources that did not match, if any, go to the extra
1155 # source list of the project settings
1156 foreach my $source (@sources_c) {
1157 if ($source ne "") {
1158 push @{@$project_settings[$T_SOURCES_C]},$source;
1161 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1162 foreach my $source (@sources_cxx) {
1163 if ($source ne "") {
1164 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1167 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1168 foreach my $source (@sources_rc) {
1169 if ($source ne "") {
1170 push @{@$project_settings[$T_SOURCES_RC]},$source;
1173 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1174 foreach my $source (@sources_misc) {
1175 if ($source ne "") {
1176 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1179 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1183 # Scans the specified workspace file to find the project files
1184 sub source_scan_workspace_file($);
1185 sub source_scan_workspace_file($)
1187 my $filename=$_[0];
1188 my $path=dirname($filename);
1189 my @components;
1191 if (! -e $filename) {
1192 return;
1195 if (!open(FILEIWS,$filename)) {
1196 print STDERR "error: unable to open $filename for reading:\n";
1197 print STDERR " $!\n";
1198 return;
1201 my $prj_name;
1202 my $prj_path;
1204 if ($filename =~ /.dsw$/i) {
1205 while (<FILEIWS>) {
1206 # Remove any trailing CrLf
1207 s/\r\n$/\n/;
1209 # catch a project definition
1210 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1211 $prj_name=$1;
1212 $prj_path=$2;
1213 @components=split /[\/\\]+/, $prj_path;
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 (/^#/) {
1219 # ignore Comments
1220 } elsif (/^Global:/) {
1221 # ignore the Global section
1222 } elsif (/\w:/) {
1223 print STDERR "unknown section $_\n";
1224 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1225 print "\nFileversion: $3\n";
1228 close(FILEIWS);
1229 } elsif ($filename =~ /.sln$/i) {
1230 while (<FILEIWS>) {
1231 # Remove any trailing CrLf
1232 s/\r\n$/\n/;
1234 # catch a project definition
1235 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1236 $prj_name=$2;
1237 $prj_path=$3;
1238 if ($prj_path eq "Solution Items") { next; }
1239 @components=split /[\/\\]+/, $3;
1240 $prj_path=search_from($path, \@components);
1241 print "Name: $prj_name\nPath: $prj_path\n";
1242 source_scan_project_file(\@main_project,1,$prj_path);
1243 next;
1244 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1245 print "\nFileversion: $3\n";
1248 close(FILEIWS);
1251 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1255 # Scans the specified directory to:
1256 # - see if we should create a Makefile in this directory. We normally do
1257 # so if we find a project file and sources
1258 # - get a list of targets for this directory
1259 # - get the list of source files
1260 sub source_scan_directory($$$$);
1261 sub source_scan_directory($$$$)
1263 # a reference to the parent's project
1264 my $parent_project=$_[0];
1265 # the full relative path to the current directory, including a
1266 # trailing '/', or an empty string if this is the top level directory
1267 my $path=$_[1];
1268 # the name of this directory, including a trailing '/', or an empty
1269 # string if this is the top level directory
1270 my $dirname=$_[2];
1271 # if set then no targets will be looked for and the sources will all
1272 # end up in the parent_project's 'misc' bucket
1273 my $no_target=$_[3];
1275 # reference to the project for this directory. May not be used
1276 my $project;
1277 # list of targets found in the 'current' directory
1278 my %targets;
1279 # list of sources found in the current directory
1280 my @sources_c=();
1281 my @sources_cxx=();
1282 my @sources_rc=();
1283 my @sources_misc=();
1284 # true if this directory contains a Windows project
1285 my $has_win_project=0;
1286 # true if this directory contains headers
1287 my $has_headers=0;
1288 # If we don't find any executable/library then we might make up targets
1289 # from the list of .dsp/.mak files we find since they usually have the
1290 # same name as their target.
1291 my @prj_files=();
1292 my @mak_files=();
1294 if (defined $opt_single_target or $dirname eq "") {
1295 # Either there is a single target and thus a single project,
1296 # or we are in the top level directory for which a project
1297 # already exists
1298 $project=$parent_project;
1299 } else {
1300 $project=[];
1301 project_init($project, $path, \@global_settings);
1303 my $project_settings=@$project[$P_SETTINGS];
1305 # First find out what this directory contains:
1306 # collect all sources, targets and subdirectories
1307 my $directory=get_directory_contents($path);
1308 foreach my $dentry (@$directory) {
1309 if ($dentry =~ /^\./) {
1310 next;
1312 my $fullentry="$path$dentry";
1313 if (-d "$fullentry") {
1314 if ($dentry =~ /^(Release|Debug)/i) {
1315 # These directories are often used to store the object files and the
1316 # resulting executable/library. They should not contain anything else.
1317 my @candidates=grep /\.(exe|dll|lib)$/i, @{get_directory_contents("$fullentry")};
1318 foreach my $candidate (sort @candidates) {
1319 my $dlldup = $candidate;
1320 $dlldup =~ s/\.lib$/.dll/;
1321 if ($candidate =~ /\.lib$/ and $targets{$dlldup})
1323 # Often lib files are created together with dll files, even if the dll file is the
1324 # real target.
1325 next;
1327 $targets{$candidate}=1;
1329 } elsif ($dentry =~ /^include/i) {
1330 # This directory must contain headers we're going to need
1331 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1332 source_scan_directory($project,"$fullentry/","$dentry/",1);
1333 } else {
1334 # Recursively scan this directory. Any source file that cannot be
1335 # attributed to a project in one of the subdirectories will be
1336 # attributed to this project.
1337 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1339 } elsif (-f "$fullentry") {
1340 if ($dentry =~ /\.(exe|dll|lib)$/i) {
1341 $targets{$dentry}=1;
1342 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1343 push @sources_c,"$dentry";
1344 } elsif ($dentry =~ /\.cpp$/i) {
1345 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1346 push @sources_misc,"$dentry";
1347 @$project_settings[$T_FLAGS]|=$TF_MFC;
1348 } else {
1349 push @sources_cxx,"$dentry";
1351 } elsif ($dentry =~ /\.cxx$/i) {
1352 @$project_settings[$T_FLAGS]|=$TF_HASCXX;
1353 push @sources_cxx,"$dentry";
1354 } elsif ($dentry =~ /\.rc$/i) {
1355 push @sources_rc,"$dentry";
1356 } elsif ($dentry =~ /\.def$/i) {
1357 @$project_settings[$T_FLAGS]|=$TF_HASDEF;
1358 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1359 $has_headers=1;
1360 push @sources_misc,"$dentry";
1361 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1362 @$project_settings[$T_FLAGS]|=$TF_MFC;
1364 } elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
1365 push @prj_files,"$dentry";
1366 $has_win_project=1;
1367 } elsif ($dentry =~ /\.mak$/i) {
1368 push @mak_files,"$dentry";
1369 $has_win_project=1;
1370 } elsif ($dentry =~ /^makefile/i) {
1371 $has_win_project=1;
1376 if ($has_headers) {
1377 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1379 # If we have a single target then all we have to do is assign
1380 # all the sources to it and we're done
1381 # FIXME: does this play well with the --interactive mode?
1382 if ($opt_single_target) {
1383 my $target=@{@$project[$P_TARGETS]}[0];
1384 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1385 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1386 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1387 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1388 return;
1390 if ($no_target) {
1391 my $parent_settings=@$parent_project[$P_SETTINGS];
1392 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1393 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1394 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1395 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1396 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1397 return;
1400 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1401 @{@$project_settings[$T_SOURCES_C]}+
1402 @{@$project_settings[$T_SOURCES_CXX]}+
1403 @{@$project_settings[$T_SOURCES_RC]};
1404 if ($source_count == 0) {
1405 # A project without real sources is not a project, get out!
1406 if ($project!=$parent_project) {
1407 my $parent_settings=@$parent_project[$P_SETTINGS];
1408 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1409 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1411 return;
1413 #print "targets=",%targets,"\n";
1414 #print "target_count=$target_count\n";
1415 #print "has_win_project=$has_win_project\n";
1416 #print "dirname=$dirname\n";
1418 my $target_count;
1419 if (($has_win_project != 0) or ($dirname eq "")) {
1420 # Deal with cases where we could not find any executable/library, and
1421 # thus have no target, although we did find some sort of windows project.
1422 $target_count=keys %targets;
1423 if ($target_count == 0) {
1424 # Try to come up with a target list based on .dsp/.mak files
1425 my $prj_list;
1426 if (@prj_files > 0) {
1427 print "Projectfile found! You might want to try using it directly.\n";
1428 $prj_list=\@prj_files;
1429 } else {
1430 $prj_list=\@mak_files;
1432 foreach my $filename (@$prj_list) {
1433 $filename =~ s/\.(dsp|vcproj|mak)$//i;
1434 if ($opt_target_type == $TT_DLL) {
1435 $filename = "$filename.dll";
1437 $targets{$filename}=1;
1439 $target_count=keys %targets;
1440 if ($target_count == 0) {
1441 # Still nothing, try the name of the directory
1442 my $name;
1443 if ($dirname eq "") {
1444 # Bad luck, this is the top level directory!
1445 $name=(split /\//, cwd)[-1];
1446 } else {
1447 $name=$dirname;
1448 # Remove the trailing '/'. Also eliminate whatever is after the last
1449 # '.' as it is likely to be meaningless (.orig, .new, ...)
1450 $name =~ s+(/|\.[^.]*)$++;
1451 if ($name eq "src") {
1452 # 'src' is probably a subdirectory of the real project directory.
1453 # Try again with the parent (if any).
1454 my $parent=$path;
1455 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1456 $name=$parent;
1457 } else {
1458 $name=(split /\//, cwd)[-1];
1462 $name =~ s+(/|\.[^.]*)$++;
1463 if ($opt_target_type == $TT_DLL) {
1464 $name = canonize($name).".dll";
1465 } elsif ($opt_target_type == $TT_LIB) {
1466 $name = "lib".canonize($name).".a";
1467 } else {
1468 $name = canonize($name).".exe";
1470 $targets{$name}=1;
1474 # Ask confirmation to the user if he wishes so
1475 if ($opt_is_interactive == $OPT_ASK_YES) {
1476 my $target_list=join " ",keys %targets;
1477 print "\n*** In ",($path?$path:"./"),"\n";
1478 print "* winemaker found the following list of (potential) targets\n";
1479 print "* $target_list\n";
1480 print "* Type enter to use it as is, your own comma-separated list of\n";
1481 print "* targets, 'none' to assign the source files to a parent directory,\n";
1482 print "* or 'ignore' to ignore everything in this directory tree.\n";
1483 print "* Target list:\n";
1484 $target_list=<STDIN>;
1485 chomp $target_list;
1486 if ($target_list eq "") {
1487 # Keep the target list as is, i.e. do nothing
1488 } elsif ($target_list eq "none") {
1489 # Empty the target list
1490 undef %targets;
1491 } elsif ($target_list eq "ignore") {
1492 # Ignore this subtree altogether
1493 return;
1494 } else {
1495 undef %targets;
1496 foreach my $target (split /,/,$target_list) {
1497 $target =~ s+^\s*++;
1498 $target =~ s+\s*$++;
1499 $targets{$target}=1;
1505 # If we have no project at this level, then transfer all
1506 # the sources to the parent project
1507 $target_count=keys %targets;
1508 if ($target_count == 0) {
1509 if ($project!=$parent_project) {
1510 my $parent_settings=@$parent_project[$P_SETTINGS];
1511 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1512 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1513 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1514 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1515 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1517 return;
1520 # Otherwise add this project to the project list, except for
1521 # the main project which is already in the list.
1522 if ($dirname ne "") {
1523 push @projects,$project;
1526 # Ask for project-wide options
1527 if ($opt_ask_project_options == $OPT_ASK_YES) {
1528 my $flag_desc="";
1529 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1530 $flag_desc="mfc";
1532 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1533 if (defined $flag_desc) {
1534 print "* (currently $flag_desc)\n";
1536 print "* or 'skip' to skip the target specific options,\n";
1537 print "* or 'never' to not be asked this question again:\n";
1538 while (1) {
1539 my $options=<STDIN>;
1540 chomp $options;
1541 if ($options eq "skip") {
1542 $opt_ask_target_options=$OPT_ASK_SKIP;
1543 last;
1544 } elsif ($options eq "never") {
1545 $opt_ask_project_options=$OPT_ASK_NO;
1546 last;
1547 } elsif (source_set_options($project_settings,$options)) {
1548 last;
1550 print "Please re-enter the options:\n";
1554 # - Create the targets
1555 # - Check if we have both libraries and programs
1556 # - Match each target with source files (sort in reverse
1557 # alphabetical order to get the longest matches first)
1558 my @local_dlls=();
1559 my @local_libs=();
1560 my @local_depends=();
1561 my @exe_list=();
1562 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1563 # Create the target...
1564 my $target=[];
1565 target_init($target);
1566 @$target[$T_NAME]=$target_name;
1567 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1568 if ($target_name =~ /\.dll$/) {
1569 @$target[$T_TYPE]=$TT_DLL;
1570 push @local_depends,"$target_name.so";
1571 push @local_dlls,$target_name;
1572 my $canon=canonize($target_name);
1573 if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
1574 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
1575 } else {
1576 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
1578 } elsif ($target_name =~ /\.lib$/) {
1579 $target_name =~ s/(.*)\.lib/lib$1.a/;
1580 @$target[$T_NAME]=$target_name;
1581 @$target[$T_TYPE]=$TT_LIB;
1582 push @local_depends,"$target_name";
1583 push @local_libs,$target_name;
1584 push @{@$target[$T_ARFLAGS]},("rc");
1585 } elsif ($target_name =~ /\.a$/) {
1586 @$target[$T_NAME]=$target_name;
1587 @$target[$T_TYPE]=$TT_LIB;
1588 push @local_depends,"$target_name";
1589 push @local_libs,$target_name;
1590 push @{@$target[$T_ARFLAGS]},("rc");
1591 } else {
1592 @$target[$T_TYPE]=$opt_target_type;
1593 push @exe_list,$target;
1594 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1596 my $basename=$target_name;
1597 $basename=~ s/\.(dll|exe)$//i;
1598 # This is the default link list of Visual Studio
1599 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1600 my @std_libraries=qw(uuid);
1601 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1602 @$target[$T_DLLS]=\@std_imports;
1603 @$target[$T_LIBRARIES]=\@std_libraries;
1604 } else {
1605 @$target[$T_DLLS]=[];
1606 @$target[$T_LIBRARIES]=[];
1608 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1609 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1610 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1611 push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
1614 push @{@$project[$P_TARGETS]},$target;
1616 # Ask for target-specific options
1617 if ($opt_ask_target_options == $OPT_ASK_YES) {
1618 my $flag_desc="";
1619 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1620 $flag_desc=" (mfc";
1622 if ($flag_desc ne "") {
1623 $flag_desc.=")";
1625 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1626 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1627 while (1) {
1628 my $options=<STDIN>;
1629 chomp $options;
1630 if ($options eq "never") {
1631 $opt_ask_target_options=$OPT_ASK_NO;
1632 last;
1633 } elsif (source_set_options($target,$options)) {
1634 last;
1636 print "Please re-enter the options:\n";
1639 if (@$target[$T_FLAGS] & $TF_MFC) {
1640 @$project_settings[$T_FLAGS]|=$TF_MFC;
1641 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1642 push @{@$target[$T_DLLS]},"mfc.dll";
1643 # FIXME: Link with the MFC in the Unix sense, until we
1644 # start exporting the functions properly.
1645 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1646 push @{@$target[$T_LIBRARIES]},"mfc";
1649 # Match sources...
1650 if ($target_count == 1) {
1651 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1652 @$project_settings[$T_SOURCES_C]=[];
1653 @sources_c=();
1655 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1656 @$project_settings[$T_SOURCES_CXX]=[];
1657 @sources_cxx=();
1659 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1660 @$project_settings[$T_SOURCES_RC]=[];
1661 @sources_rc=();
1663 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1664 # No need for sorting these sources
1665 @$project_settings[$T_SOURCES_MISC]=[];
1666 @sources_misc=();
1667 } else {
1668 foreach my $source (@sources_c) {
1669 if ($source =~ /^$basename/i) {
1670 push @{@$target[$T_SOURCES_C]},$source;
1671 $source="";
1674 foreach my $source (@sources_cxx) {
1675 if ($source =~ /^$basename/i) {
1676 push @{@$target[$T_SOURCES_CXX]},$source;
1677 $source="";
1680 foreach my $source (@sources_rc) {
1681 if ($source =~ /^$basename/i) {
1682 push @{@$target[$T_SOURCES_RC]},$source;
1683 $source="";
1686 foreach my $source (@sources_misc) {
1687 if ($source =~ /^$basename/i) {
1688 push @{@$target[$T_SOURCES_MISC]},$source;
1689 $source="";
1693 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1694 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1695 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1696 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1698 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1699 $opt_ask_target_options=$OPT_ASK_YES;
1702 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1703 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1704 if ($opt_arch != $OPT_ARCH_DEFAULT) {
1705 push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
1706 push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
1710 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1711 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1713 # The sources that did not match, if any, go to the extra
1714 # source list of the project settings
1715 foreach my $source (@sources_c) {
1716 if ($source ne "") {
1717 push @{@$project_settings[$T_SOURCES_C]},$source;
1720 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1721 foreach my $source (@sources_cxx) {
1722 if ($source ne "") {
1723 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1726 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1727 foreach my $source (@sources_rc) {
1728 if ($source ne "") {
1729 push @{@$project_settings[$T_SOURCES_RC]},$source;
1732 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1733 foreach my $source (@sources_misc) {
1734 if ($source ne "") {
1735 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1738 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1740 # Finally if we are building both libraries and programs in
1741 # this directory, then the programs should be linked with all
1742 # the libraries
1743 if (@local_dlls > 0 and @exe_list > 0) {
1744 foreach my $target (@exe_list) {
1745 push @{@$target[$T_DLL_PATH]},"-L.";
1746 push @{@$target[$T_DLLS]},@local_dlls;
1749 if (@local_libs > 0 and @exe_list > 0) {
1750 foreach my $target (@exe_list) {
1751 push @{@$target[$T_LIBRARY_PATH]},"-L.";
1752 push @{@$target[$T_LIBRARIES]},@local_libs;
1758 # Scan the source directories in search of things to build
1759 sub source_scan()
1761 # If there's a single target then this is going to be the default target
1762 if (defined $opt_single_target) {
1763 # Create the main target
1764 my $main_target=[];
1765 target_init($main_target);
1766 @$main_target[$T_NAME]=$opt_single_target;
1767 @$main_target[$T_TYPE]=$opt_target_type;
1769 # Add it to the list
1770 push @{$main_project[$P_TARGETS]},$main_target;
1773 # The main directory is always going to be there
1774 push @projects,\@main_project;
1776 if (defined $opt_work_dir) {
1777 # Now scan the directory tree looking for source files and, maybe, targets
1778 print "Scanning the source directories...\n";
1779 source_scan_directory(\@main_project,"","",0);
1780 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1781 } elsif (defined $opt_work_file) {
1782 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1783 source_scan_project_file(\@main_project,0,$opt_work_file);
1784 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1785 source_scan_workspace_file($opt_work_file);
1790 #####
1792 # Source search
1794 #####
1797 # Performs a directory traversal and renames the files so that:
1798 # - they have the case desired by the user
1799 # - their extension is of the appropriate case
1800 # - they don't contain annoying characters like ' ', '$', '#', ...
1801 # But only perform these changes for source files and directories.
1802 sub fix_file_and_directory_names($);
1803 sub fix_file_and_directory_names($)
1805 my $dirname=$_[0];
1807 my $directory=get_directory_contents($dirname);
1808 foreach my $dentry (@$directory)
1810 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1811 next;
1813 # Set $warn to 1 if the user should be warned of the renaming
1814 my $warn;
1815 my $new_name=$dentry;
1817 if (-f "$dirname/$dentry")
1819 # Don't rename Winemaker's makefiles
1820 next if ($dentry eq "Makefile" and
1821 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1823 # Leave non-source files alone
1824 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
1826 # Only all lowercase extensions are supported (because of
1827 # rules like '.c.o:').
1828 $new_name =~ s/\.C$/.c/;
1829 $new_name =~ s/\.cpp$/.cpp/i;
1830 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1831 $new_name =~ s/\.rc$/.rc/i;
1832 # And this last one is to avoid confusion when running make
1833 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1836 # Adjust the case to the user's preferences
1837 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1838 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1840 $new_name=lc $new_name;
1843 # make doesn't support these characters well
1844 $new_name =~ s/[ \$]/_/g;
1846 # And finally, perform the renaming
1847 if ($new_name ne $dentry)
1849 if ($warn) {
1850 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1852 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1853 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1854 print STDERR " $!\n";
1855 $new_name=$dentry;
1857 else
1859 clear_directory_cache($dirname);
1862 if (-d "$dirname/$new_name") {
1863 fix_file_and_directory_names("$dirname/$new_name");
1870 #####
1872 # Source fixup
1874 #####
1877 # Try to find a file for the specified filename. The attempt is
1878 # case-insensitive which is why it's not trivial. If a match is
1879 # found then we return the pathname with the correct case.
1880 sub search_from($$)
1882 my $dirname=$_[0];
1883 my $path=$_[1];
1884 my $real_path="";
1886 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1887 $dirname=cwd;
1888 } elsif ($dirname !~ m+^/+) {
1889 $dirname=cwd . "/" . $dirname;
1891 if ($dirname !~ m+/$+) {
1892 $dirname.="/";
1895 foreach my $component (@$path) {
1896 $component=~s/^\"//;
1897 $component=~s/\"$//;
1898 #print " looking for $component in \"$dirname\"\n";
1899 if ($component eq ".") {
1900 # Pass it as is
1901 $real_path.="./";
1902 } elsif ($component eq "..") {
1903 # Go up one level
1904 if ($dirname =~ /\.\.\/$/) {
1905 $dirname.="../";
1906 } else {
1907 $dirname=dirname($dirname) . "/";
1909 $real_path.="../";
1910 } else {
1911 # The file/directory may have been renamed before. Also try to
1912 # match the renamed file.
1913 my $renamed=$component;
1914 $renamed =~ s/[ \$]/_/g;
1915 if ($renamed eq $component) {
1916 undef $renamed;
1919 my $directory=get_directory_contents $dirname;
1920 my $found;
1921 foreach my $dentry (@$directory) {
1922 if ($dentry =~ /^\Q$component\E$/i or
1923 (defined $renamed and $dentry =~ /^$renamed$/i)
1925 $dirname.="$dentry/";
1926 $real_path.="$dentry/";
1927 $found=1;
1928 last;
1931 if (!defined $found) {
1932 # Give up
1933 #print " could not find $component in $dirname\n";
1934 return;
1938 $real_path=~ s+/$++;
1939 #print " -> found $real_path\n";
1940 return $real_path;
1944 # Performs a case-insensitive search for the specified file in the
1945 # include path.
1946 # $line is the line number that should be referenced when an error occurs
1947 # $filename is the file we are looking for
1948 # $dirname is the directory of the file containing the '#include' directive
1949 # if '"' was used, it is an empty string otherwise
1950 # $project and $target specify part of the include path
1951 sub get_real_include_name($$$$$)
1953 my $line=$_[0];
1954 my $filename=$_[1];
1955 my $dirname=$_[2];
1956 my $project=$_[3];
1957 my $target=$_[4];
1959 if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a-zA-Z]:[\/\\]?/) {
1960 # This is not a relative path, we cannot make any check
1961 my $warning="path:$filename";
1962 if (!defined $warnings{$warning}) {
1963 $warnings{$warning}="1";
1964 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1965 print STDERR "$line: $filename\n";
1967 } else {
1968 # Here's how we proceed:
1969 # - split the filename we look for into its components
1970 # - then for each directory in the include path
1971 # - trace the directory components starting from that directory
1972 # - if we fail to find a match at any point then continue with
1973 # the next directory in the include path
1974 # - otherwise, rejoice, our quest is over.
1975 my @file_components=split /[\/\\]+/, $filename;
1976 #print " Searching for $filename from @$project[$P_PATH]\n";
1978 my $real_filename;
1979 if ($dirname ne "") {
1980 # This is an 'include ""' -> look in dirname first.
1981 #print " in $dirname (include \"\")\n";
1982 $real_filename=search_from($dirname,\@file_components);
1983 if (defined $real_filename) {
1984 return $real_filename;
1987 my $project_settings=@$project[$P_SETTINGS];
1988 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1989 my $dirname=$include;
1990 $dirname=~ s+^-I++;
1991 $dirname=~ s+\s$++;
1992 if (!is_absolute($dirname)) {
1993 $dirname="@$project[$P_PATH]$dirname";
1994 } else {
1995 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1996 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1998 #print " in $dirname\n";
1999 $real_filename=search_from("$dirname",\@file_components);
2000 if (defined $real_filename) {
2001 return $real_filename;
2004 my $dotdotpath=@$project[$P_PATH];
2005 $dotdotpath =~ s/[^\/]+/../g;
2006 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
2007 my $dirname=$include;
2008 $dirname=~ s+^-I++;
2009 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
2010 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
2011 #print " in $dirname (global setting)\n";
2012 $real_filename=search_from("$dirname",\@file_components);
2013 if (defined $real_filename) {
2014 return $real_filename;
2018 $filename =~ s+\\\\+/+g; # in include ""
2019 $filename =~ s+\\+/+g; # in include <> !
2020 if ($opt_lower_include) {
2021 return lc "$filename";
2023 return $filename;
2026 sub print_pack($$$)
2028 my $indent=$_[0];
2029 my $size=$_[1];
2030 my $trailer=$_[2];
2032 if ($size =~ /^(1|2|4|8)$/) {
2033 print FILEO "$indent#include <pshpack$size.h>$trailer";
2034 } else {
2035 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
2036 print FILEO "$indent#include <pshpack4.h>$trailer";
2041 # 'Parses' a source file and fixes constructs that would not work with
2042 # Winelib. The parsing is rather simple and not all non-portable features
2043 # are corrected. The most important feature that is corrected is the case
2044 # and path separator of '#include' directives. This requires that each
2045 # source file be associated to a project & target so that the proper
2046 # include path is used.
2047 # Also note that the include path is relative to the directory in which the
2048 # compiler is run, i.e. that of the project, not to that of the file.
2049 sub fix_file($$$)
2051 my $filename=$_[0];
2052 my $project=$_[1];
2053 my $target=$_[2];
2054 $filename="@$project[$P_PATH]$filename";
2055 if (! -e $filename) {
2056 return;
2059 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
2060 my $dirname=dirname($filename);
2061 my $is_mfc=0;
2062 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
2063 $is_mfc=1;
2066 print " $filename\n";
2067 if (! -e "$filename.bak") {
2068 if (!copy("$filename","$filename.bak")) {
2069 print STDERR "error: unable to make a backup of $filename:\n";
2070 print STDERR " $!\n";
2071 return;
2074 if (!open(FILEI,"$filename.bak")) {
2075 print STDERR "error: unable to open $filename.bak for reading:\n";
2076 print STDERR " $!\n";
2077 return;
2079 if (!open(FILEO,">$filename")) {
2080 print STDERR "error: unable to open $filename for writing:\n";
2081 print STDERR " $!\n";
2082 return;
2084 my $line=0;
2085 my $modified=0;
2086 my $rc_block_depth=0;
2087 my $rc_textinclude_state=0;
2088 my @pack_stack;
2089 while (<FILEI>) {
2090 # Remove any trailing CtrlZ, which isn't strictly in the file
2091 if (/\x1A/) {
2092 s/\x1A//;
2093 last if (/^$/)
2095 $line++;
2096 s/\r\n$/\n/;
2097 if (!/\n$/) {
2098 # Make sure all files are '\n' terminated
2099 $_ .= "\n";
2101 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2102 # VC6 automatically includes 'afxres.h', an MFC specific header, in
2103 # the RC files it generates (even in non-MFC projects). So we replace
2104 # it with 'winresrc.h' its very close standard cousin so that non MFC
2105 # projects can compile in Wine without the MFC sources.
2106 my $warning="mfc:afxres.h";
2107 if (!defined $warnings{$warning}) {
2108 $warnings{$warning}="1";
2109 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2110 print STDERR "warning: the above warning is issued only once\n";
2112 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2113 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
2114 print FILEO "$1$2\"winresrc.h\"$'";
2115 $modified=1;
2117 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
2118 my $from_file=($2 eq "<"?"":$dirname);
2119 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2120 print FILEO "$1$2$real_include_name$4$'";
2121 $modified|=($real_include_name ne $3);
2123 } elsif (/^(\s*)\#\s*pragma\s+comment\s*\(\s*lib\s*,\s*\"(\w+)\.lib\"\s*\)/) {
2124 my $pragma_indent=$1;
2125 my $pragma_lib=$2;
2126 push @{@$target[$T_LIBRARIES]},$pragma_lib;
2127 print FILEO "$pragma_indent/* winemaker: Added -l$pragma_lib to the libraries */\n";
2128 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
2129 # Pragma pack handling
2131 # pack_stack is an array of references describing the stack of
2132 # pack directives currently in effect. Each directive if described
2133 # by a reference to an array containing:
2134 # - "push" for pack(push,...) directives, "" otherwise
2135 # - the directive's identifier at index 1
2136 # - the directive's alignment value at index 2
2138 # Don't believe a word of what the documentation says: it's all wrong.
2139 # The code below is based on the actual behavior of Visual C/C++ 6.
2140 my $pack_indent=$1;
2141 my $pack_header=$2;
2142 if (/^(\))/) {
2143 # pragma pack()
2144 # Pushes the default stack alignment
2145 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2146 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2147 print_pack($pack_indent,4,$');
2148 push @pack_stack, [ "", "", 4 ];
2150 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
2151 # pragma pack(pop)
2152 # pragma pack(pop,n)
2153 # Goes up the stack until it finds a pack(push,...), and pops it
2154 # Ignores any pack(n) entry
2155 # Issues a warning if the pack is of the form pack(push,label)
2156 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2157 my $pack_comment=$';
2158 $pack_comment =~ s/^\s*//;
2159 if ($pack_comment ne "") {
2160 print FILEO "$pack_indent$pack_comment";
2162 while (1) {
2163 my $alignment=pop @pack_stack;
2164 if (!defined $alignment) {
2165 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2166 last;
2168 if (@$alignment[1]) {
2169 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2171 print FILEO "$pack_indent#include <poppack.h>\n";
2172 if (@$alignment[0]) {
2173 last;
2177 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2178 # pragma pack(pop,label[,n])
2179 # Goes up the stack until finding a pack(push,...) and pops it.
2180 # 'n', if specified, is ignored.
2181 # Ignores any pack(n) entry
2182 # Issues a warning if the label of the pack does not match,
2183 # or if it is in fact a pack(push,n)
2184 my $label=$2;
2185 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2186 my $pack_comment=$';
2187 $pack_comment =~ s/^\s*//;
2188 if ($pack_comment ne "") {
2189 print FILEO "$pack_indent$pack_comment";
2191 while (1) {
2192 my $alignment=pop @pack_stack;
2193 if (!defined $alignment) {
2194 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2195 last;
2197 if (@$alignment[1] and @$alignment[1] ne $label) {
2198 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2200 print FILEO "$pack_indent#include <poppack.h>\n";
2201 if (@$alignment[0]) {
2202 last;
2206 } elsif (/^(push\s*\))/) {
2207 # pragma pack(push)
2208 # Push the current alignment
2209 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2210 if (@pack_stack > 0) {
2211 my $alignment=$pack_stack[$#pack_stack];
2212 print_pack($pack_indent,@$alignment[2],$');
2213 push @pack_stack, [ "push", "", @$alignment[2] ];
2214 } else {
2215 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2216 print_pack($pack_indent,4,$');
2217 push @pack_stack, [ "push", "", 4 ];
2220 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2221 # pragma pack([push,]n)
2222 # Push new alignment n
2223 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2224 print_pack($pack_indent,$3,"$'");
2225 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2227 } elsif (/^((\w+)\s*\))/) {
2228 # pragma pack(label)
2229 # label must in fact be a macro that resolves to an integer
2230 # Then behaves like 'pragma pack(n)'
2231 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2232 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2233 print_pack($pack_indent,4,$');
2234 push @pack_stack, [ "", "", 4 ];
2236 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2237 # pragma pack(push,label[,n])
2238 # Pushes a new label on the stack. It is possible to push the same
2239 # label multiple times. If 'n' is omitted then the alignment is
2240 # unchanged. Otherwise it becomes 'n'.
2241 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2242 my $size;
2243 if (defined $4) {
2244 $size=$4;
2245 } elsif (@pack_stack > 0) {
2246 my $alignment=$pack_stack[$#pack_stack];
2247 $size=@$alignment[2];
2248 } else {
2249 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2250 $size=4;
2252 print_pack($pack_indent,$size,$');
2253 push @pack_stack, [ "push", $2, $size ];
2255 } else {
2256 # pragma pack(??? -> What's that?
2257 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2258 print FILEO "$pack_indent$pack_header$_";
2261 $modified=1;
2263 } elsif ($is_rc) {
2264 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]+)([\">]?)/) {
2265 my $from_file=($5 eq "<"?"":$dirname);
2266 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2267 print FILEO "$1$5$real_include_name$7$'";
2268 $modified|=($real_include_name ne $6);
2270 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2271 my $from_file=($2 eq "<"?"":$dirname);
2272 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2273 print FILEO "$1$2$real_include_name$4$'";
2274 $modified|=($real_include_name ne $3);
2276 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2277 $rc_textinclude_state=1;
2278 print FILEO;
2280 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2281 print FILEO "$1winresrc.h$2$'";
2282 $modified=1;
2284 } elsif (/^\s*BEGIN(\W.*)?$/) {
2285 $rc_textinclude_state|=2;
2286 $rc_block_depth++;
2287 print FILEO;
2289 } elsif (/^\s*END(\W.*)?$/) {
2290 $rc_textinclude_state=0;
2291 if ($rc_block_depth>0) {
2292 $rc_block_depth--;
2294 print FILEO;
2296 } else {
2297 print FILEO;
2300 } else {
2301 print FILEO;
2305 close(FILEI);
2306 close(FILEO);
2307 if ($opt_backup == 0 or $modified == 0) {
2308 if (!unlink("$filename.bak")) {
2309 print STDERR "error: unable to delete $filename.bak:\n";
2310 print STDERR " $!\n";
2316 # Analyzes each source file in turn to find and correct issues
2317 # that would cause it not to compile.
2318 sub fix_source()
2320 print "Fixing the source files...\n";
2321 foreach my $project (@projects) {
2322 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2323 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2324 fix_file($source,$project,$target);
2332 #####
2334 # File generation
2336 #####
2339 # A convenience function to generate all the lists (defines,
2340 # C sources, C++ source, etc.) in the Makefile
2341 sub generate_list($$$;$)
2343 my $name=$_[0];
2344 my $last=$_[1];
2345 my $list=$_[2];
2346 my $data=$_[3];
2347 my $first=$name;
2349 if ($name) {
2350 printf FILEO "%-22s=",$name;
2352 if (defined $list) {
2353 foreach my $item (@$list) {
2354 my $value;
2355 if (defined $data) {
2356 $value=&$data($item);
2357 } else {
2358 if (defined $item) {
2359 $value=$item;
2360 } else {
2361 $value="";
2364 if ($value ne "") {
2365 if ($first) {
2366 print FILEO " $value";
2367 $first=0;
2368 } else {
2369 print FILEO " \\\n\t\t\t$value";
2374 if ($last) {
2375 print FILEO "\n";
2380 # Generates a project's Makefile and all the target files
2381 sub generate_project_files($)
2383 my $project=$_[0];
2384 my $project_settings=@$project[$P_SETTINGS];
2385 my @dll_list=();
2386 my @lib_list=();
2387 my @exe_list=();
2389 # Then sort the targets and separate the libraries from the programs
2390 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2391 if (@$target[$T_TYPE] == $TT_DLL) {
2392 push @dll_list,$target;
2393 } elsif (@$target[$T_TYPE] == $TT_LIB) {
2394 push @lib_list,$target;
2395 } else {
2396 push @exe_list,$target;
2399 @$project[$P_TARGETS]=[];
2400 push @{@$project[$P_TARGETS]}, @dll_list;
2401 push @{@$project[$P_TARGETS]}, @lib_list;
2402 push @{@$project[$P_TARGETS]}, @exe_list;
2404 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2405 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2406 print STDERR " $!\n";
2407 return;
2409 binmode( FILEO, ':utf8' );
2411 my $cpp_to_object;
2412 if (@$project_settings[$T_FLAGS] & $TF_HASCXX) {
2413 $cpp_to_object=".cxx=.o";
2414 } else {
2415 $cpp_to_object=".cpp=.o";
2418 print FILEO "### Generated by Winemaker $version\n";
2419 print FILEO "###\n";
2420 print FILEO "### Invocation command line was\n";
2421 print FILEO "### $0";
2422 foreach(@ARGV) {
2423 print FILEO " $_";
2425 print FILEO "\n\n\n";
2427 generate_list("SRCDIR",1,[ "." ]);
2428 if (@$project[$P_PATH] eq "") {
2429 # This is the main project. It is also responsible for recursively
2430 # calling the other projects
2431 generate_list("SUBDIRS",1,\@projects,sub
2433 if ($_[0] != \@main_project) {
2434 my $subdir=@{$_[0]}[$P_PATH];
2435 $subdir =~ s+/$++;
2436 return $subdir;
2438 # Eliminating the main project by returning undefined!
2441 if (@{@$project[$P_TARGETS]} > 0) {
2442 generate_list("DLLS",1,\@dll_list,sub
2444 return @{$_[0]}[$T_NAME];
2446 generate_list("LIBS",1,\@lib_list,sub
2448 return @{$_[0]}[$T_NAME];
2450 generate_list("EXES",1,\@exe_list,sub
2452 return "@{$_[0]}[$T_NAME]";
2454 print FILEO "\n\n\n";
2456 print FILEO "### Common settings\n\n";
2457 # Make it so that the project-wide settings override the global settings
2458 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2459 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2460 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2461 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2462 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2463 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2464 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2465 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2466 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2467 print FILEO "\n\n";
2469 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2470 @{@$project_settings[$T_SOURCES_CXX]}+
2471 @{@$project_settings[$T_SOURCES_RC]};
2472 my $no_extra=($extra_source_count == 0);
2473 if (!$no_extra) {
2474 print FILEO "### Extra source lists\n\n";
2475 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2476 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2477 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2478 print FILEO "\n";
2479 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:$cpp_to_object)"]);
2480 print FILEO "\n\n\n";
2483 # Iterate over all the targets...
2484 foreach my $target (@{@$project[$P_TARGETS]}) {
2485 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2486 my $canon=canonize("@$target[$T_NAME]");
2487 $canon =~ s+_so$++;
2489 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2490 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2491 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2492 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2493 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2494 generate_list("${canon}_ARFLAGS",1,@$target[$T_ARFLAGS]);
2495 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2496 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2497 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2498 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2499 print FILEO "\n";
2500 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:$cpp_to_object)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2501 print FILEO "\n\n\n";
2503 print FILEO "### Global source lists\n\n";
2504 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2506 my $canon=canonize(@{$_[0]}[$T_NAME]);
2507 $canon =~ s+_so$++;
2508 return "\$(${canon}_C_SRCS)";
2510 if (!$no_extra) {
2511 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2513 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2515 my $canon=canonize(@{$_[0]}[$T_NAME]);
2516 $canon =~ s+_so$++;
2517 return "\$(${canon}_CXX_SRCS)";
2519 if (!$no_extra) {
2520 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2522 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2524 my $canon=canonize(@{$_[0]}[$T_NAME]);
2525 $canon =~ s+_so$++;
2526 return "\$(${canon}_RC_SRCS)";
2528 if (!$no_extra) {
2529 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2532 print FILEO "\n\n";
2533 print FILEO "### Tools\n\n";
2534 print FILEO "CC = winegcc\n";
2535 print FILEO "CXX = wineg++\n";
2536 print FILEO "RC = wrc\n";
2537 print FILEO "AR = ar\n";
2538 print FILEO "\n\n";
2540 print FILEO "### Generic targets\n\n";
2541 print FILEO "all:";
2542 if (@$project[$P_PATH] eq "") {
2543 print FILEO " \$(SUBDIRS)";
2545 if (@{@$project[$P_TARGETS]} > 0) {
2546 print FILEO " \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2548 print FILEO "\n\n";
2549 print FILEO "### Build rules\n";
2550 print FILEO "\n";
2551 print FILEO ".PHONY: all clean dummy\n";
2552 print FILEO "\n";
2553 print FILEO "\$(SUBDIRS): dummy\n";
2554 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2555 print FILEO "\n";
2556 print FILEO "# Implicit rules\n";
2557 print FILEO "\n";
2558 print FILEO ".SUFFIXES: .cpp .cxx .rc .res\n";
2559 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2560 print FILEO "\n";
2561 print FILEO ".c.o:\n";
2562 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2563 print FILEO "\n";
2564 print FILEO ".cpp.o:\n";
2565 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2566 print FILEO "\n";
2567 print FILEO ".cxx.o:\n";
2568 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2569 print FILEO "\n";
2570 print FILEO ".rc.res:\n";
2571 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2572 print FILEO "\n";
2573 print FILEO "# Rules for cleaning\n";
2574 print FILEO "\n";
2575 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2576 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2577 print FILEO "\n";
2578 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2579 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:$cpp_to_object)\n";
2580 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2581 print FILEO "\n";
2582 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2583 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2584 print FILEO "\n";
2585 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2586 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2587 print FILEO "\n";
2589 if (@{@$project[$P_TARGETS]} > 0) {
2590 print FILEO "### Target specific build rules\n";
2591 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2592 foreach my $target (@{@$project[$P_TARGETS]}) {
2593 my $canon=canonize("@$target[$T_NAME]");
2594 $canon =~ s/_so$//;
2596 if (@$target[$T_TYPE] == $TT_DLL && (@$project_settings[$T_FLAGS] & $TF_HASDEF)) {
2597 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
2598 } elsif (@$target[$T_TYPE] == $TT_DLL) {
2599 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
2600 } else {
2601 print FILEO "\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2604 if (@$target[$T_TYPE] == $TT_LIB) {
2605 print FILEO "\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2606 } else {
2607 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2608 print FILEO "\t\$(CXX)";
2609 } else {
2610 print FILEO "\t\$(CC)";
2612 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_DLL_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2614 print FILEO "\n\n";
2617 close(FILEO);
2623 # This is where we finally generate files. In fact this method does not
2624 # do anything itself but calls the methods that do the actual work.
2625 sub generate()
2627 print "Generating project files...\n";
2629 foreach my $project (@projects) {
2630 my $path=@$project[$P_PATH];
2631 if ($path eq "") {
2632 $path=".";
2633 } else {
2634 $path =~ s+/$++;
2636 print " $path\n";
2637 generate_project_files($project);
2643 #####
2645 # Option defaults
2647 #####
2649 $opt_backup=1;
2650 $opt_lower=$OPT_LOWER_UPPERCASE;
2651 $opt_lower_include=1;
2653 $opt_work_dir=undef;
2654 $opt_single_target=undef;
2655 $opt_target_type=$TT_GUIEXE;
2656 $opt_flags=0;
2657 $opt_arch=$OPT_ARCH_DEFAULT;
2658 $opt_is_interactive=$OPT_ASK_NO;
2659 $opt_ask_project_options=$OPT_ASK_NO;
2660 $opt_ask_target_options=$OPT_ASK_NO;
2661 $opt_no_generated_files=0;
2662 $opt_no_source_fix=0;
2663 $opt_no_banner=0;
2667 #####
2669 # Main
2671 #####
2673 sub print_banner()
2675 print "Winemaker $version\n";
2676 print "Copyright 2000-2004 François Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2677 print "Copyright 2004 Dimitrie O. Paun\n";
2678 print "Copyright 2009-2012 André Hentschel\n";
2681 sub usage()
2683 print_banner();
2684 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2685 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2686 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2687 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll|--lib]\n";
2688 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2689 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2690 print STDERR " [--generated-files|--nogenerated-files]\n";
2691 print STDERR " [--wine32]\n";
2692 print STDERR " work_directory|project_file|workspace_file\n";
2693 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2694 print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
2695 print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2696 print STDERR "\tPlease read the manual page before use.\n";
2697 exit (2);
2700 binmode(STDOUT, ":utf8");
2702 target_init(\@global_settings);
2704 foreach(@ARGV) {
2705 my $arg=$_;
2706 # General options
2707 if ($arg eq "--nobanner") {
2708 $opt_no_banner=1;
2709 } elsif ($arg eq "--backup") {
2710 $opt_backup=1;
2711 } elsif ($arg eq "--nobackup") {
2712 $opt_backup=0;
2713 } elsif ($arg eq "--single-target") {
2714 $opt_single_target=shift @ARGV;
2715 } elsif ($arg eq "--lower-none") {
2716 $opt_lower=$OPT_LOWER_NONE;
2717 } elsif ($arg eq "--lower-all") {
2718 $opt_lower=$OPT_LOWER_ALL;
2719 } elsif ($arg eq "--lower-uppercase") {
2720 $opt_lower=$OPT_LOWER_UPPERCASE;
2721 } elsif ($arg eq "--lower-include") {
2722 $opt_lower_include=1;
2723 } elsif ($arg eq "--nolower-include") {
2724 $opt_lower_include=0;
2725 } elsif ($arg eq "--nosource-fix") {
2726 $opt_no_source_fix=1;
2727 } elsif ($arg eq "--generated-files") {
2728 $opt_no_generated_files=0;
2729 } elsif ($arg eq "--nogenerated-files") {
2730 $opt_no_generated_files=1;
2731 } elsif ($arg eq "--wine32") {
2732 $opt_arch=$OPT_ARCH_32;
2733 } elsif ($arg =~ /^-D/) {
2734 push @{$global_settings[$T_DEFINES]},$arg;
2735 } elsif ($arg =~ /^-I/) {
2736 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2737 } elsif ($arg =~ /^-P/) {
2738 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2739 } elsif ($arg =~ /^-i/) {
2740 push @{$global_settings[$T_DLLS]},$';
2741 } elsif ($arg =~ /^-L/) {
2742 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2743 } elsif ($arg =~ /^-l/) {
2744 push @{$global_settings[$T_LIBRARIES]},$arg;
2746 # 'Source'-based method options
2747 } elsif ($arg eq "--dll") {
2748 $opt_target_type=$TT_DLL;
2749 } elsif ($arg eq "--lib") {
2750 $opt_target_type=$TT_LIB;
2751 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2752 $opt_target_type=$TT_GUIEXE;
2753 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2754 $opt_target_type=$TT_CUIEXE;
2755 } elsif ($arg eq "--interactive") {
2756 $opt_is_interactive=$OPT_ASK_YES;
2757 $opt_ask_project_options=$OPT_ASK_YES;
2758 $opt_ask_target_options=$OPT_ASK_YES;
2759 } elsif ($arg eq "--mfc") {
2760 $opt_flags|=$TF_MFC;
2761 } elsif ($arg eq "--nomfc") {
2762 $opt_flags&=~$TF_MFC;
2763 $opt_flags|=$TF_NOMFC;
2764 } elsif ($arg eq "--nodlls") {
2765 $opt_flags|=$TF_NODLLS;
2766 } elsif ($arg eq "--nomsvcrt") {
2767 $opt_flags|=$TF_NOMSVCRT;
2769 # Catch errors
2770 } else {
2771 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2772 if (!defined $opt_work_dir and !defined $opt_work_file) {
2773 if (-f $arg) {
2774 $opt_work_file=$arg;
2776 else {
2777 $opt_work_dir=$arg;
2779 } else {
2780 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2781 usage();
2783 } else {
2784 usage();
2789 if (!defined $opt_work_dir and !defined $opt_work_file) {
2790 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2791 usage();
2792 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2793 print STDERR "error: could not chdir to the work directory\n";
2794 print STDERR " $!\n";
2795 usage();
2798 if ($opt_no_banner == 0) {
2799 print_banner();
2802 project_init(\@main_project, "", \@global_settings);
2804 # Fix the file and directory names
2805 fix_file_and_directory_names(".");
2807 # Scan the sources to identify the projects and targets
2808 source_scan();
2810 # Fix the source files
2811 if (! $opt_no_source_fix) {
2812 fix_source();
2815 # Generate the Makefile and the spec file
2816 if (! $opt_no_generated_files) {
2817 generate();