push 22b3e00525a9a3743634eb8f21ffe1bf98bf885e
[wine/hacks.git] / tools / winemaker
blob5300e15918b86852addfda51380176813b925d69
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 $prj_target_cflags.="-finline-functions ";
632 } elsif (/^Ob2$/) {
633 # auto In-line Function Expansion
634 $prj_target_cflags.="-finline-functions ";
635 } elsif (/^Ox$/) {
636 # Use maximum optimization
637 $prj_target_cflags.="-O3 ";
638 } elsif (/^Oy$/) {
639 # Frame-Pointer Omission
640 $prj_target_cflags.="-fomit-frame-pointer ";
641 } elsif (/^Oy-$/) {
642 # Frame-Pointer Omission
643 $prj_target_cflags.="-fno-omit-frame-pointer ";
644 } elsif (/^GZ$/) {
645 # Catch Release-Build Errors in Debug Build
646 } elsif (/^M[DLT]d?$/) {
647 # Use Multithreaded Run-Time Library
648 } elsif (/^D\s*\"(.*)\"/) {
649 # Preprocessor Definitions
650 $prj_target_cflags.="-D".$1." ";
651 } elsif (/^I/) {
652 # Additional Include Directories
653 #$prj_target_cflags.="-I" fixpath(option)
654 } elsif (/^U\s*\"(.*)\"/) {
655 # Undefines a previously defined symbol
656 $prj_target_cflags.="-U".$1." ";
657 } elsif (/^Fp/) {
658 # Name .PCH File
659 } elsif (/^F[Rr]/) {
660 # Create .SBR File
661 } elsif (/^YX$/) {
662 # Automatic Use of Precompiled Headers
663 } elsif (/^FD$/) {
664 # Generate File Dependencies
665 } elsif (/^c$/) {
666 # Compile Without Linking
667 # this option is always present and is already specified in the suffix rules
668 } elsif (/^GB$/) {
669 # Blend Optimization
670 $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 ";
671 } elsif (/^G6$/) {
672 # Pentium Pro Optimization
673 $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 ";
674 } elsif (/^G5$/) {
675 # Pentium Optimization
676 $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 ";
677 } elsif (/^G3$/) {
678 # 80386 Optimization
679 $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 ";
680 } elsif (/^G4$/) {
681 # 80486 Optimization
682 $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 ";
683 } elsif (/^Yc/) {
684 # Create Precompiled Header
685 } elsif (/^Yu/) {
686 # Use Precompiled Header
687 } elsif (/^Za$/) {
688 # Disable Language Extensions
689 $prj_target_cflags.="-ansi ";
690 } elsif (/^Ze$/) {
691 # Enable Microsoft Extensions
692 } elsif (/^Zm[[:digit:]]+$/) {
693 # Specify Memory Allocation Limit
694 } elsif (/^Zp1?$/) {
695 # Packs structures on 1-byte boundaries
696 $prj_target_cflags.="-fpack-struct ";
697 } elsif (/^Zp(2|4|8|16)$/) {
698 # Struct Member Alignment
699 $prj_target_cflags.="-fpack-struct=".$1;
700 } else {
701 print "C compiler option $_ not implemented\n";
705 #print "\nOptions: $prj_target_cflags\n";
706 next;
707 } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
708 $prj_target_ldflags=$1;
709 @prj_target_options=split(" /", $prj_target_ldflags);
710 $prj_target_ldflags="";
711 $prj_target_libs=$prj_target_options[0];
712 #print "\n$prj_target_libs bevor\n";
713 $prj_target_libs=~s/\\/\//g;
714 $prj_target_libs=~s/\.lib//g;
715 $prj_target_libs=~s/\s+/ -l/g;
716 #print "\n$prj_target_libs after\n";
717 shift (@prj_target_options);
718 foreach ( @prj_target_options ) {
719 if ($_ eq "") {
720 # empty
721 } elsif (/^base:(.*)/) {
722 # Base Address
723 $prj_target_ldflags.="--image-base ".$1." ";
724 } elsif (/^debug$/) {
725 # Generate Debug Info
726 } elsif (/^dll$/) {
727 # Build a DLL
728 $prj_target_type=3;
729 } elsif (/^incremental:[[:alpha:]]+$/) {
730 # Link Incrmentally
731 } elsif (/^implib:/) {
732 # Name import library
733 } elsif (/^libpath:\"(.*)\"/) {
734 # Additional Libpath
735 push @{@$project_settings[$T_DLL_PATH]},"-L$1";
736 } elsif (/^machine:[[:alnum:]]+$/) {
737 # Specify Target Platform
738 } elsif (/^map/) {
739 # Generate Mapfile
740 if (/^map:(.*)/) {
741 $prj_target_ldflags.="-Map ".$1." ";
742 } else {
743 $prj_target_ldflags.="-Map ".$prj_name.".map ";
745 } elsif (/^nologo$/) {
746 # Suppress Startup Banner and Information Messages
747 } elsif (/^out:/) {
748 # Output File Name
749 # may use it as Target?
750 } elsif (/^pdbtype:/) {
751 # Program Database Storage
752 } elsif (/^subsystem:/) {
753 # Specify Subsystem
754 } elsif (/^version:[[:digit:].]+$/) {
755 # Version Information
756 } else {
757 print "Linker option $_ not implemented\n";
760 next;
761 } elsif (/^LIB32=/ && $found_cfg==1) {
762 #$libflag = 1;
763 next;
764 } elsif (/^SOURCE=(.*)$/) {
765 my @components=split /[\/\\]+/, $1;
766 $sfilet=search_from($path, \@components);
767 if ($sfilet =~ /\.(exe|dll)$/i) {
768 $targets{$sfilet}=1;
769 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
770 push @sources_c,$sfilet;
771 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
772 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
773 push @sources_misc,$sfilet;
774 @$project_settings[$T_FLAGS]|=$TF_MFC;
775 } else {
776 push @sources_cxx,$sfilet;
778 } elsif ($sfilet =~ /\.rc$/i) {
779 push @sources_rc,$sfilet;
780 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
781 push @sources_misc,$sfilet;
782 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
783 @$project_settings[$T_FLAGS]|=$TF_MFC;
786 next;
788 } elsif (/^# (Begin|End) Source File/) {
789 # Source-Files already handled
790 next;
791 } elsif (/^# (Begin|End) Group/) {
792 # Groups are ignored
793 next;
794 } elsif (/^# (Begin|End) Custom Build/) {
795 # Custom Builds are ignored
796 next;
797 } elsif (/^# ADD LIB32 /) {
798 #"ARFLAGS=rus"
799 next;
800 } elsif (/^# Begin Target$/) {
801 # Targets are ignored
802 next;
803 } elsif (/^# End Target$/) {
804 # Targets are ignored
805 next;
806 } elsif (/^!/) {
807 if ($found_cfg == 1) {
808 $found_cfg=0;
810 if (/if (.*)\(CFG\)" == "(.*)"/i) {
811 if ($2 eq $prj_cfg) {
812 $found_cfg=1;
815 next;
816 } elsif (/^CFG=(.*)/i) {
817 $prj_cfg=$1;
818 next;
820 else { # Line recognized
821 # print "|\n";
824 close(FILEI);
826 push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
827 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
828 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
829 push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
830 } elsif ($filename =~ /.vcproj$/i) {
831 # Import des Moduls XML::Simple
832 use XML::Simple;
834 my $project_xml = XMLin($filename, forcearray=>1);
836 $targets{$project_xml->{'Name'}.".exe"}=1;
837 my $sfilet;
838 for my $vc_files (@{$project_xml->{'Files'}}) {
839 for my $vc_filter (@{$vc_files->{'Filter'}}) {
840 for my $vc_file (@{$vc_filter->{'File'}}) {
841 $sfilet=$vc_file->{'RelativePath'};
842 $sfilet=~s/\\\\/\\/g; #remove double backslash
843 $sfilet=~s/^\.\\//; #remove starting 'this directory'
844 $sfilet=~s/\\/\//g; #make slashes out of backslashes
845 if ($sfilet =~ /\.(exe|dll)$/i) {
846 $targets{$sfilet}=1;
847 } elsif ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
848 push @sources_c,$sfilet;
849 } elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
850 if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
851 push @sources_misc,$sfilet;
852 @$project_settings[$T_FLAGS]|=$TF_MFC;
853 } else {
854 push @sources_cxx,$sfilet;
856 } elsif ($sfilet =~ /\.rc$/i) {
857 push @sources_rc,$sfilet;
858 } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
859 push @sources_misc,$sfilet;
860 if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
861 @$project_settings[$T_FLAGS]|=$TF_MFC;
867 $prj_target_cflags="";
868 for my $vc_configurations (@{$project_xml->{'Configurations'}}) {
869 for my $vc_configuration (@{$vc_configurations->{'Configuration'}}) {
870 for my $vc_tool (@{$vc_configuration->{'Tool'}}) {
871 if ($vc_tool->{'Name'} ne 'VCCLCompilerTool') { next; }
872 if (defined $vc_tool->{'Optimization'}) {$prj_target_cflags.="-O".$vc_tool->{'Optimization'}." ";}
873 if (defined $vc_tool->{'WarningLevel'}) {
874 if ($vc_tool->{'WarningLevel'}==0) {
875 $prj_target_cflags.="-w ";
876 } elsif ($vc_tool->{'WarningLevel'}<4) {
877 $prj_target_cflags.="-W ";
878 } elsif ($vc_tool->{'WarningLevel'}==4) {
879 $prj_target_cflags.="-Wall ";
880 } elsif ($vc_tool->{'WarningLevel'} eq "X") {
881 $prj_target_cflags.="-Werror ";
884 if (defined $vc_tool->{'PreprocessorDefinitions'}) {
885 $vc_tool->{'PreprocessorDefinitions'}=~s/;/ -D/g;
886 $prj_target_cflags.="-D".$vc_tool->{'PreprocessorDefinitions'}." ";
888 if (defined $vc_tool->{'AdditionalIncludeDirectories'}) {
889 $vc_tool->{'AdditionalIncludeDirectories'}=~s/\\/\//g;
890 $vc_tool->{'AdditionalIncludeDirectories'}=~s/;/ -I/g;
891 push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$vc_tool->{'AdditionalIncludeDirectories'};
894 last;
897 push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
898 push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
901 my $target_count;
902 $target_count=keys %targets;
905 # Add this project to the project list, except for
906 # the main project which is already in the list.
907 if ($is_sub_project == 1) {
908 push @projects,$project;
911 # Ask for project-wide options
912 if ($opt_ask_project_options == $OPT_ASK_YES) {
913 my $flag_desc="";
914 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
915 $flag_desc="mfc";
917 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
918 if (defined $flag_desc) {
919 print "* (currently $flag_desc)\n";
921 print "* or 'skip' to skip the target specific options,\n";
922 print "* or 'never' to not be asked this question again:\n";
923 while (1) {
924 my $options=<STDIN>;
925 chomp $options;
926 if ($options eq "skip") {
927 $opt_ask_target_options=$OPT_ASK_SKIP;
928 last;
929 } elsif ($options eq "never") {
930 $opt_ask_project_options=$OPT_ASK_NO;
931 last;
932 } elsif (source_set_options($project_settings,$options)) {
933 last;
935 print "Please re-enter the options:\n";
939 # - Create the targets
940 # - Check if we have both libraries and programs
941 # - Match each target with source files (sort in reverse
942 # alphabetical order to get the longest matches first)
943 my @local_dlls=();
944 my @local_depends=();
945 my @exe_list=();
946 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
947 # Create the target...
948 my $target=[];
949 target_init($target);
950 @$target[$T_NAME]=$target_name;
951 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
952 if ($target_name =~ /\.dll$/) {
953 @$target[$T_TYPE]=$TT_DLL;
954 push @local_depends,"$target_name.so";
955 push @local_dlls,$target_name;
956 my $canon=canonize($target_name);
957 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
958 } else {
959 @$target[$T_TYPE]=$opt_target_type;
960 push @exe_list,$target;
961 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
963 my $basename=$target_name;
964 $basename=~ s/\.(dll|exe)$//i;
965 # This is the default link list of Visual Studio
966 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
967 my @std_libraries=qw(uuid);
968 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
969 @$target[$T_DLLS]=\@std_imports;
970 @$target[$T_LIBRARIES]=\@std_libraries;
971 } else {
972 @$target[$T_DLLS]=[];
973 @$target[$T_LIBRARIES]=[];
975 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
976 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
977 push @{@$target[$T_LDFLAGS]},"-m32";
979 push @{@$project[$P_TARGETS]},$target;
981 # Ask for target-specific options
982 if ($opt_ask_target_options == $OPT_ASK_YES) {
983 my $flag_desc="";
984 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
985 $flag_desc=" (mfc";
987 if ($flag_desc ne "") {
988 $flag_desc.=")";
990 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
991 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
992 while (1) {
993 my $options=<STDIN>;
994 chomp $options;
995 if ($options eq "never") {
996 $opt_ask_target_options=$OPT_ASK_NO;
997 last;
998 } elsif (source_set_options($target,$options)) {
999 last;
1001 print "Please re-enter the options:\n";
1004 if (@$target[$T_FLAGS] & $TF_MFC) {
1005 @$project_settings[$T_FLAGS]|=$TF_MFC;
1006 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1007 push @{@$target[$T_DLLS]},"mfc.dll";
1008 # FIXME: Link with the MFC in the Unix sense, until we
1009 # start exporting the functions properly.
1010 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1011 push @{@$target[$T_LIBRARIES]},"mfc";
1014 # Match sources...
1015 if ($target_count == 1) {
1016 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1017 @$project_settings[$T_SOURCES_C]=[];
1018 @sources_c=();
1020 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1021 @$project_settings[$T_SOURCES_CXX]=[];
1022 @sources_cxx=();
1024 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1025 @$project_settings[$T_SOURCES_RC]=[];
1026 @sources_rc=();
1028 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1029 # No need for sorting these sources
1030 @$project_settings[$T_SOURCES_MISC]=[];
1031 @sources_misc=();
1033 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1034 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1035 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1036 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1038 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1039 $opt_ask_target_options=$OPT_ASK_YES;
1042 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1043 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1044 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1047 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1048 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1050 # The sources that did not match, if any, go to the extra
1051 # source list of the project settings
1052 foreach my $source (@sources_c) {
1053 if ($source ne "") {
1054 push @{@$project_settings[$T_SOURCES_C]},$source;
1057 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1058 foreach my $source (@sources_cxx) {
1059 if ($source ne "") {
1060 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1063 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1064 foreach my $source (@sources_rc) {
1065 if ($source ne "") {
1066 push @{@$project_settings[$T_SOURCES_RC]},$source;
1069 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1070 foreach my $source (@sources_misc) {
1071 if ($source ne "") {
1072 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1075 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1079 # Scans the specified workspace file to find the project files
1080 sub source_scan_workspace_file($);
1081 sub source_scan_workspace_file($)
1083 my $filename=$_[0];
1084 my $path=dirname($filename);
1085 my @components;
1087 if (! -e $filename) {
1088 return;
1091 if (!open(FILEIWS,$filename)) {
1092 print STDERR "error: unable to open $filename for reading:\n";
1093 print STDERR " $!\n";
1094 return;
1097 my $prj_name;
1098 my $prj_path;
1100 if ($filename =~ /.dsw$/i) {
1101 while (<FILEIWS>) {
1102 # Remove any trailing CrLf
1103 s/\r\n$/\n/;
1105 # catch a project definition
1106 if (/^Project:\s\"(.*)\"=\"?(.*)\s-/) {
1107 $prj_name=$1;
1108 $prj_path=$2;
1109 $prj_path=~s/\"$//;
1110 @components=split /[\/\\]+/, $prj_path;
1111 $prj_path=search_from($path, \@components);
1112 print "Name: $prj_name\nPath: $prj_path\n";
1113 source_scan_project_file(\@main_project,1,$prj_path);
1114 next;
1115 } elsif (/^#/) {
1116 # ignore Comments
1117 } elsif (/\w:/) {
1118 print STDERR "unknown section $_\n";
1119 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1120 print "\nFileversion: $3\n";
1123 close(FILEIWS);
1124 } elsif ($filename =~ /.sln$/i) {
1125 while (<FILEIWS>) {
1126 # Remove any trailing CrLf
1127 s/\r\n$/\n/;
1129 # catch a project definition
1130 if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
1131 $prj_name=$2;
1132 $prj_path=$3;
1133 @components=split /[\/\\]+/, $3;
1134 $prj_path=search_from($path, \@components);
1135 print "Name: $prj_name\nPath: $prj_path\n";
1136 source_scan_project_file(\@main_project,1,$prj_path);
1137 next;
1138 } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
1139 print "\nFileversion: $3\n";
1142 close(FILEIWS);
1145 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1149 # Scans the specified directory to:
1150 # - see if we should create a Makefile in this directory. We normally do
1151 # so if we find a project file and sources
1152 # - get a list of targets for this directory
1153 # - get the list of source files
1154 sub source_scan_directory($$$$);
1155 sub source_scan_directory($$$$)
1157 # a reference to the parent's project
1158 my $parent_project=$_[0];
1159 # the full relative path to the current directory, including a
1160 # trailing '/', or an empty string if this is the top level directory
1161 my $path=$_[1];
1162 # the name of this directory, including a trailing '/', or an empty
1163 # string if this is the top level directory
1164 my $dirname=$_[2];
1165 # if set then no targets will be looked for and the sources will all
1166 # end up in the parent_project's 'misc' bucket
1167 my $no_target=$_[3];
1169 # reference to the project for this directory. May not be used
1170 my $project;
1171 # list of targets found in the 'current' directory
1172 my %targets;
1173 # list of sources found in the current directory
1174 my @sources_c=();
1175 my @sources_cxx=();
1176 my @sources_rc=();
1177 my @sources_misc=();
1178 # true if this directory contains a Windows project
1179 my $has_win_project=0;
1180 # true if this directory contains headers
1181 my $has_headers=0;
1182 # If we don't find any executable/library then we might make up targets
1183 # from the list of .dsp/.mak files we find since they usually have the
1184 # same name as their target.
1185 my @dsp_files=();
1186 my @mak_files=();
1188 if (defined $opt_single_target or $dirname eq "") {
1189 # Either there is a single target and thus a single project,
1190 # or we are in the top level directory for which a project
1191 # already exists
1192 $project=$parent_project;
1193 } else {
1194 $project=[];
1195 project_init($project, $path, \@global_settings);
1197 my $project_settings=@$project[$P_SETTINGS];
1199 # First find out what this directory contains:
1200 # collect all sources, targets and subdirectories
1201 my $directory=get_directory_contents($path);
1202 foreach my $dentry (@$directory) {
1203 if ($dentry =~ /^\./) {
1204 next;
1206 my $fullentry="$path$dentry";
1207 if (-d "$fullentry") {
1208 if ($dentry =~ /^(Release|Debug)/i) {
1209 # These directories are often used to store the object files and the
1210 # resulting executable/library. They should not contain anything else.
1211 my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
1212 foreach my $candidate (@candidates) {
1213 $targets{$candidate}=1;
1215 } elsif ($dentry =~ /^include/i) {
1216 # This directory must contain headers we're going to need
1217 push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
1218 source_scan_directory($project,"$fullentry/","$dentry/",1);
1219 } else {
1220 # Recursively scan this directory. Any source file that cannot be
1221 # attributed to a project in one of the subdirectories will be
1222 # attributed to this project.
1223 source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
1225 } elsif (-f "$fullentry") {
1226 if ($dentry =~ /\.(exe|dll)$/i) {
1227 $targets{$dentry}=1;
1228 } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
1229 push @sources_c,"$dentry";
1230 } elsif ($dentry =~ /\.(cpp|cxx)$/i) {
1231 if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1232 push @sources_misc,"$dentry";
1233 @$project_settings[$T_FLAGS]|=$TF_MFC;
1234 } else {
1235 push @sources_cxx,"$dentry";
1237 } elsif ($dentry =~ /\.rc$/i) {
1238 push @sources_rc,"$dentry";
1239 } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
1240 $has_headers=1;
1241 push @sources_misc,"$dentry";
1242 if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
1243 @$project_settings[$T_FLAGS]|=$TF_MFC;
1245 } elsif ($dentry =~ /\.dsp$/i) {
1246 push @dsp_files,"$dentry";
1247 $has_win_project=1;
1248 } elsif ($dentry =~ /\.mak$/i) {
1249 push @mak_files,"$dentry";
1250 $has_win_project=1;
1251 } elsif ($dentry =~ /^makefile/i) {
1252 $has_win_project=1;
1257 if ($has_headers) {
1258 push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
1260 # If we have a single target then all we have to do is assign
1261 # all the sources to it and we're done
1262 # FIXME: does this play well with the --interactive mode?
1263 if ($opt_single_target) {
1264 my $target=@{@$project[$P_TARGETS]}[0];
1265 push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
1266 push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
1267 push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
1268 push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
1269 return;
1271 if ($no_target) {
1272 my $parent_settings=@$parent_project[$P_SETTINGS];
1273 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
1274 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
1275 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
1276 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1277 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1278 return;
1281 my $source_count=@sources_c+@sources_cxx+@sources_rc+
1282 @{@$project_settings[$T_SOURCES_C]}+
1283 @{@$project_settings[$T_SOURCES_CXX]}+
1284 @{@$project_settings[$T_SOURCES_RC]};
1285 if ($source_count == 0) {
1286 # A project without real sources is not a project, get out!
1287 if ($project!=$parent_project) {
1288 my $parent_settings=@$parent_project[$P_SETTINGS];
1289 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1290 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1292 return;
1294 #print "targets=",%targets,"\n";
1295 #print "target_count=$target_count\n";
1296 #print "has_win_project=$has_win_project\n";
1297 #print "dirname=$dirname\n";
1299 my $target_count;
1300 if (($has_win_project != 0) or ($dirname eq "")) {
1301 # Deal with cases where we could not find any executable/library, and
1302 # thus have no target, although we did find some sort of windows project.
1303 $target_count=keys %targets;
1304 if ($target_count == 0) {
1305 # Try to come up with a target list based on .dsp/.mak files
1306 my $prj_list;
1307 if (@dsp_files > 0) {
1308 $prj_list=\@dsp_files;
1309 } else {
1310 $prj_list=\@mak_files;
1312 foreach my $filename (@$prj_list) {
1313 $filename =~ s/\.(dsp|mak)$//i;
1314 if ($opt_target_type == $TT_DLL) {
1315 $filename = "$filename.dll";
1317 $targets{$filename}=1;
1319 $target_count=keys %targets;
1320 if ($target_count == 0) {
1321 # Still nothing, try the name of the directory
1322 my $name;
1323 if ($dirname eq "") {
1324 # Bad luck, this is the top level directory!
1325 $name=(split /\//, cwd)[-1];
1326 } else {
1327 $name=$dirname;
1328 # Remove the trailing '/'. Also eliminate whatever is after the last
1329 # '.' as it is likely to be meaningless (.orig, .new, ...)
1330 $name =~ s+(/|\.[^.]*)$++;
1331 if ($name eq "src") {
1332 # 'src' is probably a subdirectory of the real project directory.
1333 # Try again with the parent (if any).
1334 my $parent=$path;
1335 if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
1336 $name=$parent;
1337 } else {
1338 $name=(split /\//, cwd)[-1];
1342 $name =~ s+(/|\.[^.]*)$++;
1343 if ($opt_target_type == $TT_DLL) {
1344 $name = canonize($name).".dll";
1345 } else {
1346 $name = canonize($name).".exe";
1348 $targets{$name}=1;
1352 # Ask confirmation to the user if he wishes so
1353 if ($opt_is_interactive == $OPT_ASK_YES) {
1354 my $target_list=join " ",keys %targets;
1355 print "\n*** In ",($path?$path:"./"),"\n";
1356 print "* winemaker found the following list of (potential) targets\n";
1357 print "* $target_list\n";
1358 print "* Type enter to use it as is, your own comma-separated list of\n";
1359 print "* targets, 'none' to assign the source files to a parent directory,\n";
1360 print "* or 'ignore' to ignore everything in this directory tree.\n";
1361 print "* Target list:\n";
1362 $target_list=<STDIN>;
1363 chomp $target_list;
1364 if ($target_list eq "") {
1365 # Keep the target list as is, i.e. do nothing
1366 } elsif ($target_list eq "none") {
1367 # Empty the target list
1368 undef %targets;
1369 } elsif ($target_list eq "ignore") {
1370 # Ignore this subtree altogether
1371 return;
1372 } else {
1373 undef %targets;
1374 foreach my $target (split /,/,$target_list) {
1375 $target =~ s+^\s*++;
1376 $target =~ s+\s*$++;
1377 $targets{$target}=1;
1383 # If we have no project at this level, then transfer all
1384 # the sources to the parent project
1385 $target_count=keys %targets;
1386 if ($target_count == 0) {
1387 if ($project!=$parent_project) {
1388 my $parent_settings=@$parent_project[$P_SETTINGS];
1389 push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
1390 push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
1391 push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
1392 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
1393 push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
1395 return;
1398 # Otherwise add this project to the project list, except for
1399 # the main project which is already in the list.
1400 if ($dirname ne "") {
1401 push @projects,$project;
1404 # Ask for project-wide options
1405 if ($opt_ask_project_options == $OPT_ASK_YES) {
1406 my $flag_desc="";
1407 if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
1408 $flag_desc="mfc";
1410 print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
1411 if (defined $flag_desc) {
1412 print "* (currently $flag_desc)\n";
1414 print "* or 'skip' to skip the target specific options,\n";
1415 print "* or 'never' to not be asked this question again:\n";
1416 while (1) {
1417 my $options=<STDIN>;
1418 chomp $options;
1419 if ($options eq "skip") {
1420 $opt_ask_target_options=$OPT_ASK_SKIP;
1421 last;
1422 } elsif ($options eq "never") {
1423 $opt_ask_project_options=$OPT_ASK_NO;
1424 last;
1425 } elsif (source_set_options($project_settings,$options)) {
1426 last;
1428 print "Please re-enter the options:\n";
1432 # - Create the targets
1433 # - Check if we have both libraries and programs
1434 # - Match each target with source files (sort in reverse
1435 # alphabetical order to get the longest matches first)
1436 my @local_dlls=();
1437 my @local_depends=();
1438 my @exe_list=();
1439 foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
1440 # Create the target...
1441 my $target=[];
1442 target_init($target);
1443 @$target[$T_NAME]=$target_name;
1444 @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
1445 if ($target_name =~ /\.dll$/) {
1446 @$target[$T_TYPE]=$TT_DLL;
1447 push @local_depends,"$target_name.so";
1448 push @local_dlls,$target_name;
1449 my $canon=canonize($target_name);
1450 push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)");
1451 } else {
1452 @$target[$T_TYPE]=$opt_target_type;
1453 push @exe_list,$target;
1454 push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
1456 my $basename=$target_name;
1457 $basename=~ s/\.(dll|exe)$//i;
1458 # This is the default link list of Visual Studio
1459 my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
1460 my @std_libraries=qw(uuid);
1461 if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
1462 @$target[$T_DLLS]=\@std_imports;
1463 @$target[$T_LIBRARIES]=\@std_libraries;
1464 } else {
1465 @$target[$T_DLLS]=[];
1466 @$target[$T_LIBRARIES]=[];
1468 if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1469 push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
1470 push @{@$target[$T_LDFLAGS]},"-m32";
1472 push @{@$project[$P_TARGETS]},$target;
1474 # Ask for target-specific options
1475 if ($opt_ask_target_options == $OPT_ASK_YES) {
1476 my $flag_desc="";
1477 if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
1478 $flag_desc=" (mfc";
1480 if ($flag_desc ne "") {
1481 $flag_desc.=")";
1483 print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
1484 print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
1485 while (1) {
1486 my $options=<STDIN>;
1487 chomp $options;
1488 if ($options eq "never") {
1489 $opt_ask_target_options=$OPT_ASK_NO;
1490 last;
1491 } elsif (source_set_options($target,$options)) {
1492 last;
1494 print "Please re-enter the options:\n";
1497 if (@$target[$T_FLAGS] & $TF_MFC) {
1498 @$project_settings[$T_FLAGS]|=$TF_MFC;
1499 push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
1500 push @{@$target[$T_DLLS]},"mfc.dll";
1501 # FIXME: Link with the MFC in the Unix sense, until we
1502 # start exporting the functions properly.
1503 push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
1504 push @{@$target[$T_LIBRARIES]},"mfc";
1507 # Match sources...
1508 if ($target_count == 1) {
1509 push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
1510 @$project_settings[$T_SOURCES_C]=[];
1511 @sources_c=();
1513 push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
1514 @$project_settings[$T_SOURCES_CXX]=[];
1515 @sources_cxx=();
1517 push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
1518 @$project_settings[$T_SOURCES_RC]=[];
1519 @sources_rc=();
1521 push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
1522 # No need for sorting these sources
1523 @$project_settings[$T_SOURCES_MISC]=[];
1524 @sources_misc=();
1525 } else {
1526 foreach my $source (@sources_c) {
1527 if ($source =~ /^$basename/i) {
1528 push @{@$target[$T_SOURCES_C]},$source;
1529 $source="";
1532 foreach my $source (@sources_cxx) {
1533 if ($source =~ /^$basename/i) {
1534 push @{@$target[$T_SOURCES_CXX]},$source;
1535 $source="";
1538 foreach my $source (@sources_rc) {
1539 if ($source =~ /^$basename/i) {
1540 push @{@$target[$T_SOURCES_RC]},$source;
1541 $source="";
1544 foreach my $source (@sources_misc) {
1545 if ($source =~ /^$basename/i) {
1546 push @{@$target[$T_SOURCES_MISC]},$source;
1547 $source="";
1551 @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
1552 @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
1553 @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
1554 @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
1556 if ($opt_ask_target_options == $OPT_ASK_SKIP) {
1557 $opt_ask_target_options=$OPT_ASK_YES;
1560 if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
1561 push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
1562 push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
1565 if (@$project_settings[$T_FLAGS] & $TF_MFC) {
1566 push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
1568 # The sources that did not match, if any, go to the extra
1569 # source list of the project settings
1570 foreach my $source (@sources_c) {
1571 if ($source ne "") {
1572 push @{@$project_settings[$T_SOURCES_C]},$source;
1575 @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
1576 foreach my $source (@sources_cxx) {
1577 if ($source ne "") {
1578 push @{@$project_settings[$T_SOURCES_CXX]},$source;
1581 @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
1582 foreach my $source (@sources_rc) {
1583 if ($source ne "") {
1584 push @{@$project_settings[$T_SOURCES_RC]},$source;
1587 @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
1588 foreach my $source (@sources_misc) {
1589 if ($source ne "") {
1590 push @{@$project_settings[$T_SOURCES_MISC]},$source;
1593 @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
1595 # Finally if we are building both libraries and programs in
1596 # this directory, then the programs should be linked with all
1597 # the libraries
1598 if (@local_dlls > 0 and @exe_list > 0) {
1599 foreach my $target (@exe_list) {
1600 push @{@$target[$T_DLL_PATH]},"-L.";
1601 push @{@$target[$T_DLLS]},@local_dlls;
1607 # Scan the source directories in search of things to build
1608 sub source_scan()
1610 # If there's a single target then this is going to be the default target
1611 if (defined $opt_single_target) {
1612 # Create the main target
1613 my $main_target=[];
1614 target_init($main_target);
1615 @$main_target[$T_NAME]=$opt_single_target;
1616 @$main_target[$T_TYPE]=$opt_target_type;
1618 # Add it to the list
1619 push @{$main_project[$P_TARGETS]},$main_target;
1622 # The main directory is always going to be there
1623 push @projects,\@main_project;
1625 if (defined $opt_work_dir) {
1626 # Now scan the directory tree looking for source files and, maybe, targets
1627 print "Scanning the source directories...\n";
1628 source_scan_directory(\@main_project,"","",0);
1629 @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
1630 } elsif (defined $opt_work_file) {
1631 if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
1632 source_scan_project_file(\@main_project,0,$opt_work_file);
1633 } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
1634 source_scan_workspace_file($opt_work_file);
1639 #####
1641 # Source search
1643 #####
1646 # Performs a directory traversal and renames the files so that:
1647 # - they have the case desired by the user
1648 # - their extension is of the appropriate case
1649 # - they don't contain annoying characters like ' ', '$', '#', ...
1650 # But only perform these changes for source files and directories.
1651 sub fix_file_and_directory_names($);
1652 sub fix_file_and_directory_names($)
1654 my $dirname=$_[0];
1656 my $directory=get_directory_contents($dirname);
1657 foreach my $dentry (@$directory)
1659 if ($dentry =~ /^\./ or $dentry eq "CVS") {
1660 next;
1662 # Set $warn to 1 if the user should be warned of the renaming
1663 my $warn;
1664 my $new_name=$dentry;
1666 if (-f "$dirname/$dentry")
1668 # Don't rename Winemaker's makefiles
1669 next if ($dentry eq "Makefile" and
1670 `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
1672 # Leave non-source files alone
1673 next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
1675 # Only all lowercase extensions are supported (because of
1676 # rules like '.c.o:'.
1677 $new_name =~ s/\.C$/.c/;
1678 $new_name =~ s/\.cpp$/.cpp/i;
1679 $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
1680 $new_name =~ s/\.rc$/.rc/i;
1681 # And this last one is to avoid confusion then running make
1682 $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
1685 # Adjust the case to the user's preferences
1686 if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
1687 ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
1689 $new_name=lc $new_name;
1692 # autoconf and make don't support these characters well
1693 $new_name =~ s/[ \$]/_/g;
1695 # And finally, perform the renaming
1696 if ($new_name ne $dentry)
1698 if ($warn) {
1699 print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
1701 if (!rename("$dirname/$dentry","$dirname/$new_name")) {
1702 print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
1703 print STDERR " $!\n";
1704 $new_name=$dentry;
1706 else
1708 clear_directory_cache($dirname);
1711 if (-d "$dirname/$new_name") {
1712 fix_file_and_directory_names("$dirname/$new_name");
1719 #####
1721 # Source fixup
1723 #####
1726 # Try to find a file for the specified filename. The attempt is
1727 # case-insensitive which is why it's not trivial. If a match is
1728 # found then we return the pathname with the correct case.
1729 sub search_from($$)
1731 my $dirname=$_[0];
1732 my $path=$_[1];
1733 my $real_path="";
1735 if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
1736 $dirname=cwd;
1737 } elsif ($dirname !~ m+^/+) {
1738 $dirname=cwd . "/" . $dirname;
1740 if ($dirname !~ m+/$+) {
1741 $dirname.="/";
1744 foreach my $component (@$path) {
1745 $component=~s/^\"//;
1746 $component=~s/\"$//;
1747 #print " looking for $component in \"$dirname\"\n";
1748 if ($component eq ".") {
1749 # Pass it as is
1750 $real_path.="./";
1751 } elsif ($component eq "..") {
1752 # Go up one level
1753 $dirname=dirname($dirname) . "/";
1754 $real_path.="../";
1755 } else {
1756 # The file/directory may have been renamed before. Also try to
1757 # match the renamed file.
1758 my $renamed=$component;
1759 $renamed =~ s/[ \$]/_/g;
1760 if ($renamed eq $component) {
1761 undef $renamed;
1764 my $directory=get_directory_contents $dirname;
1765 my $found;
1766 foreach my $dentry (@$directory) {
1767 if ($dentry =~ /^\Q$component\E$/i or
1768 (defined $renamed and $dentry =~ /^$renamed$/i)
1770 $dirname.="$dentry/";
1771 $real_path.="$dentry/";
1772 $found=1;
1773 last;
1776 if (!defined $found) {
1777 # Give up
1778 #print " could not find $component in $dirname\n";
1779 return;
1783 $real_path=~ s+/$++;
1784 #print " -> found $real_path\n";
1785 return $real_path;
1789 # Performs a case-insensitive search for the specified file in the
1790 # include path.
1791 # $line is the line number that should be referenced when an error occurs
1792 # $filename is the file we are looking for
1793 # $dirname is the directory of the file containing the '#include' directive
1794 # if '"' was used, it is an empty string otherwise
1795 # $project and $target specify part of the include path
1796 sub get_real_include_name($$$$$)
1798 my $line=$_[0];
1799 my $filename=$_[1];
1800 my $dirname=$_[2];
1801 my $project=$_[3];
1802 my $target=$_[4];
1804 if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
1805 # This is not a relative path, we cannot make any check
1806 my $warning="path:$filename";
1807 if (!defined $warnings{$warning}) {
1808 $warnings{$warning}="1";
1809 print STDERR "warning: cannot check the case of absolute pathnames:\n";
1810 print STDERR "$line: $filename\n";
1812 } else {
1813 # Here's how we proceed:
1814 # - split the filename we look for into its components
1815 # - then for each directory in the include path
1816 # - trace the directory components starting from that directory
1817 # - if we fail to find a match at any point then continue with
1818 # the next directory in the include path
1819 # - otherwise, rejoice, our quest is over.
1820 my @file_components=split /[\/\\]+/, $filename;
1821 #print " Searching for $filename from @$project[$P_PATH]\n";
1823 my $real_filename;
1824 if ($dirname ne "") {
1825 # This is an 'include ""' -> look in dirname first.
1826 #print " in $dirname (include \"\")\n";
1827 $real_filename=search_from($dirname,\@file_components);
1828 if (defined $real_filename) {
1829 return $real_filename;
1832 my $project_settings=@$project[$P_SETTINGS];
1833 foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
1834 my $dirname=$include;
1835 $dirname=~ s+^-I++;
1836 if (!is_absolute($dirname)) {
1837 $dirname="@$project[$P_PATH]$dirname";
1838 } else {
1839 $dirname=~ s+^\$\(TOPSRCDIR\)/++;
1840 $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
1842 #print " in $dirname\n";
1843 $real_filename=search_from("$dirname",\@file_components);
1844 if (defined $real_filename) {
1845 return $real_filename;
1848 my $dotdotpath=@$project[$P_PATH];
1849 $dotdotpath =~ s/[^\/]+/../g;
1850 foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
1851 my $dirname=$include;
1852 $dirname=~ s+^-I++;
1853 $dirname=~ s+^\$\(TOPSRCDIR\)\/++;
1854 $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
1855 #print " in $dirname (global setting)\n";
1856 $real_filename=search_from("$dirname",\@file_components);
1857 if (defined $real_filename) {
1858 return $real_filename;
1862 $filename =~ s+\\\\+/+g; # in include ""
1863 $filename =~ s+\\+/+g; # in include <> !
1864 if ($opt_lower_include) {
1865 return lc "$filename";
1867 return $filename;
1870 sub print_pack($$$)
1872 my $indent=$_[0];
1873 my $size=$_[1];
1874 my $trailer=$_[2];
1876 if ($size =~ /^(1|2|4|8)$/) {
1877 print FILEO "$indent#include <pshpack$size.h>$trailer";
1878 } else {
1879 print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
1880 print FILEO "$indent#include <pshpack4.h>$trailer";
1885 # 'Parses' a source file and fixes constructs that would not work with
1886 # Winelib. The parsing is rather simple and not all non-portable features
1887 # are corrected. The most important feature that is corrected is the case
1888 # and path separator of '#include' directives. This requires that each
1889 # source file be associated to a project & target so that the proper
1890 # include path is used.
1891 # Also note that the include path is relative to the directory in which the
1892 # compiler is run, i.e. that of the project, not to that of the file.
1893 sub fix_file($$$)
1895 my $filename=$_[0];
1896 my $project=$_[1];
1897 my $target=$_[2];
1898 $filename="@$project[$P_PATH]$filename";
1899 if (! -e $filename) {
1900 return;
1903 my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
1904 my $dirname=dirname($filename);
1905 my $is_mfc=0;
1906 if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
1907 $is_mfc=1;
1910 print " $filename\n";
1911 #FIXME:assuming that because there is a .bak file, this is what we want is
1912 #probably flawed. Or is it???
1913 if (! -e "$filename.bak") {
1914 if (!copy("$filename","$filename.bak")) {
1915 print STDERR "error: unable to make a backup of $filename:\n";
1916 print STDERR " $!\n";
1917 return;
1920 if (!open(FILEI,"$filename.bak")) {
1921 print STDERR "error: unable to open $filename.bak for reading:\n";
1922 print STDERR " $!\n";
1923 return;
1925 if (!open(FILEO,">$filename")) {
1926 print STDERR "error: unable to open $filename for writing:\n";
1927 print STDERR " $!\n";
1928 return;
1930 my $line=0;
1931 my $modified=0;
1932 my $rc_block_depth=0;
1933 my $rc_textinclude_state=0;
1934 my @pack_stack;
1935 while (<FILEI>) {
1936 # Remove any trailing CtrlZ, which isn't strictly in the file
1937 if (/\x1A/) {
1938 s/\x1A//;
1939 last if (/^$/)
1941 $line++;
1942 s/\r\n$/\n/;
1943 if (!/\n$/) {
1944 # Make sure all files are '\n' terminated
1945 $_ .= "\n";
1947 if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
1948 # VC6 automatically includes 'afxres.h', an MFC specific header, in
1949 # the RC files it generates (even in non-MFC projects). So we replace
1950 # it with 'winresrc.h' its very close standard cousin so that non MFC
1951 # projects can compile in Wine without the MFC sources.
1952 my $warning="mfc:afxres.h";
1953 if (!defined $warnings{$warning}) {
1954 $warnings{$warning}="1";
1955 print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
1956 print STDERR "warning: the above warning is issued only once\n";
1958 print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
1959 print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
1960 print FILEO "$1$2\"winresrc.h\"$'";
1961 $modified=1;
1963 } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
1964 my $from_file=($2 eq "<"?"":$dirname);
1965 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
1966 print FILEO "$1$2$real_include_name$4$'";
1967 $modified|=($real_include_name ne $3);
1969 } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
1970 # Pragma pack handling
1972 # pack_stack is an array of references describing the stack of
1973 # pack directives currently in effect. Each directive if described
1974 # by a reference to an array containing:
1975 # - "push" for pack(push,...) directives, "" otherwise
1976 # - the directive's identifier at index 1
1977 # - the directive's alignment value at index 2
1979 # Don't believe a word of what the documentation says: it's all wrong.
1980 # The code below is based on the actual behavior of Visual C/C++ 6.
1981 my $pack_indent=$1;
1982 my $pack_header=$2;
1983 if (/^(\))/) {
1984 # pragma pack()
1985 # Pushes the default stack alignment
1986 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1987 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
1988 print_pack($pack_indent,4,$');
1989 push @pack_stack, [ "", "", 4 ];
1991 } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
1992 # pragma pack(pop)
1993 # pragma pack(pop,n)
1994 # Goes up the stack until it finds a pack(push,...), and pops it
1995 # Ignores any pack(n) entry
1996 # Issues a warning if the pack is of the form pack(push,label)
1997 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
1998 my $pack_comment=$';
1999 $pack_comment =~ s/^\s*//;
2000 if ($pack_comment ne "") {
2001 print FILEO "$pack_indent$pack_comment";
2003 while (1) {
2004 my $alignment=pop @pack_stack;
2005 if (!defined $alignment) {
2006 print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
2007 last;
2009 if (@$alignment[1]) {
2010 print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
2012 print FILEO "$pack_indent#include <poppack.h>\n";
2013 if (@$alignment[0]) {
2014 last;
2018 } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
2019 # pragma pack(pop,label[,n])
2020 # Goes up the stack until finding a pack(push,...) and pops it.
2021 # 'n', if specified, is ignored.
2022 # Ignores any pack(n) entry
2023 # Issues a warning if the label of the pack does not match,
2024 # or if it is in fact a pack(push,n)
2025 my $label=$2;
2026 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2027 my $pack_comment=$';
2028 $pack_comment =~ s/^\s*//;
2029 if ($pack_comment ne "") {
2030 print FILEO "$pack_indent$pack_comment";
2032 while (1) {
2033 my $alignment=pop @pack_stack;
2034 if (!defined $alignment) {
2035 print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
2036 last;
2038 if (@$alignment[1] and @$alignment[1] ne $label) {
2039 print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
2041 print FILEO "$pack_indent#include <poppack.h>\n";
2042 if (@$alignment[0]) {
2043 last;
2047 } elsif (/^(push\s*\))/) {
2048 # pragma pack(push)
2049 # Push the current alignment
2050 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2051 if (@pack_stack > 0) {
2052 my $alignment=$pack_stack[$#pack_stack];
2053 print_pack($pack_indent,@$alignment[2],$');
2054 push @pack_stack, [ "push", "", @$alignment[2] ];
2055 } else {
2056 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2057 print_pack($pack_indent,4,$');
2058 push @pack_stack, [ "push", "", 4 ];
2061 } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
2062 # pragma pack([push,]n)
2063 # Push new alignment n
2064 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2065 print_pack($pack_indent,$3,"$'");
2066 push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
2068 } elsif (/^((\w+)\s*\))/) {
2069 # pragma pack(label)
2070 # label must in fact be a macro that resolves to an integer
2071 # Then behaves like 'pragma pack(n)'
2072 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2073 print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
2074 print_pack($pack_indent,4,$');
2075 push @pack_stack, [ "", "", 4 ];
2077 } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
2078 # pragma pack(push,label[,n])
2079 # Pushes a new label on the stack. It is possible to push the same
2080 # label multiple times. If 'n' is omitted then the alignment is
2081 # unchanged. Otherwise it becomes 'n'.
2082 print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
2083 my $size;
2084 if (defined $4) {
2085 $size=$4;
2086 } elsif (@pack_stack > 0) {
2087 my $alignment=$pack_stack[$#pack_stack];
2088 $size=@$alignment[2];
2089 } else {
2090 print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
2091 $size=4;
2093 print_pack($pack_indent,$size,$');
2094 push @pack_stack, [ "push", $2, $size ];
2096 } else {
2097 # pragma pack(??? -> What's that?
2098 print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
2099 print FILEO "$pack_indent$pack_header$_";
2102 $modified=1;
2104 } elsif ($is_rc) {
2105 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]+)([\">]?)/) {
2106 my $from_file=($5 eq "<"?"":$dirname);
2107 my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
2108 print FILEO "$1$5$real_include_name$7$'";
2109 $modified|=($real_include_name ne $6);
2111 } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
2112 my $from_file=($2 eq "<"?"":$dirname);
2113 my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
2114 print FILEO "$1$2$real_include_name$4$'";
2115 $modified|=($real_include_name ne $3);
2117 } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
2118 $rc_textinclude_state=1;
2119 print FILEO;
2121 } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2122 print FILEO "$1winresrc.h$2$'";
2123 $modified=1;
2125 } elsif (/^\s*BEGIN(\W.*)?$/) {
2126 $rc_textinclude_state|=2;
2127 $rc_block_depth++;
2128 print FILEO;
2130 } elsif (/^\s*END(\W.*)?$/) {
2131 $rc_textinclude_state=0;
2132 if ($rc_block_depth>0) {
2133 $rc_block_depth--;
2135 print FILEO;
2137 } else {
2138 print FILEO;
2141 } else {
2142 print FILEO;
2146 close(FILEI);
2147 close(FILEO);
2148 if ($opt_backup == 0 or $modified == 0) {
2149 if (!unlink("$filename.bak")) {
2150 print STDERR "error: unable to delete $filename.bak:\n";
2151 print STDERR " $!\n";
2157 # Analyzes each source file in turn to find and correct issues
2158 # that would cause it not to compile.
2159 sub fix_source()
2161 print "Fixing the source files...\n";
2162 foreach my $project (@projects) {
2163 foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
2164 foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2165 fix_file($source,$project,$target);
2173 #####
2175 # File generation
2177 #####
2180 # A convenience function to generate all the lists (defines,
2181 # C sources, C++ source, etc.) in the Makefile
2182 sub generate_list($$$;$)
2184 my $name=$_[0];
2185 my $last=$_[1];
2186 my $list=$_[2];
2187 my $data=$_[3];
2188 my $first=$name;
2190 if ($name) {
2191 printf FILEO "%-22s=",$name;
2193 if (defined $list) {
2194 foreach my $item (@$list) {
2195 my $value;
2196 if (defined $data) {
2197 $value=&$data($item);
2198 } else {
2199 $value=$item;
2201 if ($value ne "") {
2202 if ($first) {
2203 print FILEO " $value";
2204 $first=0;
2205 } else {
2206 print FILEO " \\\n\t\t\t$value";
2211 if ($last) {
2212 print FILEO "\n";
2217 # Generates a project's Makefile and all the target files
2218 sub generate_project_files($)
2220 my $project=$_[0];
2221 my $project_settings=@$project[$P_SETTINGS];
2222 my @dll_list=();
2223 my @exe_list=();
2225 # Then sort the targets and separate the libraries from the programs
2226 foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2227 if (@$target[$T_TYPE] == $TT_DLL) {
2228 push @dll_list,$target;
2229 } else {
2230 push @exe_list,$target;
2233 @$project[$P_TARGETS]=[];
2234 push @{@$project[$P_TARGETS]}, @dll_list;
2235 push @{@$project[$P_TARGETS]}, @exe_list;
2237 if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
2238 print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2239 print STDERR " $!\n";
2240 return;
2243 print FILEO "### Generated by Winemaker $version\n";
2244 print FILEO "\n\n";
2246 generate_list("SRCDIR",1,[ "." ]);
2247 if (@$project[$P_PATH] eq "") {
2248 # This is the main project. It is also responsible for recursively
2249 # calling the other projects
2250 generate_list("SUBDIRS",1,\@projects,sub
2252 if ($_[0] != \@main_project) {
2253 my $subdir=@{$_[0]}[$P_PATH];
2254 $subdir =~ s+/$++;
2255 return $subdir;
2257 # Eliminating the main project by returning undefined!
2260 if (@{@$project[$P_TARGETS]} > 0) {
2261 generate_list("DLLS",1,\@dll_list,sub
2263 return @{$_[0]}[$T_NAME];
2265 generate_list("EXES",1,\@exe_list,sub
2267 return "@{$_[0]}[$T_NAME]";
2269 print FILEO "\n\n\n";
2271 print FILEO "### Common settings\n\n";
2272 # Make it so that the project-wide settings override the global settings
2273 generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
2274 generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
2275 generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2276 generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2277 generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
2278 generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2279 generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2280 generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
2281 generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2282 print FILEO "\n\n";
2284 my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
2285 @{@$project_settings[$T_SOURCES_CXX]}+
2286 @{@$project_settings[$T_SOURCES_RC]};
2287 my $no_extra=($extra_source_count == 0);
2288 if (!$no_extra) {
2289 print FILEO "### Extra source lists\n\n";
2290 generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
2291 generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
2292 generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2293 print FILEO "\n";
2294 generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
2295 print FILEO "\n\n\n";
2298 # Iterate over all the targets...
2299 foreach my $target (@{@$project[$P_TARGETS]}) {
2300 print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2301 my $canon=canonize("@$target[$T_NAME]");
2302 $canon =~ s+_so$++;
2304 generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2305 generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
2306 generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
2307 generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2308 generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2309 generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2310 generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2311 generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
2312 generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2313 print FILEO "\n";
2314 generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2315 print FILEO "\n\n\n";
2317 print FILEO "### Global source lists\n\n";
2318 generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2320 my $canon=canonize(@{$_[0]}[$T_NAME]);
2321 $canon =~ s+_so$++;
2322 return "\$(${canon}_C_SRCS)";
2324 if (!$no_extra) {
2325 generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
2327 generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2329 my $canon=canonize(@{$_[0]}[$T_NAME]);
2330 $canon =~ s+_so$++;
2331 return "\$(${canon}_CXX_SRCS)";
2333 if (!$no_extra) {
2334 generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
2336 generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2338 my $canon=canonize(@{$_[0]}[$T_NAME]);
2339 $canon =~ s+_so$++;
2340 return "\$(${canon}_RC_SRCS)";
2342 if (!$no_extra) {
2343 generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2346 print FILEO "\n\n";
2347 print FILEO "### Tools\n\n";
2348 print FILEO "CC = winegcc\n";
2349 print FILEO "CXX = wineg++\n";
2350 print FILEO "RC = wrc\n";
2351 print FILEO "\n\n";
2353 print FILEO "### Generic targets\n\n";
2354 print FILEO "all:";
2355 if (@$project[$P_PATH] eq "") {
2356 print FILEO " \$(SUBDIRS)";
2358 if (@{@$project[$P_TARGETS]} > 0) {
2359 print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2361 print FILEO "\n\n";
2362 print FILEO "### Build rules\n";
2363 print FILEO "\n";
2364 print FILEO ".PHONY: all clean dummy\n";
2365 print FILEO "\n";
2366 print FILEO "\$(SUBDIRS): dummy\n";
2367 print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
2368 print FILEO "\n";
2369 print FILEO "# Implicit rules\n";
2370 print FILEO "\n";
2371 print FILEO ".SUFFIXES: .cpp .rc .res\n";
2372 print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
2373 print FILEO "\n";
2374 print FILEO ".c.o:\n";
2375 print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2376 print FILEO "\n";
2377 print FILEO ".cpp.o:\n";
2378 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2379 print FILEO "\n";
2380 print FILEO ".cxx.o:\n";
2381 print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
2382 print FILEO "\n";
2383 print FILEO ".rc.res:\n";
2384 print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
2385 print FILEO "\n";
2386 print FILEO "# Rules for cleaning\n";
2387 print FILEO "\n";
2388 print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2389 print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
2390 print FILEO "\n";
2391 print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
2392 print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2393 print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n";
2394 print FILEO "\n";
2395 print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
2396 print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
2397 print FILEO "\n";
2398 print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
2399 print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
2400 print FILEO "\n";
2402 if (@{@$project[$P_TARGETS]} > 0) {
2403 print FILEO "### Target specific build rules\n";
2404 print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2405 foreach my $target (@{@$project[$P_TARGETS]}) {
2406 my $canon=canonize("@$target[$T_NAME]");
2407 $canon =~ s/_so$//;
2409 print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n";
2410 if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
2411 print FILEO "\t\$(CXX)";
2412 } else {
2413 print FILEO "\t\$(CC)";
2415 print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2416 print FILEO "\n\n";
2419 close(FILEO);
2425 # This is where we finally generate files. In fact this method does not
2426 # do anything itself but calls the methods that do the actual work.
2427 sub generate()
2429 print "Generating project files...\n";
2431 foreach my $project (@projects) {
2432 my $path=@$project[$P_PATH];
2433 if ($path eq "") {
2434 $path=".";
2435 } else {
2436 $path =~ s+/$++;
2438 print " $path\n";
2439 generate_project_files($project);
2445 #####
2447 # Option defaults
2449 #####
2451 $opt_backup=1;
2452 $opt_lower=$OPT_LOWER_UPPERCASE;
2453 $opt_lower_include=1;
2455 $opt_work_dir=undef;
2456 $opt_single_target=undef;
2457 $opt_target_type=$TT_GUIEXE;
2458 $opt_flags=0;
2459 $opt_is_interactive=$OPT_ASK_NO;
2460 $opt_ask_project_options=$OPT_ASK_NO;
2461 $opt_ask_target_options=$OPT_ASK_NO;
2462 $opt_no_generated_files=0;
2463 $opt_no_source_fix=0;
2464 $opt_no_banner=0;
2468 #####
2470 # Main
2472 #####
2474 sub print_banner()
2476 print "Winemaker $version\n";
2477 print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2478 print "Copyright 2004 Dimitrie O. Paun\n";
2479 print "Copyright 2009 André Hentschel\n";
2482 sub usage()
2484 print_banner();
2485 print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2486 print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2487 print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2488 print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2489 print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2490 print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2491 print STDERR " [--generated-files|--nogenerated-files]\n";
2492 print STDERR " work_directory|project_file|workspace_file\n";
2493 print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2494 print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
2495 print STDERR "process it will modify and rename some of the files in that directory.\n";
2496 print STDERR "\tPlease read the manual page before use.\n";
2497 exit (2);
2500 target_init(\@global_settings);
2502 while (@ARGV>0) {
2503 my $arg=shift @ARGV;
2504 # General options
2505 if ($arg eq "--nobanner") {
2506 $opt_no_banner=1;
2507 } elsif ($arg eq "--backup") {
2508 $opt_backup=1;
2509 } elsif ($arg eq "--nobackup") {
2510 $opt_backup=0;
2511 } elsif ($arg eq "--single-target") {
2512 $opt_single_target=shift @ARGV;
2513 } elsif ($arg eq "--lower-none") {
2514 $opt_lower=$OPT_LOWER_NONE;
2515 } elsif ($arg eq "--lower-all") {
2516 $opt_lower=$OPT_LOWER_ALL;
2517 } elsif ($arg eq "--lower-uppercase") {
2518 $opt_lower=$OPT_LOWER_UPPERCASE;
2519 } elsif ($arg eq "--lower-include") {
2520 $opt_lower_include=1;
2521 } elsif ($arg eq "--nolower-include") {
2522 $opt_lower_include=0;
2523 } elsif ($arg eq "--nosource-fix") {
2524 $opt_no_source_fix=1;
2525 } elsif ($arg eq "--generated-files") {
2526 $opt_no_generated_files=0;
2527 } elsif ($arg eq "--nogenerated-files") {
2528 $opt_no_generated_files=1;
2529 } elsif ($arg =~ /^-D/) {
2530 push @{$global_settings[$T_DEFINES]},$arg;
2531 } elsif ($arg =~ /^-I/) {
2532 push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2533 } elsif ($arg =~ /^-P/) {
2534 push @{$global_settings[$T_DLL_PATH]},"-L$'";
2535 } elsif ($arg =~ /^-i/) {
2536 push @{$global_settings[$T_DLLS]},$';
2537 } elsif ($arg =~ /^-L/) {
2538 push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2539 } elsif ($arg =~ /^-l/) {
2540 push @{$global_settings[$T_LIBRARIES]},$';
2542 # 'Source'-based method options
2543 } elsif ($arg eq "--dll") {
2544 $opt_target_type=$TT_DLL;
2545 } elsif ($arg eq "--guiexe" or $arg eq "--windows") {
2546 $opt_target_type=$TT_GUIEXE;
2547 } elsif ($arg eq "--cuiexe" or $arg eq "--console") {
2548 $opt_target_type=$TT_CUIEXE;
2549 } elsif ($arg eq "--interactive") {
2550 $opt_is_interactive=$OPT_ASK_YES;
2551 $opt_ask_project_options=$OPT_ASK_YES;
2552 $opt_ask_target_options=$OPT_ASK_YES;
2553 } elsif ($arg eq "--mfc") {
2554 $opt_flags|=$TF_MFC;
2555 } elsif ($arg eq "--nomfc") {
2556 $opt_flags&=~$TF_MFC;
2557 $opt_flags|=$TF_NOMFC;
2558 } elsif ($arg eq "--nodlls") {
2559 $opt_flags|=$TF_NODLLS;
2560 } elsif ($arg eq "--nomsvcrt") {
2561 $opt_flags|=$TF_NOMSVCRT;
2563 # Catch errors
2564 } else {
2565 if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2566 if (!defined $opt_work_dir and !defined $opt_work_file) {
2567 if (-f $arg) {
2568 $opt_work_file=$arg;
2570 else {
2571 $opt_work_dir=$arg;
2573 } else {
2574 print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2575 usage();
2577 } else {
2578 usage();
2583 if (!defined $opt_work_dir and !defined $opt_work_file) {
2584 print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2585 usage();
2586 } elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2587 print STDERR "error: could not chdir to the work directory\n";
2588 print STDERR " $!\n";
2589 usage();
2592 if ($opt_no_banner == 0) {
2593 print_banner();
2596 project_init(\@main_project, "", \@global_settings);
2598 # Fix the file and directory names
2599 fix_file_and_directory_names(".");
2601 # Scan the sources to identify the projects and targets
2602 source_scan();
2604 # Fix the source files
2605 if (! $opt_no_source_fix) {
2606 fix_source();
2609 # Generate the Makefile and the spec file
2610 if (! $opt_no_generated_files) {
2611 generate();