2000-11-05 06:23:39 +01:00
#!/usr/bin/perl -w
2002-09-06 20:36:19 +02:00
use strict;
2000-11-05 06:23:39 +01:00
2004-03-03 03:19:20 +01:00
# Copyright 2000-2004 Francois Gouget for CodeWeavers
2004-02-27 22:24:20 +01:00
# Copyright 2004 Dimitrie O. Paun
2011-01-04 22:43:01 +01:00
# Copyright 2009-2011 André Hentschel
2000-11-05 06:23:39 +01:00
#
2002-03-10 00:29:33 +01:00
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
2006-05-18 14:49:52 +02:00
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2002-03-10 00:29:33 +01:00
#
2011-11-23 21:36:14 +01:00
my $version="0.8.1";
2000-11-05 06:23:39 +01:00
use Cwd;
use File::Basename;
use File::Copy;
#####
#
# Options
#
#####
# The following constants define what we do with the case of filenames
##
# Never rename a file to lowercase
my $OPT_LOWER_NONE=0;
##
# Rename all files to lowercase
my $OPT_LOWER_ALL=1;
##
# Rename only files that are all uppercase to lowercase
my $OPT_LOWER_UPPERCASE=2;
# The following constants define whether to ask questions or not
##
# No (synonym of never)
my $OPT_ASK_NO=0;
##
# Yes (always)
my $OPT_ASK_YES=1;
##
# Skip the questions till the end of this scope
my $OPT_ASK_SKIP=-1;
2009-05-01 11:37:01 +02:00
# The following constants define the architecture
2010-04-21 20:22:13 +02:00
##
2011-08-03 11:36:15 +02:00
# Default Architecture will be chosen
2010-04-21 20:22:13 +02:00
my $OPT_ARCH_DEFAULT=0;
2009-05-01 11:37:01 +02:00
##
# 32-Bit Target
my $OPT_ARCH_32=32;
##
# 64-Bit Target
my $OPT_ARCH_64=64;
2000-11-05 06:23:39 +01:00
# General options
2001-01-10 23:43:21 +01:00
##
# This is the directory in which winemaker will operate.
my $opt_work_dir;
2009-04-02 18:53:14 +02:00
##
# This is the file in which winemaker will operate if a project file is specified.
my $opt_work_file;
2000-11-05 06:23:39 +01:00
##
# Make a backup of the files
my $opt_backup;
##
# Defines which files to rename
my $opt_lower;
2000-11-10 23:29:11 +01:00
##
# If we don't find the file referenced by an include, lower it
my $opt_lower_include;
2001-09-24 03:11:50 +02:00
##
# If true then winemaker should not attempt to fix the source. This is
# useful if the source is known to be already in a suitable form and is
# readonly
my $opt_no_source_fix;
2000-11-05 06:23:39 +01:00
# Options for the 'Source' method
##
2002-06-01 04:55:48 +02:00
# Specifies that we have only one target so that all sources relate
# to this target. By default this variable is left undefined which
# means winemaker should try to find out by itself what the targets
# are. If not undefined then this contains the name of the default
2000-11-05 06:23:39 +01:00
# target (without the extension).
my $opt_single_target;
##
2002-06-01 04:55:48 +02:00
# If '$opt_single_target' has been specified then this is the type of
# that target. Otherwise it specifies whether the default target type
2000-11-05 06:23:39 +01:00
# is guiexe or cuiexe.
my $opt_target_type;
##
# Contains the default set of flags to be used when creating a new target.
my $opt_flags;
2009-05-01 11:37:01 +02:00
##
# Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets
my $opt_arch;
2000-11-05 06:23:39 +01:00
##
2002-06-01 04:55:48 +02:00
# If true then winemaker should ask questions to the user as it goes
2000-11-05 06:23:39 +01:00
# along.
my $opt_is_interactive;
my $opt_ask_project_options;
my $opt_ask_target_options;
##
2004-03-03 03:19:20 +01:00
# If false then winemaker should not generate the makefiles.
2000-11-10 23:29:11 +01:00
my $opt_no_generated_files;
2000-11-05 06:23:39 +01:00
##
# Specifies not to print the banner if set.
my $opt_no_banner;
#####
#
# Target modelization
#
#####
2002-06-01 04:55:48 +02:00
# The description of a target is stored in an array. The constants
2000-11-05 06:23:39 +01:00
# below identify what is stored at each index of the array.
##
# This is the name of the target.
my $T_NAME=0;
##
# Defines the type of target we want to build. See the TT_xxx
# constants below
my $T_TYPE=1;
##
2002-06-01 04:55:48 +02:00
# This is a bitfield containing flags refining the way the target
2000-11-05 06:23:39 +01:00
# should be handled. See the TF_xxx constants below
2004-03-03 03:19:20 +01:00
my $T_FLAGS=2;
2000-11-05 06:23:39 +01:00
##
2002-06-01 04:55:48 +02:00
# This is a reference to an array containing the list of the
2000-11-05 06:23:39 +01:00
# resp. C, C++, RC, other (.h, .hxx, etc.) source files.
2004-03-03 03:19:20 +01:00
my $T_SOURCES_C=3;
my $T_SOURCES_CXX=4;
my $T_SOURCES_RC=5;
my $T_SOURCES_MISC=6;
##
# This is a reference to an array containing the list of
# C compiler options
my $T_CEXTRA=7;
##
# This is a reference to an array containing the list of
# C++ compiler options
my $T_CXXEXTRA=8;
##
# This is a reference to an array containing the list of
# RC compiler options
my $T_RCEXTRA=9;
2000-11-05 06:23:39 +01:00
##
2002-06-01 04:55:48 +02:00
# This is a reference to an array containing the list of macro
2000-11-05 06:23:39 +01:00
# definitions
2004-03-03 03:19:20 +01:00
my $T_DEFINES=10;
2000-11-05 06:23:39 +01:00
##
2002-06-01 04:55:48 +02:00
# This is a reference to an array containing the list of directory
2000-11-05 06:23:39 +01:00
# names that constitute the include path
2004-03-03 03:19:20 +01:00
my $T_INCLUDE_PATH=11;
##
# Flags for the linker
my $T_LDFLAGS=12;
2000-11-05 06:23:39 +01:00
2011-11-19 19:42:56 +01:00
##
# Flags for the archiver
my $T_ARFLAGS=13;
2000-11-05 06:23:39 +01:00
##
2001-07-30 20:44:48 +02:00
# Same as T_INCLUDE_PATH but for the dll search path
2011-11-19 19:42:56 +01:00
my $T_DLL_PATH=14;
2001-07-30 20:44:48 +02:00
##
# The list of Windows dlls to import
2011-11-19 19:42:56 +01:00
my $T_DLLS=15;
2000-11-05 06:23:39 +01:00
##
2001-07-30 20:44:48 +02:00
# Same as T_INCLUDE_PATH but for the library search path
2011-11-19 19:42:56 +01:00
my $T_LIBRARY_PATH=16;
2000-11-15 23:12:20 +01:00
##
# The list of Unix libraries to link with
2011-11-19 19:42:56 +01:00
my $T_LIBRARIES=17;
2000-11-05 06:23:39 +01:00
# The following constants define the recognized types of target
##
2002-06-01 04:55:48 +02:00
# This is not a real target. This type of target is used to collect
2000-11-05 06:23:39 +01:00
# the sources that don't seem to belong to any other target. Thus no
2002-06-01 04:55:48 +02:00
# real target is generated for them, we just put the sources of the
2000-11-05 06:23:39 +01:00
# fake target in the global source list.
my $TT_SETTINGS=0;
##
# For executables in the windows subsystem
my $TT_GUIEXE=1;
##
# For executables in the console subsystem
my $TT_CUIEXE=2;
##
# For dynamically linked libraries
my $TT_DLL=3;
2011-11-19 19:42:56 +01:00
##
# For static libraries
my $TT_LIB=4;
2000-11-05 06:23:39 +01:00
# The following constants further refine how the target should be handled
##
# This target is an MFC-based target
my $TF_MFC=4;
2002-09-10 02:20:27 +02:00
##
# User has specified --nomfc option for this target or globally
my $TF_NOMFC=8;
##
# --nodlls option: Do not use standard DLL set
my $TF_NODLLS=16;
2004-02-03 00:02:32 +01:00
##
# --nomsvcrt option: Do not link with msvcrt
my $TF_NOMSVCRT=32;
2011-01-04 22:43:01 +01:00
##
# This target has a def file (only use it with TT_DLL)
my $TF_HASDEF=64;
2000-11-05 06:23:39 +01:00
##
# Initialize a target:
2002-06-01 04:55:48 +02:00
# - set the target type to TT_SETTINGS, i.e. no real target will
# be generated.
2002-09-06 20:36:19 +02:00
sub target_init($)
2000-11-05 06:23:39 +01:00
{
my $target=$_[0];
@$target[$T_TYPE]=$TT_SETTINGS;
@$target[$T_FLAGS]=$opt_flags;
@$target[$T_SOURCES_C]=[];
@$target[$T_SOURCES_CXX]=[];
@$target[$T_SOURCES_RC]=[];
@$target[$T_SOURCES_MISC]=[];
2004-03-03 03:19:20 +01:00
@$target[$T_CEXTRA]=[];
@$target[$T_CXXEXTRA]=[];
@$target[$T_RCEXTRA]=[];
2000-11-05 06:23:39 +01:00
@$target[$T_DEFINES]=[];
@$target[$T_INCLUDE_PATH]=[];
2004-03-03 03:19:20 +01:00
@$target[$T_LDFLAGS]=[];
2011-11-19 19:42:56 +01:00
@$target[$T_ARFLAGS]=[];
2001-07-30 20:44:48 +02:00
@$target[$T_DLL_PATH]=[];
@$target[$T_DLLS]=[];
2000-11-05 06:23:39 +01:00
@$target[$T_LIBRARY_PATH]=[];
2000-11-15 23:12:20 +01:00
@$target[$T_LIBRARIES]=[];
2000-11-05 06:23:39 +01:00
}
#####
#
# Project modelization
#
#####
2002-06-01 04:55:48 +02:00
# First we have the notion of project. A project is described by an
# array (since we don't have structs in perl). The constants below
2000-11-05 06:23:39 +01:00
# identify what is stored at each index of the array.
##
2002-06-01 04:55:48 +02:00
# This is the path in which this project is located. In other
2012-02-05 14:03:32 +01:00
# words, this is the path to the Makefile.
2000-11-05 06:23:39 +01:00
my $P_PATH=0;
##
2002-06-01 04:55:48 +02:00
# This index contains a reference to an array containing the project-wide
# settings. The structure of that arrray is actually identical to that of
2000-11-05 06:23:39 +01:00
# a regular target since it can also contain extra sources.
my $P_SETTINGS=1;
##
2002-06-01 04:55:48 +02:00
# This index contains a reference to an array of targets for this
# project. Each target describes how an executable or library is to
# be built. For each target this description takes the same form as
2000-11-05 06:23:39 +01:00
# that of the project: an array. So this entry is an array of arrays.
my $P_TARGETS=2;
##
# Initialize a project:
# - set the project's path
# - initialize the target list
# - create a default target (will be removed later if unnecessary)
2009-02-25 10:33:48 +01:00
sub project_init($$$)
2000-11-05 06:23:39 +01:00
{
2009-02-25 10:33:48 +01:00
my ($project, $path, $global_settings)=@_;
2000-11-05 06:23:39 +01:00
my $project_settings=[];
target_init($project_settings);
2009-02-25 10:33:48 +01:00
@$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}];
@$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}];
@$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}];
@$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}];
@$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}];
@$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}];
2000-11-05 06:23:39 +01:00
@$project[$P_PATH]=$path;
@$project[$P_SETTINGS]=$project_settings;
@$project[$P_TARGETS]=[];
}
#####
#
# Global variables
#
#####
my %warnings;
my %templates;
2004-12-13 13:00:59 +01:00
##
# This maps a directory name to a reference to an array listing
# its contents (files and directories)
my %directories;
2000-11-05 06:23:39 +01:00
##
2002-06-01 04:55:48 +02:00
# Contains the list of all projects. This list tells us what are
# the subprojects of the main Makefile and where we have to generate
2000-11-05 06:23:39 +01:00
# Makefiles.
my @projects=();
##
2002-06-01 04:55:48 +02:00
# This is the main project, i.e. the one in the "." directory.
# It may well be empty in which case the main Makefile will only
2000-11-05 06:23:39 +01:00
# call out subprojects.
my @main_project;
##
# Contains the defaults for the include path, etc.
2002-06-01 04:55:48 +02:00
# We store the defaults as if this were a target except that we only
2000-11-05 06:23:39 +01:00
# exploit the defines, include path, library path, library list and misc
# sources fields.
my @global_settings;
#####
#
# Utility functions
#
#####
##
2002-06-01 04:55:48 +02:00
# Cleans up a name to make it an acceptable Makefile
2000-11-05 06:23:39 +01:00
# variable name.
2002-09-06 20:36:19 +02:00
sub canonize($)
2000-11-05 06:23:39 +01:00
{
my $name=$_[0];
$name =~ tr/a-zA-Z0-9_/_/c;
return $name;
}
##
# Returns true is the specified pathname is absolute.
2002-06-01 04:55:48 +02:00
# Note: pathnames that start with a variable '$' or
2000-11-05 06:23:39 +01:00
# '~' are considered absolute.
2002-09-06 20:36:19 +02:00
sub is_absolute($)
2000-11-05 06:23:39 +01:00
{
my $path=$_[0];
return ($path =~ /^[\/~\$]/);
}
2004-10-30 04:11:19 +02:00
##
# Retrieves the contents of the specified directory.
# We either get it from the directories hashtable which acts as a
# cache, or use opendir, readdir, closedir and store the result
# in the hashtable.
sub get_directory_contents($)
{
my $dirname=$_[0];
my $directory;
#print "getting the contents of $dirname\n";
# check for a cached version
$dirname =~ s+/$++;
if ($dirname eq "") {
$dirname=cwd;
}
$directory=$directories{$dirname};
if (defined $directory) {
#print "->@$directory\n";
return $directory;
}
# Read this directory
if (opendir(DIRECTORY, "$dirname")) {
my @files=readdir DIRECTORY;
closedir(DIRECTORY);
$directory=\@files;
} else {
# Return an empty list
#print "error: cannot open $dirname\n";
my @files;
$directory=\@files;
}
#print "->@$directory\n";
$directories{$dirname}=$directory;
return $directory;
}
2009-02-25 10:32:36 +01:00
##
# Removes a directory from the cache.
# This is needed if one of its files or subdirectory has been renamed.
sub clear_directory_cache($)
{
my ($dirname)=@_;
delete $directories{$dirname};
}
2000-11-05 06:23:39 +01:00
#####
#
# 'Source'-based Project analysis
#
#####
##
# Allows the user to specify makefile and target specific options
# - target: the structure in which to store the results
# - options: the string containing the options
2002-09-06 20:36:19 +02:00
sub source_set_options($$)
2000-11-05 06:23:39 +01:00
{
my $target=$_[0];
my $options=$_[1];
#FIXME: we must deal with escaping of stuff and all
2002-09-06 20:36:19 +02:00
foreach my $option (split / /,$options) {
2000-11-05 06:23:39 +01:00
if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) {
push @{@$target[$T_DEFINES]},$option;
} elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) {
push @{@$target[$T_INCLUDE_PATH]},$option;
2001-07-30 20:44:48 +02:00
} elsif ($option =~ /^-P/) {
push @{@$target[$T_DLL_PATH]},"-L$'";
} elsif ($option =~ /^-i/) {
2004-02-27 22:24:20 +01:00
push @{@$target[$T_DLLS]},"$'";
2000-11-05 06:23:39 +01:00
} elsif ($option =~ /^-L/) {
push @{@$target[$T_LIBRARY_PATH]},$option;
2000-11-15 23:12:20 +01:00
} elsif ($option =~ /^-l/) {
2001-07-30 20:44:48 +02:00
push @{@$target[$T_LIBRARIES]},"$'";
2002-09-10 02:20:27 +02:00
} elsif ($option =~ /^--mfc/) {
@$target[$T_FLAGS]|=$TF_MFC;
@$target[$T_FLAGS]&=~$TF_NOMFC;
2000-11-25 02:38:39 +01:00
} elsif ($option =~ /^--nomfc/) {
@$target[$T_FLAGS]&=~$TF_MFC;
2002-09-10 02:20:27 +02:00
@$target[$T_FLAGS]|=$TF_NOMFC;
} elsif ($option =~ /^--nodlls/) {
@$target[$T_FLAGS]|=$TF_NODLLS;
2004-02-03 00:02:32 +01:00
} elsif ($option =~ /^--nomsvcrt/) {
@$target[$T_FLAGS]|=$TF_NOMSVCRT;
2000-11-05 06:23:39 +01:00
} else {
2000-11-30 21:36:04 +01:00
print STDERR "error: unknown option \"$option\"\n";
return 0;
2000-11-05 06:23:39 +01:00
}
}
2000-11-30 21:36:04 +01:00
return 1;
2000-11-05 06:23:39 +01:00
}
2009-04-02 18:53:14 +02:00
##
# Scans the specified project file to:
# - get a list of targets for this project
# - get some settings
# - get the list of source files
sub source_scan_project_file($$$);
sub source_scan_project_file($$$)
{
# a reference to the parent's project
my $parent_project=$_[0];
# 0 if it is a single project, 1 if it is part of a workspace
my $is_sub_project=$_[1];
# the name of the project file, with complete path, or without if in
# the same directory
my $filename=$_[2];
# reference to the project for this file. May not be used
my $project;
# list of sources found in the current file
my @sources_c=();
my @sources_cxx=();
my @sources_rc=();
my @sources_misc=();
# some more settings
my $path=dirname($filename);
my $prj_target_cflags;
2009-08-13 16:43:37 +02:00
my $prj_target_defines;
2009-04-02 18:53:14 +02:00
my $prj_target_ldflags;
my $prj_target_libs;
my $prj_name;
my $found_cfg=0;
my $prj_cfg;
2010-05-10 19:59:01 +02:00
my $prj_target_type=$TT_GUIEXE;
2009-04-02 18:53:14 +02:00
my @prj_target_options;
if (!($path=~/\/$/)) {
$path.="/";
}
if (defined $opt_single_target or $is_sub_project == 0) {
# Either there is a single target and thus a single project,
# or we are a single project-file for which a project
# already exists
$project=$parent_project;
} else {
$project=[];
project_init($project, $path, \@global_settings);
}
my $project_settings=@$project[$P_SETTINGS];
if ($filename =~ /.dsp$/i) {
# First find out what this project file contains:
# collect all sources, find targets and settings
if (!open(FILEI,$filename)) {
print STDERR "error: unable to open $filename for reading:\n";
print STDERR " $!\n";
return;
}
my $sfilet;
while (<FILEI>) {
# Remove any trailing CtrlZ, which isn't strictly in the file
if (/\x1A/) {
s/\x1A//;
last if (/^$/)
}
# Remove any trailing CrLf
s/\r\n$/\n/;
if (!/\n$/) {
# Make sure all lines are '\n' terminated
$_ .= "\n";
}
if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) {
2009-08-29 13:10:01 +02:00
$prj_name="$1";
2009-11-21 18:13:44 +01:00
$prj_name=~s/\s+/_/g;
2009-04-02 18:53:14 +02:00
#print $prj_name;
next;
} elsif (/^# TARGTYPE/) {
2011-11-19 19:42:34 +01:00
if (/[[:space:]]0+x0*101$/) {
2010-05-10 19:59:01 +02:00
# Application
$prj_target_type=$TT_GUIEXE;
2011-11-19 19:42:34 +01:00
}elsif (/[[:space:]]0+x0*102$/) {
2010-05-10 19:59:01 +02:00
# Dynamic-Link Library
$prj_target_type=$TT_DLL;
2011-11-19 19:42:34 +01:00
}elsif (/[[:space:]]0+x0*103$/) {
2010-05-10 19:59:01 +02:00
# Console Application
$prj_target_type=$TT_CUIEXE;
2011-11-19 19:42:34 +01:00
}elsif (/[[:space:]]0+x0*104$/) {
2010-05-10 19:59:01 +02:00
# Static Library
2011-11-19 19:42:56 +01:00
$prj_target_type=$TT_LIB;
2009-04-02 18:53:14 +02:00
}
next;
} elsif (/^# ADD CPP(.*)/ && $found_cfg==1) {
$prj_target_cflags=$1;
2011-11-19 19:41:38 +01:00
@prj_target_options=split(/\s+\//, $prj_target_cflags);
2009-04-02 18:53:14 +02:00
$prj_target_cflags="";
foreach ( @prj_target_options ) {
if ($_ eq "") {
# empty
} elsif (/nologo/) {
# Suppress Startup Banner and Information Messages
} elsif (/^W0$/) {
# Turns off all warning messages
$prj_target_cflags.="-w ";
} elsif (/^W[123]$/) {
# Warning Level
$prj_target_cflags.="-W ";
} elsif (/^W4$/) {
# Warning Level
$prj_target_cflags.="-Wall ";
} elsif (/^WX$/) {
# Warnings As Errors
$prj_target_cflags.="-Werror ";
} elsif (/^Gm$/) {
# Enable Minimal Rebuild
} elsif (/^GX$/) {
# Enable Exception Handling
$prj_target_cflags.="-fexceptions ";
2010-11-30 23:56:37 +01:00
} elsif (/^Gd$/) {
# use cdecl calling convention (default)
} elsif (/^Gr$/) {
# use fastcall calling convention
} elsif (/^Gz$/) {
# use stdcall calling convention
$prj_target_cflags.="-mrtd ";
2009-04-02 18:53:14 +02:00
} elsif (/^Z[d7iI]$/) {
# Debug Info
$prj_target_cflags.="-g ";
} elsif (/^Od$/) {
# Disable Optimizations
$prj_target_cflags.="-O0 ";
} elsif (/^O1$/) {
# Minimize Size
$prj_target_cflags.="-Os ";
} elsif (/^O2$/) {
# Maximize Speed
$prj_target_cflags.="-O2 ";
} elsif (/^Ob0$/) {
# Disables inline Expansion
$prj_target_cflags.="-fno-inline ";
} elsif (/^Ob1$/) {
2009-04-25 16:27:42 +02:00
#In-line Function Expansion
$prj_target_cflags.="-finline-functions ";
2009-04-02 18:53:14 +02:00
} elsif (/^Ob2$/) {
# auto In-line Function Expansion
$prj_target_cflags.="-finline-functions ";
2009-04-25 16:27:42 +02:00
} elsif (/^Ox$/) {
# Use maximum optimization
$prj_target_cflags.="-O3 ";
2009-04-02 18:53:14 +02:00
} elsif (/^Oy$/) {
# Frame-Pointer Omission
$prj_target_cflags.="-fomit-frame-pointer ";
2009-04-25 16:41:48 +02:00
} elsif (/^Oy-$/) {
# Frame-Pointer Omission
$prj_target_cflags.="-fno-omit-frame-pointer ";
2009-04-02 18:53:14 +02:00
} elsif (/^GZ$/) {
# Catch Release-Build Errors in Debug Build
} elsif (/^M[DLT]d?$/) {
# Use Multithreaded Run-Time Library
} elsif (/^D\s*\"(.*)\"/) {
# Preprocessor Definitions
2009-08-13 16:43:37 +02:00
$prj_target_defines.="-D".$1." ";
2009-05-19 21:01:55 +02:00
} elsif (/^I\s*\"(.*)\"/) {
2009-04-02 18:53:14 +02:00
# Additional Include Directories
2009-05-19 21:01:55 +02:00
$sfilet=$1;
$sfilet=~s/\\/\//g;
2010-06-22 18:01:13 +02:00
if ($sfilet=~/^\w:/) {
print STDERR "warning: Can't fix path $sfilet\n"
} else {
push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." ";
}
2009-04-02 18:53:14 +02:00
} elsif (/^U\s*\"(.*)\"/) {
# Undefines a previously defined symbol
$prj_target_cflags.="-U".$1." ";
} elsif (/^Fp/) {
# Name .PCH File
} elsif (/^F[Rr]/) {
# Create .SBR File
} elsif (/^YX$/) {
# Automatic Use of Precompiled Headers
} elsif (/^FD$/) {
# Generate File Dependencies
} elsif (/^c$/) {
# Compile Without Linking
# this option is always present and is already specified in the suffix rules
} elsif (/^GB$/) {
# Blend Optimization
2010-09-19 20:42:44 +02:00
$prj_target_cflags.="-D_M_IX86=500 ";
2009-04-02 18:53:14 +02:00
} elsif (/^G6$/) {
# Pentium Pro Optimization
2010-09-19 20:42:44 +02:00
$prj_target_cflags.="-D_M_IX86=600 ";
2009-04-02 18:53:14 +02:00
} elsif (/^G5$/) {
# Pentium Optimization
2010-09-19 20:42:44 +02:00
$prj_target_cflags.="-D_M_IX86=500 ";
2009-04-02 18:53:14 +02:00
} elsif (/^G3$/) {
# 80386 Optimization
2010-09-19 20:42:44 +02:00
$prj_target_cflags.="-D_M_IX86=300 ";
2009-04-02 18:53:14 +02:00
} elsif (/^G4$/) {
# 80486 Optimization
2010-09-19 20:42:44 +02:00
$prj_target_cflags.="-D_M_IX86=400 ";
2009-04-02 18:53:14 +02:00
} elsif (/^Yc/) {
# Create Precompiled Header
} elsif (/^Yu/) {
# Use Precompiled Header
} elsif (/^Za$/) {
# Disable Language Extensions
$prj_target_cflags.="-ansi ";
} elsif (/^Ze$/) {
# Enable Microsoft Extensions
} elsif (/^Zm[[:digit:]]+$/) {
# Specify Memory Allocation Limit
} elsif (/^Zp1?$/) {
# Packs structures on 1-byte boundaries
$prj_target_cflags.="-fpack-struct ";
} elsif (/^Zp(2|4|8|16)$/) {
# Struct Member Alignment
$prj_target_cflags.="-fpack-struct=".$1;
} else {
print "C compiler option $_ not implemented\n";
}
}
#print "\nOptions: $prj_target_cflags\n";
next;
} elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) {
$prj_target_ldflags=$1;
2011-11-19 19:41:38 +01:00
@prj_target_options=split(/\s+\//, $prj_target_ldflags);
2009-04-02 18:53:14 +02:00
$prj_target_ldflags="";
$prj_target_libs=$prj_target_options[0];
$prj_target_libs=~s/\\/\//g;
$prj_target_libs=~s/\.lib//g;
2009-04-21 20:32:34 +02:00
$prj_target_libs=~s/\s+/ -l/g;
2009-04-02 18:53:14 +02:00
shift (@prj_target_options);
foreach ( @prj_target_options ) {
if ($_ eq "") {
# empty
} elsif (/^base:(.*)/) {
# Base Address
$prj_target_ldflags.="--image-base ".$1." ";
} elsif (/^debug$/) {
# Generate Debug Info
} elsif (/^dll$/) {
# Build a DLL
2010-05-10 19:59:01 +02:00
$prj_target_type=$TT_DLL;
2009-04-02 18:53:14 +02:00
} elsif (/^incremental:[[:alpha:]]+$/) {
# Link Incrmentally
} elsif (/^implib:/) {
# Name import library
} elsif (/^libpath:\"(.*)\"/) {
# Additional Libpath
push @{@$project_settings[$T_DLL_PATH]},"-L$1";
} elsif (/^machine:[[:alnum:]]+$/) {
# Specify Target Platform
} elsif (/^map/) {
# Generate Mapfile
if (/^map:(.*)/) {
$prj_target_ldflags.="-Map ".$1." ";
} else {
$prj_target_ldflags.="-Map ".$prj_name.".map ";
}
} elsif (/^nologo$/) {
# Suppress Startup Banner and Information Messages
} elsif (/^out:/) {
# Output File Name
# may use it as Target?
} elsif (/^pdbtype:/) {
# Program Database Storage
} elsif (/^subsystem:/) {
# Specify Subsystem
} elsif (/^version:[[:digit:].]+$/) {
# Version Information
} else {
print "Linker option $_ not implemented\n";
}
}
next;
} elsif (/^LIB32=/ && $found_cfg==1) {
#$libflag = 1;
next;
} elsif (/^SOURCE=(.*)$/) {
my @components=split /[\/\\]+/, $1;
$sfilet=search_from($path, \@components);
2010-06-22 18:01:07 +02:00
if (!defined $sfilet) { next; }
2009-08-29 13:10:01 +02:00
if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
2009-04-02 18:53:14 +02:00
push @sources_c,$sfilet;
} elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
push @sources_misc,$sfilet;
@$project_settings[$T_FLAGS]|=$TF_MFC;
} else {
push @sources_cxx,$sfilet;
}
} elsif ($sfilet =~ /\.rc$/i) {
push @sources_rc,$sfilet;
2011-01-04 22:43:01 +01:00
} elsif ($sfilet =~ /\.def$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASDEF;
2009-04-02 18:53:14 +02:00
} elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
push @sources_misc,$sfilet;
if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
@$project_settings[$T_FLAGS]|=$TF_MFC;
}
}
next;
} elsif (/^# (Begin|End) Source File/) {
# Source-Files already handled
next;
} elsif (/^# (Begin|End) Group/) {
# Groups are ignored
next;
} elsif (/^# (Begin|End) Custom Build/) {
# Custom Builds are ignored
next;
} elsif (/^# ADD LIB32 /) {
#"ARFLAGS=rus"
next;
} elsif (/^# Begin Target$/) {
# Targets are ignored
next;
} elsif (/^# End Target$/) {
# Targets are ignored
next;
} elsif (/^!/) {
if ($found_cfg == 1) {
$found_cfg=0;
}
if (/if (.*)\(CFG\)" == "(.*)"/i) {
if ($2 eq $prj_cfg) {
$found_cfg=1;
}
}
next;
} elsif (/^CFG=(.*)/i) {
$prj_cfg=$1;
next;
}
else { # Line recognized
# print "|\n";
}
}
close(FILEI);
push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
2009-08-13 16:43:37 +02:00
push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
2009-04-02 18:53:14 +02:00
push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags;
} elsif ($filename =~ /.vcproj$/i) {
2009-05-30 16:58:30 +02:00
# Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl)
require XML::LibXML;
2009-04-02 18:53:14 +02:00
2009-05-30 16:58:30 +02:00
my $xmlparser = XML::LibXML->new();
my $project_xml = $xmlparser->parse_file($filename);
2009-04-02 18:53:14 +02:00
my $sfilet;
2009-05-30 16:58:30 +02:00
my $configt;
foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) {
foreach my $vc_project_attr ($vc_project->attributes) {
if ($vc_project_attr->getName eq "Name") {
2009-08-29 13:10:01 +02:00
$prj_name=$vc_project_attr->getValue;
2009-11-21 18:13:44 +01:00
$prj_name=~s/\s+/_/g;
2009-05-30 16:58:30 +02:00
last;
}
}
}
for (my $flevel = 0; $flevel <= 5; $flevel++) {
foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) {
foreach my $vc_file_attr ($vc_file->attributes) {
if ($vc_file_attr->getName eq "RelativePath") {
$sfilet = $vc_file_attr->getValue;
$sfilet=~s/\\\\/\\/g; #remove double backslash
$sfilet=~s/^\.\\//; #remove starting 'this directory'
$sfilet=~s/\\/\//g; #make slashes out of backslashes
2009-08-29 13:10:01 +02:00
if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) {
2009-05-30 16:58:30 +02:00
push @sources_c,$sfilet;
} elsif ($sfilet =~ /\.(cpp|cxx)$/i) {
if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
push @sources_misc,$sfilet;
@$project_settings[$T_FLAGS]|=$TF_MFC;
} else {
push @sources_cxx,$sfilet;
}
} elsif ($sfilet =~ /\.rc$/i) {
push @sources_rc,$sfilet;
2011-01-04 22:43:01 +01:00
} elsif ($sfilet =~ /\.def$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASDEF;
2009-05-30 16:58:30 +02:00
} elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
2009-04-02 18:53:14 +02:00
push @sources_misc,$sfilet;
2009-05-30 16:58:30 +02:00
if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
@$project_settings[$T_FLAGS]|=$TF_MFC;
}
2009-04-02 18:53:14 +02:00
}
}
}
}
}
2009-05-30 16:58:30 +02:00
my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration');
my $vc_configuration = $vc_configurations[0];
foreach my $vc_configuration_attr ($vc_configuration->attributes) {
if ($vc_configuration_attr->getName eq "ConfigurationType") {
if ($vc_configuration_attr->getValue==1) {
2010-05-10 19:59:01 +02:00
$prj_target_type=$TT_GUIEXE; # Application
2009-05-30 16:58:30 +02:00
} elsif ($vc_configuration_attr->getValue==2) {
2010-05-10 19:59:01 +02:00
$prj_target_type=$TT_DLL; # Dynamic-Link Library
2011-11-19 19:42:56 +01:00
} elsif ($vc_configuration_attr->getValue==4) {
$prj_target_type=$TT_LIB; # Static Library
2009-05-30 16:58:30 +02:00
}
}
}
foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) {
my @find_tool = $vc_configuration_tools->attributes;
2009-08-10 17:44:09 +02:00
if ($find_tool[0]->getValue eq "VCCLCompilerTool") {
foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) {
if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";}
if ($vc_compiler_tool->getName eq "WarningLevel") {
if ($vc_compiler_tool->getValue==0) {
$prj_target_cflags.="-w ";
} elsif ($vc_compiler_tool->getValue<4) {
$prj_target_cflags.="-W ";
} elsif ($vc_compiler_tool->getValue==4) {
$prj_target_cflags.="-Wall ";
} elsif ($vc_compiler_tool->getValue eq "X") {
$prj_target_cflags.="-Werror ";
}
}
if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") {
$configt=$vc_compiler_tool->getValue;
2011-02-10 22:04:16 +01:00
$configt=~s/;\s*/ -D/g;
2009-08-13 16:43:37 +02:00
$prj_target_defines.="-D".$configt." ";
2009-08-10 17:44:09 +02:00
}
if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") {
$configt=$vc_compiler_tool->getValue;
$configt=~s/\\/\//g;
$configt=~s/;/ -I/g;
push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt;
2009-04-21 20:32:52 +02:00
}
2009-04-02 18:53:14 +02:00
}
2009-08-10 17:44:09 +02:00
}
if ($find_tool[0]->getValue eq "VCLinkerTool") {
foreach my $vc_linker_tool ($vc_configuration_tools->attributes) {
if ($vc_linker_tool->getName eq "AdditionalDependencies") {
$prj_target_libs=" ".$vc_linker_tool->getValue;
$prj_target_libs=~s/\\/\//g;
$prj_target_libs=~s/\.lib//g;
$prj_target_libs=~s/\s+/ -l/g;
}
2009-05-30 16:58:30 +02:00
}
2009-04-02 18:53:14 +02:00
}
}
2009-05-30 16:58:30 +02:00
2009-08-10 17:44:09 +02:00
push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs;
2009-04-02 18:53:14 +02:00
push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags;
push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags;
2009-08-13 16:43:37 +02:00
push @{@$project_settings[$T_DEFINES]},$prj_target_defines;
2009-04-02 18:53:14 +02:00
}
# Add this project to the project list, except for
# the main project which is already in the list.
if ($is_sub_project == 1) {
push @projects,$project;
}
# Ask for project-wide options
if ($opt_ask_project_options == $OPT_ASK_YES) {
my $flag_desc="";
if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
$flag_desc="mfc";
}
print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
if (defined $flag_desc) {
print "* (currently $flag_desc)\n";
}
print "* or 'skip' to skip the target specific options,\n";
print "* or 'never' to not be asked this question again:\n";
while (1) {
my $options=<STDIN>;
chomp $options;
if ($options eq "skip") {
$opt_ask_target_options=$OPT_ASK_SKIP;
last;
} elsif ($options eq "never") {
$opt_ask_project_options=$OPT_ASK_NO;
last;
} elsif (source_set_options($project_settings,$options)) {
last;
}
print "Please re-enter the options:\n";
}
}
2009-08-29 13:10:01 +02:00
# Create the target...
my $target=[];
target_init($target);
2009-04-02 18:53:14 +02:00
2011-11-19 19:42:56 +01:00
if ($prj_target_type==$TT_GUIEXE or $prj_target_type==$TT_CUIEXE) {
2009-08-29 13:10:01 +02:00
$prj_name=lc($prj_name.".exe");
@$target[$T_TYPE]=$opt_target_type;
push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
2011-11-19 19:42:56 +01:00
} elsif ($prj_target_type==$TT_LIB) {
$prj_name=lc("lib".$prj_name.".a");
@$target[$T_TYPE]=$TT_LIB;
push @{@$target[$T_ARFLAGS]},("rc");
2009-08-29 13:10:01 +02:00
} else {
$prj_name=lc($prj_name.".dll");
@$target[$T_TYPE]=$TT_DLL;
my $canon=canonize($prj_name);
2011-01-04 22:43:01 +01:00
if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
} else {
push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
}
2009-08-29 13:10:01 +02:00
}
2009-04-02 18:53:14 +02:00
2009-08-29 13:10:01 +02:00
@$target[$T_NAME]=$prj_name;
@$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
2009-04-02 18:53:14 +02:00
2009-08-29 13:10:01 +02:00
# This is the default link list of Visual Studio
my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
my @std_libraries=qw(uuid);
if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
@$target[$T_DLLS]=\@std_imports;
@$target[$T_LIBRARIES]=\@std_libraries;
} else {
@$target[$T_DLLS]=[];
@$target[$T_LIBRARIES]=[];
}
if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
2010-04-21 20:22:13 +02:00
if ($opt_arch != $OPT_ARCH_DEFAULT) {
push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
}
2009-08-29 13:10:01 +02:00
}
push @{@$project[$P_TARGETS]},$target;
2009-04-02 18:53:14 +02:00
2009-08-29 13:10:01 +02:00
# Ask for target-specific options
if ($opt_ask_target_options == $OPT_ASK_YES) {
my $flag_desc="";
if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
$flag_desc=" (mfc";
}
if ($flag_desc ne "") {
$flag_desc.=")";
}
print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n";
while (1) {
my $options=<STDIN>;
chomp $options;
if ($options eq "never") {
$opt_ask_target_options=$OPT_ASK_NO;
last;
} elsif (source_set_options($target,$options)) {
last;
}
print "Please re-enter the options:\n";
2009-04-02 18:53:14 +02:00
}
}
2009-08-29 13:10:01 +02:00
if (@$target[$T_FLAGS] & $TF_MFC) {
@$project_settings[$T_FLAGS]|=$TF_MFC;
push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
push @{@$target[$T_DLLS]},"mfc.dll";
# FIXME: Link with the MFC in the Unix sense, until we
# start exporting the functions properly.
push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
push @{@$target[$T_LIBRARIES]},"mfc";
}
# Match sources...
push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
@$project_settings[$T_SOURCES_C]=[];
@sources_c=();
push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
@$project_settings[$T_SOURCES_CXX]=[];
@sources_cxx=();
push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
@$project_settings[$T_SOURCES_RC]=[];
@sources_rc=();
push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
@$project_settings[$T_SOURCES_MISC]=[];
@sources_misc=();
@$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
@$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
@$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
@$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
2009-04-02 18:53:14 +02:00
if ($opt_ask_target_options == $OPT_ASK_SKIP) {
$opt_ask_target_options=$OPT_ASK_YES;
}
if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
2010-04-21 20:22:13 +02:00
if ($opt_arch != $OPT_ARCH_DEFAULT) {
push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
}
2009-04-02 18:53:14 +02:00
}
if (@$project_settings[$T_FLAGS] & $TF_MFC) {
push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
}
# The sources that did not match, if any, go to the extra
# source list of the project settings
foreach my $source (@sources_c) {
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_C]},$source;
}
}
@$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
foreach my $source (@sources_cxx) {
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_CXX]},$source;
}
}
@$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
foreach my $source (@sources_rc) {
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_RC]},$source;
}
}
@$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
foreach my $source (@sources_misc) {
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_MISC]},$source;
}
}
@$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
}
2009-04-02 18:53:24 +02:00
##
# Scans the specified workspace file to find the project files
sub source_scan_workspace_file($);
sub source_scan_workspace_file($)
{
my $filename=$_[0];
my $path=dirname($filename);
my @components;
if (! -e $filename) {
return;
}
if (!open(FILEIWS,$filename)) {
print STDERR "error: unable to open $filename for reading:\n";
print STDERR " $!\n";
return;
}
my $prj_name;
my $prj_path;
if ($filename =~ /.dsw$/i) {
while (<FILEIWS>) {
# Remove any trailing CrLf
s/\r\n$/\n/;
# catch a project definition
2009-05-01 11:37:13 +02:00
if (/^Project:\s\"(.*)\"=(.*)\s-/) {
2009-04-02 18:53:24 +02:00
$prj_name=$1;
$prj_path=$2;
2009-04-25 15:47:59 +02:00
@components=split /[\/\\]+/, $prj_path;
2009-04-02 18:53:24 +02:00
$prj_path=search_from($path, \@components);
print "Name: $prj_name\nPath: $prj_path\n";
source_scan_project_file(\@main_project,1,$prj_path);
next;
} elsif (/^#/) {
# ignore Comments
2010-06-22 18:01:03 +02:00
} elsif (/^Global:/) {
# ignore the Global section
2009-04-02 18:53:24 +02:00
} elsif (/\w:/) {
print STDERR "unknown section $_\n";
} elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
print "\nFileversion: $3\n";
}
}
close(FILEIWS);
} elsif ($filename =~ /.sln$/i) {
while (<FILEIWS>) {
# Remove any trailing CrLf
s/\r\n$/\n/;
# catch a project definition
if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) {
$prj_name=$2;
$prj_path=$3;
2010-11-16 19:59:32 +01:00
if ($prj_path eq "Solution Items") { next; }
2009-04-02 18:53:24 +02:00
@components=split /[\/\\]+/, $3;
$prj_path=search_from($path, \@components);
print "Name: $prj_name\nPath: $prj_path\n";
source_scan_project_file(\@main_project,1,$prj_path);
next;
} elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) {
print "\nFileversion: $3\n";
}
}
close(FILEIWS);
}
@projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
}
2000-11-05 06:23:39 +01:00
##
# Scans the specified directory to:
2002-06-01 04:55:48 +02:00
# - see if we should create a Makefile in this directory. We normally do
2000-11-05 06:23:39 +01:00
# so if we find a project file and sources
# - get a list of targets for this directory
# - get the list of source files
2002-09-06 20:36:19 +02:00
sub source_scan_directory($$$$);
sub source_scan_directory($$$$)
2000-11-05 06:23:39 +01:00
{
# a reference to the parent's project
my $parent_project=$_[0];
2002-06-01 04:55:48 +02:00
# the full relative path to the current directory, including a
2000-11-05 06:23:39 +01:00
# trailing '/', or an empty string if this is the top level directory
my $path=$_[1];
# the name of this directory, including a trailing '/', or an empty
# string if this is the top level directory
my $dirname=$_[2];
2002-06-01 04:55:48 +02:00
# if set then no targets will be looked for and the sources will all
2001-03-03 01:17:11 +01:00
# end up in the parent_project's 'misc' bucket
my $no_target=$_[3];
2000-11-05 06:23:39 +01:00
# reference to the project for this directory. May not be used
my $project;
# list of targets found in the 'current' directory
my %targets;
# list of sources found in the current directory
my @sources_c=();
my @sources_cxx=();
my @sources_rc=();
my @sources_misc=();
# true if this directory contains a Windows project
my $has_win_project=0;
2004-03-03 03:19:20 +01:00
# true if this directory contains headers
my $has_headers=0;
2002-06-01 04:55:48 +02:00
# If we don't find any executable/library then we might make up targets
# from the list of .dsp/.mak files we find since they usually have the
2000-11-05 06:23:39 +01:00
# same name as their target.
2010-05-10 19:58:12 +02:00
my @prj_files=();
2000-11-05 06:23:39 +01:00
my @mak_files=();
if (defined $opt_single_target or $dirname eq "") {
2002-06-01 04:55:48 +02:00
# Either there is a single target and thus a single project,
# or we are in the top level directory for which a project
2000-11-05 06:23:39 +01:00
# already exists
$project=$parent_project;
} else {
$project=[];
2009-02-25 10:33:48 +01:00
project_init($project, $path, \@global_settings);
2000-11-05 06:23:39 +01:00
}
2000-11-10 23:29:11 +01:00
my $project_settings=@$project[$P_SETTINGS];
2000-11-05 06:23:39 +01:00
# First find out what this directory contains:
# collect all sources, targets and subdirectories
my $directory=get_directory_contents($path);
2002-09-06 20:36:19 +02:00
foreach my $dentry (@$directory) {
2000-11-05 06:23:39 +01:00
if ($dentry =~ /^\./) {
next;
}
my $fullentry="$path$dentry";
if (-d "$fullentry") {
if ($dentry =~ /^(Release|Debug)/i) {
2002-06-01 04:55:48 +02:00
# These directories are often used to store the object files and the
2000-11-05 06:23:39 +01:00
# resulting executable/library. They should not contain anything else.
2011-11-23 21:36:14 +01:00
my @candidates=grep /\.(exe|dll|lib)$/i, @{get_directory_contents("$fullentry")};
foreach my $candidate (sort @candidates) {
my $dlldup = $candidate;
$dlldup =~ s/\.lib$/.dll/;
if ($candidate =~ /\.lib$/ and $targets{$dlldup})
{
# Often lib files are created together with dll files, even if the dll file is the
# real target.
next;
}
$targets{$candidate}=1;
}
2000-12-02 21:12:45 +01:00
} elsif ($dentry =~ /^include/i) {
# This directory must contain headers we're going to need
push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry";
2001-03-03 01:17:11 +01:00
source_scan_directory($project,"$fullentry/","$dentry/",1);
2000-11-05 06:23:39 +01:00
} else {
2002-06-01 04:55:48 +02:00
# Recursively scan this directory. Any source file that cannot be
# attributed to a project in one of the subdirectories will be
2001-03-03 01:17:11 +01:00
# attributed to this project.
source_scan_directory($project,"$fullentry/","$dentry/",$no_target);
2000-11-05 06:23:39 +01:00
}
} elsif (-f "$fullentry") {
2011-11-23 21:36:14 +01:00
if ($dentry =~ /\.(exe|dll|lib)$/i) {
2000-11-05 06:23:39 +01:00
$targets{$dentry}=1;
2003-10-28 22:13:54 +01:00
} elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) {
2000-11-05 06:23:39 +01:00
push @sources_c,"$dentry";
} elsif ($dentry =~ /\.(cpp|cxx)$/i) {
2002-09-10 02:20:27 +02:00
if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
2000-11-10 23:29:11 +01:00
push @sources_misc,"$dentry";
2000-11-25 02:38:39 +01:00
@$project_settings[$T_FLAGS]|=$TF_MFC;
2000-11-10 23:29:11 +01:00
} else {
push @sources_cxx,"$dentry";
}
2000-11-05 06:23:39 +01:00
} elsif ($dentry =~ /\.rc$/i) {
push @sources_rc,"$dentry";
2011-01-04 22:43:01 +01:00
} elsif ($dentry =~ /\.def$/i) {
@$project_settings[$T_FLAGS]|=$TF_HASDEF;
2001-03-23 20:07:59 +01:00
} elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
2004-03-03 03:19:20 +01:00
$has_headers=1;
2000-11-05 06:23:39 +01:00
push @sources_misc,"$dentry";
2002-09-10 02:20:27 +02:00
if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) {
2000-11-25 02:38:39 +01:00
@$project_settings[$T_FLAGS]|=$TF_MFC;
2000-11-10 23:29:11 +01:00
}
2010-05-10 19:58:12 +02:00
} elsif ($dentry =~ /\.(dsp|vcproj)$/i) {
push @prj_files,"$dentry";
2000-11-05 06:23:39 +01:00
$has_win_project=1;
} elsif ($dentry =~ /\.mak$/i) {
push @mak_files,"$dentry";
$has_win_project=1;
} elsif ($dentry =~ /^makefile/i) {
$has_win_project=1;
}
}
}
2004-03-03 03:19:20 +01:00
if ($has_headers) {
push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
}
2002-06-01 04:55:48 +02:00
# If we have a single target then all we have to do is assign
2000-11-05 06:23:39 +01:00
# all the sources to it and we're done
# FIXME: does this play well with the --interactive mode?
if ($opt_single_target) {
my $target=@{@$project[$P_TARGETS]}[0];
push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c;
push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx;
push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc;
push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc;
return;
}
2001-03-03 01:17:11 +01:00
if ($no_target) {
my $parent_settings=@$parent_project[$P_SETTINGS];
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c;
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx;
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc;
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
2001-04-20 20:26:35 +02:00
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
2001-03-03 01:17:11 +01:00
return;
}
2000-11-05 06:23:39 +01:00
my $source_count=@sources_c+@sources_cxx+@sources_rc+
@{@$project_settings[$T_SOURCES_C]}+
@{@$project_settings[$T_SOURCES_CXX]}+
@{@$project_settings[$T_SOURCES_RC]};
if ($source_count == 0) {
# A project without real sources is not a project, get out!
if ($project!=$parent_project) {
2001-03-03 01:17:11 +01:00
my $parent_settings=@$parent_project[$P_SETTINGS];
2000-11-05 06:23:39 +01:00
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
}
return;
}
#print "targets=",%targets,"\n";
#print "target_count=$target_count\n";
#print "has_win_project=$has_win_project\n";
#print "dirname=$dirname\n";
my $target_count;
if (($has_win_project != 0) or ($dirname eq "")) {
2002-06-01 04:55:48 +02:00
# Deal with cases where we could not find any executable/library, and
2000-11-05 06:23:39 +01:00
# thus have no target, although we did find some sort of windows project.
$target_count=keys %targets;
if ($target_count == 0) {
# Try to come up with a target list based on .dsp/.mak files
my $prj_list;
2010-05-10 19:58:12 +02:00
if (@prj_files > 0) {
2010-05-11 20:03:04 +02:00
print "Projectfile found! You might want to try using it directly.\n";
2010-05-10 19:58:12 +02:00
$prj_list=\@prj_files;
2000-11-05 06:23:39 +01:00
} else {
2010-05-10 19:58:12 +02:00
$prj_list=\@mak_files;
2000-11-05 06:23:39 +01:00
}
2002-09-06 20:36:19 +02:00
foreach my $filename (@$prj_list) {
2010-05-10 19:58:12 +02:00
$filename =~ s/\.(dsp|vcproj|mak)$//i;
2000-11-05 06:23:39 +01:00
if ($opt_target_type == $TT_DLL) {
2002-09-26 05:20:59 +02:00
$filename = "$filename.dll";
2000-11-05 06:23:39 +01:00
}
$targets{$filename}=1;
}
$target_count=keys %targets;
if ($target_count == 0) {
# Still nothing, try the name of the directory
my $name;
if ($dirname eq "") {
# Bad luck, this is the top level directory!
$name=(split /\//, cwd)[-1];
} else {
$name=$dirname;
2002-06-01 04:55:48 +02:00
# Remove the trailing '/'. Also eliminate whatever is after the last
2000-11-05 06:23:39 +01:00
# '.' as it is likely to be meaningless (.orig, .new, ...)
$name =~ s+(/|\.[^.]*)$++;
if ($name eq "src") {
# 'src' is probably a subdirectory of the real project directory.
# Try again with the parent (if any).
my $parent=$path;
if ($parent =~ s+([^/]*)/[^/]*/$+$1+) {
$name=$parent;
} else {
$name=(split /\//, cwd)[-1];
}
}
}
$name =~ s+(/|\.[^.]*)$++;
if ($opt_target_type == $TT_DLL) {
2009-04-23 20:41:32 +02:00
$name = canonize($name).".dll";
2012-01-15 18:02:57 +01:00
} elsif ($opt_target_type == $TT_LIB) {
$name = "lib".canonize($name).".a";
2003-01-02 20:27:23 +01:00
} else {
2009-04-23 20:41:32 +02:00
$name = canonize($name).".exe";
2000-11-05 06:23:39 +01:00
}
$targets{$name}=1;
}
}
# Ask confirmation to the user if he wishes so
if ($opt_is_interactive == $OPT_ASK_YES) {
my $target_list=join " ",keys %targets;
2000-11-30 21:34:39 +01:00
print "\n*** In ",($path?$path:"./"),"\n";
2000-11-10 23:29:11 +01:00
print "* winemaker found the following list of (potential) targets\n";
print "* $target_list\n";
print "* Type enter to use it as is, your own comma-separated list of\n";
print "* targets, 'none' to assign the source files to a parent directory,\n";
print "* or 'ignore' to ignore everything in this directory tree.\n";
print "* Target list:\n";
2000-11-05 06:23:39 +01:00
$target_list=<STDIN>;
chomp $target_list;
if ($target_list eq "") {
# Keep the target list as is, i.e. do nothing
} elsif ($target_list eq "none") {
# Empty the target list
undef %targets;
} elsif ($target_list eq "ignore") {
# Ignore this subtree altogether
return;
} else {
undef %targets;
2002-09-06 20:36:19 +02:00
foreach my $target (split /,/,$target_list) {
2000-11-05 06:23:39 +01:00
$target =~ s+^\s*++;
$target =~ s+\s*$++;
$targets{$target}=1;
}
}
}
}
2002-06-01 04:55:48 +02:00
# If we have no project at this level, then transfer all
2000-11-05 06:23:39 +01:00
# the sources to the parent project
$target_count=keys %targets;
if ($target_count == 0) {
if ($project!=$parent_project) {
my $parent_settings=@$parent_project[$P_SETTINGS];
push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c;
push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx;
push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc;
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc;
push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]};
}
return;
}
2002-06-01 04:55:48 +02:00
# Otherwise add this project to the project list, except for
2000-11-05 06:23:39 +01:00
# the main project which is already in the list.
if ($dirname ne "") {
push @projects,$project;
}
# Ask for project-wide options
if ($opt_ask_project_options == $OPT_ASK_YES) {
2000-11-10 23:29:11 +01:00
my $flag_desc="";
if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) {
$flag_desc="mfc";
}
2004-02-27 22:24:20 +01:00
print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n";
2000-11-10 23:29:11 +01:00
if (defined $flag_desc) {
print "* (currently $flag_desc)\n";
}
print "* or 'skip' to skip the target specific options,\n";
print "* or 'never' to not be asked this question again:\n";
2000-11-30 21:36:04 +01:00
while (1) {
my $options=<STDIN>;
chomp $options;
if ($options eq "skip") {
$opt_ask_target_options=$OPT_ASK_SKIP;
last;
} elsif ($options eq "never") {
$opt_ask_project_options=$OPT_ASK_NO;
last;
} elsif (source_set_options($project_settings,$options)) {
last;
}
print "Please re-enter the options:\n";
2000-11-05 06:23:39 +01:00
}
}
# - Create the targets
# - Check if we have both libraries and programs
2002-06-01 04:55:48 +02:00
# - Match each target with source files (sort in reverse
2000-11-05 06:23:39 +01:00
# alphabetical order to get the longest matches first)
2001-07-30 20:44:48 +02:00
my @local_dlls=();
2011-11-23 21:36:14 +01:00
my @local_libs=();
2000-11-05 06:23:39 +01:00
my @local_depends=();
2000-11-15 23:12:20 +01:00
my @exe_list=();
2002-09-18 20:30:29 +02:00
foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) {
2000-11-05 06:23:39 +01:00
# Create the target...
my $target=[];
target_init($target);
@$target[$T_NAME]=$target_name;
2000-11-10 23:29:11 +01:00
@$target[$T_FLAGS]|=@$project_settings[$T_FLAGS];
2002-09-26 05:20:59 +02:00
if ($target_name =~ /\.dll$/) {
2000-11-05 06:23:39 +01:00
@$target[$T_TYPE]=$TT_DLL;
2002-09-26 05:20:59 +02:00
push @local_depends,"$target_name.so";
push @local_dlls,$target_name;
2005-01-11 11:39:10 +01:00
my $canon=canonize($target_name);
2011-01-04 22:43:01 +01:00
if (@$project_settings[$T_FLAGS] & $TF_HASDEF) {
push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.def)");
} else {
push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:.dll=.spec)");
}
2011-11-23 21:36:14 +01:00
} elsif ($target_name =~ /\.lib$/) {
$target_name =~ s/(.*)\.lib/lib$1.a/;
@$target[$T_NAME]=$target_name;
@$target[$T_TYPE]=$TT_LIB;
push @local_depends,"$target_name";
push @local_libs,$target_name;
push @{@$target[$T_ARFLAGS]},("rc");
2012-01-15 18:02:57 +01:00
} elsif ($target_name =~ /\.a$/) {
@$target[$T_NAME]=$target_name;
@$target[$T_TYPE]=$TT_LIB;
push @local_depends,"$target_name";
push @local_libs,$target_name;
push @{@$target[$T_ARFLAGS]},("rc");
2000-11-05 06:23:39 +01:00
} else {
@$target[$T_TYPE]=$opt_target_type;
2000-11-15 23:12:20 +01:00
push @exe_list,$target;
2004-03-03 03:19:20 +01:00
push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows");
2000-11-05 06:23:39 +01:00
}
2002-09-26 05:20:59 +02:00
my $basename=$target_name;
$basename=~ s/\.(dll|exe)$//i;
2009-02-05 17:36:39 +01:00
# This is the default link list of Visual Studio
my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32);
2004-01-30 23:55:00 +01:00
my @std_libraries=qw(uuid);
2002-09-13 19:43:25 +02:00
if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) {
2002-12-15 04:00:40 +01:00
@$target[$T_DLLS]=\@std_imports;
2004-01-30 23:55:00 +01:00
@$target[$T_LIBRARIES]=\@std_libraries;
2002-09-10 02:20:27 +02:00
} else {
@$target[$T_DLLS]=[];
2004-01-30 23:55:00 +01:00
@$target[$T_LIBRARIES]=[];
2002-09-10 02:20:27 +02:00
}
2004-03-03 03:19:20 +01:00
if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
push @{@$target[$T_LDFLAGS]},"-mno-cygwin";
2010-04-21 20:22:13 +02:00
if ($opt_arch != $OPT_ARCH_DEFAULT) {
push @{@$target[$T_LDFLAGS]},"-m$opt_arch";
}
2004-03-03 03:19:20 +01:00
}
2000-11-05 06:23:39 +01:00
push @{@$project[$P_TARGETS]},$target;
# Ask for target-specific options
if ($opt_ask_target_options == $OPT_ASK_YES) {
2000-11-10 23:29:11 +01:00
my $flag_desc="";
if ((@$target[$T_FLAGS] & $TF_MFC)!=0) {
$flag_desc=" (mfc";
}
if ($flag_desc ne "") {
$flag_desc.=")";
}
2004-02-27 22:24:20 +01:00
print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n";
2000-11-10 23:29:11 +01:00
print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n";
2000-11-30 21:36:04 +01:00
while (1) {
my $options=<STDIN>;
chomp $options;
if ($options eq "never") {
$opt_ask_target_options=$OPT_ASK_NO;
last;
} elsif (source_set_options($target,$options)) {
last;
}
print "Please re-enter the options:\n";
2000-11-05 06:23:39 +01:00
}
}
if (@$target[$T_FLAGS] & $TF_MFC) {
@$project_settings[$T_FLAGS]|=$TF_MFC;
2001-07-30 20:44:48 +02:00
push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)";
push @{@$target[$T_DLLS]},"mfc.dll";
2002-06-01 04:55:48 +02:00
# FIXME: Link with the MFC in the Unix sense, until we
2000-11-15 23:12:20 +01:00
# start exporting the functions properly.
2001-07-30 20:44:48 +02:00
push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)";
2000-11-15 23:12:20 +01:00
push @{@$target[$T_LIBRARIES]},"mfc";
2000-11-05 06:23:39 +01:00
}
# Match sources...
if ($target_count == 1) {
2000-12-02 21:12:45 +01:00
push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c;
@$project_settings[$T_SOURCES_C]=[];
2000-11-05 06:23:39 +01:00
@sources_c=();
2000-12-02 21:12:45 +01:00
push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx;
@$project_settings[$T_SOURCES_CXX]=[];
2000-11-05 06:23:39 +01:00
@sources_cxx=();
2000-12-02 21:12:45 +01:00
push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc;
@$project_settings[$T_SOURCES_RC]=[];
2000-11-05 06:23:39 +01:00
@sources_rc=();
2000-12-02 21:12:45 +01:00
push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc;
# No need for sorting these sources
@$project_settings[$T_SOURCES_MISC]=[];
2000-11-05 06:23:39 +01:00
@sources_misc=();
} else {
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_c) {
2000-11-05 06:23:39 +01:00
if ($source =~ /^$basename/i) {
push @{@$target[$T_SOURCES_C]},$source;
$source="";
}
}
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_cxx) {
2000-11-05 06:23:39 +01:00
if ($source =~ /^$basename/i) {
push @{@$target[$T_SOURCES_CXX]},$source;
$source="";
}
}
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_rc) {
2000-11-05 06:23:39 +01:00
if ($source =~ /^$basename/i) {
push @{@$target[$T_SOURCES_RC]},$source;
$source="";
}
}
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_misc) {
2000-11-05 06:23:39 +01:00
if ($source =~ /^$basename/i) {
push @{@$target[$T_SOURCES_MISC]},$source;
$source="";
}
}
}
@$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}];
@$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}];
@$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}];
@$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}];
}
if ($opt_ask_target_options == $OPT_ASK_SKIP) {
$opt_ask_target_options=$OPT_ASK_YES;
}
2004-02-27 22:24:20 +01:00
if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) {
2004-03-03 03:19:20 +01:00
push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin";
push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin";
2010-04-21 20:22:13 +02:00
if ($opt_arch != $OPT_ARCH_DEFAULT) {
push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch";
push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch";
}
2004-02-27 22:24:20 +01:00
}
2000-11-05 06:23:39 +01:00
if (@$project_settings[$T_FLAGS] & $TF_MFC) {
push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)";
}
2002-06-01 04:55:48 +02:00
# The sources that did not match, if any, go to the extra
2000-11-05 06:23:39 +01:00
# source list of the project settings
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_c) {
2000-11-05 06:23:39 +01:00
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_C]},$source;
}
}
@$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}];
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_cxx) {
2000-11-05 06:23:39 +01:00
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_CXX]},$source;
}
}
@$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}];
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_rc) {
2000-11-05 06:23:39 +01:00
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_RC]},$source;
}
}
@$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}];
2002-09-06 20:36:19 +02:00
foreach my $source (@sources_misc) {
2000-11-05 06:23:39 +01:00
if ($source ne "") {
push @{@$project_settings[$T_SOURCES_MISC]},$source;
}
}
@$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}];
2002-06-01 04:55:48 +02:00
# Finally if we are building both libraries and programs in
# this directory, then the programs should be linked with all
2000-11-05 06:23:39 +01:00
# the libraries
2001-07-30 20:44:48 +02:00
if (@local_dlls > 0 and @exe_list > 0) {
2002-09-06 20:36:19 +02:00
foreach my $target (@exe_list) {
2001-07-30 20:44:48 +02:00
push @{@$target[$T_DLL_PATH]},"-L.";
2002-09-26 05:20:59 +02:00
push @{@$target[$T_DLLS]},@local_dlls;
2000-11-05 06:23:39 +01:00
}
}
2011-11-23 21:36:14 +01:00
if (@local_libs > 0 and @exe_list > 0) {
foreach my $target (@exe_list) {
push @{@$target[$T_LIBRARY_PATH]},"-L.";
push @{@$target[$T_LIBRARIES]},@local_libs;
}
}
2000-11-05 06:23:39 +01:00
}
##
# Scan the source directories in search of things to build
2002-09-06 20:36:19 +02:00
sub source_scan()
2000-11-05 06:23:39 +01:00
{
# If there's a single target then this is going to be the default target
if (defined $opt_single_target) {
2001-01-11 21:17:42 +01:00
# Create the main target
my $main_target=[];
target_init($main_target);
2002-09-26 05:20:59 +02:00
@$main_target[$T_NAME]=$opt_single_target;
2000-11-05 06:23:39 +01:00
@$main_target[$T_TYPE]=$opt_target_type;
2001-01-11 21:17:42 +01:00
# Add it to the list
push @{$main_project[$P_TARGETS]},$main_target;
2000-11-05 06:23:39 +01:00
}
# The main directory is always going to be there
push @projects,\@main_project;
2009-04-02 18:53:14 +02:00
if (defined $opt_work_dir) {
# Now scan the directory tree looking for source files and, maybe, targets
print "Scanning the source directories...\n";
source_scan_directory(\@main_project,"","",0);
@projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
} elsif (defined $opt_work_file) {
if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) {
source_scan_project_file(\@main_project,0,$opt_work_file);
2009-04-02 18:53:24 +02:00
} elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) {
source_scan_workspace_file($opt_work_file);
2009-04-02 18:53:14 +02:00
}
}
2000-11-05 06:23:39 +01:00
}
#####
#
# Source search
#
#####
##
# Performs a directory traversal and renames the files so that:
# - they have the case desired by the user
# - their extension is of the appropriate case
# - they don't contain annoying characters like ' ', '$', '#', ...
2005-02-21 19:29:44 +01:00
# But only perform these changes for source files and directories.
2002-09-06 20:36:19 +02:00
sub fix_file_and_directory_names($);
sub fix_file_and_directory_names($)
2000-11-05 06:23:39 +01:00
{
my $dirname=$_[0];
2009-02-25 10:32:36 +01:00
my $directory=get_directory_contents($dirname);
foreach my $dentry (@$directory)
{
2000-11-05 06:23:39 +01:00
if ($dentry =~ /^\./ or $dentry eq "CVS") {
2009-02-25 10:32:36 +01:00
next;
2000-11-05 06:23:39 +01:00
}
# Set $warn to 1 if the user should be warned of the renaming
2005-02-21 19:29:44 +01:00
my $warn;
2000-11-05 06:23:39 +01:00
my $new_name=$dentry;
2005-02-21 19:29:44 +01:00
if (-f "$dirname/$dentry")
{
2009-02-25 10:32:36 +01:00
# Don't rename Winemaker's makefiles
next if ($dentry eq "Makefile" and
`head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
# Leave non-source files alone
2011-01-04 22:43:01 +01:00
next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc|spec|def))$/i);
2009-02-25 10:32:36 +01:00
# Only all lowercase extensions are supported (because of
2010-11-30 23:54:58 +01:00
# rules like '.c.o:').
2009-02-25 10:32:36 +01:00
$new_name =~ s/\.C$/.c/;
$new_name =~ s/\.cpp$/.cpp/i;
$warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
$new_name =~ s/\.rc$/.rc/i;
2010-11-30 23:54:58 +01:00
# And this last one is to avoid confusion when running make
2009-02-25 10:32:36 +01:00
$warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
2000-11-05 06:23:39 +01:00
}
# Adjust the case to the user's preferences
2002-06-01 04:55:48 +02:00
if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
2000-11-05 06:23:39 +01:00
($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
) {
2009-02-25 10:32:36 +01:00
$new_name=lc $new_name;
2000-11-05 06:23:39 +01:00
}
2010-11-30 23:54:58 +01:00
# make doesn't support these characters well
2005-02-21 19:29:44 +01:00
$new_name =~ s/[ \$]/_/g;
2000-11-05 06:23:39 +01:00
# And finally, perform the renaming
2009-02-25 10:32:36 +01:00
if ($new_name ne $dentry)
{
if ($warn) {
print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
}
if (!rename("$dirname/$dentry","$dirname/$new_name")) {
print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
print STDERR " $!\n";
$new_name=$dentry;
}
else
{
clear_directory_cache($dirname);
}
2000-11-05 06:23:39 +01:00
}
if (-d "$dirname/$new_name") {
2009-02-25 10:32:36 +01:00
fix_file_and_directory_names("$dirname/$new_name");
2000-11-05 06:23:39 +01:00
}
}
}
#####
#
# Source fixup
#
#####
##
2002-06-01 04:55:48 +02:00
# Try to find a file for the specified filename. The attempt is
# case-insensitive which is why it's not trivial. If a match is
2000-11-05 06:23:39 +01:00
# found then we return the pathname with the correct case.
2002-09-06 20:36:19 +02:00
sub search_from($$)
2000-11-05 06:23:39 +01:00
{
my $dirname=$_[0];
my $path=$_[1];
my $real_path="";
2010-11-30 23:54:58 +01:00
$dirname =~ s/(\.\/)+//;
2009-04-24 17:40:32 +02:00
if ($dirname eq "" or $dirname eq "." or $dirname eq "./") {
2000-11-05 06:23:39 +01:00
$dirname=cwd;
2005-01-11 11:39:10 +01:00
} elsif ($dirname !~ m+^/+) {
2000-11-05 06:23:39 +01:00
$dirname=cwd . "/" . $dirname;
}
if ($dirname !~ m+/$+) {
$dirname.="/";
}
2002-09-06 20:36:19 +02:00
foreach my $component (@$path) {
2009-04-29 19:42:24 +02:00
$component=~s/^\"//;
$component=~s/\"$//;
2000-11-07 21:27:16 +01:00
#print " looking for $component in \"$dirname\"\n";
2000-11-05 06:23:39 +01:00
if ($component eq ".") {
# Pass it as is
$real_path.="./";
} elsif ($component eq "..") {
# Go up one level
2010-11-30 23:55:59 +01:00
if ($dirname =~ /\.\.\/$/) {
$dirname.="../";
} else {
$dirname=dirname($dirname) . "/";
}
2000-11-05 06:23:39 +01:00
$real_path.="../";
} else {
2002-06-01 04:55:48 +02:00
# The file/directory may have been renamed before. Also try to
2001-04-23 20:16:13 +02:00
# match the renamed file.
my $renamed=$component;
$renamed =~ s/[ \$]/_/g;
if ($renamed eq $component) {
undef $renamed;
}
2000-11-05 06:23:39 +01:00
my $directory=get_directory_contents $dirname;
my $found;
2002-09-06 20:36:19 +02:00
foreach my $dentry (@$directory) {
2008-12-20 01:23:45 +01:00
if ($dentry =~ /^\Q$component\E$/i or
2001-04-23 20:16:13 +02:00
(defined $renamed and $dentry =~ /^$renamed$/i)
) {
2000-11-05 06:23:39 +01:00
$dirname.="$dentry/";
$real_path.="$dentry/";
$found=1;
last;
}
}
if (!defined $found) {
# Give up
2000-11-07 21:27:16 +01:00
#print " could not find $component in $dirname\n";
2000-11-05 06:23:39 +01:00
return;
}
}
}
$real_path=~ s+/$++;
2000-11-07 21:27:16 +01:00
#print " -> found $real_path\n";
2000-11-05 06:23:39 +01:00
return $real_path;
}
##
2002-06-01 04:55:48 +02:00
# Performs a case-insensitive search for the specified file in the
2000-11-05 06:23:39 +01:00
# include path.
# $line is the line number that should be referenced when an error occurs
# $filename is the file we are looking for
# $dirname is the directory of the file containing the '#include' directive
# if '"' was used, it is an empty string otherwise
# $project and $target specify part of the include path
2002-09-06 20:36:19 +02:00
sub get_real_include_name($$$$$)
2000-11-05 06:23:39 +01:00
{
my $line=$_[0];
my $filename=$_[1];
my $dirname=$_[2];
my $project=$_[3];
my $target=$_[4];
2010-11-30 23:54:58 +01:00
if ($filename =~ /^([a-zA-Z]:)?[\/\\]/ or $filename =~ /^[a-zA-Z]:[\/\\]?/) {
2000-11-05 06:23:39 +01:00
# This is not a relative path, we cannot make any check
my $warning="path:$filename";
if (!defined $warnings{$warning}) {
$warnings{$warning}="1";
print STDERR "warning: cannot check the case of absolute pathnames:\n";
print STDERR "$line: $filename\n";
}
} else {
# Here's how we proceed:
# - split the filename we look for into its components
# - then for each directory in the include path
# - trace the directory components starting from that directory
2002-06-01 04:55:48 +02:00
# - if we fail to find a match at any point then continue with
2000-11-05 06:23:39 +01:00
# the next directory in the include path
# - otherwise, rejoice, our quest is over.
my @file_components=split /[\/\\]+/, $filename;
2000-11-07 21:27:16 +01:00
#print " Searching for $filename from @$project[$P_PATH]\n";
2000-11-05 06:23:39 +01:00
my $real_filename;
if ($dirname ne "") {
2000-11-07 21:27:16 +01:00
# This is an 'include ""' -> look in dirname first.
#print " in $dirname (include \"\")\n";
2000-11-05 06:23:39 +01:00
$real_filename=search_from($dirname,\@file_components);
if (defined $real_filename) {
return $real_filename;
}
}
my $project_settings=@$project[$P_SETTINGS];
2002-09-06 20:36:19 +02:00
foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) {
2000-11-07 21:27:16 +01:00
my $dirname=$include;
$dirname=~ s+^-I++;
2009-05-19 21:01:55 +02:00
$dirname=~ s+\s$++;
2000-11-07 21:27:16 +01:00
if (!is_absolute($dirname)) {
$dirname="@$project[$P_PATH]$dirname";
} else {
2001-04-20 20:26:35 +02:00
$dirname=~ s+^\$\(TOPSRCDIR\)/++;
$dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+;
2000-11-07 21:27:16 +01:00
}
#print " in $dirname\n";
2000-11-05 06:23:39 +01:00
$real_filename=search_from("$dirname",\@file_components);
if (defined $real_filename) {
return $real_filename;
}
}
my $dotdotpath=@$project[$P_PATH];
$dotdotpath =~ s/[^\/]+/../g;
2002-09-06 20:36:19 +02:00
foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) {
2000-11-07 21:27:16 +01:00
my $dirname=$include;
$dirname=~ s+^-I++;
$dirname=~ s+^\$\(TOPSRCDIR\)\/++;
2001-04-20 20:26:35 +02:00
$dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+;
2000-11-07 21:27:16 +01:00
#print " in $dirname (global setting)\n";
2000-11-05 06:23:39 +01:00
$real_filename=search_from("$dirname",\@file_components);
if (defined $real_filename) {
return $real_filename;
}
}
}
$filename =~ s+\\\\+/+g; # in include ""
$filename =~ s+\\+/+g; # in include <> !
2000-11-10 23:29:11 +01:00
if ($opt_lower_include) {
2000-11-05 06:23:39 +01:00
return lc "$filename";
}
return $filename;
}
2002-09-06 20:36:19 +02:00
sub print_pack($$$)
2001-04-18 19:39:42 +02:00
{
my $indent=$_[0];
my $size=$_[1];
my $trailer=$_[2];
if ($size =~ /^(1|2|4|8)$/) {
print FILEO "$indent#include <pshpack$size.h>$trailer";
} else {
print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n";
print FILEO "$indent#include <pshpack4.h>$trailer";
}
}
2000-11-05 06:23:39 +01:00
##
2002-06-01 04:55:48 +02:00
# 'Parses' a source file and fixes constructs that would not work with
# Winelib. The parsing is rather simple and not all non-portable features
# are corrected. The most important feature that is corrected is the case
# and path separator of '#include' directives. This requires that each
# source file be associated to a project & target so that the proper
2000-11-05 06:23:39 +01:00
# include path is used.
2002-06-01 04:55:48 +02:00
# Also note that the include path is relative to the directory in which the
2000-11-07 21:27:16 +01:00
# compiler is run, i.e. that of the project, not to that of the file.
2002-09-06 20:36:19 +02:00
sub fix_file($$$)
2000-11-05 06:23:39 +01:00
{
my $filename=$_[0];
my $project=$_[1];
my $target=$_[2];
$filename="@$project[$P_PATH]$filename";
if (! -e $filename) {
return;
}
my $is_rc=($filename =~ /\.(rc2?|dlg)$/i);
my $dirname=dirname($filename);
my $is_mfc=0;
if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) {
$is_mfc=1;
}
print " $filename\n";
if (! -e "$filename.bak") {
if (!copy("$filename","$filename.bak")) {
print STDERR "error: unable to make a backup of $filename:\n";
print STDERR " $!\n";
return;
}
}
if (!open(FILEI,"$filename.bak")) {
print STDERR "error: unable to open $filename.bak for reading:\n";
print STDERR " $!\n";
return;
}
if (!open(FILEO,">$filename")) {
print STDERR "error: unable to open $filename for writing:\n";
print STDERR " $!\n";
return;
}
my $line=0;
my $modified=0;
my $rc_block_depth=0;
my $rc_textinclude_state=0;
2001-04-18 19:39:42 +02:00
my @pack_stack;
2000-11-05 06:23:39 +01:00
while (<FILEI>) {
2001-07-13 00:21:44 +02:00
# Remove any trailing CtrlZ, which isn't strictly in the file
if (/\x1A/) {
s/\x1A//;
last if (/^$/)
}
2000-11-05 06:23:39 +01:00
$line++;
2001-02-12 02:22:58 +01:00
s/\r\n$/\n/;
if (!/\n$/) {
# Make sure all files are '\n' terminated
$_ .= "\n";
}
2001-04-18 19:39:42 +02:00
if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) {
2002-06-01 04:55:48 +02:00
# VC6 automatically includes 'afxres.h', an MFC specific header, in
# the RC files it generates (even in non-MFC projects). So we replace
2009-04-02 18:53:12 +02:00
# it with 'winresrc.h' its very close standard cousin so that non MFC
2001-02-12 02:22:58 +01:00
# projects can compile in Wine without the MFC sources.
2000-11-05 06:23:39 +01:00
my $warning="mfc:afxres.h";
if (!defined $warnings{$warning}) {
$warnings{$warning}="1";
2009-04-02 18:53:12 +02:00
print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n";
2000-11-05 06:23:39 +01:00
print STDERR "warning: the above warning is issued only once\n";
}
2001-04-18 19:39:42 +02:00
print FILEO "$1/* winemaker: $2\"afxres.h\" */\n";
2009-04-02 18:53:12 +02:00
print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n";
print FILEO "$1$2\"winresrc.h\"$'";
2000-11-05 06:23:39 +01:00
$modified=1;
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) {
my $from_file=($2 eq "<"?"":$dirname);
my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
print FILEO "$1$2$real_include_name$4$'";
$modified|=($real_include_name ne $3);
2001-04-18 19:39:42 +02:00
} elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) {
# Pragma pack handling
#
2002-06-01 04:55:48 +02:00
# pack_stack is an array of references describing the stack of
# pack directives currently in effect. Each directive if described
2001-04-18 19:39:42 +02:00
# by a reference to an array containing:
# - "push" for pack(push,...) directives, "" otherwise
# - the directive's identifier at index 1
2008-05-06 15:54:52 +02:00
# - the directive's alignment value at index 2
2001-04-18 19:39:42 +02:00
#
# Don't believe a word of what the documentation says: it's all wrong.
# The code below is based on the actual behavior of Visual C/C++ 6.
my $pack_indent=$1;
my $pack_header=$2;
if (/^(\))/) {
# pragma pack()
# Pushes the default stack alignment
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
print_pack($pack_indent,4,$');
push @pack_stack, [ "", "", 4 ];
} elsif (/^(pop\s*(,\s*\d+\s*)?\))/) {
# pragma pack(pop)
# pragma pack(pop,n)
# Goes up the stack until it finds a pack(push,...), and pops it
# Ignores any pack(n) entry
# Issues a warning if the pack is of the form pack(push,label)
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
my $pack_comment=$';
2001-04-20 20:26:35 +02:00
$pack_comment =~ s/^\s*//;
2001-04-18 19:39:42 +02:00
if ($pack_comment ne "") {
print FILEO "$pack_indent$pack_comment";
}
while (1) {
my $alignment=pop @pack_stack;
if (!defined $alignment) {
print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n";
last;
}
if (@$alignment[1]) {
print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n";
}
print FILEO "$pack_indent#include <poppack.h>\n";
if (@$alignment[0]) {
last;
}
}
} elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) {
# pragma pack(pop,label[,n])
# Goes up the stack until finding a pack(push,...) and pops it.
# 'n', if specified, is ignored.
# Ignores any pack(n) entry
# Issues a warning if the label of the pack does not match,
# or if it is in fact a pack(push,n)
my $label=$2;
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
my $pack_comment=$';
2001-04-20 20:26:35 +02:00
$pack_comment =~ s/^\s*//;
2001-04-18 19:39:42 +02:00
if ($pack_comment ne "") {
print FILEO "$pack_indent$pack_comment";
}
while (1) {
my $alignment=pop @pack_stack;
if (!defined $alignment) {
print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n";
last;
}
if (@$alignment[1] and @$alignment[1] ne $label) {
print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n";
}
print FILEO "$pack_indent#include <poppack.h>\n";
if (@$alignment[0]) {
last;
}
}
} elsif (/^(push\s*\))/) {
# pragma pack(push)
# Push the current alignment
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
if (@pack_stack > 0) {
my $alignment=$pack_stack[$#pack_stack];
print_pack($pack_indent,@$alignment[2],$');
push @pack_stack, [ "push", "", @$alignment[2] ];
} else {
print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
print_pack($pack_indent,4,$');
push @pack_stack, [ "push", "", 4 ];
}
} elsif (/^((push\s*,\s*)?(\d+)\s*\))/) {
# pragma pack([push,]n)
# Push new alignment n
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
print_pack($pack_indent,$3,"$'");
push @pack_stack, [ ($2 ? "push" : ""), "", $3 ];
} elsif (/^((\w+)\s*\))/) {
# pragma pack(label)
# label must in fact be a macro that resolves to an integer
# Then behaves like 'pragma pack(n)'
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n";
print_pack($pack_indent,4,$');
push @pack_stack, [ "", "", 4 ];
} elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) {
# pragma pack(push,label[,n])
# Pushes a new label on the stack. It is possible to push the same
2002-06-01 04:55:48 +02:00
# label multiple times. If 'n' is omitted then the alignment is
2001-04-18 19:39:42 +02:00
# unchanged. Otherwise it becomes 'n'.
print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n";
my $size;
if (defined $4) {
$size=$4;
} elsif (@pack_stack > 0) {
my $alignment=$pack_stack[$#pack_stack];
$size=@$alignment[2];
} else {
print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n";
$size=4;
}
print_pack($pack_indent,$size,$');
push @pack_stack, [ "push", $2, $size ];
2000-11-05 06:23:39 +01:00
} else {
2001-04-18 19:39:42 +02:00
# pragma pack(??? -> What's that?
print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n";
print FILEO "$pack_indent$pack_header$_";
2000-11-05 06:23:39 +01:00
}
2001-04-18 19:39:42 +02:00
$modified=1;
2000-11-05 06:23:39 +01:00
} elsif ($is_rc) {
2001-04-20 20:26:35 +02:00
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]+)([\">]?)/) {
2000-11-05 06:23:39 +01:00
my $from_file=($5 eq "<"?"":$dirname);
my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target);
print FILEO "$1$5$real_include_name$7$'";
$modified|=($real_include_name ne $6);
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) {
my $from_file=($2 eq "<"?"":$dirname);
my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target);
print FILEO "$1$2$real_include_name$4$'";
$modified|=($real_include_name ne $3);
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) {
$rc_textinclude_state=1;
print FILEO;
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) {
2009-04-02 18:53:12 +02:00
print FILEO "$1winresrc.h$2$'";
2000-11-05 06:23:39 +01:00
$modified=1;
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} elsif (/^\s*BEGIN(\W.*)?$/) {
$rc_textinclude_state|=2;
$rc_block_depth++;
print FILEO;
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} elsif (/^\s*END(\W.*)?$/) {
$rc_textinclude_state=0;
if ($rc_block_depth>0) {
$rc_block_depth--;
}
print FILEO;
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} else {
print FILEO;
}
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
} else {
print FILEO;
}
}
2001-04-18 19:39:42 +02:00
2000-11-05 06:23:39 +01:00
close(FILEI);
close(FILEO);
if ($opt_backup == 0 or $modified == 0) {
if (!unlink("$filename.bak")) {
print STDERR "error: unable to delete $filename.bak:\n";
print STDERR " $!\n";
}
}
}
##
2002-06-01 04:55:48 +02:00
# Analyzes each source file in turn to find and correct issues
2000-11-05 06:23:39 +01:00
# that would cause it not to compile.
2002-09-06 20:36:19 +02:00
sub fix_source()
2000-11-05 06:23:39 +01:00
{
print "Fixing the source files...\n";
2002-09-06 20:36:19 +02:00
foreach my $project (@projects) {
foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) {
foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) {
2000-11-05 06:23:39 +01:00
fix_file($source,$project,$target);
}
}
}
}
#####
#
# File generation
#
#####
##
2002-06-01 04:55:48 +02:00
# A convenience function to generate all the lists (defines,
2000-11-05 06:23:39 +01:00
# C sources, C++ source, etc.) in the Makefile
2002-09-06 20:36:19 +02:00
sub generate_list($$$;$)
2000-11-05 06:23:39 +01:00
{
my $name=$_[0];
my $last=$_[1];
my $list=$_[2];
my $data=$_[3];
2000-11-25 02:38:39 +01:00
my $first=$name;
2000-11-05 06:23:39 +01:00
if ($name) {
2000-11-30 21:34:39 +01:00
printf FILEO "%-22s=",$name;
2000-11-05 06:23:39 +01:00
}
2000-11-25 02:38:39 +01:00
if (defined $list) {
2002-09-06 20:36:19 +02:00
foreach my $item (@$list) {
2000-11-05 06:23:39 +01:00
my $value;
if (defined $data) {
2010-06-17 21:10:01 +02:00
$value=&$data($item);
2000-11-05 06:23:39 +01:00
} else {
2010-06-17 21:10:01 +02:00
if (defined $item) {
$value=$item;
} else {
$value="";
}
2000-11-05 06:23:39 +01:00
}
if ($value ne "") {
2000-11-25 02:38:39 +01:00
if ($first) {
print FILEO " $value";
$first=0;
} else {
print FILEO " \\\n\t\t\t$value";
}
2000-11-05 06:23:39 +01:00
}
}
}
if ($last) {
2000-11-25 02:38:39 +01:00
print FILEO "\n";
2000-11-05 06:23:39 +01:00
}
}
##
2005-01-11 11:39:10 +01:00
# Generates a project's Makefile and all the target files
2002-09-06 20:36:19 +02:00
sub generate_project_files($)
2000-11-05 06:23:39 +01:00
{
my $project=$_[0];
my $project_settings=@$project[$P_SETTINGS];
2000-11-15 23:12:20 +01:00
my @dll_list=();
2011-11-19 19:42:56 +01:00
my @lib_list=();
2000-11-15 23:12:20 +01:00
my @exe_list=();
2000-11-05 06:23:39 +01:00
# Then sort the targets and separate the libraries from the programs
2002-09-06 20:36:19 +02:00
foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) {
2000-11-05 06:23:39 +01:00
if (@$target[$T_TYPE] == $TT_DLL) {
2000-11-15 23:12:20 +01:00
push @dll_list,$target;
2011-11-19 19:42:56 +01:00
} elsif (@$target[$T_TYPE] == $TT_LIB) {
push @lib_list,$target;
2000-11-05 06:23:39 +01:00
} else {
2000-11-15 23:12:20 +01:00
push @exe_list,$target;
2000-11-05 06:23:39 +01:00
}
}
@$project[$P_TARGETS]=[];
2000-11-15 23:12:20 +01:00
push @{@$project[$P_TARGETS]}, @dll_list;
2011-11-19 19:42:56 +01:00
push @{@$project[$P_TARGETS]}, @lib_list;
2000-11-15 23:12:20 +01:00
push @{@$project[$P_TARGETS]}, @exe_list;
2000-11-05 06:23:39 +01:00
2004-02-27 22:24:20 +01:00
if (!open(FILEO,">@$project[$P_PATH]Makefile")) {
print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n";
2000-11-05 06:23:39 +01:00
print STDERR " $!\n";
return;
}
2009-04-23 19:07:42 +02:00
print FILEO "### Generated by Winemaker $version\n";
2012-02-05 14:03:32 +01:00
print FILEO "###\n";
print FILEO "### Invocation command line was\n";
print FILEO "### $0";
foreach(@ARGV) {
print FILEO " $_";
}
print FILEO "\n\n\n";
2000-11-15 23:12:20 +01:00
2004-02-27 22:24:20 +01:00
generate_list("SRCDIR",1,[ "." ]);
2000-11-05 06:23:39 +01:00
if (@$project[$P_PATH] eq "") {
2002-06-01 04:55:48 +02:00
# This is the main project. It is also responsible for recursively
2000-11-05 06:23:39 +01:00
# calling the other projects
2002-06-01 04:55:48 +02:00
generate_list("SUBDIRS",1,\@projects,sub
2000-11-05 06:23:39 +01:00
{
if ($_[0] != \@main_project) {
my $subdir=@{$_[0]}[$P_PATH];
$subdir =~ s+/$++;
return $subdir;
}
# Eliminating the main project by returning undefined!
});
}
if (@{@$project[$P_TARGETS]} > 0) {
2001-05-07 20:19:57 +02:00
generate_list("DLLS",1,\@dll_list,sub
2000-11-05 06:23:39 +01:00
{
return @{$_[0]}[$T_NAME];
});
2011-11-19 19:42:56 +01:00
generate_list("LIBS",1,\@lib_list,sub
{
return @{$_[0]}[$T_NAME];
});
2001-05-07 20:19:57 +02:00
generate_list("EXES",1,\@exe_list,sub
2000-11-05 06:23:39 +01:00
{
2002-09-26 05:20:59 +02:00
return "@{$_[0]}[$T_NAME]";
2000-11-05 06:23:39 +01:00
});
2000-11-25 02:38:39 +01:00
print FILEO "\n\n\n";
2000-11-05 06:23:39 +01:00
2002-09-11 03:09:58 +02:00
print FILEO "### Common settings\n\n";
2000-11-05 06:23:39 +01:00
# Make it so that the project-wide settings override the global settings
2004-03-03 03:19:20 +01:00
generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]);
generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]);
generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]);
2009-02-25 10:33:48 +01:00
generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
2002-09-11 03:09:58 +02:00
generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
2009-02-25 10:33:48 +01:00
generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]);
2002-09-11 03:09:58 +02:00
generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]);
generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]);
2000-11-05 06:23:39 +01:00
print FILEO "\n\n";
my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+
@{@$project_settings[$T_SOURCES_CXX]}+
@{@$project_settings[$T_SOURCES_RC]};
2002-09-11 03:09:58 +02:00
my $no_extra=($extra_source_count == 0);
2000-11-05 06:23:39 +01:00
if (!$no_extra) {
print FILEO "### Extra source lists\n\n";
generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]);
generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]);
generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]);
2000-11-25 02:38:39 +01:00
print FILEO "\n";
generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]);
print FILEO "\n\n\n";
2000-11-05 06:23:39 +01:00
}
2001-05-07 20:19:57 +02:00
2000-11-05 06:23:39 +01:00
# Iterate over all the targets...
2002-09-06 20:36:19 +02:00
foreach my $target (@{@$project[$P_TARGETS]}) {
2000-11-25 02:38:39 +01:00
print FILEO "### @$target[$T_NAME] sources and settings\n\n";
2000-11-05 06:23:39 +01:00
my $canon=canonize("@$target[$T_NAME]");
$canon =~ s+_so$++;
2003-01-02 20:27:23 +01:00
generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
2000-11-05 06:23:39 +01:00
generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]);
generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]);
generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]);
2004-03-03 03:19:20 +01:00
generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]);
2011-11-19 19:42:56 +01:00
generate_list("${canon}_ARFLAGS",1,@$target[$T_ARFLAGS]);
2001-07-30 20:44:48 +02:00
generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]);
2002-07-19 05:15:20 +02:00
generate_list("${canon}_DLLS",1,@$target[$T_DLLS]);
2001-05-07 20:19:57 +02:00
generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]);
generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]);
2000-11-25 02:38:39 +01:00
print FILEO "\n";
2004-02-27 22:24:20 +01:00
generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]);
2000-11-25 02:38:39 +01:00
print FILEO "\n\n\n";
2000-11-05 06:23:39 +01:00
}
print FILEO "### Global source lists\n\n";
2001-05-07 20:19:57 +02:00
generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub
2000-11-05 06:23:39 +01:00
{
my $canon=canonize(@{$_[0]}[$T_NAME]);
$canon =~ s+_so$++;
return "\$(${canon}_C_SRCS)";
});
if (!$no_extra) {
generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]);
}
2001-05-07 20:19:57 +02:00
generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub
2000-11-05 06:23:39 +01:00
{
my $canon=canonize(@{$_[0]}[$T_NAME]);
$canon =~ s+_so$++;
return "\$(${canon}_CXX_SRCS)";
});
if (!$no_extra) {
generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]);
}
2001-05-07 20:19:57 +02:00
generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub
2000-11-05 06:23:39 +01:00
{
my $canon=canonize(@{$_[0]}[$T_NAME]);
$canon =~ s+_so$++;
return "\$(${canon}_RC_SRCS)";
});
if (!$no_extra) {
2000-11-25 02:38:39 +01:00
generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]);
2000-11-05 06:23:39 +01:00
}
}
2004-02-27 22:24:20 +01:00
print FILEO "\n\n";
print FILEO "### Tools\n\n";
print FILEO "CC = winegcc\n";
print FILEO "CXX = wineg++\n";
print FILEO "RC = wrc\n";
2011-11-19 19:42:56 +01:00
print FILEO "AR = ar\n";
2004-02-27 22:24:20 +01:00
print FILEO "\n\n";
2000-11-05 06:23:39 +01:00
2004-03-03 03:19:20 +01:00
print FILEO "### Generic targets\n\n";
2001-05-29 22:50:58 +02:00
print FILEO "all:";
2000-11-05 06:23:39 +01:00
if (@$project[$P_PATH] eq "") {
2001-05-29 22:50:58 +02:00
print FILEO " \$(SUBDIRS)";
2000-11-05 06:23:39 +01:00
}
2000-11-25 02:38:39 +01:00
if (@{@$project[$P_TARGETS]} > 0) {
2011-11-19 19:42:56 +01:00
print FILEO " \$(DLLS:%=%.so) \$(LIBS) \$(EXES)";
2000-11-25 02:38:39 +01:00
}
print FILEO "\n\n";
2004-03-03 03:19:20 +01:00
print FILEO "### Build rules\n";
print FILEO "\n";
print FILEO ".PHONY: all clean dummy\n";
print FILEO "\n";
print FILEO "\$(SUBDIRS): dummy\n";
print FILEO "\t\@cd \$\@ && \$(MAKE)\n";
print FILEO "\n";
print FILEO "# Implicit rules\n";
print FILEO "\n";
print FILEO ".SUFFIXES: .cpp .rc .res\n";
print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n";
print FILEO "\n";
print FILEO ".c.o:\n";
print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
print FILEO "\n";
print FILEO ".cpp.o:\n";
print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
print FILEO "\n";
print FILEO ".cxx.o:\n";
print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n";
print FILEO "\n";
print FILEO ".rc.res:\n";
print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n";
print FILEO "\n";
print FILEO "# Rules for cleaning\n";
print FILEO "\n";
2005-09-29 12:42:43 +02:00
print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n";
2004-03-03 03:19:20 +01:00
print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n";
print FILEO "\n";
print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n";
print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n";
2011-11-19 19:42:56 +01:00
print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(LIBS) \$(EXES) \$(EXES:%=%.so)\n";
2004-03-03 03:19:20 +01:00
print FILEO "\n";
print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n";
print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n";
print FILEO "\n";
print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n";
print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n";
print FILEO "\n";
2001-05-07 20:19:57 +02:00
2000-11-05 06:23:39 +01:00
if (@{@$project[$P_TARGETS]} > 0) {
2005-01-11 11:39:10 +01:00
print FILEO "### Target specific build rules\n";
2009-02-25 10:33:48 +01:00
print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n";
2002-09-06 20:36:19 +02:00
foreach my $target (@{@$project[$P_TARGETS]}) {
2000-11-05 06:23:39 +01:00
my $canon=canonize("@$target[$T_NAME]");
$canon =~ s/_so$//;
2004-02-27 22:24:20 +01:00
2011-01-04 22:43:01 +01:00
if (@$target[$T_TYPE] == $TT_DLL && (@$project_settings[$T_FLAGS] & $TF_HASDEF)) {
print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.def)\n";
} elsif (@$target[$T_TYPE] == $TT_DLL) {
2010-11-16 22:43:55 +01:00
print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS) \$(${canon}_MODULE:.dll=.spec)\n";
} else {
2011-05-11 19:00:31 +02:00
print FILEO "\$(${canon}_MODULE): \$(${canon}_OBJS)\n";
2010-11-16 22:43:55 +01:00
}
2011-11-19 19:42:56 +01:00
if (@$target[$T_TYPE] == $TT_LIB) {
print FILEO "\t\$(AR) \$(${canon}_ARFLAGS) \$\@ \$(${canon}_OBJS)\n";
2001-03-04 02:03:55 +01:00
} else {
2011-11-19 19:42:56 +01:00
if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
print FILEO "\t\$(CXX)";
} else {
print FILEO "\t\$(CC)";
}
print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n";
2001-03-04 02:03:55 +01:00
}
2000-11-25 02:38:39 +01:00
print FILEO "\n\n";
2000-11-05 06:23:39 +01:00
}
}
close(FILEO);
2001-05-07 20:19:57 +02:00
2000-11-05 06:23:39 +01:00
}
##
2002-06-01 04:55:48 +02:00
# This is where we finally generate files. In fact this method does not
2000-11-05 06:23:39 +01:00
# do anything itself but calls the methods that do the actual work.
2002-09-06 20:36:19 +02:00
sub generate()
2000-11-05 06:23:39 +01:00
{
print "Generating project files...\n";
2002-09-06 20:36:19 +02:00
foreach my $project (@projects) {
2000-11-05 06:23:39 +01:00
my $path=@$project[$P_PATH];
if ($path eq "") {
$path=".";
} else {
$path =~ s+/$++;
}
print " $path\n";
generate_project_files($project);
}
}
#####
#
# Option defaults
#
#####
$opt_backup=1;
$opt_lower=$OPT_LOWER_UPPERCASE;
2000-11-10 23:29:11 +01:00
$opt_lower_include=1;
2000-11-05 06:23:39 +01:00
2004-03-03 03:19:20 +01:00
$opt_work_dir=undef;
$opt_single_target=undef;
2000-11-05 06:23:39 +01:00
$opt_target_type=$TT_GUIEXE;
$opt_flags=0;
2010-04-21 20:22:13 +02:00
$opt_arch=$OPT_ARCH_DEFAULT;
2000-11-05 06:23:39 +01:00
$opt_is_interactive=$OPT_ASK_NO;
$opt_ask_project_options=$OPT_ASK_NO;
$opt_ask_target_options=$OPT_ASK_NO;
2000-11-10 23:29:11 +01:00
$opt_no_generated_files=0;
2001-09-24 03:11:50 +02:00
$opt_no_source_fix=0;
2000-11-05 06:23:39 +01:00
$opt_no_banner=0;
#####
#
# Main
#
#####
2002-09-06 20:36:19 +02:00
sub print_banner()
2001-01-11 21:17:42 +01:00
{
print "Winemaker $version\n";
2011-01-04 22:43:01 +01:00
print "Copyright 2000-2004 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
2009-04-23 19:07:54 +02:00
print "Copyright 2004 Dimitrie O. Paun\n";
2011-01-04 22:43:01 +01:00
print "Copyright 2009-2011 André Hentschel\n";
2001-01-11 21:17:42 +01:00
}
2002-09-06 20:36:19 +02:00
sub usage()
2001-01-11 21:17:42 +01:00
{
print_banner();
2001-09-24 03:11:50 +02:00
print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n";
2001-01-11 21:17:42 +01:00
print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n";
2004-02-27 22:24:20 +01:00
print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n";
2012-01-15 18:02:57 +01:00
print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll|--lib]\n";
2001-07-30 20:44:48 +02:00
print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2004-02-03 00:02:32 +01:00
print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n";
2004-02-27 22:24:20 +01:00
print STDERR " [--generated-files|--nogenerated-files]\n";
2010-04-21 20:22:13 +02:00
print STDERR " [--wine32]\n";
2009-04-02 18:53:24 +02:00
print STDERR " work_directory|project_file|workspace_file\n";
2001-01-11 21:17:42 +01:00
print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
2009-08-29 13:11:12 +02:00
print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n";
print STDERR "During this process it will modify and rename some of the corresponding files.\n";
2001-01-11 21:17:42 +01:00
print STDERR "\tPlease read the manual page before use.\n";
exit (2);
}
2002-09-13 19:43:25 +02:00
target_init(\@global_settings);
2012-02-05 14:03:32 +01:00
foreach(@ARGV) {
my $arg=$_;
2000-11-05 06:23:39 +01:00
# General options
if ($arg eq "--nobanner") {
$opt_no_banner=1;
} elsif ($arg eq "--backup") {
$opt_backup=1;
} elsif ($arg eq "--nobackup") {
$opt_backup=0;
} elsif ($arg eq "--single-target") {
$opt_single_target=shift @ARGV;
} elsif ($arg eq "--lower-none") {
$opt_lower=$OPT_LOWER_NONE;
} elsif ($arg eq "--lower-all") {
$opt_lower=$OPT_LOWER_ALL;
} elsif ($arg eq "--lower-uppercase") {
$opt_lower=$OPT_LOWER_UPPERCASE;
2000-11-10 23:29:11 +01:00
} elsif ($arg eq "--lower-include") {
$opt_lower_include=1;
2000-11-25 02:38:39 +01:00
} elsif ($arg eq "--nolower-include") {
2000-11-10 23:29:11 +01:00
$opt_lower_include=0;
2001-09-24 03:11:50 +02:00
} elsif ($arg eq "--nosource-fix") {
$opt_no_source_fix=1;
2000-11-10 23:29:11 +01:00
} elsif ($arg eq "--generated-files") {
$opt_no_generated_files=0;
2000-11-25 02:38:39 +01:00
} elsif ($arg eq "--nogenerated-files") {
2000-11-10 23:29:11 +01:00
$opt_no_generated_files=1;
2010-04-21 20:22:13 +02:00
} elsif ($arg eq "--wine32") {
$opt_arch=$OPT_ARCH_32;
2000-11-05 06:23:39 +01:00
} elsif ($arg =~ /^-D/) {
push @{$global_settings[$T_DEFINES]},$arg;
} elsif ($arg =~ /^-I/) {
push @{$global_settings[$T_INCLUDE_PATH]},$arg;
2001-07-30 20:44:48 +02:00
} elsif ($arg =~ /^-P/) {
push @{$global_settings[$T_DLL_PATH]},"-L$'";
} elsif ($arg =~ /^-i/) {
2004-02-27 22:24:20 +01:00
push @{$global_settings[$T_DLLS]},$';
2000-11-05 06:23:39 +01:00
} elsif ($arg =~ /^-L/) {
push @{$global_settings[$T_LIBRARY_PATH]},$arg;
2000-11-15 23:12:20 +01:00
} elsif ($arg =~ /^-l/) {
2011-03-25 21:16:55 +01:00
push @{$global_settings[$T_LIBRARIES]},$arg;
2000-11-05 06:23:39 +01:00
# 'Source'-based method options
} elsif ($arg eq "--dll") {
$opt_target_type=$TT_DLL;
2012-01-15 18:02:57 +01:00
} elsif ($arg eq "--lib") {
$opt_target_type=$TT_LIB;
2000-11-05 06:23:39 +01:00
} elsif ($arg eq "--guiexe" or $arg eq "--windows") {
$opt_target_type=$TT_GUIEXE;
} elsif ($arg eq "--cuiexe" or $arg eq "--console") {
$opt_target_type=$TT_CUIEXE;
} elsif ($arg eq "--interactive") {
$opt_is_interactive=$OPT_ASK_YES;
$opt_ask_project_options=$OPT_ASK_YES;
$opt_ask_target_options=$OPT_ASK_YES;
} elsif ($arg eq "--mfc") {
2000-11-15 23:12:20 +01:00
$opt_flags|=$TF_MFC;
2000-11-05 06:23:39 +01:00
} elsif ($arg eq "--nomfc") {
2002-09-10 02:20:27 +02:00
$opt_flags&=~$TF_MFC;
$opt_flags|=$TF_NOMFC;
} elsif ($arg eq "--nodlls") {
$opt_flags|=$TF_NODLLS;
2004-02-03 00:02:32 +01:00
} elsif ($arg eq "--nomsvcrt") {
$opt_flags|=$TF_NOMSVCRT;
2000-11-05 06:23:39 +01:00
# Catch errors
} else {
if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2009-04-02 18:53:14 +02:00
if (!defined $opt_work_dir and !defined $opt_work_file) {
if (-f $arg) {
$opt_work_file=$arg;
}
else {
$opt_work_dir=$arg;
}
} else {
print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
usage();
}
2001-01-10 23:43:21 +01:00
} else {
2009-04-02 18:53:14 +02:00
usage();
2000-11-05 06:23:39 +01:00
}
}
}
2009-04-02 18:53:14 +02:00
if (!defined $opt_work_dir and !defined $opt_work_file) {
print STDERR "error: you must specify the directory or project file containing the sources to be converted\n";
2001-01-11 21:17:42 +01:00
usage();
2009-04-02 18:53:14 +02:00
} elsif (defined $opt_work_dir and !chdir $opt_work_dir) {
2001-01-10 23:43:21 +01:00
print STDERR "error: could not chdir to the work directory\n";
print STDERR " $!\n";
2001-01-11 21:17:42 +01:00
usage();
2001-01-10 23:43:21 +01:00
}
2001-01-11 21:17:42 +01:00
if ($opt_no_banner == 0) {
print_banner();
2000-11-05 06:23:39 +01:00
}
2009-02-25 10:33:48 +01:00
project_init(\@main_project, "", \@global_settings);
2002-09-10 02:20:27 +02:00
2000-11-05 06:23:39 +01:00
# Fix the file and directory names
fix_file_and_directory_names(".");
# Scan the sources to identify the projects and targets
source_scan();
# Fix the source files
2001-09-24 03:11:50 +02:00
if (! $opt_no_source_fix) {
fix_source();
}
2000-11-05 06:23:39 +01:00
# Generate the Makefile and the spec file
2000-11-10 23:29:11 +01:00
if (! $opt_no_generated_files) {
2000-11-05 06:23:39 +01:00
generate();
}