include: Define IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT and code for IN6_IS_ADDR_L...
[wine/hacks.git] / tools / winemaker
blobeca64173c8ddade92c704dae69b9ebb2f1bc1d34
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 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.7.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 # General options
70 # This is the directory in which winemaker will operate.
71 my $opt_work_dir;
74 # This is the file in which winemaker will operate if a project file is specified.
75 my $opt_work_file;
78 # Make a backup of the files
79 my $opt_backup;
82 # Defines which files to rename
83 my $opt_lower;
86 # If we don't find the file referenced by an include, lower it
87 my $opt_lower_include;
90 # If true then winemaker should not attempt to fix the source. This is
91 # useful if the source is known to be already in a suitable form and is
92 # readonly
93 my $opt_no_source_fix;
95 # Options for the 'Source' method
98 # Specifies that we have only one target so that all sources relate
99 # to this target. By default this variable is left undefined which
100 # means winemaker should try to find out by itself what the targets
101 # are. If not undefined then this contains the name of the default
102 # target (without the extension).
103 my $opt_single_target;
106 # If '$opt_single_target' has been specified then this is the type of
107 # that target. Otherwise it specifies whether the default target type
108 # is guiexe or cuiexe.
109 my $opt_target_type;
112 # Contains the default set of flags to be used when creating a new target.
113 my $opt_flags;
116 # If true then winemaker should ask questions to the user as it goes
117 # along.
118 my $opt_is_interactive;
119 my $opt_ask_project_options;
120 my $opt_ask_target_options;
123 # If false then winemaker should not generate the makefiles.
124 my $opt_no_generated_files;
127 # Specifies not to print the banner if set.
128 my $opt_no_banner;
132 #####
134 # Target modelization
136 #####
138 # The description of a target is stored in an array. The constants
139 # below identify what is stored at each index of the array.
142 # This is the name of the target.
143 my $T_NAME=0;
146 # Defines the type of target we want to build. See the TT_xxx
147 # constants below
148 my $T_TYPE=1;
151 # This is a bitfield containing flags refining the way the target
152 # should be handled. See the TF_xxx constants below
153 my $T_FLAGS=2;
156 # This is a reference to an array containing the list of the
157 # resp. C, C++, RC, other (.h, .hxx, etc.) source files.
158 my $T_SOURCES_C=3;
159 my $T_SOURCES_CXX=4;
160 my $T_SOURCES_RC=5;
161 my $T_SOURCES_MISC=6;
164 # This is a reference to an array containing the list of
165 # C compiler options
166 my $T_CEXTRA=7;
169 # This is a reference to an array containing the list of
170 # C++ compiler options
171 my $T_CXXEXTRA=8;
174 # This is a reference to an array containing the list of
175 # RC compiler options
176 my $T_RCEXTRA=9;
179 # This is a reference to an array containing the list of macro
180 # definitions
181 my $T_DEFINES=10;
184 # This is a reference to an array containing the list of directory
185 # names that constitute the include path
186 my $T_INCLUDE_PATH=11;
189 # Flags for the linker
190 my $T_LDFLAGS=12;
193 # Same as T_INCLUDE_PATH but for the dll search path
194 my $T_DLL_PATH=13;
197 # The list of Windows dlls to import
198 my $T_DLLS=14;
201 # Same as T_INCLUDE_PATH but for the library search path
202 my $T_LIBRARY_PATH=15;
205 # The list of Unix libraries to link with
206 my $T_LIBRARIES=16;
209 # The list of dependencies between targets
210 my $T_DEPENDS=17;
213 # The following constants define the recognized types of target
216 # This is not a real target. This type of target is used to collect
217 # the sources that don't seem to belong to any other target. Thus no
218 # real target is generated for them, we just put the sources of the
219 # fake target in the global source list.
220 my $TT_SETTINGS=0;
223 # For executables in the windows subsystem
224 my $TT_GUIEXE=1;
227 # For executables in the console subsystem
228 my $TT_CUIEXE=2;
231 # For dynamically linked libraries
232 my $TT_DLL=3;
235 # The following constants further refine how the target should be handled
238 # This target is an MFC-based target
239 my $TF_MFC=4;
242 # User has specified --nomfc option for this target or globally
243 my $TF_NOMFC=8;
246 # --nodlls option: Do not use standard DLL set
247 my $TF_NODLLS=16;
250 # --nomsvcrt option: Do not link with msvcrt
251 my $TF_NOMSVCRT=32;
254 # Initialize a target:
255 # - set the target type to TT_SETTINGS, i.e. no real target will
256 # be generated.
257 sub target_init($)
259 my $target=$_[0];
261 @$target[$T_TYPE]=$TT_SETTINGS;
262 # leaving $T_INIT undefined
263 @$target[$T_FLAGS]=$opt_flags;
264 @$target[$T_SOURCES_C]=[];
265 @$target[$T_SOURCES_CXX]=[];
266 @$target[$T_SOURCES_RC]=[];
267 @$target[$T_SOURCES_MISC]=[];
268 @$target[$T_CEXTRA]=[];
269 @$target[$T_CXXEXTRA]=[];
270 @$target[$T_RCEXTRA]=[];
271 @$target[$T_DEFINES]=[];
272 @$target[$T_INCLUDE_PATH]=[];
273 @$target[$T_LDFLAGS]=[];
274 @$target[$T_DLL_PATH]=[];
275 @$target[$T_DLLS]=[];
276 @$target[$T_LIBRARY_PATH]=[];
277 @$target[$T_LIBRARIES]=[];
282 #####
284 # Project modelization
286 #####
288 # First we have the notion of project. A project is described by an
289 # array (since we don't have structs in perl). The constants below
290 # identify what is stored at each index of the array.
293 # This is the path in which this project is located. In other
294 # words, this is the path to the Makefile.
295 my $P_PATH=0;
298 # This index contains a reference to an array containing the project-wide
299 # settings. The structure of that arrray is actually identical to that of
300 # a regular target since it can also contain extra sources.
301 my $P_SETTINGS=1;
304 # This index contains a reference to an array of targets for this
305 # project. Each target describes how an executable or library is to
306 # be built. For each target this description takes the same form as
307 # that of the project: an array. So this entry is an array of arrays.
308 my $P_TARGETS=2;
311 # Initialize a project:
312 # - set the project's path
313 # - initialize the target list
314 # - create a default target (will be removed later if unnecessary)
315 sub project_init($$$)
317 my ($project, $path, $global_settings)=@_;
319 my $project_settings=[];
320 target_init($project_settings);
321 @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
322 @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
323 @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
324 @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
325 @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
326 @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
328 @$project[$P_PATH]=$path;
329 @$project[$P_SETTINGS]=$project_settings;
330 @$project[$P_TARGETS]=[];
335 #####
337 # Global variables
339 #####
341 my %warnings;
343 my %templates;
346 # This maps a directory name to a reference to an array listing
347 # its contents (files and directories)
348 my %directories;
351 # Contains the list of all projects. This list tells us what are
352 # the subprojects of the main Makefile and where we have to generate
353 # Makefiles.
354 my @projects=();
357 # This is the main project, i.e. the one in the "." directory.
358 # It may well be empty in which case the main Makefile will only
359 # call out subprojects.
360 my @main_project;
363 # Contains the defaults for the include path, etc.
364 # We store the defaults as if this were a target except that we only
365 # exploit the defines, include path, library path, library list and misc
366 # sources fields.
367 my @global_settings;
371 #####
373 # Utility functions
375 #####
378 # Cleans up a name to make it an acceptable Makefile
379 # variable name.
380 sub canonize($)
382 my $name=$_[0];
384 $name =~ tr/a-zA-Z0-9_/_/c;
385 return $name;
389 # Returns true is the specified pathname is absolute.
390 # Note: pathnames that start with a variable '$' or
391 # '~' are considered absolute.
392 sub is_absolute($)
394 my $path=$_[0];
396 return ($path =~ /^[\/~\$]/);
400 # Retrieves the contents of the specified directory.
401 # We either get it from the directories hashtable which acts as a
402 # cache, or use opendir, readdir, closedir and store the result
403 # in the hashtable.
404 sub get_directory_contents($)
406 my $dirname=$_[0];
407 my $directory;
409 #print "getting the contents of $dirname\n";
411 # check for a cached version
412 $dirname =~ s+/$++;
413 if ($dirname eq "") {
414 $dirname=cwd;
416 $directory=$directories{$dirname};
417 if (defined $directory) {
418 #print "->@$directory\n";
419 return $directory;
422 # Read this directory
423 if (opendir(DIRECTORY, "$dirname")) {
424 my @files=readdir DIRECTORY;
425 closedir(DIRECTORY);
426 $directory=\@files;
427 } else {
428 # Return an empty list
429 #print "error: cannot open $dirname\n";
430 my @files;
431 $directory=\@files;
433 #print "->@$directory\n";
434 $directories{$dirname}=$directory;
435 return $directory;
439 # Removes a directory from the cache.
440 # This is needed if one of its files or subdirectory has been renamed.
441 sub clear_directory_cache($)
443 my ($dirname)=@_;
444 delete $directories{$dirname};
448 #####
450 # 'Source'-based Project analysis
452 #####
455 # Allows the user to specify makefile and target specific options
456 # - target: the structure in which to store the results
457 # - options: the string containing the options
458 sub source_set_options($$)
460 my $target=$_[0];
461 my $options=$_[1];
463 #FIXME: we must deal with escaping of stuff and all
464 foreach my $option (split / /,$options) {
465 if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
466 push @{@$target[$T_DEFINES]},$option;
467 } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
468 push @{@$target[$T_INCLUDE_PATH]},$option;
469 } elsif ($option =~ /^-P/) {
470 push @{@$target[$T_DLL_PATH]},"-L$'";
471 } elsif ($option =~ /^-i/) {
472 push @{@$target[$T_DLLS]},"$'";
473 } elsif ($option =~ /^-L/) {
474 push @{@$target[$T_LIBRARY_PATH]},$option;
475 } elsif ($option =~ /^-l/) {
476 push @{@$target[$T_LIBRARIES]},"$'";
477 } elsif ($option =~ /^--mfc/) {
478 @$target[$T_FLAGS]|=$TF_MFC;
479 @$target[$T_FLAGS]&=~$TF_NOMFC;
480 } elsif ($option =~ /^--nomfc/) {
481 @$target[$T_FLAGS]&=~$TF_MFC;
482 @$target[$T_FLAGS]|=$TF_NOMFC;
483 } elsif ($option =~ /^--nodlls/) {
484 @$target[$T_FLAGS]|=$TF_NODLLS;
485 } elsif ($option =~ /^--nomsvcrt/) {
486 @$target[$T_FLAGS]|=$TF_NOMSVCRT;
487 } else {
488 print STDERR "error: unknown option \"$option\"\n";
489 return 0;
492 return 1;
496 # Scans the specified project file to:
497 # - get a list of targets for this project
498 # - get some settings
499 # - get the list of source files
500 sub source_scan_project_file($$$);
501 sub source_scan_project_file($$$)
503 # a reference to the parent's project
504 my $parent_project=$_[0];
505 # 0 if it is a single project, 1 if it is part of a workspace
506 my $is_sub_project=$_[1];
507 # the name of the project file, with complete path, or without if in
508 # the same directory
509 my $filename=$_[2];
511 # reference to the project for this file. May not be used
512 my $project;
513 # list of targets found in the current file
514 my %targets;
515 # list of sources found in the current file
516 my @sources_c=();
517 my @sources_cxx=();
518 my @sources_rc=();
519 my @sources_misc=();
520 # some more settings
521 my $path=dirname($filename);
522 my $prj_target_cflags;
523 my $prj_target_ldflags;
524 my $prj_target_libs;
525 my $prj_name;
526 my $found_cfg=0;
527 my $prj_cfg;
528 my $prj_target_type=1;
529 my @prj_target_options;
531 if (!($path=~/\/$/)) {
532 $path.="/";
535 if (defined $opt_single_target or $is_sub_project == 0) {
536 # Either there is a single target and thus a single project,
537 # or we are a single project-file for which a project
538 # already exists
539 $project=$parent_project;
540 } else {
541 $project=[];
542 project_init($project, $path, \@global_settings);
544 my $project_settings=@$project[$P_SETTINGS];
546 if ($filename =~ /.dsp$/i) {
547 # First find out what this project file contains:
548 # collect all sources, find targets and settings
549 if (!open(FILEI,$filename)) {
550 print STDERR "error: unable to open $filename for reading:\n";
551 print STDERR " $!\n";
552 return;
554 my $sfilet;
555 while (<FILEI>) {
556 # Remove any trailing CtrlZ, which isn't strictly in the file
557 if (/\x1A/) {
558 s/\x1A//;
559 last if (/^$/)
562 # Remove any trailing CrLf
563 s/\r\n$/\n/;
564 if (!/\n$/) {
565 # Make sure all lines are '\n' terminated
566 $_ .= "\n";
569 if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
570 $prj_name="$1.exe";
571 $targets{$prj_name}=1;
572 #print $prj_name;
573 next;
574 } elsif (/^# TARGTYPE/) {
575 if (/[[:space:]]0x0101$/) {
576 # Win32 (x86) Application
577 $prj_target_type=1;
578 }elsif (/[[:space:]]0x0102$/) {
579 # Win32 (x86) Dynamic-Link Library
580 $prj_target_type=3;
581 }elsif (/[[:space:]]0x0103$/) {
582 # Win32 (x86) Console Application
583 $prj_target_type=2;
584 }elsif (/[[:space:]]0x0104$/) {
585 # Win32 (x86) Static Library
587 next;
588 } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
589 $prj_target_cflags=$1;
590 @prj_target_options=split(" /", $prj_target_cflags);
591 $prj_target_cflags="";
592 foreach ( @prj_target_options ) {
593 if ($_ eq "") {
594 # empty
595 } elsif (/nologo/) {
596 # Suppress Startup Banner and Information Messages
597 } elsif (/^W0$/) {
598 # Turns off all warning messages
599 $prj_target_cflags.="-w ";
600 } elsif (/^W[123]$/) {
601 # Warning Level
602 $prj_target_cflags.="-W ";
603 } elsif (/^W4$/) {
604 # Warning Level
605 $prj_target_cflags.="-Wall ";
606 } elsif (/^WX$/) {
607 # Warnings As Errors
608 $prj_target_cflags.="-Werror ";
609 } elsif (/^Gm$/) {
610 # Enable Minimal Rebuild
611 } elsif (/^GX$/) {
612 # Enable Exception Handling
613 $prj_target_cflags.="-fexceptions ";
614 } elsif (/^Z[d7iI]$/) {
615 # Debug Info
616 $prj_target_cflags.="-g ";
617 } elsif (/^Od$/) {
618 # Disable Optimizations
619 $prj_target_cflags.="-O0 ";
620 } elsif (/^O1$/) {
621 # Minimize Size
622 $prj_target_cflags.="-Os ";
623 } elsif (/^O2$/) {
624 # Maximize Speed
625 $prj_target_cflags.="-O2 ";
626 } elsif (/^Ob0$/) {
627 # Disables inline Expansion
628 $prj_target_cflags.="-fno-inline ";
629 } elsif (/^Ob1$/) {
630 # In-line Function Expansion
631 } elsif (/^Ob2$/) {
632 # auto In-line Function Expansion
633 $prj_target_cflags.="-finline-functions ";
634 } elsif (/^Oy$/) {
635 # Frame-Pointer Omission
636 $prj_target_cflags.="-fomit-frame-pointer ";
637 } elsif (/^GZ$/) {
638 # Catch Release-Build Errors in Debug Build
639 } elsif (/^M[DLT]d?$/) {
640 # Use Multithreaded Run-Time Library
641 } elsif (/^D\s*\"(.*)\"/) {
642 # Preprocessor Definitions
643 $prj_target_cflags.="-D".$1." ";
644 } elsif (/^I/) {
645 # Additional Include Directories
646 #$prj_target_cflags.="-I" fixpath(option)
647 } elsif (/^U\s*\"(.*)\"/) {
648 # Undefines a previously defined symbol
649 $prj_target_cflags.="-U".$1." ";
650 } elsif (/^Fp/) {
651 # Name .PCH File
652 } elsif (/^F[Rr]/) {
653 # Create .SBR File
654 } elsif (/^YX$/) {
655 # Automatic Use of Precompiled Headers
656 } elsif (/^FD$/) {
657 # Generate File Dependencies
658 } elsif (/^c$/) {
659 # Compile Without Linking
660 # this option is always present and is already specified in the suffix rules
661 } elsif (/^GB$/) {
662 # Blend Optimization
663 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
664 } elsif (/^G6$/) {
665 # Pentium Pro Optimization
666 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
667 } elsif (/^G5$/) {
668 # Pentium Optimization
669 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
670 } elsif (/^G3$/) {
671 # 80386 Optimization
672 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
673 } elsif (/^G4$/) {
674 # 80486 Optimization
675 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
676 } elsif (/^Yc/) {
677 # Create Precompiled Header
678 } elsif (/^Yu/) {
679 # Use Precompiled Header
680 } elsif (/^Za$/) {
681 # Disable Language Extensions
682 $prj_target_cflags.="-ansi ";
683 } elsif (/^Ze$/) {
684 # Enable Microsoft Extensions
685 } elsif (/^Zm[[:digit:]]+$/) {
686 # Specify Memory Allocation Limit
687 } elsif (/^Zp1?$/) {
688 # Packs structures on 1-byte boundaries
689 $prj_target_cflags.="-fpack-struct ";
690 } elsif (/^Zp(2|4|8|16)$/) {
691 # Struct Member Alignment
692 $prj_target_cflags.="-fpack-struct=".$1;
693 } else {
694 print "C compiler option $_ not implemented\n";
698 #print "\nOptions: $prj_target_cflags\n";
699 next;
700 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
701 $prj_target_ldflags=$1;
702 @prj_target_options=split(" /", $prj_target_ldflags);
703 $prj_target_ldflags="";
704 $prj_target_libs=$prj_target_options[0];
705 #print "\n$prj_target_libs bevor\n";
706 $prj_target_libs=~s/\\/\//g;
707 $prj_target_libs=~s/\.lib//g;
708 $prj_target_libs=~s/\s+/ -l/g;
709 #print "\n$prj_target_libs after\n";
710 shift (@prj_target_options);
711 foreach ( @prj_target_options ) {
712 if ($_ eq "") {
713 # empty
714 } elsif (/^base:(.*)/) {
715 # Base Address
716 $prj_target_ldflags.="--image-base ".$1." ";
717 } elsif (/^debug$/) {
718 # Generate Debug Info
719 } elsif (/^dll$/) {
720 # Build a DLL
721 $prj_target_type=3;
722 } elsif (/^incremental:[[:alpha:]]+$/) {
723 # Link Incrmentally
724 } elsif (/^implib:/) {
725 # Name import library
726 } elsif (/^libpath:\"(.*)\"/) {
727 # Additional Libpath
728 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
729 } elsif (/^machine:[[:alnum:]]+$/) {
730 # Specify Target Platform
731 } elsif (/^map/) {
732 # Generate Mapfile
733 if (/^map:(.*)/) {
734 $prj_target_ldflags.="-Map ".$1." ";
735 } else {
736 $prj_target_ldflags.="-Map ".$prj_name.".map ";
738 } elsif (/^nologo$/) {
739 # Suppress Startup Banner and Information Messages
740 } elsif (/^out:/) {
741 # Output File Name
742 # may use it as Target?
743 } elsif (/^pdbtype:/) {
744 # Program Database Storage
745 } elsif (/^subsystem:/) {
746 # Specify Subsystem
747 } elsif (/^version:[[:digit:].]+$/) {
748 # Version Information
749 } else {
750 print "Linker option $_ not implemented\n";
753 next;
754 } elsif (/^LIB32=/ && $found_cfg==1) {
755 #$libflag = 1;
756 next;
757 } elsif (/^SOURCE=(.*)$/) {
758 my @components=split /[\/\\]+/, $1;
759 $sfilet=search_from($path, \@components);
760 if ($sfilet =~ /\.(exe|dll)$/i) {
761 $targets{$sfilet}=1;
762 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
763 push @sources_c,$sfilet;
764 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
765 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
766 push @sources_misc,$sfilet;
767 @$project_settings[$T_FLAGS]|=$TF_MFC;
768 } else {
769 push @sources_cxx,$sfilet;
771 } elsif ($sfilet =~ /\.rc$/i) {
772 push @sources_rc,$sfilet;
773 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
774 push @sources_misc,$sfilet;
775 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
776 @$project_settings[$T_FLAGS]|=$TF_MFC;
779 next;
781 } elsif (/^# (Begin|End) Source File/) {
782 # Source-Files already handled
783 next;
784 } elsif (/^# (Begin|End) Group/) {
785 # Groups are ignored
786 next;
787 } elsif (/^# (Begin|End) Custom Build/) {
788 # Custom Builds are ignored
789 next;
790 } elsif (/^# ADD LIB32 /) {
791 #"ARFLAGS=rus"
792 next;
793 } elsif (/^# Begin Target$/) {
794 # Targets are ignored
795 next;
796 } elsif (/^# End Target$/) {
797 # Targets are ignored
798 next;
799 } elsif (/^!/) {
800 if ($found_cfg == 1) {
801 $found_cfg=0;
803 if (/if (.*)\(CFG\)" == "(.*)"/i) {
804 if ($2 eq $prj_cfg) {
805 $found_cfg=1;
808 next;
809 } elsif (/^CFG=(.*)/i) {
810 $prj_cfg=$1;
811 next;
813 else { # Line recognized
814 # print "|\n";
817 close(FILEI);
819 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
820 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
821 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
822 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
823 } elsif ($filename =~ /.vcproj$/i) {
824 # Import des Moduls XML::Simple
825 use XML::Simple;
827 my $project_xml = XMLin($filename, forcearray=>1);
829 $targets{$project_xml->{'Name'}.".exe"}=1;
830 my $sfilet;
831 for my $vc_files (@{$project_xml->{'Files'}}) {
832 for my $vc_filter (@{$vc_files->{'Filter'}}) {
833 for my $vc_file (@{$vc_filter->{'File'}}) {
834 $sfilet=$vc_file->{'RelativePath'};
835 $sfilet=~s/\\\\/\\/g; #remove double backslash
836 $sfilet=~s/^\.\\//; #remove starting 'this directory'
837 $sfilet=~s/\\/\//g; #make slashes out of backslashes
838 if ($sfilet =~ /\.(exe|dll)$/i) {
839 $targets{$sfilet}=1;
840 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
841 push @sources_c,$sfilet;
842 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
843 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
844 push @sources_misc,$sfilet;
845 @$project_settings[$T_FLAGS]|=$TF_MFC;
846 } else {
847 push @sources_cxx,$sfilet;
849 } elsif ($sfilet =~ /\.rc$/i) {
850 push @sources_rc,$sfilet;
851 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
852 push @sources_misc,$sfilet;
853 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
854 @$project_settings[$T_FLAGS]|=$TF_MFC;
860 $prj_target_cflags="";
861 for my $vc_configurations (@{$project_xml->{'Configurations'}}) {
862 for my $vc_configuration (@{$vc_configurations->{'Configuration'}}) {
863 for my $vc_tool (@{$vc_configuration->{'Tool'}}) {
864 if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
865 if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
866 if (defined $vc_tool->{'WarningLevel'}) {
867 if ($vc_tool->{'WarningLevel'}==0) {
868 $prj_target_cflags.="-w ";
869 } elsif ($vc_tool->{'WarningLevel'}<4) {
870 $prj_target_cflags.="-W ";
871 } elsif ($vc_tool->{'WarningLevel'}==4) {
872 $prj_target_cflags.="-Wall ";
873 } elsif ($vc_tool->{'WarningLevel'} eq "X") {
874 $prj_target_cflags.="-Werror ";
877 if (defined $vc_tool->{'PreprocessorDefinitions'}) {
878 $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
879 $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
881 if (defined $vc_tool->{'AdditionalIncludeDirectories'}) {
882 $vc_tool->{'AdditionalIncludeDirectories'}=~s/\\/\//g;
883 $vc_tool->{'AdditionalIncludeDirectories'}=~s/;/ -I/g;
884 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$vc_tool->{'AdditionalIncludeDirectories'};
887 last;
890 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
891 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
894 my $target_count;
895 $target_count=keys %targets;
898 # Add this project to the project list, except for
899 # the main project which is already in the list.
900 if ($is_sub_project == 1) {
901 push @projects,$project;
904 # Ask for project-wide options
905 if ($opt_ask_project_options == $OPT_ASK_YES) {
906 my $flag_desc="";
907 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
908 $flag_desc="mfc";
910 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
911 if (defined $flag_desc) {
912 print "* (currently $flag_desc)\n";
914 print "* or 'skip' to skip the target specific options,\n";
915 print "* or 'never' to not be asked this question again:\n";
916 while (1) {
917 my $options=<STDIN>;
918 chomp $options;
919 if ($options eq "skip") {
920 $opt_ask_target_options=$OPT_ASK_SKIP;
921 last;
922 } elsif ($options eq "never") {
923 $opt_ask_project_options=$OPT_ASK_NO;
924 last;
925 } elsif (source_set_options($project_settings,$options)) {
926 last;
928 print "Please re-enter the options:\n";
932 # - Create the targets
933 # - Check if we have both libraries and programs
934 # - Match each target with source files (sort in reverse
935 # alphabetical order to get the longest matches first)
936 my @local_dlls=();
937 my @local_depends=();
938 my @exe_list=();
939 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
940 # Create the target...
941 my $target=[];
942 target_init($target);
943 @$target[$T_NAME]=$target_name;
944 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
945 if ($target_name =~ /\.dll$/) {
946 @$target[$T_TYPE]=$TT_DLL;
947 push @local_depends,"$target_name.so";
948 push @local_dlls,$target_name;
949 my $canon=canonize($target_name);
950 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
951 } else {
952 @$target[$T_TYPE]=$opt_target_type;
953 push @exe_list,$target;
954 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
956 my $basename=$target_name;
957 $basename=~ s/\.(dll|exe)$//i;
958 # This is the default link list of Visual Studio
959 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
960 my @std_libraries=qw(uuid);
961 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
962 @$target[$T_DLLS]=\@std_imports;
963 @$target[$T_LIBRARIES]=\@std_libraries;
964 } else {
965 @$target[$T_DLLS]=[];
966 @$target[$T_LIBRARIES]=[];
968 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
969 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
970 push @{@$target[$T_LDFLAGS]},"-m32";
972 push @{@$project[$P_TARGETS]},$target;
974 # Ask for target-specific options
975 if ($opt_ask_target_options == $OPT_ASK_YES) {
976 my $flag_desc="";
977 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
978 $flag_desc=" (mfc";
980 if ($flag_desc ne "") {
981 $flag_desc.=")";
983 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
984 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
985 while (1) {
986 my $options=<STDIN>;
987 chomp $options;
988 if ($options eq "never") {
989 $opt_ask_target_options=$OPT_ASK_NO;
990 last;
991 } elsif (source_set_options($target,$options)) {
992 last;
994 print "Please re-enter the options:\n";
997 if (@$target[$T_FLAGS] & $TF_MFC) {
998 @$project_settings[$T_FLAGS]|=$TF_MFC;
999 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1000 push @{@$target[$T_DLLS]},"mfc.dll";
1001 # FIXME: Link with the MFC in the Unix sense, until we
1002 # start exporting the functions properly.
1003 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1004 push @{@$target[$T_LIBRARIES]},"mfc";
1007 # Match sources...
1008 if ($target_count == 1) {
1009 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1010 @$project_settings[$T_SOURCES_C]=[];
1011 @sources_c=();
1013 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1014 @$project_settings[$T_SOURCES_CXX]=[];
1015 @sources_cxx=();
1017 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1018 @$project_settings[$T_SOURCES_RC]=[];
1019 @sources_rc=();
1021 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1022 # No need for sorting these sources
1023 @$project_settings[$T_SOURCES_MISC]=[];
1024 @sources_misc=();
1026 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1027 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1028 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1029 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1031 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1032 $opt_ask_target_options=$OPT_ASK_YES;
1035 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1036 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1037 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1040 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1041 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1043 # The sources that did not match, if any, go to the extra
1044 # source list of the project settings
1045 foreach my $source (@sources_c) {
1046 if ($source ne "") {
1047 push @{@$project_settings[$T_SOURCES_C]},$source;
1050 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1051 foreach my $source (@sources_cxx) {
1052 if ($source ne "") {
1053 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1056 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1057 foreach my $source (@sources_rc) {
1058 if ($source ne "") {
1059 push @{@$project_settings[$T_SOURCES_RC]},$source;
1062 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1063 foreach my $source (@sources_misc) {
1064 if ($source ne "") {
1065 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1068 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1072 # Scans the specified workspace file to find the project files
1073 sub source_scan_workspace_file($);
1074 sub source_scan_workspace_file($)
1076 my $filename=$_[0];
1077 my $path=dirname($filename);
1078 my @components;
1080 if (! -e $filename) {
1081 return;
1084 if (!open(FILEIWS,$filename)) {
1085 print STDERR "error: unable to open $filename for reading:\n";
1086 print STDERR " $!\n";
1087 return;
1090 my $prj_name;
1091 my $prj_path;
1093 if ($filename =~ /.dsw$/i) {
1094 while (<FILEIWS>) {
1095 # Remove any trailing CrLf
1096 s/\r\n$/\n/;
1098 # catch a project definition
1099 if (/^Project:\s\"(.*)\"=(.*)\s-/) {
1100 $prj_name=$1;
1101 $prj_path=$2;
1102 @components=split /[\/\\]+/, $2;
1103 $prj_path=search_from($path, \@components);
1104 print "Name: $prj_name\nPath: $prj_path\n";
1105 source_scan_project_file(\@main_project,1,$prj_path);
1106 next;
1107 } elsif (/^#/) {
1108 # ignore Comments
1109 } elsif (/\w:/) {
1110 print STDERR "unknown section $_\n";
1111 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1112 print "\nFileversion: $3\n";
1115 close(FILEIWS);
1116 } elsif ($filename =~ /.sln$/i) {
1117 while (<FILEIWS>) {
1118 # Remove any trailing CrLf
1119 s/\r\n$/\n/;
1121 # catch a project definition
1122 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1123 $prj_name=$2;
1124 $prj_path=$3;
1125 @components=split /[\/\\]+/, $3;
1126 $prj_path=search_from($path, \@components);
1127 print "Name: $prj_name\nPath: $prj_path\n";
1128 source_scan_project_file(\@main_project,1,$prj_path);
1129 next;
1130 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1131 print "\nFileversion: $3\n";
1134 close(FILEIWS);
1137 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1141 # Scans the specified directory to:
1142 # - see if we should create a Makefile in this directory. We normally do
1143 # so if we find a project file and sources
1144 # - get a list of targets for this directory
1145 # - get the list of source files
1146 sub source_scan_directory($$$$);
1147 sub source_scan_directory($$$$)
1149 # a reference to the parent's project
1150 my $parent_project=$_[0];
1151 # the full relative path to the current directory, including a
1152 # trailing '/', or an empty string if this is the top level directory
1153 my $path=$_[1];
1154 # the name of this directory, including a trailing '/', or an empty
1155 # string if this is the top level directory
1156 my $dirname=$_[2];
1157 # if set then no targets will be looked for and the sources will all
1158 # end up in the parent_project's 'misc' bucket
1159 my $no_target=$_[3];
1161 # reference to the project for this directory. May not be used
1162 my $project;
1163 # list of targets found in the 'current' directory
1164 my %targets;
1165 # list of sources found in the current directory
1166 my @sources_c=();
1167 my @sources_cxx=();
1168 my @sources_rc=();
1169 my @sources_misc=();
1170 # true if this directory contains a Windows project
1171 my $has_win_project=0;
1172 # true if this directory contains headers
1173 my $has_headers=0;
1174 # If we don't find any executable/library then we might make up targets
1175 # from the list of .dsp/.mak files we find since they usually have the
1176 # same name as their target.
1177 my @dsp_files=();
1178 my @mak_files=();
1180 if (defined $opt_single_target or $dirname eq "") {
1181 # Either there is a single target and thus a single project,
1182 # or we are in the top level directory for which a project
1183 # already exists
1184 $project=$parent_project;
1185 } else {
1186 $project=[];
1187 project_init($project, $path, \@global_settings);
1189 my $project_settings=@$project[$P_SETTINGS];
1191 # First find out what this directory contains:
1192 # collect all sources, targets and subdirectories
1193 my $directory=get_directory_contents($path);
1194 foreach my $dentry (@$directory) {
1195 if ($dentry =~ /^\./) {
1196 next;
1198 my $fullentry="$path$dentry";
1199 if (-d "$fullentry") {
1200 if ($dentry =~ /^(Release|Debug)/i) {
1201 # These directories are often used to store the object files and the
1202 # resulting executable/library. They should not contain anything else.
1203 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1204 foreach my $candidate (@candidates) {
1205 $targets{$candidate}=1;
1207 } elsif ($dentry =~ /^include/i) {
1208 # This directory must contain headers we're going to need
1209 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1210 source_scan_directory($project,"$fullentry/","$dentry/",1);
1211 } else {
1212 # Recursively scan this directory. Any source file that cannot be
1213 # attributed to a project in one of the subdirectories will be
1214 # attributed to this project.
1215 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1217 } elsif (-f "$fullentry") {
1218 if ($dentry =~ /\.(exe|dll)$/i) {
1219 $targets{$dentry}=1;
1220 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1221 push @sources_c,"$dentry";
1222 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1223 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1224 push @sources_misc,"$dentry";
1225 @$project_settings[$T_FLAGS]|=$TF_MFC;
1226 } else {
1227 push @sources_cxx,"$dentry";
1229 } elsif ($dentry =~ /\.rc$/i) {
1230 push @sources_rc,"$dentry";
1231 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1232 $has_headers=1;
1233 push @sources_misc,"$dentry";
1234 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1235 @$project_settings[$T_FLAGS]|=$TF_MFC;
1237 } elsif ($dentry =~ /\.dsp$/i) {
1238 push @dsp_files,"$dentry";
1239 $has_win_project=1;
1240 } elsif ($dentry =~ /\.mak$/i) {
1241 push @mak_files,"$dentry";
1242 $has_win_project=1;
1243 } elsif ($dentry =~ /^makefile/i) {
1244 $has_win_project=1;
1249 if ($has_headers) {
1250 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1252 # If we have a single target then all we have to do is assign
1253 # all the sources to it and we're done
1254 # FIXME: does this play well with the --interactive mode?
1255 if ($opt_single_target) {
1256 my $target=@{@$project[$P_TARGETS]}[0];
1257 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1258 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1259 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1260 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1261 return;
1263 if ($no_target) {
1264 my $parent_settings=@$parent_project[$P_SETTINGS];
1265 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1266 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1267 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1268 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1269 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1270 return;
1273 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1274 @{@$project_settings[$T_SOURCES_C]}+
1275 @{@$project_settings[$T_SOURCES_CXX]}+
1276 @{@$project_settings[$T_SOURCES_RC]};
1277 if ($source_count == 0) {
1278 # A project without real sources is not a project, get out!
1279 if ($project!=$parent_project) {
1280 my $parent_settings=@$parent_project[$P_SETTINGS];
1281 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1282 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1284 return;
1286 #print "targets=",%targets,"\n";
1287 #print "target_count=$target_count\n";
1288 #print "has_win_project=$has_win_project\n";
1289 #print "dirname=$dirname\n";
1291 my $target_count;
1292 if (($has_win_project != 0) or ($dirname eq "")) {
1293 # Deal with cases where we could not find any executable/library, and
1294 # thus have no target, although we did find some sort of windows project.
1295 $target_count=keys %targets;
1296 if ($target_count == 0) {
1297 # Try to come up with a target list based on .dsp/.mak files
1298 my $prj_list;
1299 if (@dsp_files > 0) {
1300 $prj_list=\@dsp_files;
1301 } else {
1302 $prj_list=\@mak_files;
1304 foreach my $filename (@$prj_list) {
1305 $filename =~ s/\.(dsp|mak)$//i;
1306 if ($opt_target_type == $TT_DLL) {
1307 $filename = "$filename.dll";
1309 $targets{$filename}=1;
1311 $target_count=keys %targets;
1312 if ($target_count == 0) {
1313 # Still nothing, try the name of the directory
1314 my $name;
1315 if ($dirname eq "") {
1316 # Bad luck, this is the top level directory!
1317 $name=(split /\//, cwd)[-1];
1318 } else {
1319 $name=$dirname;
1320 # Remove the trailing '/'. Also eliminate whatever is after the last
1321 # '.' as it is likely to be meaningless (.orig, .new, ...)
1322 $name =~ s+(/|\.[^.]*)$++;
1323 if ($name eq "src") {
1324 # 'src' is probably a subdirectory of the real project directory.
1325 # Try again with the parent (if any).
1326 my $parent=$path;
1327 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1328 $name=$parent;
1329 } else {
1330 $name=(split /\//, cwd)[-1];
1334 $name =~ s+(/|\.[^.]*)$++;
1335 if ($opt_target_type == $TT_DLL) {
1336 $name = canonize($name).".dll";
1337 } else {
1338 $name = canonize($name).".exe";
1340 $targets{$name}=1;
1344 # Ask confirmation to the user if he wishes so
1345 if ($opt_is_interactive == $OPT_ASK_YES) {
1346 my $target_list=join " ",keys %targets;
1347 print "\n*** In ",($path?$path:"./"),"\n";
1348 print "* winemaker found the following list of (potential) targets\n";
1349 print "* $target_list\n";
1350 print "* Type enter to use it as is, your own comma-separated list of\n";
1351 print "* targets, 'none' to assign the source files to a parent directory,\n";
1352 print "* or 'ignore' to ignore everything in this directory tree.\n";
1353 print "* Target list:\n";
1354 $target_list=<STDIN>;
1355 chomp $target_list;
1356 if ($target_list eq "") {
1357 # Keep the target list as is, i.e. do nothing
1358 } elsif ($target_list eq "none") {
1359 # Empty the target list
1360 undef %targets;
1361 } elsif ($target_list eq "ignore") {
1362 # Ignore this subtree altogether
1363 return;
1364 } else {
1365 undef %targets;
1366 foreach my $target (split /,/,$target_list) {
1367 $target =~ s+^\s*++;
1368 $target =~ s+\s*$++;
1369 $targets{$target}=1;
1375 # If we have no project at this level, then transfer all
1376 # the sources to the parent project
1377 $target_count=keys %targets;
1378 if ($target_count == 0) {
1379 if ($project!=$parent_project) {
1380 my $parent_settings=@$parent_project[$P_SETTINGS];
1381 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1382 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1383 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1384 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1385 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1387 return;
1390 # Otherwise add this project to the project list, except for
1391 # the main project which is already in the list.
1392 if ($dirname ne "") {
1393 push @projects,$project;
1396 # Ask for project-wide options
1397 if ($opt_ask_project_options == $OPT_ASK_YES) {
1398 my $flag_desc="";
1399 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1400 $flag_desc="mfc";
1402 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1403 if (defined $flag_desc) {
1404 print "* (currently $flag_desc)\n";
1406 print "* or 'skip' to skip the target specific options,\n";
1407 print "* or 'never' to not be asked this question again:\n";
1408 while (1) {
1409 my $options=<STDIN>;
1410 chomp $options;
1411 if ($options eq "skip") {
1412 $opt_ask_target_options=$OPT_ASK_SKIP;
1413 last;
1414 } elsif ($options eq "never") {
1415 $opt_ask_project_options=$OPT_ASK_NO;
1416 last;
1417 } elsif (source_set_options($project_settings,$options)) {
1418 last;
1420 print "Please re-enter the options:\n";
1424 # - Create the targets
1425 # - Check if we have both libraries and programs
1426 # - Match each target with source files (sort in reverse
1427 # alphabetical order to get the longest matches first)
1428 my @local_dlls=();
1429 my @local_depends=();
1430 my @exe_list=();
1431 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1432 # Create the target...
1433 my $target=[];
1434 target_init($target);
1435 @$target[$T_NAME]=$target_name;
1436 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1437 if ($target_name =~ /\.dll$/) {
1438 @$target[$T_TYPE]=$TT_DLL;
1439 push @local_depends,"$target_name.so";
1440 push @local_dlls,$target_name;
1441 my $canon=canonize($target_name);
1442 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1443 } else {
1444 @$target[$T_TYPE]=$opt_target_type;
1445 push @exe_list,$target;
1446 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1448 my $basename=$target_name;
1449 $basename=~ s/\.(dll|exe)$//i;
1450 # This is the default link list of Visual Studio
1451 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1452 my @std_libraries=qw(uuid);
1453 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1454 @$target[$T_DLLS]=\@std_imports;
1455 @$target[$T_LIBRARIES]=\@std_libraries;
1456 } else {
1457 @$target[$T_DLLS]=[];
1458 @$target[$T_LIBRARIES]=[];
1460 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1461 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1462 push @{@$target[$T_LDFLAGS]},"-m32";
1464 push @{@$project[$P_TARGETS]},$target;
1466 # Ask for target-specific options
1467 if ($opt_ask_target_options == $OPT_ASK_YES) {
1468 my $flag_desc="";
1469 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1470 $flag_desc=" (mfc";
1472 if ($flag_desc ne "") {
1473 $flag_desc.=")";
1475 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1476 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1477 while (1) {
1478 my $options=<STDIN>;
1479 chomp $options;
1480 if ($options eq "never") {
1481 $opt_ask_target_options=$OPT_ASK_NO;
1482 last;
1483 } elsif (source_set_options($target,$options)) {
1484 last;
1486 print "Please re-enter the options:\n";
1489 if (@$target[$T_FLAGS] & $TF_MFC) {
1490 @$project_settings[$T_FLAGS]|=$TF_MFC;
1491 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1492 push @{@$target[$T_DLLS]},"mfc.dll";
1493 # FIXME: Link with the MFC in the Unix sense, until we
1494 # start exporting the functions properly.
1495 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1496 push @{@$target[$T_LIBRARIES]},"mfc";
1499 # Match sources...
1500 if ($target_count == 1) {
1501 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1502 @$project_settings[$T_SOURCES_C]=[];
1503 @sources_c=();
1505 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1506 @$project_settings[$T_SOURCES_CXX]=[];
1507 @sources_cxx=();
1509 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1510 @$project_settings[$T_SOURCES_RC]=[];
1511 @sources_rc=();
1513 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1514 # No need for sorting these sources
1515 @$project_settings[$T_SOURCES_MISC]=[];
1516 @sources_misc=();
1517 } else {
1518 foreach my $source (@sources_c) {
1519 if ($source =~ /^$basename/i) {
1520 push @{@$target[$T_SOURCES_C]},$source;
1521 $source="";
1524 foreach my $source (@sources_cxx) {
1525 if ($source =~ /^$basename/i) {
1526 push @{@$target[$T_SOURCES_CXX]},$source;
1527 $source="";
1530 foreach my $source (@sources_rc) {
1531 if ($source =~ /^$basename/i) {
1532 push @{@$target[$T_SOURCES_RC]},$source;
1533 $source="";
1536 foreach my $source (@sources_misc) {
1537 if ($source =~ /^$basename/i) {
1538 push @{@$target[$T_SOURCES_MISC]},$source;
1539 $source="";
1543 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1544 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1545 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1546 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1548 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1549 $opt_ask_target_options=$OPT_ASK_YES;
1552 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1553 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1554 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1557 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1558 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1560 # The sources that did not match, if any, go to the extra
1561 # source list of the project settings
1562 foreach my $source (@sources_c) {
1563 if ($source ne "") {
1564 push @{@$project_settings[$T_SOURCES_C]},$source;
1567 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1568 foreach my $source (@sources_cxx) {
1569 if ($source ne "") {
1570 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1573 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1574 foreach my $source (@sources_rc) {
1575 if ($source ne "") {
1576 push @{@$project_settings[$T_SOURCES_RC]},$source;
1579 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1580 foreach my $source (@sources_misc) {
1581 if ($source ne "") {
1582 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1585 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1587 # Finally if we are building both libraries and programs in
1588 # this directory, then the programs should be linked with all
1589 # the libraries
1590 if (@local_dlls > 0 and @exe_list > 0) {
1591 foreach my $target (@exe_list) {
1592 push @{@$target[$T_DLL_PATH]},"-L.";
1593 push @{@$target[$T_DLLS]},@local_dlls;
1599 # Scan the source directories in search of things to build
1600 sub source_scan()
1602 # If there's a single target then this is going to be the default target
1603 if (defined $opt_single_target) {
1604 # Create the main target
1605 my $main_target=[];
1606 target_init($main_target);
1607 @$main_target[$T_NAME]=$opt_single_target;
1608 @$main_target[$T_TYPE]=$opt_target_type;
1610 # Add it to the list
1611 push @{$main_project[$P_TARGETS]},$main_target;
1614 # The main directory is always going to be there
1615 push @projects,\@main_project;
1617 if (defined $opt_work_dir) {
1618 # Now scan the directory tree looking for source files and, maybe, targets
1619 print "Scanning the source directories...\n";
1620 source_scan_directory(\@main_project,"","",0);
1621 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1622 } elsif (defined $opt_work_file) {
1623 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1624 source_scan_project_file(\@main_project,0,$opt_work_file);
1625 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1626 source_scan_workspace_file($opt_work_file);
1631 #####
1633 # Source search
1635 #####
1638 # Performs a directory traversal and renames the files so that:
1639 # - they have the case desired by the user
1640 # - their extension is of the appropriate case
1641 # - they don't contain annoying characters like ' ', '$', '#', ...
1642 # But only perform these changes for source files and directories.
1643 sub fix_file_and_directory_names($);
1644 sub fix_file_and_directory_names($)
1646 my $dirname=$_[0];
1648 my $directory=get_directory_contents($dirname);
1649 foreach my $dentry (@$directory)
1651 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1652 next;
1654 # Set $warn to 1 if the user should be warned of the renaming
1655 my $warn;
1656 my $new_name=$dentry;
1658 if (-f "$dirname/$dentry")
1660 # Don't rename Winemaker's makefiles
1661 next if ($dentry eq "Makefile" and
1662 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1664 # Leave non-source files alone
1665 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1667 # Only all lowercase extensions are supported (because of
1668 # rules like '.c.o:'.
1669 $new_name =~ s/\.C$/.c/;
1670 $new_name =~ s/\.cpp$/.cpp/i;
1671 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1672 $new_name =~ s/\.rc$/.rc/i;
1673 # And this last one is to avoid confusion then running make
1674 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1677 # Adjust the case to the user's preferences
1678 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1679 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1681 $new_name=lc $new_name;
1684 # autoconf and make don't support these characters well
1685 $new_name =~ s/[ \$]/_/g;
1687 # And finally, perform the renaming
1688 if ($new_name ne $dentry)
1690 if ($warn) {
1691 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1693 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1694 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1695 print STDERR " $!\n";
1696 $new_name=$dentry;
1698 else
1700 clear_directory_cache($dirname);
1703 if (-d "$dirname/$new_name") {
1704 fix_file_and_directory_names("$dirname/$new_name");
1711 #####
1713 # Source fixup
1715 #####
1718 # Try to find a file for the specified filename. The attempt is
1719 # case-insensitive which is why it's not trivial. If a match is
1720 # found then we return the pathname with the correct case.
1721 sub search_from($$)
1723 my $dirname=$_[0];
1724 my $path=$_[1];
1725 my $real_path="";
1727 if ($dirname eq "" or $dirname eq ".") {
1728 $dirname=cwd;
1729 } elsif ($dirname !~ m+^/+) {
1730 $dirname=cwd . "/" . $dirname;
1732 if ($dirname !~ m+/$+) {
1733 $dirname.="/";
1736 foreach my $component (@$path) {
1737 #print " looking for $component in \"$dirname\"\n";
1738 if ($component eq ".") {
1739 # Pass it as is
1740 $real_path.="./";
1741 } elsif ($component eq "..") {
1742 # Go up one level
1743 $dirname=dirname($dirname) . "/";
1744 $real_path.="../";
1745 } else {
1746 # The file/directory may have been renamed before. Also try to
1747 # match the renamed file.
1748 my $renamed=$component;
1749 $renamed =~ s/[ \$]/_/g;
1750 if ($renamed eq $component) {
1751 undef $renamed;
1754 my $directory=get_directory_contents $dirname;
1755 my $found;
1756 foreach my $dentry (@$directory) {
1757 if ($dentry =~ /^\Q$component\E$/i or
1758 (defined $renamed and $dentry =~ /^$renamed$/i)
1760 $dirname.="$dentry/";
1761 $real_path.="$dentry/";
1762 $found=1;
1763 last;
1766 if (!defined $found) {
1767 # Give up
1768 #print " could not find $component in $dirname\n";
1769 return;
1773 $real_path=~ s+/$++;
1774 #print " -> found $real_path\n";
1775 return $real_path;
1779 # Performs a case-insensitive search for the specified file in the
1780 # include path.
1781 # $line is the line number that should be referenced when an error occurs
1782 # $filename is the file we are looking for
1783 # $dirname is the directory of the file containing the '#include' directive
1784 # if '"' was used, it is an empty string otherwise
1785 # $project and $target specify part of the include path
1786 sub get_real_include_name($$$$$)
1788 my $line=$_[0];
1789 my $filename=$_[1];
1790 my $dirname=$_[2];
1791 my $project=$_[3];
1792 my $target=$_[4];
1794 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1795 # This is not a relative path, we cannot make any check
1796 my $warning="path:$filename";
1797 if (!defined $warnings{$warning}) {
1798 $warnings{$warning}="1";
1799 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1800 print STDERR "$line: $filename\n";
1802 } else {
1803 # Here's how we proceed:
1804 # - split the filename we look for into its components
1805 # - then for each directory in the include path
1806 # - trace the directory components starting from that directory
1807 # - if we fail to find a match at any point then continue with
1808 # the next directory in the include path
1809 # - otherwise, rejoice, our quest is over.
1810 my @file_components=split /[\/\\]+/, $filename;
1811 #print " Searching for $filename from @$project[$P_PATH]\n";
1813 my $real_filename;
1814 if ($dirname ne "") {
1815 # This is an 'include ""' -> look in dirname first.
1816 #print " in $dirname (include \"\")\n";
1817 $real_filename=search_from($dirname,\@file_components);
1818 if (defined $real_filename) {
1819 return $real_filename;
1822 my $project_settings=@$project[$P_SETTINGS];
1823 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1824 my $dirname=$include;
1825 $dirname=~ s+^-I++;
1826 if (!is_absolute($dirname)) {
1827 $dirname="@$project[$P_PATH]$dirname";
1828 } else {
1829 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1830 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1832 #print " in $dirname\n";
1833 $real_filename=search_from("$dirname",\@file_components);
1834 if (defined $real_filename) {
1835 return $real_filename;
1838 my $dotdotpath=@$project[$P_PATH];
1839 $dotdotpath =~ s/[^\/]+/../g;
1840 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1841 my $dirname=$include;
1842 $dirname=~ s+^-I++;
1843 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1844 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1845 #print " in $dirname (global setting)\n";
1846 $real_filename=search_from("$dirname",\@file_components);
1847 if (defined $real_filename) {
1848 return $real_filename;
1852 $filename =~ s+\\\\+/+g; # in include ""
1853 $filename =~ s+\\+/+g; # in include <> !
1854 if ($opt_lower_include) {
1855 return lc "$filename";
1857 return $filename;
1860 sub print_pack($$$)
1862 my $indent=$_[0];
1863 my $size=$_[1];
1864 my $trailer=$_[2];
1866 if ($size =~ /^(1|2|4|8)$/) {
1867 print FILEO "$indent#include <pshpack$size.h>$trailer";
1868 } else {
1869 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1870 print FILEO "$indent#include <pshpack4.h>$trailer";
1875 # 'Parses' a source file and fixes constructs that would not work with
1876 # Winelib. The parsing is rather simple and not all non-portable features
1877 # are corrected. The most important feature that is corrected is the case
1878 # and path separator of '#include' directives. This requires that each
1879 # source file be associated to a project & target so that the proper
1880 # include path is used.
1881 # Also note that the include path is relative to the directory in which the
1882 # compiler is run, i.e. that of the project, not to that of the file.
1883 sub fix_file($$$)
1885 my $filename=$_[0];
1886 my $project=$_[1];
1887 my $target=$_[2];
1888 $filename="@$project[$P_PATH]$filename";
1889 if (! -e $filename) {
1890 return;
1893 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1894 my $dirname=dirname($filename);
1895 my $is_mfc=0;
1896 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1897 $is_mfc=1;
1900 print " $filename\n";
1901 #FIXME:assuming that because there is a .bak file, this is what we want is
1902 #probably flawed. Or is it???
1903 if (! -e "$filename.bak") {
1904 if (!copy("$filename","$filename.bak")) {
1905 print STDERR "error: unable to make a backup of $filename:\n";
1906 print STDERR " $!\n";
1907 return;
1910 if (!open(FILEI,"$filename.bak")) {
1911 print STDERR "error: unable to open $filename.bak for reading:\n";
1912 print STDERR " $!\n";
1913 return;
1915 if (!open(FILEO,">$filename")) {
1916 print STDERR "error: unable to open $filename for writing:\n";
1917 print STDERR " $!\n";
1918 return;
1920 my $line=0;
1921 my $modified=0;
1922 my $rc_block_depth=0;
1923 my $rc_textinclude_state=0;
1924 my @pack_stack;
1925 while (<FILEI>) {
1926 # Remove any trailing CtrlZ, which isn't strictly in the file
1927 if (/\x1A/) {
1928 s/\x1A//;
1929 last if (/^$/)
1931 $line++;
1932 s/\r\n$/\n/;
1933 if (!/\n$/) {
1934 # Make sure all files are '\n' terminated
1935 $_ .= "\n";
1937 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1938 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1939 # the RC files it generates (even in non-MFC projects). So we replace
1940 # it with 'winresrc.h' its very close standard cousin so that non MFC
1941 # projects can compile in Wine without the MFC sources.
1942 my $warning="mfc:afxres.h";
1943 if (!defined $warnings{$warning}) {
1944 $warnings{$warning}="1";
1945 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1946 print STDERR "warning: the above warning is issued only once\n";
1948 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1949 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1950 print FILEO "$1$2\"winresrc.h\"$'";
1951 $modified=1;
1953 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1954 my $from_file=($2 eq "<"?"":$dirname);
1955 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1956 print FILEO "$1$2$real_include_name$4$'";
1957 $modified|=($real_include_name ne $3);
1959 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1960 # Pragma pack handling
1962 # pack_stack is an array of references describing the stack of
1963 # pack directives currently in effect. Each directive if described
1964 # by a reference to an array containing:
1965 # - "push" for pack(push,...) directives, "" otherwise
1966 # - the directive's identifier at index 1
1967 # - the directive's alignment value at index 2
1969 # Don't believe a word of what the documentation says: it's all wrong.
1970 # The code below is based on the actual behavior of Visual C/C++ 6.
1971 my $pack_indent=$1;
1972 my $pack_header=$2;
1973 if (/^(\))/) {
1974 # pragma pack()
1975 # Pushes the default stack alignment
1976 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1977 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1978 print_pack($pack_indent,4,$');
1979 push @pack_stack, [ "", "", 4 ];
1981 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1982 # pragma pack(pop)
1983 # pragma pack(pop,n)
1984 # Goes up the stack until it finds a pack(push,...), and pops it
1985 # Ignores any pack(n) entry
1986 # Issues a warning if the pack is of the form pack(push,label)
1987 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1988 my $pack_comment=$';
1989 $pack_comment =~ s/^\s*//;
1990 if ($pack_comment ne "") {
1991 print FILEO "$pack_indent$pack_comment";
1993 while (1) {
1994 my $alignment=pop @pack_stack;
1995 if (!defined $alignment) {
1996 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
1997 last;
1999 if (@$alignment[1]) {
2000 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2002 print FILEO "$pack_indent#include <poppack.h>\n";
2003 if (@$alignment[0]) {
2004 last;
2008 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2009 # pragma pack(pop,label[,n])
2010 # Goes up the stack until finding a pack(push,...) and pops it.
2011 # 'n', if specified, is ignored.
2012 # Ignores any pack(n) entry
2013 # Issues a warning if the label of the pack does not match,
2014 # or if it is in fact a pack(push,n)
2015 my $label=$2;
2016 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2017 my $pack_comment=$';
2018 $pack_comment =~ s/^\s*//;
2019 if ($pack_comment ne "") {
2020 print FILEO "$pack_indent$pack_comment";
2022 while (1) {
2023 my $alignment=pop @pack_stack;
2024 if (!defined $alignment) {
2025 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2026 last;
2028 if (@$alignment[1] and @$alignment[1] ne $label) {
2029 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2031 print FILEO "$pack_indent#include <poppack.h>\n";
2032 if (@$alignment[0]) {
2033 last;
2037 } elsif (/^(push\s*\))/) {
2038 # pragma pack(push)
2039 # Push the current alignment
2040 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2041 if (@pack_stack > 0) {
2042 my $alignment=$pack_stack[$#pack_stack];
2043 print_pack($pack_indent,@$alignment[2],$');
2044 push @pack_stack, [ "push", "", @$alignment[2] ];
2045 } else {
2046 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2047 print_pack($pack_indent,4,$');
2048 push @pack_stack, [ "push", "", 4 ];
2051 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2052 # pragma pack([push,]n)
2053 # Push new alignment n
2054 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2055 print_pack($pack_indent,$3,"$'");
2056 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2058 } elsif (/^((\w+)\s*\))/) {
2059 # pragma pack(label)
2060 # label must in fact be a macro that resolves to an integer
2061 # Then behaves like 'pragma pack(n)'
2062 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2063 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2064 print_pack($pack_indent,4,$');
2065 push @pack_stack, [ "", "", 4 ];
2067 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2068 # pragma pack(push,label[,n])
2069 # Pushes a new label on the stack. It is possible to push the same
2070 # label multiple times. If 'n' is omitted then the alignment is
2071 # unchanged. Otherwise it becomes 'n'.
2072 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2073 my $size;
2074 if (defined $4) {
2075 $size=$4;
2076 } elsif (@pack_stack > 0) {
2077 my $alignment=$pack_stack[$#pack_stack];
2078 $size=@$alignment[2];
2079 } else {
2080 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2081 $size=4;
2083 print_pack($pack_indent,$size,$');
2084 push @pack_stack, [ "push", $2, $size ];
2086 } else {
2087 # pragma pack(??? -> What's that?
2088 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2089 print FILEO "$pack_indent$pack_header$_";
2092 $modified=1;
2094 } elsif ($is_rc) {
2095 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]+)([\">]?)/) {
2096 my $from_file=($5 eq "<"?"":$dirname);
2097 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2098 print FILEO "$1$5$real_include_name$7$'";
2099 $modified|=($real_include_name ne $6);
2101 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2102 my $from_file=($2 eq "<"?"":$dirname);
2103 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2104 print FILEO "$1$2$real_include_name$4$'";
2105 $modified|=($real_include_name ne $3);
2107 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2108 $rc_textinclude_state=1;
2109 print FILEO;
2111 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2112 print FILEO "$1winresrc.h$2$'";
2113 $modified=1;
2115 } elsif (/^\s*BEGIN(\W.*)?$/) {
2116 $rc_textinclude_state|=2;
2117 $rc_block_depth++;
2118 print FILEO;
2120 } elsif (/^\s*END(\W.*)?$/) {
2121 $rc_textinclude_state=0;
2122 if ($rc_block_depth>0) {
2123 $rc_block_depth--;
2125 print FILEO;
2127 } else {
2128 print FILEO;
2131 } else {
2132 print FILEO;
2136 close(FILEI);
2137 close(FILEO);
2138 if ($opt_backup == 0 or $modified == 0) {
2139 if (!unlink("$filename.bak")) {
2140 print STDERR "error: unable to delete $filename.bak:\n";
2141 print STDERR " $!\n";
2147 # Analyzes each source file in turn to find and correct issues
2148 # that would cause it not to compile.
2149 sub fix_source()
2151 print "Fixing the source files...\n";
2152 foreach my $project (@projects) {
2153 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2154 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2155 fix_file($source,$project,$target);
2163 #####
2165 # File generation
2167 #####
2170 # A convenience function to generate all the lists (defines,
2171 # C sources, C++ source, etc.) in the Makefile
2172 sub generate_list($$$;$)
2174 my $name=$_[0];
2175 my $last=$_[1];
2176 my $list=$_[2];
2177 my $data=$_[3];
2178 my $first=$name;
2180 if ($name) {
2181 printf FILEO "%-22s=",$name;
2183 if (defined $list) {
2184 foreach my $item (@$list) {
2185 my $value;
2186 if (defined $data) {
2187 $value=&$data($item);
2188 } else {
2189 $value=$item;
2191 if ($value ne "") {
2192 if ($first) {
2193 print FILEO " $value";
2194 $first=0;
2195 } else {
2196 print FILEO " \\\n\t\t\t$value";
2201 if ($last) {
2202 print FILEO "\n";
2207 # Generates a project's Makefile and all the target files
2208 sub generate_project_files($)
2210 my $project=$_[0];
2211 my $project_settings=@$project[$P_SETTINGS];
2212 my @dll_list=();
2213 my @exe_list=();
2215 # Then sort the targets and separate the libraries from the programs
2216 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2217 if (@$target[$T_TYPE] == $TT_DLL) {
2218 push @dll_list,$target;
2219 } else {
2220 push @exe_list,$target;
2223 @$project[$P_TARGETS]=[];
2224 push @{@$project[$P_TARGETS]}, @dll_list;
2225 push @{@$project[$P_TARGETS]}, @exe_list;
2227 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2228 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2229 print STDERR " $!\n";
2230 return;
2233 print FILEO "### Generated by Winemaker $version\n";
2234 print FILEO "\n\n";
2236 generate_list("SRCDIR",1,[ "." ]);
2237 if (@$project[$P_PATH] eq "") {
2238 # This is the main project. It is also responsible for recursively
2239 # calling the other projects
2240 generate_list("SUBDIRS",1,\@projects,sub
2242 if ($_[0] != \@main_project) {
2243 my $subdir=@{$_[0]}[$P_PATH];
2244 $subdir =~ s+/$++;
2245 return $subdir;
2247 # Eliminating the main project by returning undefined!
2250 if (@{@$project[$P_TARGETS]} > 0) {
2251 generate_list("DLLS",1,\@dll_list,sub
2253 return @{$_[0]}[$T_NAME];
2255 generate_list("EXES",1,\@exe_list,sub
2257 return "@{$_[0]}[$T_NAME]";
2259 print FILEO "\n\n\n";
2261 print FILEO "### Common settings\n\n";
2262 # Make it so that the project-wide settings override the global settings
2263 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2264 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2265 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2266 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2267 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2268 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2269 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2270 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2271 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2272 print FILEO "\n\n";
2274 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2275 @{@$project_settings[$T_SOURCES_CXX]}+
2276 @{@$project_settings[$T_SOURCES_RC]};
2277 my $no_extra=($extra_source_count == 0);
2278 if (!$no_extra) {
2279 print FILEO "### Extra source lists\n\n";
2280 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2281 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2282 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2283 print FILEO "\n";
2284 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2285 print FILEO "\n\n\n";
2288 # Iterate over all the targets...
2289 foreach my $target (@{@$project[$P_TARGETS]}) {
2290 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2291 my $canon=canonize("@$target[$T_NAME]");
2292 $canon =~ s+_so$++;
2294 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2295 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2296 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2297 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2298 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2299 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2300 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2301 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2302 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2303 print FILEO "\n";
2304 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2305 print FILEO "\n\n\n";
2307 print FILEO "### Global source lists\n\n";
2308 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2310 my $canon=canonize(@{$_[0]}[$T_NAME]);
2311 $canon =~ s+_so$++;
2312 return "\$(${canon}_C_SRCS)";
2314 if (!$no_extra) {
2315 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2317 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2319 my $canon=canonize(@{$_[0]}[$T_NAME]);
2320 $canon =~ s+_so$++;
2321 return "\$(${canon}_CXX_SRCS)";
2323 if (!$no_extra) {
2324 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2326 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2328 my $canon=canonize(@{$_[0]}[$T_NAME]);
2329 $canon =~ s+_so$++;
2330 return "\$(${canon}_RC_SRCS)";
2332 if (!$no_extra) {
2333 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2336 print FILEO "\n\n";
2337 print FILEO "### Tools\n\n";
2338 print FILEO "CC = winegcc\n";
2339 print FILEO "CXX = wineg++\n";
2340 print FILEO "RC = wrc\n";
2341 print FILEO "\n\n";
2343 print FILEO "### Generic targets\n\n";
2344 print FILEO "all:";
2345 if (@$project[$P_PATH] eq "") {
2346 print FILEO " \$(SUBDIRS)";
2348 if (@{@$project[$P_TARGETS]} > 0) {
2349 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2351 print FILEO "\n\n";
2352 print FILEO "### Build rules\n";
2353 print FILEO "\n";
2354 print FILEO ".PHONY: all clean dummy\n";
2355 print FILEO "\n";
2356 print FILEO "\$(SUBDIRS): dummy\n";
2357 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2358 print FILEO "\n";
2359 print FILEO "# Implicit rules\n";
2360 print FILEO "\n";
2361 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2362 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2363 print FILEO "\n";
2364 print FILEO ".c.o:\n";
2365 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2366 print FILEO "\n";
2367 print FILEO ".cpp.o:\n";
2368 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2369 print FILEO "\n";
2370 print FILEO ".cxx.o:\n";
2371 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2372 print FILEO "\n";
2373 print FILEO ".rc.res:\n";
2374 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2375 print FILEO "\n";
2376 print FILEO "# Rules for cleaning\n";
2377 print FILEO "\n";
2378 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2379 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2380 print FILEO "\n";
2381 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2382 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2383 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2384 print FILEO "\n";
2385 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2386 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2387 print FILEO "\n";
2388 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2389 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2390 print FILEO "\n";
2392 if (@{@$project[$P_TARGETS]} > 0) {
2393 print FILEO "### Target specific build rules\n";
2394 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2395 foreach my $target (@{@$project[$P_TARGETS]}) {
2396 my $canon=canonize("@$target[$T_NAME]");
2397 $canon =~ s/_so$//;
2399 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2400 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2401 print FILEO "\t\$(CXX)";
2402 } else {
2403 print FILEO "\t\$(CC)";
2405 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2406 print FILEO "\n\n";
2409 close(FILEO);
2415 # This is where we finally generate files. In fact this method does not
2416 # do anything itself but calls the methods that do the actual work.
2417 sub generate()
2419 print "Generating project files...\n";
2421 foreach my $project (@projects) {
2422 my $path=@$project[$P_PATH];
2423 if ($path eq "") {
2424 $path=".";
2425 } else {
2426 $path =~ s+/$++;
2428 print " $path\n";
2429 generate_project_files($project);
2435 #####
2437 # Option defaults
2439 #####
2441 $opt_backup=1;
2442 $opt_lower=$OPT_LOWER_UPPERCASE;
2443 $opt_lower_include=1;
2445 $opt_work_dir=undef;
2446 $opt_single_target=undef;
2447 $opt_target_type=$TT_GUIEXE;
2448 $opt_flags=0;
2449 $opt_is_interactive=$OPT_ASK_NO;
2450 $opt_ask_project_options=$OPT_ASK_NO;
2451 $opt_ask_target_options=$OPT_ASK_NO;
2452 $opt_no_generated_files=0;
2453 $opt_no_source_fix=0;
2454 $opt_no_banner=0;
2458 #####
2460 # Main
2462 #####
2464 sub print_banner()
2466 print "Winemaker $version\n";
2467 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2468 print "Copyright 2004 Dimitrie O. Paun\n";
2469 print "Copyright 2009 André Hentschel\n";
2472 sub usage()
2474 print_banner();
2475 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2476 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2477 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2478 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2479 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2480 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2481 print STDERR " [--generated-files|--nogenerated-files]\n";
2482 print STDERR " work_directory|project_file|workspace_file\n";
2483 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2484 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2485 print STDERR "process it will modify and rename some of the files in that directory.\n";
2486 print STDERR "\tPlease read the manual page before use.\n";
2487 exit (2);
2490 target_init(\@global_settings);
2492 while (@ARGV>0) {
2493 my $arg=shift @ARGV;
2494 # General options
2495 if ($arg eq "--nobanner") {
2496 $opt_no_banner=1;
2497 } elsif ($arg eq "--backup") {
2498 $opt_backup=1;
2499 } elsif ($arg eq "--nobackup") {
2500 $opt_backup=0;
2501 } elsif ($arg eq "--single-target") {
2502 $opt_single_target=shift @ARGV;
2503 } elsif ($arg eq "--lower-none") {
2504 $opt_lower=$OPT_LOWER_NONE;
2505 } elsif ($arg eq "--lower-all") {
2506 $opt_lower=$OPT_LOWER_ALL;
2507 } elsif ($arg eq "--lower-uppercase") {
2508 $opt_lower=$OPT_LOWER_UPPERCASE;
2509 } elsif ($arg eq "--lower-include") {
2510 $opt_lower_include=1;
2511 } elsif ($arg eq "--nolower-include") {
2512 $opt_lower_include=0;
2513 } elsif ($arg eq "--nosource-fix") {
2514 $opt_no_source_fix=1;
2515 } elsif ($arg eq "--generated-files") {
2516 $opt_no_generated_files=0;
2517 } elsif ($arg eq "--nogenerated-files") {
2518 $opt_no_generated_files=1;
2519 } elsif ($arg =~ /^-D/) {
2520 push @{$global_settings[$T_DEFINES]},$arg;
2521 } elsif ($arg =~ /^-I/) {
2522 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2523 } elsif ($arg =~ /^-P/) {
2524 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2525 } elsif ($arg =~ /^-i/) {
2526 push @{$global_settings[$T_DLLS]},$';
2527 } elsif ($arg =~ /^-L/) {
2528 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2529 } elsif ($arg =~ /^-l/) {
2530 push @{$global_settings[$T_LIBRARIES]},$';
2532 # 'Source'-based method options
2533 } elsif ($arg eq "--dll") {
2534 $opt_target_type=$TT_DLL;
2535 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2536 $opt_target_type=$TT_GUIEXE;
2537 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2538 $opt_target_type=$TT_CUIEXE;
2539 } elsif ($arg eq "--interactive") {
2540 $opt_is_interactive=$OPT_ASK_YES;
2541 $opt_ask_project_options=$OPT_ASK_YES;
2542 $opt_ask_target_options=$OPT_ASK_YES;
2543 } elsif ($arg eq "--mfc") {
2544 $opt_flags|=$TF_MFC;
2545 } elsif ($arg eq "--nomfc") {
2546 $opt_flags&=~$TF_MFC;
2547 $opt_flags|=$TF_NOMFC;
2548 } elsif ($arg eq "--nodlls") {
2549 $opt_flags|=$TF_NODLLS;
2550 } elsif ($arg eq "--nomsvcrt") {
2551 $opt_flags|=$TF_NOMSVCRT;
2553 # Catch errors
2554 } else {
2555 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2556 if (!defined $opt_work_dir and !defined $opt_work_file) {
2557 if (-f $arg) {
2558 $opt_work_file=$arg;
2560 else {
2561 $opt_work_dir=$arg;
2563 } else {
2564 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2565 usage();
2567 } else {
2568 usage();
2573 if (!defined $opt_work_dir and !defined $opt_work_file) {
2574 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2575 usage();
2576 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2577 print STDERR "error: could not chdir to the work directory\n";
2578 print STDERR " $!\n";
2579 usage();
2582 if ($opt_no_banner == 0) {
2583 print_banner();
2586 project_init(\@main_project, "", \@global_settings);
2588 # Fix the file and directory names
2589 fix_file_and_directory_names(".");
2591 # Scan the sources to identify the projects and targets
2592 source_scan();
2594 # Fix the source files
2595 if (! $opt_no_source_fix) {
2596 fix_source();
2599 # Generate the Makefile and the spec file
2600 if (! $opt_no_generated_files) {
2601 generate();