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
2002-09-06 20:36:19 +02:00
# Copyright 2000-2002 Francois Gouget for CodeWeavers
2000-11-05 06:23:39 +01:00
# fgouget@codeweavers.com
#
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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2002-08-09 02:57:57 +02:00
my $version="0.5.9";
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;
# General options
2001-01-10 23:43:21 +01:00
##
# This is the directory in which winemaker will operate.
my $opt_work_dir;
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;
##
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;
##
2002-06-01 04:55:48 +02:00
# If false then winemaker should not generate any file, i.e.
2000-11-10 23:29:11 +01:00
# no makefiles, but also no .spec files, no configure.in, etc.
my $opt_no_generated_files;
2000-11-05 06:23:39 +01:00
2001-09-24 03:11:50 +02:00
##
# If true then winemaker should not generate the spec files.
# This is useful if winemaker is being used to create a build environment
my $opt_no_generated_specs;
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;
##
# Defines the target's enty point, i.e. the function that is called
# on startup.
my $T_INIT=2;
##
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
2000-11-15 23:12:20 +01:00
my $T_FLAGS=3;
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.
2000-11-15 23:12:20 +01:00
my $T_SOURCES_C=4;
my $T_SOURCES_CXX=5;
my $T_SOURCES_RC=6;
my $T_SOURCES_MISC=7;
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
2000-11-15 23:12:20 +01:00
my $T_DEFINES=8;
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
2000-11-15 23:12:20 +01:00
my $T_INCLUDE_PATH=9;
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
my $T_DLL_PATH=10;
##
# The list of Windows dlls to import
my $T_DLLS=11;
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
my $T_LIBRARY_PATH=12;
2000-11-15 23:12:20 +01:00
##
# The list of Unix libraries to link with
2001-07-30 20:44:48 +02:00
my $T_LIBRARIES=13;
2000-11-05 06:23:39 +01:00
##
# The list of dependencies between targets
2001-07-30 20:44:48 +02:00
my $T_DEPENDS=14;
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;
# The following constants further refine how the target should be handled
##
# This target needs a wrapper
my $TF_WRAP=1;
##
# This target is a wrapper
my $TF_WRAPPER=2;
##
# 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;
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;
# leaving $T_INIT undefined
@$target[$T_FLAGS]=$opt_flags;
@$target[$T_SOURCES_C]=[];
@$target[$T_SOURCES_CXX]=[];
@$target[$T_SOURCES_RC]=[];
@$target[$T_SOURCES_MISC]=[];
@$target[$T_DEFINES]=[];
@$target[$T_INCLUDE_PATH]=[];
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
@$target[$T_DEPENDS]=[];
}
2002-09-06 20:36:19 +02:00
sub get_default_init($)
2000-11-05 06:23:39 +01:00
{
my $type=$_[0];
if ($type == $TT_GUIEXE) {
return "WinMain";
} elsif ($type == $TT_CUIEXE) {
return "main";
} elsif ($type == $TT_DLL) {
return "DllMain";
}
}
#####
#
# 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
2000-11-05 06:23:39 +01:00
# words, this is the path to the Makefile.
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)
2002-09-06 20:36:19 +02:00
sub project_init($$)
2000-11-05 06:23:39 +01:00
{
my $project=$_[0];
my $path=$_[1];
my $project_settings=[];
target_init($project_settings);
@$project[$P_PATH]=$path;
@$project[$P_SETTINGS]=$project_settings;
@$project[$P_TARGETS]=[];
}
#####
#
# Global variables
#
#####
my %warnings;
my %templates;
##
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;
##
2002-06-01 04:55:48 +02:00
# If one of the projects requires the MFc then we set this global variable
2000-11-05 06:23:39 +01:00
# to true so that configure asks the user to provide a path tothe MFC
my $needs_mfc=0;
#####
#
# 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 =~ /^[\/~\$]/);
}
##
# Performs a binary search looking for the specified item
2002-09-06 20:36:19 +02:00
sub bsearch($$)
2000-11-05 06:23:39 +01:00
{
my $array=$_[0];
my $item=$_[1];
my $last=@{$array}-1;
my $first=0;
while ($first<=$last) {
my $index=int(($first+$last)/2);
my $cmp=@$array[$index] cmp $item;
if ($cmp<0) {
$first=$index+1;
} elsif ($cmp>0) {
$last=$index-1;
} else {
return $index;
}
}
}
#####
#
# '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/) {
2002-09-13 19:55:54 +02:00
my $dllname = $';
2003-08-05 20:31:32 +02:00
if ($dllname =~ /^msvcrt$/) {
2002-09-13 19:55:54 +02:00
push @{@$target[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
}
push @{@$target[$T_DLLS]},$dllname;
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 =~ /^--wrap/) {
2001-03-01 23:11:10 +01:00
if (@$target[$T_TYPE] != $TT_DLL) {
@$target[$T_FLAGS]|=$TF_WRAP;
2002-09-10 02:20:27 +02:00
} else {
print STDERR "warning: option --wrap is illegal for DLLs - ignoring";
};
} elsif ($option =~ /^--nowrap/) {
if (@$target[$T_TYPE] != $TT_DLL) {
@$target[$T_FLAGS]&=~$TF_WRAP;
} else {
print STDERR "warning: option --nowrap is illegal for DLLs - ignoring";
2001-03-01 23:11:10 +01:00
}
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;
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
}
}
2002-09-10 02:20:27 +02:00
if (@$target[$T_TYPE] != $TT_DLL &&
@$target[$T_FLAGS] & $TF_MFC &&
!(@$target[$T_FLAGS] & $TF_WRAP)) {
print STDERR "info: option --mfc requires --wrap";
@$target[$T_FLAGS]|=$TF_WRAP;
}
2000-11-30 21:36:04 +01:00
return 1;
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;
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.
my @dsp_files=();
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=[];
project_init($project,$path);
}
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.
my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")};
2002-09-06 20:36:19 +02:00
foreach my $candidate (@candidates) {
2002-09-26 05:20:59 +02:00
$targets{$candidate}=1;
2000-11-05 06:23:39 +01:00
}
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") {
2002-09-26 05:20:59 +02:00
if ($dentry =~ /\.(exe|dll)$/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";
2001-03-23 20:07:59 +01:00
} elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) {
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
}
2000-11-05 06:23:39 +01:00
} elsif ($dentry =~ /\.dsp$/i) {
push @dsp_files,"$dentry";
$has_win_project=1;
} elsif ($dentry =~ /\.mak$/i) {
push @mak_files,"$dentry";
$has_win_project=1;
} elsif ($dentry =~ /^makefile/i) {
$has_win_project=1;
}
}
}
closedir(DIRECTORY);
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;
if (@dsp_files > 0) {
$prj_list=\@dsp_files;
} else {
$prj_list=\@mak_files;
}
2002-09-06 20:36:19 +02:00
foreach my $filename (@$prj_list) {
2000-11-05 06:23:39 +01:00
$filename =~ s/\.(dsp|mak)$//i;
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) {
2002-09-26 05:20:59 +02:00
$name = "$name.dll";
2003-01-02 20:27:23 +01:00
} else {
$name = "$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";
}
if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) {
if ($flag_desc ne "") {
$flag_desc.=", ";
}
$flag_desc.="wrapped";
}
2001-07-30 20:44:48 +02:00
print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc/--wrap),\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=();
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;
@$target[$T_INIT]=get_default_init($TT_DLL);
@$target[$T_FLAGS]&=~$TF_WRAP;
2002-09-26 05:20:59 +02:00
push @local_depends,"$target_name.so";
push @local_dlls,$target_name;
2000-11-05 06:23:39 +01:00
} else {
@$target[$T_TYPE]=$opt_target_type;
@$target[$T_INIT]=get_default_init($opt_target_type);
2000-11-15 23:12:20 +01:00
push @exe_list,$target;
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;
2002-06-01 04:55:48 +02:00
# This is the default link list of Visual Studio, except odbccp32
2002-12-15 04:00:40 +01:00
# and uuid which we don't have in Wine.
my @std_imports=qw(advapi32 comdlg32 gdi32 kernel32 odbc32 ole32 oleaut32 shell32 user32 winspool);
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;
2002-09-10 02:20:27 +02:00
} else {
@$target[$T_DLLS]=[];
}
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 ((@$target[$T_FLAGS] & $TF_WRAP)!=0) {
if ($flag_desc ne "") {
$flag_desc.=", ";
} else {
$flag_desc=" (";
}
$flag_desc.="wrapped";
}
if ($flag_desc ne "") {
$flag_desc.=")";
}
2001-07-30 20:44:48 +02:00
print "* Specify any link option (-P/-i/-L/-l/--mfc/--wrap) 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
}
}
2002-07-19 05:15:20 +02:00
push @{@$target[$T_DLL_PATH]},"-L\$(WINE_DLL_ROOT)";
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;
}
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
push @{@$target[$T_DEPENDS]},@local_depends;
}
}
}
##
# 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;
# Now scan the directory tree looking for source files and, maybe, targets
print "Scanning the source directories...\n";
2001-03-03 01:17:11 +01:00
source_scan_directory(\@main_project,"","",0);
2000-11-05 06:23:39 +01:00
@projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects;
}
#####
#
# 'vc.dsp'-based Project analysis
#
#####
#sub analyze_vc_dsp
#{
2002-06-01 04:55:48 +02:00
#
2000-11-05 06:23:39 +01:00
#}
#####
#
# Creating the wrapper targets
#
#####
2002-09-06 20:36:19 +02:00
sub postprocess_targets()
2000-11-05 06:23:39 +01:00
{
2002-09-06 20:36:19 +02:00
foreach my $project (@projects) {
foreach my $target (@{@$project[$P_TARGETS]}) {
2000-11-05 06:23:39 +01:00
if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) {
my $wrapper=[];
target_init($wrapper);
@$wrapper[$T_NAME]=@$target[$T_NAME];
@$wrapper[$T_TYPE]=@$target[$T_TYPE];
@$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]);
@$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC);
2003-04-08 21:42:30 +02:00
@$wrapper[$T_DLLS]=[ "kernel32", "user32" ];
2002-09-09 21:17:52 +02:00
push @{@$wrapper[$T_LIBRARIES]}, "dl";
2000-11-05 06:23:39 +01:00
push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c";
my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c");
if (defined $index) {
splice(@{@$target[$T_SOURCES_C]},$index,1);
}
2002-09-26 05:20:59 +02:00
@$target[$T_NAME]=@$target[$T_NAME];
@$target[$T_NAME]=~ s/.exe$/.dll/;
2000-11-05 06:23:39 +01:00
@$target[$T_TYPE]=$TT_DLL;
push @{@$project[$P_TARGETS]},$wrapper;
}
2000-11-10 23:29:11 +01:00
if ((@$target[$T_FLAGS] & $TF_MFC) != 0) {
@{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC;
$needs_mfc=1;
}
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 ' ', '$', '#', ...
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];
if (opendir(DIRECTORY, "$dirname")) {
2002-09-06 20:36:19 +02:00
foreach my $dentry (readdir DIRECTORY) {
2000-11-05 06:23:39 +01:00
if ($dentry =~ /^\./ or $dentry eq "CVS") {
next;
}
# Set $warn to 1 if the user should be warned of the renaming
my $warn=0;
# autoconf and make don't support these characters well
my $new_name=$dentry;
$new_name =~ s/[ \$]/_/g;
2002-06-01 04:55:48 +02:00
# Only all lowercase extensions are supported (because of the
2000-11-30 21:36:04 +01:00
# transformations ':.c=.o') .
2000-11-05 06:23:39 +01:00
if (-f "$dirname/$new_name") {
2000-11-30 21:36:04 +01:00
if ($new_name =~ /\.C$/) {
$new_name =~ s/\.C$/.c/;
}
if ($new_name =~ /\.cpp$/i) {
2000-11-05 06:23:39 +01:00
$new_name =~ s/\.cpp$/.cpp/i;
}
if ($new_name =~ s/\.cxx$/.cpp/i) {
$warn=1;
}
2000-11-30 21:36:04 +01:00
if ($new_name =~ /\.rc$/i) {
2000-11-05 06:23:39 +01:00
$new_name =~ s/\.rc$/.rc/i;
}
# And this last one is to avoid confusion then running make
if ($new_name =~ s/^makefile$/makefile.win/) {
$warn=1;
}
}
# 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]/)
) {
$new_name=lc $new_name;
}
# And finally, perform the renaming
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;
}
}
if (-d "$dirname/$new_name") {
fix_file_and_directory_names("$dirname/$new_name");
}
}
closedir(DIRECTORY);
}
}
#####
#
# Source fixup
#
#####
##
2002-06-01 04:55:48 +02:00
# This maps a directory name to a reference to an array listing
2000-11-05 06:23:39 +01:00
# its contents (files and directories)
my %directories;
##
# Retrieves the contents of the specified directory.
2002-06-01 04:55:48 +02:00
# We either get it from the directories hashtable which acts as a
# cache, or use opendir, readdir, closedir and store the result
2000-11-05 06:23:39 +01:00
# in the hashtable.
2002-09-06 20:36:19 +02:00
sub get_directory_contents($)
2000-11-05 06:23:39 +01:00
{
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;
}
2002-06-01 04:55:48 +02:00
2000-11-05 06:23:39 +01:00
# 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;
}
##
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="";
if ($dirname eq "" or $dirname eq ".") {
$dirname=cwd;
} elsif ($dirname =~ m+^[^/]+) {
$dirname=cwd . "/" . $dirname;
}
if ($dirname !~ m+/$+) {
$dirname.="/";
}
2002-09-06 20:36:19 +02:00
foreach my $component (@$path) {
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
$dirname=dirname($dirname) . "/";
$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) {
2001-04-23 20:16:13 +02:00
if ($dentry =~ /^$component$/i or
(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];
if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) {
# 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++;
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";
2002-06-01 04:55:48 +02:00
#FIXME:assuming that because there is a .bak file, this is what we want is
2000-11-05 06:23:39 +01:00
#probably flawed. Or is it???
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
# it with 'winres.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";
print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n";
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";
print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winres.h' */\n";
print FILEO "$1$2\"winres.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
# - the directive's alignement value at index 2
#
# 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\")/) {
print FILEO "$1winres.h$2$'";
$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]}) {
2000-11-05 06:23:39 +01:00
if (@$target[$T_FLAGS] & $TF_WRAPPER) {
next;
}
2002-09-06 20:36:19 +02:00
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
#
#####
##
# Generates a target's .spec file
2002-09-06 20:36:19 +02:00
sub generate_spec_file($$$)
2000-11-05 06:23:39 +01:00
{
2002-09-26 05:20:59 +02:00
return if ($opt_no_generated_specs);
2000-11-05 06:23:39 +01:00
my $path=$_[0];
my $target=$_[1];
my $project_settings=$_[2];
my $basename=@$target[$T_NAME];
2002-09-26 05:20:59 +02:00
if (@$target[$T_FLAGS] & $TF_WRAPPER) {
2000-11-05 06:23:39 +01:00
$basename.="_wrapper";
}
if (!open(FILEO,">$path$basename.spec")) {
print STDERR "error: could not open \"$path$basename.spec\" for writing\n";
print STDERR " $!\n";
return;
}
2002-06-01 04:55:48 +02:00
# Don't forget to export the 'Main' function for wrapped executables,
2000-11-05 06:23:39 +01:00
# except for MFC ones!
2002-09-09 21:17:52 +02:00
if ((@$target[$T_FLAGS]&($TF_WRAP|$TF_WRAPPER|$TF_MFC)) == $TF_WRAP) {
2000-11-05 06:23:39 +01:00
if (@$target[$T_TYPE] == $TT_GUIEXE) {
print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n";
} elsif (@$target[$T_TYPE] == $TT_CUIEXE) {
print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n";
} else {
print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n";
}
}
close(FILEO);
}
##
# Generates a target's wrapper file
2002-09-06 20:36:19 +02:00
sub generate_wrapper_file($$)
2000-11-05 06:23:39 +01:00
{
my $path=$_[0];
my $target=$_[1];
2002-09-13 19:43:25 +02:00
my $app_name=@$target[$T_NAME];
2003-04-08 21:42:30 +02:00
my $wrapper_name=$app_name;
$app_name=~ s/\.exe$/\.dll/;
2000-11-05 06:23:39 +01:00
2003-04-08 21:42:30 +02:00
return generate_from_template("$path${wrapper_name}_wrapper.c","wrapper.c",[
2002-09-28 00:06:56 +02:00
["APP_NAME",$app_name],
2002-09-11 03:09:58 +02:00
["APP_TYPE",(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE")],
["APP_INIT",(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\"")],
["APP_MFC",(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":"NULL")]]);
2000-11-05 06:23:39 +01:00
}
##
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) {
$value=&$data($item);
} else {
$value=$item;
}
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
}
}
##
# Generates a project's Makefile.in 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=();
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;
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;
push @{@$project[$P_TARGETS]}, @exe_list;
2000-11-05 06:23:39 +01:00
if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) {
print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n";
print STDERR " $!\n";
return;
}
2000-11-15 23:12:20 +01:00
print FILEO "### Generated by Winemaker\n";
print FILEO "\n\n";
2000-11-05 06:23:39 +01:00
print FILEO "### Generic autoconf variables\n\n";
2000-11-30 21:34:39 +01:00
generate_list("TOPSRCDIR",1,[ "\@top_srcdir\@" ]);
2002-09-10 02:42:43 +02:00
my $dotdotpath=@$project[$P_PATH];
$dotdotpath =~ s%[^/]+%..%g;
$dotdotpath =~ s%/$%%;
$dotdotpath = "." if ($dotdotpath eq "");
generate_list("TOPOBJDIR",1,[ $dotdotpath ]);
2000-11-30 21:34:39 +01:00
generate_list("SRCDIR",1,[ "\@srcdir\@" ]);
generate_list("VPATH",1,[ "\@srcdir\@" ]);
2000-11-05 06:23:39 +01:00
print FILEO "\n";
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];
});
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
2002-09-11 03:09:58 +02:00
generate_list("DEFINES",1,@$project_settings[$T_DEFINES]);
generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]);
generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]);
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";
2003-01-02 20:27:23 +01:00
my $appmode;
my $basemodule=@$target[$T_NAME];
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
if (@$target[$T_TYPE] == $TT_CUIEXE) {
$appmode = "cui";
$basemodule =~ s/\.exe$//;
} elsif (@$target[$T_TYPE] == $TT_GUIEXE) {
$appmode = "gui";
$basemodule =~ s/\.exe$//;
} else {
$appmode = "";
$basemodule =~ s/\.dll$//;
}
generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]);
generate_list("${canon}_BASEMODULE",1,[$basemodule]);
generate_list("${canon}_APPMODE",1,[$appmode]);
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]);
2002-09-28 00:06:56 +02:00
generate_list("${canon}_SPEC_SRCS",1,[ (@$target[$T_TYPE] == $TT_DLL?"@$target[$T_NAME].spec":"") ]);
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]);
generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS]);
2000-11-25 02:38:39 +01:00
print FILEO "\n";
generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(EXTRA_OBJS)"]);
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
}
2001-05-07 20:19:57 +02:00
generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub
2000-11-05 06:23:39 +01:00
{
my $canon=canonize(@{$_[0]}[$T_NAME]);
$canon =~ s+_so$++;
return "\$(${canon}_SPEC_SRCS)";
});
}
2000-11-25 02:38:39 +01:00
print FILEO "\n\n\n";
2000-11-05 06:23:39 +01:00
print FILEO "### Generic autoconf 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 "") {
2002-08-09 02:57:57 +02:00
print FILEO " wineapploader";
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) {
2002-09-26 05:20:59 +02:00
print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)";
2000-11-25 02:38:39 +01:00
}
print FILEO "\n\n";
2002-08-09 02:57:57 +02:00
if (@$project[$P_PATH] eq "") {
print FILEO "wineapploader: wineapploader.in\n";
print FILEO "\tsed -e 's,\@bindir\\\@,\$(bindir),g' " .
"-e 's,\@winelibdir\\\@,.,g' " .
"\$(SRCDIR)/wineapploader.in >\$\@ || \$(RM) \$\@\n";
print FILEO "\n";
}
2000-11-05 06:23:39 +01:00
print FILEO "\@MAKE_RULES\@\n";
print FILEO "\n";
print FILEO "install::\n";
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
2001-10-14 18:06:18 +02:00
print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) install) || exit 1; done\n";
2000-11-05 06:23:39 +01:00
}
if (@{@$project[$P_TARGETS]} > 0) {
2003-01-02 20:27:23 +01:00
print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(INSTALL_SCRIPT) \$\$i \$(bindir); done\n";
2002-09-29 19:59:58 +02:00
print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(INSTALL_PROGRAM) \$\$i \$(dlldir); done\n";
2000-11-05 06:23:39 +01:00
}
print FILEO "\n";
print FILEO "uninstall::\n";
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
2001-10-14 18:06:18 +02:00
print FILEO "\t_list=\"\$(SUBDIRS)\"; for i in \$\$_list; do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n";
2000-11-05 06:23:39 +01:00
}
if (@{@$project[$P_TARGETS]} > 0) {
2003-01-02 20:27:23 +01:00
print FILEO "\t_list=\"\$(EXES:%.exe=%)\"; for i in \$\$_list; do \$(RM) \$(bindir)/\$\$i;done\n";
2002-09-29 19:59:58 +02:00
print FILEO "\t_list=\"\$(EXES:%=%.so) \$(DLLS:%=%.so)\"; for i in \$\$_list; do \$(RM) \$(dlldir)/\$\$i;done\n";
2000-11-05 06:23:39 +01:00
}
2002-08-09 02:57:57 +02:00
print FILEO "\n";
if (@$project[$P_PATH] eq "") {
2003-10-28 22:13:54 +01:00
print FILEO "clean::\n";
print FILEO "\t\$(RM) wineapploader\n";
print FILEO "\n";
print FILEO "distclean: clean\n";
print FILEO "\t\$(RM) config.* configure.lineno Make.rules\n";
print FILEO "\t\$(RM) -r autom4te.cache\n";
print FILEO "\tfind . -name Makefile -exec \$(RM) {} \\;\n";
print FILEO "\n";
2002-08-09 02:57:57 +02:00
}
2001-05-07 20:19:57 +02:00
2000-11-05 06:23:39 +01:00
if (@{@$project[$P_TARGETS]} > 0) {
print FILEO "### Target specific build rules\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]");
2002-08-09 02:57:57 +02:00
my $mode;
2002-09-13 19:43:25 +02:00
my $all_dlls;
my $all_libs;
2002-08-09 02:57:57 +02:00
2000-11-05 06:23:39 +01:00
$canon =~ s/_so$//;
2003-01-02 20:27:23 +01:00
if ((@$target[$T_TYPE]==$TT_GUIEXE) || (@$target[$T_TYPE]==$TT_CUIEXE)) {
$mode = "--exe \$(${canon}_MODULE) -m\$(${canon}_APPMODE)";
2002-08-09 02:57:57 +02:00
} else {
2002-09-28 00:06:56 +02:00
$mode = "";
2002-08-09 02:57:57 +02:00
}
2002-09-13 19:43:25 +02:00
if (@$target[$T_FLAGS] & $TF_WRAPPER) {
$all_dlls="\$(${canon}_DLLS:%=-l%)";
$all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(WINE_LIBRARIES)";
} else {
$all_dlls="\$(${canon}_DLLS:%=-l%) \$(GLOBAL_DLLS:%=-l%)";
$all_libs="\$(${canon}_LIBRARIES:%=-l%) \$(ALL_LIBRARIES)";
}
2003-10-28 22:13:54 +01:00
print FILEO "\$(${canon}_MODULE).dbg.c: \$(${canon}_C_SRCS) \$(${canon}_CXX_SRCS)\n";
print FILEO "\t\$(LDPATH) \$(WINEBUILD) -o \$\@ --debug -C\$(SRCDIR) \$(${canon}_C_SRCS) \$(${canon}_CXX_SRCS)\n";
print FILEO "\n";
2003-01-02 20:27:23 +01:00
print FILEO "\$(${canon}_MODULE).spec.c: \$(${canon}_SPEC_SRCS) \$(${canon}_RC_SRCS:.rc=.res) \$(${canon}_OBJS)\n";
print FILEO "\t\$(LDPATH) \$(WINEBUILD) -fPIC -o \$\@ $mode \$(${canon}_SPEC_SRCS:%=--spec %) \$(${canon}_RC_SRCS:%.rc=%.res) \$(${canon}_OBJS) \$(${canon}_DLL_PATH) \$(WINE_DLL_PATH) \$(GLOBAL_DLL_PATH) $all_dlls\n";
2000-11-15 23:12:20 +01:00
print FILEO "\n";
2003-10-28 22:13:54 +01:00
print FILEO "\$(${canon}_MODULE).so: \$(${canon}_MODULE).dbg.o \$(${canon}_MODULE).spec.o \$(${canon}_OBJS) \$(${canon}_DEPENDS)\n";
2001-03-04 02:03:55 +01:00
if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) {
print FILEO "\t\$(LDXXSHARED)";
} else {
print FILEO "\t\$(LDSHARED)";
}
2003-10-28 22:13:54 +01:00
print FILEO " \$(LDDLLFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_MODULE).dbg.o \$(${canon}_MODULE).spec.o \$(${canon}_LIBRARY_PATH) \$(ALL_LIBRARY_PATH) $all_libs \$(LIBS)\n";
2003-01-02 20:27:23 +01:00
if (@$target[$T_TYPE] != $TT_DLL) {
print FILEO "\ttest -f \$(${canon}_BASEMODULE) || \$(INSTALL_SCRIPT) wineapploader \$(${canon}_BASEMODULE)\n";
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
2002-09-06 20:36:19 +02:00
foreach my $target (@{@$project[$P_TARGETS]}) {
2003-01-02 20:27:23 +01:00
if (@$target[$T_TYPE] == $TT_DLL) {
2002-09-28 00:06:56 +02:00
generate_spec_file(@$project[$P_PATH],$target,$project_settings);
}
2000-11-05 06:23:39 +01:00
if (@$target[$T_FLAGS] & $TF_WRAPPER) {
generate_wrapper_file(@$project[$P_PATH],$target);
}
}
}
##
# Perform the replacements in the template configure files
# Return 1 for success, 0 for failure
2002-09-11 03:09:58 +02:00
sub generate_from_template($$;$)
2000-11-05 06:23:39 +01:00
{
my $filename=$_[0];
2002-09-11 03:09:58 +02:00
my $template=$_[1];
my $substitutions=$_[2];
2000-11-05 06:23:39 +01:00
2002-09-11 03:09:58 +02:00
if (!defined $templates{$template}) {
print STDERR "winemaker: internal error: No template called '$template'\n";
2000-11-05 06:23:39 +01:00
return 0;
}
if (!open(FILEO,">$filename")) {
print STDERR "error: unable to open \"$filename\" for writing:\n";
print STDERR " $!\n";
return 0;
}
2002-09-11 03:09:58 +02:00
my $warned;
foreach my $line (@{$templates{$template}}) {
if ($line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
if (defined $substitutions) {
foreach my $pattern (@$substitutions) {
$line =~ s%\#\#WINEMAKER_@$pattern[0]\#\#%@$pattern[1]%;
}
}
if (!$warned and $line =~ /(\#\#WINEMAKER_[A-Z_]+\#\#)/) {
print STDERR "warning: no value was provided for template $1 in \"$filename\"\n";
$warned=1;
2000-11-05 06:23:39 +01:00
}
}
print FILEO $line;
}
close(FILEO);
2002-09-11 03:09:58 +02:00
return 1;
2000-11-05 06:23:39 +01:00
}
##
# Generates the global files:
# configure
2002-09-11 03:09:58 +02:00
# configure.ac
2000-11-05 06:23:39 +01:00
# Make.rules.in
2002-08-09 02:57:57 +02:00
# wineapploader.in
2002-09-06 20:36:19 +02:00
sub generate_global_files()
2000-11-05 06:23:39 +01:00
{
2002-09-11 03:09:58 +02:00
my @include_path;
foreach my $path (@{$global_settings[$T_INCLUDE_PATH]}) {
if ($path !~ /^-L/ or is_absolute($')) {
push @include_path, $path;
} else {
push @include_path, "-L\$(TOPSRCDIR)/$'";
}
}
my @dll_path;
foreach my $path (@{$global_settings[$T_DLL_PATH]}) {
if ($path !~ /^-L/ or is_absolute($')) {
push @dll_path, $path;
} else {
push @dll_path, "-L\$(TOPSRCDIR)/$'";
}
}
my @library_path;
foreach my $path (@{$global_settings[$T_LIBRARY_PATH]}) {
if ($path !~ /^-L/ or is_absolute($')) {
push @library_path, $path;
} else {
push @library_path, "-L\$(TOPSRCDIR)/$'";
}
}
generate_from_template("Make.rules.in","Make.rules.in",[
["DEFINES", join(" ", @{$global_settings[$T_DEFINES]}) ],
["INCLUDE_PATH", join(" ", @include_path) ],
["DLL_PATH", join(" ", @dll_path) ],
["DLLS", join(" ", @{$global_settings[$T_DLLS]}) ],
["LIBRARY_PATH", join(" ", @library_path) ],
["LIBRARIES", join(" ", @{$global_settings[$T_LIBRARIES]}) ]]);
generate_from_template("wineapploader.in","wineapploader.in");
2000-11-05 06:23:39 +01:00
2002-09-11 03:09:58 +02:00
# Get the name of a source file for configure.ac
2000-11-05 06:23:39 +01:00
my $a_source_file;
2002-09-06 20:36:19 +02:00
search_a_file: foreach my $project (@projects) {
foreach my $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) {
2000-11-05 06:23:39 +01:00
$a_source_file=@{@$target[$T_SOURCES_C]}[0];
if (!defined $a_source_file) {
$a_source_file=@{@$target[$T_SOURCES_CXX]}[0];
}
if (!defined $a_source_file) {
$a_source_file=@{@$target[$T_SOURCES_RC]}[0];
}
if (defined $a_source_file) {
$a_source_file="@$project[$P_PATH]$a_source_file";
last search_a_file;
}
}
}
2001-01-10 23:43:21 +01:00
if (!defined $a_source_file) {
$a_source_file="Makefile.in";
}
2002-09-11 03:09:58 +02:00
generate_from_template("configure.ac","configure.ac",[
["PROJECTS",join("\n",map { "@$_[$P_PATH]Makefile" } @projects)],
["SOURCE","$a_source_file"],
["NEEDS_MFC","$needs_mfc"]]);
2002-09-13 19:43:25 +02:00
system("autoconf configure.ac > configure");
2000-11-05 06:23:39 +01:00
# Add execute permission to configure for whoever has the right to read it
my @st=stat("configure");
2001-01-11 21:17:42 +01:00
if (@st) {
2000-11-05 06:23:39 +01:00
my $mode=$st[2];
$mode|=($mode & 0444) >>2;
chmod($mode,"configure");
} else {
print "warning: could not generate the configure script. You need to run autoconf\n";
}
}
##
2002-06-01 04:55:48 +02:00
#
2002-09-06 20:36:19 +02:00
sub generate_read_templates()
2000-11-05 06:23:39 +01:00
{
my $file;
while (<DATA>) {
if (/^--- ((\w\.?)+) ---$/) {
my $filename=$1;
if (defined $templates{$filename}) {
print STDERR "winemaker: internal error: There is more than one template for $filename\n";
undef $file;
} else {
$file=[];
$templates{$filename}=$file;
}
} elsif (defined $file) {
push @$file, $_;
}
}
}
##
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";
generate_read_templates();
generate_global_files();
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
2001-01-10 23:43:21 +01:00
# $opt_work_dir=<undefined>
2000-11-05 06:23:39 +01:00
# $opt_single_target=<undefined>
$opt_target_type=$TT_GUIEXE;
$opt_flags=0;
$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_generated_specs=0;
$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";
print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n";
}
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";
print STDERR " [--lower-include|--nolower-include]\n";
2002-09-13 19:43:25 +02:00
print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n";
2001-01-11 21:17:42 +01:00
print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n";
2001-07-30 20:44:48 +02:00
print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n";
2002-09-13 19:43:25 +02:00
print STDERR " [--nodlls] [--interactive] [--single-target name]\n";
2001-09-24 03:11:50 +02:00
print STDERR " [--generated-files|--nogenerated-files] [--nogenerated-specs]\n";
2001-01-11 21:17:42 +01:00
print STDERR " work_directory\n";
print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n";
print STDERR "the specified directory so that they can be compiled with Winelib. During this\n";
print STDERR "process it will modify and rename some of the files in that directory.\n";
print STDERR "\tPlease read the manual page before use.\n";
exit (2);
}
2002-09-13 19:43:25 +02:00
target_init(\@global_settings);
2000-11-05 06:23:39 +01:00
while (@ARGV>0) {
my $arg=shift @ARGV;
# 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;
2001-09-24 03:11:50 +02:00
} elsif ($arg eq "--nogenerated-specs") {
$opt_no_generated_specs=1;
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/) {
2002-09-13 19:55:54 +02:00
my $dllname = $';
2003-08-05 20:31:32 +02:00
if ($dllname =~ /^msvcrt$/) {
2002-09-13 19:55:54 +02:00
push @{$global_settings[$T_INCLUDE_PATH]},"-I\$(WINE_INCLUDE_ROOT)/msvcrt";
}
push @{$global_settings[$T_DLLS]},$dllname;
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/) {
push @{$global_settings[$T_LIBRARIES]},$';
2000-11-05 06:23:39 +01:00
# 'Source'-based method options
} elsif ($arg eq "--dll") {
$opt_target_type=$TT_DLL;
} 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 "--wrap") {
2001-03-01 23:11:10 +01:00
$opt_flags|=$TF_WRAP;
2000-11-05 06:23:39 +01:00
} elsif ($arg eq "--nowrap") {
$opt_flags&=~$TF_WRAP;
} elsif ($arg eq "--mfc") {
2000-11-15 23:12:20 +01:00
$opt_flags|=$TF_MFC;
2000-11-05 06:23:39 +01:00
$needs_mfc=1;
} elsif ($arg eq "--nomfc") {
2002-09-10 02:20:27 +02:00
$opt_flags&=~$TF_MFC;
$opt_flags|=$TF_NOMFC;
2000-11-05 06:23:39 +01:00
$needs_mfc=0;
2002-09-10 02:20:27 +02:00
} elsif ($arg eq "--nodlls") {
$opt_flags|=$TF_NODLLS;
2000-11-05 06:23:39 +01:00
# Catch errors
} else {
if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") {
2001-01-10 23:43:21 +01:00
if (!defined $opt_work_dir) {
$opt_work_dir=$arg;
} else {
print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n";
2001-01-11 21:17:42 +01:00
usage();
2001-01-10 23:43:21 +01:00
}
} else {
2001-01-11 21:17:42 +01:00
usage();
2000-11-05 06:23:39 +01:00
}
}
2002-09-10 02:20:27 +02:00
if ($opt_flags & $TF_MFC && $opt_target_type != $TT_DLL) {
print STDERR "info: option --mfc requires --wrap\n";
$opt_flags |= $TF_WRAP;
};
2000-11-05 06:23:39 +01:00
}
2001-01-10 23:43:21 +01:00
if (!defined $opt_work_dir) {
print STDERR "error: you must specify the directory containing the sources to be converted\n";
2001-01-11 21:17:42 +01:00
usage();
2001-01-10 23:43:21 +01:00
} elsif (!chdir $opt_work_dir) {
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
}
2002-09-10 02:20:27 +02:00
project_init(\@main_project,"");
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();
2000-11-10 23:29:11 +01:00
# Create targets for wrappers, etc.
postprocess_targets();
2000-11-05 06:23:39 +01:00
# 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();
}
__DATA__
2002-09-11 03:09:58 +02:00
--- configure.ac ---
2000-11-05 06:23:39 +01:00
dnl Process this file with autoconf to produce a configure script.
dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de>
dnl <patra@itp1.physik.tu-berlin.de>
dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
2002-09-11 03:09:58 +02:00
AC_REVISION([configure.ac 1.00])
2000-11-05 06:23:39 +01:00
AC_INIT(##WINEMAKER_SOURCE##)
NEEDS_MFC=##WINEMAKER_NEEDS_MFC##
dnl **** Command-line arguments ****
AC_SUBST(OPTIONS)
dnl **** Check for some programs ****
AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
2002-09-10 02:42:43 +02:00
AC_PROG_LN_S
2000-11-05 06:23:39 +01:00
dnl **** Check for some libraries ****
dnl Check for -lm for BeOS
AC_CHECK_LIB(m,sqrt)
dnl Check for -lw for Solaris
AC_CHECK_LIB(w,iswalnum)
dnl Check for -lnsl for Solaris
AC_CHECK_FUNCS(gethostbyname,, AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl", AC_CHECK_LIB(socket, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl", , -lnsl), -lsocket))
dnl Check for -lsocket for Solaris
AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect))
dnl **** Check for gcc strength-reduce bug ****
if test "x${GCC}" = "xyes"
then
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([for gcc strength-reduce bug], ac_cv_c_gcc_strength_bug,
AC_TRY_RUN([
2000-11-05 06:23:39 +01:00
int main(void) {
static int Array[[3]];
unsigned int B = 3;
int i;
for(i=0; i<B; i++) Array[[i]] = i - 3;
exit( Array[[1]] != -2 );
}],
ac_cv_c_gcc_strength_bug="no",
ac_cv_c_gcc_strength_bug="yes",
ac_cv_c_gcc_strength_bug="yes") )
if test "$ac_cv_c_gcc_strength_bug" = "yes"
then
CFLAGS="$CFLAGS -fno-strength-reduce"
fi
fi
dnl **** Check for working dll ****
LDSHARED=""
2001-03-04 02:03:55 +01:00
LDXXSHARED=""
2000-11-15 23:12:20 +01:00
LDDLLFLAGS=""
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([whether we can build a Linux dll],
2000-11-05 06:23:39 +01:00
ac_cv_c_dll_linux,
[saved_cflags=$CFLAGS
2000-11-15 23:12:20 +01:00
CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0,-Bsymbolic"
2000-11-05 06:23:39 +01:00
AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no")
CFLAGS=$saved_cflags
])
if test "$ac_cv_c_dll_linux" = "yes"
then
2002-09-10 02:42:43 +02:00
LDSHARED="\$(CC) -shared"
LDXXSHARED="\$(CXX) -shared"
2000-11-15 23:12:20 +01:00
LDDLLFLAGS="-Wl,-Bsymbolic"
2000-11-05 06:23:39 +01:00
else
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([whether we can build a UnixWare (Solaris) dll],
2000-11-05 06:23:39 +01:00
ac_cv_c_dll_unixware,
[saved_cflags=$CFLAGS
2000-11-15 23:12:20 +01:00
CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic"
2000-11-05 06:23:39 +01:00
AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no")
CFLAGS=$saved_cflags
])
if test "$ac_cv_c_dll_unixware" = "yes"
then
2001-03-04 02:03:55 +01:00
LDSHARED="\$(CC) -Wl,-G"
LDXXSHARED="\$(CXX) -Wl,-G"
2000-11-15 23:12:20 +01:00
LDDLLFLAGS="-Wl,-B,symbolic"
2000-11-05 06:23:39 +01:00
else
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([whether we can build a NetBSD dll],
2000-11-05 06:23:39 +01:00
ac_cv_c_dll_netbsd,
[saved_cflags=$CFLAGS
2000-11-13 05:13:22 +01:00
CFLAGS="$CFLAGS -fPIC -Wl,-Bshareable,-Bforcearchive"
2000-11-05 06:23:39 +01:00
AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no")
CFLAGS=$saved_cflags
])
if test "$ac_cv_c_dll_netbsd" = "yes"
then
2000-11-13 05:13:22 +01:00
LDSHARED="\$(CC) -Wl,-Bshareable,-Bforcearchive"
2001-03-04 02:03:55 +01:00
LDXXSHARED="\$(CXX) -Wl,-Bshareable,-Bforcearchive"
2000-11-15 23:12:20 +01:00
LDDLLFLAGS="" #FIXME
2000-11-05 06:23:39 +01:00
fi
fi
fi
if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no"
then
AC_MSG_ERROR([Could not find how to build a dynamically linked library])
fi
2000-11-15 23:12:20 +01:00
CFLAGS="$CFLAGS -fPIC"
2000-11-05 06:23:39 +01:00
AC_SUBST(LDSHARED)
2001-03-04 02:03:55 +01:00
AC_SUBST(LDXXSHARED)
2000-11-15 23:12:20 +01:00
AC_SUBST(LDDLLFLAGS)
2000-11-05 06:23:39 +01:00
dnl *** check for the need to define __i386__
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([whether we need to define __i386__],ac_cv_cpp_def_i386,
2000-11-05 06:23:39 +01:00
AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__)
yes
#endif],
ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no"))
if test "$ac_cv_cpp_def_i386" = "yes"
then
CFLAGS="$CFLAGS -D__i386__"
fi
2002-07-19 05:15:20 +02:00
dnl *** check for the need to define __sparc__
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([whether we need to define __sparc__],ac_cv_cpp_def_sparc,
2002-07-19 05:15:20 +02:00
AC_EGREP_CPP(yes,[#if (defined(sparc) || defined(__sparc)) && !defined(__sparc__)
yes
#endif],
ac_cv_cpp_def_sparc="yes", ac_cv_cpp_def_sparc="no"))
if test "$ac_cv_cpp_def_sparc" = "yes"
then
CFLAGS="$CFLAGS -D__sparc__"
CXXFLAGS="$CXXFLAGS -D__sparc__"
fi
dnl *** check for the need to define __sun__
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([whether we need to define __sun__],ac_cv_cpp_def_sun,
2002-07-19 05:15:20 +02:00
AC_EGREP_CPP(yes,[#if (defined(sun) || defined(__sun)) && !defined(__sun__)
yes
#endif],
ac_cv_cpp_def_sun="yes", ac_cv_cpp_def_sun="no"))
if test "$ac_cv_cpp_def_sun" = "yes"
then
CFLAGS="$CFLAGS -D__sun__"
CXXFLAGS="$CXXFLAGS -D__sun__"
fi
2000-11-05 06:23:39 +01:00
dnl **** Test Winelib-related features of the C++ compiler
AC_LANG_CPLUSPLUS()
if test "x${GCC}" = "xyes"
then
OLDCXXFLAGS="$CXXFLAGS";
CXXFLAGS="-fpermissive";
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([for g++ -fpermissive option], has_gxx_permissive,
2000-11-05 06:23:39 +01:00
AC_TRY_COMPILE(,[
for (int i=0;i<2;i++);
i=0;
],
[has_gxx_permissive="yes"],
[has_gxx_permissive="no"])
)
CXXFLAGS="-fno-for-scope";
2003-10-28 22:13:54 +01:00
AC_CACHE_CHECK([for g++ -fno-for-scope option], has_gxx_no_for_scope,
2000-11-05 06:23:39 +01:00
AC_TRY_COMPILE(,[
for (int i=0;i<2;i++);
i=0;
],
[has_gxx_no_for_scope="yes"],
[has_gxx_no_for_scope="no"])
)
CXXFLAGS="$OLDCXXFLAGS";
if test "$has_gxx_permissive" = "yes"
then
CXXFLAGS="$CXXFLAGS -fpermissive"
fi
if test "$has_gxx_no_for_scope" = "yes"
then
CXXFLAGS="$CXXFLAGS -fno-for-scope"
fi
fi
2000-11-13 05:13:22 +01:00
AC_LANG_C()
2000-11-05 06:23:39 +01:00
dnl **** Test Winelib-related features of the C compiler
dnl none for now
2000-11-13 05:13:22 +01:00
dnl **** Macros for finding a headers/libraries in a collection of places
2001-07-30 20:44:48 +02:00
dnl AC_PATH_FILE(variable,file,action-if-not-found,default-locations)
AC_DEFUN(AC_PATH_FILE,[
AC_MSG_CHECKING([for $2])
AC_CACHE_VAL(ac_cv_pfile_$1,
[
ac_found=
ac_dummy="ifelse([$4], , , [$4])"
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
for ac_dir in $ac_dummy; do
IFS="$ac_save_ifs"
if test -z "$ac_dir"
then
ac_file="$2"
else
ac_file="$ac_dir/$2"
fi
if test -f "$ac_file"
then
ac_found=1
ac_cv_pfile_$1="$ac_dir"
break
fi
done
ifelse([$3],,,[if test -z "$ac_found"
then
$3
fi
])
])
$1="$ac_cv_pfile_$1"
if test -n "$ac_found" -o -n "[$]$1"
then
AC_MSG_RESULT([$]$1)
else
AC_MSG_RESULT(no)
fi
AC_SUBST($1)
])
2000-11-13 05:13:22 +01:00
dnl AC_PATH_HEADER(variable,header,action-if-not-found,default-locations)
2002-06-01 04:55:48 +02:00
dnl Note that the above may set variable to an empty value if the header is
2000-11-13 05:13:22 +01:00
dnl already in the include path
AC_DEFUN(AC_PATH_HEADER,[
2001-07-30 20:44:48 +02:00
AC_MSG_CHECKING([for $2 header])
AC_CACHE_VAL(ac_cv_pheader_$1,
2000-11-13 05:13:22 +01:00
[
ac_found=
ac_dummy="ifelse([$4], , :/usr/local/include, [$4])"
save_CPPFLAGS="$CPPFLAGS"
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
for ac_dir in $ac_dummy; do
IFS="$ac_save_ifs"
if test -z "$ac_dir"
then
CPPFLAGS="$save_CPPFLAGS"
else
CPPFLAGS="-I$ac_dir $save_CPPFLAGS"
fi
2001-07-30 20:44:48 +02:00
AC_TRY_COMPILE([#include <$2>],,ac_found=1;ac_cv_pheader_$1="$ac_dir";break)
2000-11-13 05:13:22 +01:00
done
CPPFLAGS="$save_CPPFLAGS"
ifelse([$3],,,[if test -z "$ac_found"
then
$3
fi
])
])
2001-07-30 20:44:48 +02:00
$1="$ac_cv_pheader_$1"
2000-11-13 05:13:22 +01:00
if test -n "$ac_found" -o -n "[$]$1"
then
AC_MSG_RESULT([$]$1)
else
AC_MSG_RESULT(no)
fi
AC_SUBST($1)
])
dnl AC_PATH_LIBRARY(variable,libraries,extra libs,action-if-not-found,default-locations)
AC_DEFUN(AC_PATH_LIBRARY,[
AC_MSG_CHECKING([for $2])
2001-07-30 20:44:48 +02:00
AC_CACHE_VAL(ac_cv_plibrary_$1,
2000-11-13 05:13:22 +01:00
[
ac_found=
ac_dummy="ifelse([$5], , :/usr/local/lib, [$5])"
save_LIBS="$LIBS"
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
for ac_dir in $ac_dummy; do
IFS="$ac_save_ifs"
if test -z "$ac_dir"
then
LIBS="$2 $3 $save_LIBS"
else
LIBS="-L$ac_dir $2 $3 $save_LIBS"
fi
2001-07-30 20:44:48 +02:00
AC_TRY_LINK(,,ac_found=1;ac_cv_plibrary_$1="$ac_dir";break)
2000-11-13 05:13:22 +01:00
done
LIBS="$save_LIBS"
ifelse([$4],,,[if test -z "$ac_found"
then
$4
fi
])
])
2001-07-30 20:44:48 +02:00
$1="$ac_cv_plibrary_$1"
2000-11-13 05:13:22 +01:00
if test -n "$ac_found" -o -n "[$]$1"
then
AC_MSG_RESULT([$]$1)
else
AC_MSG_RESULT(no)
fi
AC_SUBST($1)
])
2000-11-05 06:23:39 +01:00
dnl **** Try to find where winelib is located ****
2003-01-02 20:27:23 +01:00
LDPATH=""
2001-07-30 20:44:48 +02:00
WINE_INCLUDE_ROOT=""
WINE_INCLUDE_PATH=""
WINE_LIBRARY_ROOT=""
WINE_LIBRARY_PATH=""
WINE_DLL_ROOT=""
WINE_DLL_PATH=""
WINE_TOOL_PATH=""
WINE=""
WINEBUILD=""
WRC=""
2000-11-05 06:23:39 +01:00
2000-11-13 05:13:22 +01:00
AC_ARG_WITH(wine,
[ --with-wine=DIR the Wine package (or sources) is in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
2000-11-13 05:13:22 +01:00
WINE_ROOT="$withval";
WINE_INCLUDES="";
WINE_LIBRARIES="";
WINE_TOOLS="";
2000-11-05 06:23:39 +01:00
else
2000-11-13 05:13:22 +01:00
WINE_ROOT="";
2000-11-05 06:23:39 +01:00
fi])
2000-11-13 05:13:22 +01:00
if test -n "$WINE_ROOT"
2000-11-05 06:23:39 +01:00
then
2003-01-21 00:27:49 +01:00
WINE_INCLUDE_ROOT="$WINE_ROOT/include:$WINE_ROOT/include/wine:$WINE_ROOT/include/wine/windows:$WINE_ROOT/include/windows"
2003-10-28 22:13:54 +01:00
WINE_LIBRARY_ROOT="$WINE_ROOT:$WINE_ROOT/libs:$WINE_ROOT/lib"
WINE_DLL_ROOT="$WINE_ROOT/dlls:$WINE_ROOT/lib:$WINE_ROOT/lib/wine"
2001-07-30 20:44:48 +02:00
WINE_TOOL_PATH="$WINE_ROOT:$WINE_ROOT/bin:$WINE_ROOT/tools/wrc:$WINE_ROOT/tools/winebuild"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
AC_ARG_WITH(wine-includes,
[ --with-wine-includes=DIR the Wine includes are in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
2000-11-13 05:13:22 +01:00
WINE_INCLUDES="$withval";
2000-11-05 06:23:39 +01:00
else
2000-11-13 05:13:22 +01:00
WINE_INCLUDES="";
2000-11-05 06:23:39 +01:00
fi])
2000-11-13 05:13:22 +01:00
if test -n "$WINE_INCLUDES"
2000-11-05 06:23:39 +01:00
then
2001-07-30 20:44:48 +02:00
WINE_INCLUDE_ROOT="$WINE_INCLUDES"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
AC_ARG_WITH(wine-libraries,
[ --with-wine-libraries=DIR the Wine libraries are in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
2000-11-13 05:13:22 +01:00
WINE_LIBRARIES="$withval";
2000-11-05 06:23:39 +01:00
else
2000-11-13 05:13:22 +01:00
WINE_LIBRARIES="";
2000-11-05 06:23:39 +01:00
fi])
2000-11-13 05:13:22 +01:00
if test -n "$WINE_LIBRARIES"
2000-11-05 06:23:39 +01:00
then
2001-07-30 20:44:48 +02:00
WINE_LIBRARY_ROOT="$WINE_LIBRARIES"
fi
AC_ARG_WITH(wine-dlls,
[ --with-wine-dlls=DIR the Wine dlls are in DIR],
[if test "$withval" != "no"; then
WINE_DLLS="$withval";
else
WINE_DLLS="";
fi])
if test -n "$WINE_DLLS"
then
WINE_DLL_ROOT="$WINE_DLLS"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
AC_ARG_WITH(wine-tools,
[ --with-wine-tools=DIR the Wine tools are in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
2000-11-13 05:13:22 +01:00
WINE_TOOLS="$withval";
2000-11-05 06:23:39 +01:00
else
2000-11-13 05:13:22 +01:00
WINE_TOOLS="";
2000-11-05 06:23:39 +01:00
fi])
2000-11-13 05:13:22 +01:00
if test -n "$WINE_TOOLS"
2000-11-05 06:23:39 +01:00
then
2001-10-12 20:41:26 +02:00
WINE_TOOL_PATH="$WINE_TOOLS:$WINE_TOOLS/tools/wrc:$WINE_TOOLS/tools/winebuild"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
if test -z "$WINE_INCLUDE_ROOT"
2000-11-05 06:23:39 +01:00
then
2003-01-21 00:27:49 +01:00
WINE_INCLUDE_ROOT=":/usr/include/wine/windows:/usr/include/wine:/usr/local/include/wine/windows:/opt/wine/include/windows:/opt/wine/include/wine";
2001-07-30 20:44:48 +02:00
else
AC_PATH_FILE(WINE_INCLUDE_ROOT,[windef.h],[
AC_MSG_ERROR([Could not find the Wine headers (windef.h)])
],$WINE_INCLUDE_ROOT)
2000-11-05 06:23:39 +01:00
fi
2001-07-30 20:44:48 +02:00
AC_PATH_HEADER(WINE_INCLUDE_ROOT,[windef.h],[
AC_MSG_ERROR([Could not include the Wine headers (windef.h)])
2000-11-13 05:13:22 +01:00
],$WINE_INCLUDE_ROOT)
if test -n "$WINE_INCLUDE_ROOT"
2000-11-05 06:23:39 +01:00
then
2000-11-13 05:13:22 +01:00
WINE_INCLUDE_PATH="-I$WINE_INCLUDE_ROOT"
else
WINE_INCLUDE_PATH=""
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
if test -z "$WINE_LIBRARY_ROOT"
2000-11-05 06:23:39 +01:00
then
2001-07-30 20:44:48 +02:00
WINE_LIBRARY_ROOT=":/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine:/opt/wine/lib"
2000-11-13 05:13:22 +01:00
else
2001-07-30 20:44:48 +02:00
AC_PATH_FILE(WINE_LIBRARY_ROOT,[libwine.so],[
AC_MSG_ERROR([Could not find the Wine libraries (libwine.so)])
],$WINE_LIBRARY_ROOT)
2000-11-05 06:23:39 +01:00
fi
2001-07-28 01:56:58 +02:00
AC_PATH_LIBRARY(WINE_LIBRARY_ROOT,[-lwine],[],[
2001-07-30 20:44:48 +02:00
AC_MSG_ERROR([Could not link with the Wine libraries (libwine.so)])
2000-11-13 05:13:22 +01:00
],$WINE_LIBRARY_ROOT)
if test -n "$WINE_LIBRARY_ROOT"
2000-11-05 06:23:39 +01:00
then
2000-11-13 05:13:22 +01:00
WINE_LIBRARY_PATH="-L$WINE_LIBRARY_ROOT"
2003-01-02 20:27:23 +01:00
LDPATH="$WINE_LIBRARY_ROOT"
2000-11-13 05:13:22 +01:00
else
WINE_LIBRARY_PATH=""
2000-11-05 06:23:39 +01:00
fi
2001-07-30 20:44:48 +02:00
2003-10-28 22:13:54 +01:00
save_LIBS="$LIBS"
LIBS="$WINE_LIBRARY_PATH $LIBS"
2002-09-11 02:45:16 +02:00
2003-10-28 22:13:54 +01:00
AC_CHECK_LIB(wine_unicode,wine_cp_wcstombs,[],[
AC_MSG_ERROR([Could not find the Wine dlls (libwine_unicode.so)])
])
AC_CHECK_LIB(wine_uuid,IID_IUnknown,[],[
AC_MSG_ERROR([Could not find the Wine dlls (libwine_uuid.so)])
])
2002-09-11 02:45:16 +02:00
2003-10-28 22:13:54 +01:00
LIBS="$save_LIBS"
2002-09-11 02:45:16 +02:00
2001-07-30 20:44:48 +02:00
if test -z "$WINE_DLL_ROOT"
2000-11-05 06:23:39 +01:00
then
2001-07-30 20:44:48 +02:00
if test -n "$WINE_LIBRARY_ROOT"
then
2003-10-28 22:13:54 +01:00
WINE_DLL_ROOT="$WINE_LIBRARY_ROOT:$WINE_LIBRARY_ROOT/dlls:$WINE_LIBRARY_ROOT/wine"
2001-07-30 20:44:48 +02:00
else
2002-09-11 02:45:16 +02:00
WINE_DLL_ROOT="/lib:/lib/wine:/usr/lib:/usr/lib/wine:/usr/local/lib:/usr/local/lib/wine"
2001-07-30 20:44:48 +02:00
fi
2000-11-05 06:23:39 +01:00
fi
2003-10-27 23:14:15 +01:00
AC_PATH_FILE(WINE_DLL_ROOT,[libntdll.def],[
AC_MSG_ERROR([Could not find the Wine dlls (libntdll.def)])
2001-07-30 20:44:48 +02:00
],[$WINE_DLL_ROOT])
2003-10-27 23:14:15 +01:00
WINE_DLL_PATH="-L$WINE_DLL_ROOT"
2001-07-30 20:44:48 +02:00
2000-11-13 05:13:22 +01:00
if test -z "$WINE_TOOL_PATH"
then
2001-07-30 20:44:48 +02:00
WINE_TOOL_PATH="$PATH:/usr/local/bin:/opt/wine/bin"
2000-11-13 05:13:22 +01:00
fi
2000-11-15 23:12:20 +01:00
AC_PATH_PROG(WINE,wine,,$WINE_TOOL_PATH)
if test -z "$WINE"
then
AC_MSG_ERROR([Could not find Wine's wine tool])
fi
2000-11-13 05:13:22 +01:00
AC_PATH_PROG(WINEBUILD,winebuild,,$WINE_TOOL_PATH)
2000-11-05 06:23:39 +01:00
if test -z "$WINEBUILD"
then
2000-11-13 05:13:22 +01:00
AC_MSG_ERROR([Could not find Wine's winebuild tool])
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
AC_PATH_PROG(WRC,wrc,,$WINE_TOOL_PATH)
2000-11-05 06:23:39 +01:00
if test -z "$WRC"
then
2000-11-13 05:13:22 +01:00
AC_MSG_ERROR([Could not find Wine's wrc tool])
2000-11-05 06:23:39 +01:00
fi
2003-01-03 23:36:39 +01:00
LDPATH="LD_LIBRARY_PATH=\"$LDPATH:\$\$LD_LIBRARY_PATH\""
2003-01-02 20:27:23 +01:00
AC_SUBST(LDPATH)
2000-11-13 05:13:22 +01:00
AC_SUBST(WINE_INCLUDE_PATH)
AC_SUBST(WINE_LIBRARY_PATH)
2001-07-30 20:44:48 +02:00
AC_SUBST(WINE_DLL_PATH)
2000-11-05 06:23:39 +01:00
dnl **** Try to find where the MFC are located ****
2000-11-13 05:13:22 +01:00
AC_LANG_CPLUSPLUS()
2000-11-05 06:23:39 +01:00
if test "x$NEEDS_MFC" = "x1"
then
ATL_INCLUDE_ROOT="";
ATL_INCLUDE_PATH="";
MFC_INCLUDE_ROOT="";
MFC_INCLUDE_PATH="";
MFC_LIBRARY_ROOT="";
MFC_LIBRARY_PATH="";
2000-11-13 05:13:22 +01:00
AC_ARG_WITH(mfc,
[ --with-mfc=DIR the MFC package (or sources) is in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
MFC_ROOT="$withval";
ATL_INCLUDES="";
MFC_INCLUDES="";
MFC_LIBRARIES="";
else
MFC_ROOT="";
fi])
if test -n "$MFC_ROOT"
then
ATL_INCLUDE_ROOT="$MFC_ROOT";
MFC_INCLUDE_ROOT="$MFC_ROOT";
MFC_LIBRARY_ROOT="$MFC_ROOT";
fi
AC_ARG_WITH(atl-includes,
2000-11-13 05:13:22 +01:00
[ --with-atl-includes=DIR the ATL includes are in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
ATL_INCLUDES="$withval";
else
ATL_INCLUDES="";
fi])
if test -n "$ATL_INCLUDES"
then
ATL_INCLUDE_ROOT="$ATL_INCLUDES";
fi
AC_ARG_WITH(mfc-includes,
2000-11-13 05:13:22 +01:00
[ --with-mfc-includes=DIR the MFC includes are in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
MFC_INCLUDES="$withval";
else
MFC_INCLUDES="";
fi])
if test -n "$MFC_INCLUDES"
then
MFC_INCLUDE_ROOT="$MFC_INCLUDES";
fi
AC_ARG_WITH(mfc-libraries,
2000-11-13 05:13:22 +01:00
[ --with-mfc-libraries=DIR the MFC libraries are in DIR],
2000-11-05 06:23:39 +01:00
[if test "$withval" != "no"; then
MFC_LIBRARIES="$withval";
else
MFC_LIBRARIES="";
fi])
if test -n "$MFC_LIBRARIES"
then
MFC_LIBRARY_ROOT="$MFC_LIBRARIES";
fi
2000-11-13 05:13:22 +01:00
OLDCPPFLAGS="$CPPFLAGS"
dnl FIXME: We should not have defines in any of the include paths
2002-07-19 05:15:20 +02:00
CPPFLAGS="$WINE_INCLUDE_PATH -I$WINE_INCLUDE_ROOT/msvcrt -D_DLL -D_MT $CPPFLAGS"
ATL_INCLUDE_PATH="-I\$(WINE_INCLUDE_ROOT)/msvcrt -D_DLL -D_MT"
2000-11-05 06:23:39 +01:00
if test -z "$ATL_INCLUDE_ROOT"
then
2000-11-13 05:13:22 +01:00
ATL_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/atl:/usr/include/atl:/usr/local/include/atl:/opt/mfc/include/atl:/opt/atl/include"
else
ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT:$ATL_INCLUDE_ROOT/atl:$ATL_INCLUDE_ROOT/atl/include"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
AC_PATH_HEADER(ATL_INCLUDE_ROOT,atldef.h,[
AC_MSG_ERROR([Could not find the ATL includes])
],$ATL_INCLUDE_ROOT)
if test -n "$ATL_INCLUDE_ROOT"
2000-11-05 06:23:39 +01:00
then
2000-11-13 05:13:22 +01:00
ATL_INCLUDE_PATH="$ATL_INCLUDE_PATH -I$ATL_INCLUDE_ROOT"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
MFC_INCLUDE_PATH="$ATL_INCLUDE_PATH"
2000-11-05 06:23:39 +01:00
if test -z "$MFC_INCLUDE_ROOT"
then
2000-11-13 05:13:22 +01:00
MFC_INCLUDE_ROOT=":$WINE_INCLUDE_ROOT/mfc:/usr/include/mfc:/usr/local/include/mfc:/opt/mfc/include/mfc:/opt/mfc/include"
else
MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT:$MFC_INCLUDE_ROOT/mfc:$MFC_INCLUDE_ROOT/mfc/include"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
AC_PATH_HEADER(MFC_INCLUDE_ROOT,afx.h,[
AC_MSG_ERROR([Could not find the MFC includes])
],$MFC_INCLUDE_ROOT)
if test -n "$MFC_INCLUDE_ROOT" -a "$ATL_INCLUDE_ROOT" != "$MFC_INCLUDE_ROOT"
2000-11-05 06:23:39 +01:00
then
2000-11-13 05:13:22 +01:00
MFC_INCLUDE_PATH="$MFC_INCLUDE_PATH -I$MFC_INCLUDE_ROOT"
2000-11-05 06:23:39 +01:00
fi
2000-11-13 05:13:22 +01:00
CPPFLAGS="$OLDCPPFLAGS"
2000-11-05 06:23:39 +01:00
if test -z "$MFC_LIBRARY_ROOT"
then
2000-11-13 05:13:22 +01:00
MFC_LIBRARY_ROOT=":$WINE_LIBRARY_ROOT:/usr/lib/mfc:/usr/local/lib:/usr/local/lib/mfc:/opt/mfc/lib";
else
MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT:$MFC_LIBRARY_ROOT/lib:$MFC_LIBRARY_ROOT/mfc/src";
2000-11-05 06:23:39 +01:00
fi
2000-11-25 02:38:39 +01:00
AC_PATH_LIBRARY(MFC_LIBRARY_ROOT,[-lmfc],[$WINE_LIBRARY_PATH -lwine -lwine_unicode],[
2000-11-13 05:13:22 +01:00
AC_MSG_ERROR([Could not find the MFC library])
],$MFC_LIBRARY_ROOT)
if test -n "$MFC_LIBRARY_ROOT" -a "$MFC_LIBRARY_ROOT" != "$WINE_LIBRARY_ROOT"
2000-11-05 06:23:39 +01:00
then
2000-11-13 05:13:22 +01:00
MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT"
2000-11-05 06:23:39 +01:00
else
2000-11-13 05:13:22 +01:00
MFC_LIBRARY_PATH=""
2000-11-05 06:23:39 +01:00
fi
AC_SUBST(ATL_INCLUDE_PATH)
AC_SUBST(MFC_INCLUDE_PATH)
AC_SUBST(MFC_LIBRARY_PATH)
fi
2000-11-13 05:13:22 +01:00
AC_LANG_C()
2000-11-05 06:23:39 +01:00
dnl **** Generate output files ****
MAKE_RULES=Make.rules
AC_SUBST_FILE(MAKE_RULES)
AC_OUTPUT([
Make.rules
##WINEMAKER_PROJECTS##
])
echo
echo "Configure finished. Do 'make' to build the project."
echo
dnl Local Variables:
dnl comment-start: "dnl "
dnl comment-end: ""
dnl comment-start-skip: "\\bdnl\\b\\s *"
dnl compile-command: "autoconf"
dnl End:
--- Make.rules.in ---
# Copyright 2000 Francois Gouget for CodeWeavers
# fgouget@codeweavers.com
#
# Global rules shared by all makefiles -*-Makefile-*-
#
# Each individual makefile must define the following variables:
# TOPOBJDIR : top-level object directory
# SRCDIR : source directory for this module
#
# Each individual makefile may define the following additional variables:
#
# SUBDIRS : subdirectories that contain a Makefile
2000-11-15 23:12:20 +01:00
# DLLS : WineLib libraries to be built
# EXES : WineLib executables to be built
2000-11-05 06:23:39 +01:00
#
# CEXTRA : extra c flags (e.g. '-Wall')
# CXXEXTRA : extra c++ flags (e.g. '-Wall')
# WRCEXTRA : extra wrc flags (e.g. '-p _SysRes')
# DEFINES : defines (e.g. -DSTRICT)
# INCLUDE_PATH : additional include path
# LIBRARY_PATH : additional library path
2000-11-15 23:12:20 +01:00
# LIBRARIES : additional Unix libraries to link with
2000-11-05 06:23:39 +01:00
#
# C_SRCS : C sources for the module
# CXX_SRCS : C++ sources for the module
# RC_SRCS : resource source files
# SPEC_SRCS : interface definition files
2001-03-16 17:39:02 +01:00
# Where is Wine
2000-11-05 06:23:39 +01:00
2000-11-13 05:13:22 +01:00
WINE_INCLUDE_ROOT = @WINE_INCLUDE_ROOT@
WINE_INCLUDE_PATH = @WINE_INCLUDE_PATH@
WINE_LIBRARY_ROOT = @WINE_LIBRARY_ROOT@
WINE_LIBRARY_PATH = @WINE_LIBRARY_PATH@
2001-07-30 20:44:48 +02:00
WINE_DLL_ROOT = @WINE_DLL_ROOT@
WINE_DLL_PATH = @WINE_DLL_PATH@
2000-11-05 06:23:39 +01:00
2003-01-02 20:27:23 +01:00
LDPATH = @LDPATH@
2001-03-16 17:39:02 +01:00
2000-11-05 06:23:39 +01:00
# Where are the MFC
ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@
ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@
MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@
MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@
MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@
MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@
2002-09-11 03:09:58 +02:00
# Global definitions and options
GLOBAL_DEFINES = ##WINEMAKER_DEFINES##
GLOBAL_INCLUDE_PATH = ##WINEMAKER_INCLUDE_PATH##
GLOBAL_DLL_PATH = ##WINEMAKER_DLL_PATH##
GLOBAL_DLLS = ##WINEMAKER_DLLS##
GLOBAL_LIBRARY_PATH = ##WINEMAKER_LIBRARY_PATH##
GLOBAL_LIBRARIES = ##WINEMAKER_LIBRARIES##
2000-11-05 06:23:39 +01:00
# First some useful definitions
SHELL = /bin/sh
CC = @CC@
CPP = @CPP@
2001-05-29 22:50:58 +02:00
CXX = @CXX@
2000-11-30 21:36:04 +01:00
WRC = @WRC@
2003-01-02 20:27:23 +01:00
CFLAGS = @CFLAGS@ $(CEXTRA)
CXXFLAGS = @CXXFLAGS@ $(CXXEXTRA)
2003-03-27 19:36:27 +01:00
WRCFLAGS = $(WRCEXTRA)
2003-01-02 20:27:23 +01:00
OPTIONS = @OPTIONS@ -D_REENTRANT
2000-11-05 06:23:39 +01:00
LIBS = @LIBS@ $(LIBRARY_PATH)
2003-01-02 20:27:23 +01:00
DIVINCL = $(GLOBAL_INCLUDE_PATH) -I$(SRCDIR) $(INCLUDE_PATH) $(WINE_INCLUDE_PATH)
ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
ALLCXXFLAGS=$(DIVINCL) $(CXXFLAGS) $(GLOBAL_DEFINES) $(DEFINES) $(OPTIONS)
2002-09-13 19:43:25 +02:00
ALL_DLL_PATH = $(DLL_PATH) $(GLOBAL_DLL_PATH) $(WINE_DLL_PATH)
ALL_LIBRARY_PATH = $(LIBRARY_PATH) $(GLOBAL_LIBRARY_PATH) $(WINE_LIBRARY_PATH)
WINE_LIBRARIES = -lwine -lwine_unicode -lwine_uuid
ALL_LIBRARIES = $(LIBRARIES:%=-l%) $(GLOBAL_LIBRARIES:%=-l%) $(WINE_LIBRARIES)
2000-11-05 06:23:39 +01:00
LDSHARED = @LDSHARED@
2001-04-18 19:39:42 +02:00
LDXXSHARED= @LDXXSHARED@
2000-11-15 23:12:20 +01:00
LDDLLFLAGS= @LDDLLFLAGS@
STRIP = strip
STRIPFLAGS= --strip-unneeded
2002-09-10 02:42:43 +02:00
LN_S = @LN_S@
2000-11-05 06:23:39 +01:00
RM = rm -f
MV = mv
MKDIR = mkdir -p
2000-11-15 23:12:20 +01:00
WINE = @WINE@
2000-11-05 06:23:39 +01:00
WINEBUILD = @WINEBUILD@
@SET_MAKE@
# Installation infos
2001-06-04 04:50:29 +02:00
INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
2002-08-09 02:57:57 +02:00
INSTALL_SCRIPT = $(INSTALL)
2001-06-04 04:50:29 +02:00
INSTALL_DATA = $(INSTALL) -m 644
2000-11-05 06:23:39 +01:00
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
2002-09-17 20:31:31 +02:00
dlldir = @libdir@/wine
2000-11-05 06:23:39 +01:00
prog_manext = 1
conf_manext = 5
2000-11-30 21:36:04 +01:00
OBJS = $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) \
2002-06-01 04:55:48 +02:00
$(SPEC_SRCS:.spec=.spec.o)
2003-10-28 22:13:54 +01:00
CLEAN_FILES = *.dbg.c *.spec.c y.tab.c y.tab.h lex.yy.c \
2000-11-30 21:36:04 +01:00
core *.orig *.rej \
\\\#*\\\# *~ *% .\\\#*
2000-11-05 06:23:39 +01:00
# Implicit rules
2002-08-09 02:57:57 +02:00
.SUFFIXES: .cpp .rc .res .spec .spec.c .spec.o
2000-11-05 06:23:39 +01:00
.c.o:
$(CC) -c $(ALLCFLAGS) -o $@ $<
.cpp.o:
$(CXX) -c $(ALLCXXFLAGS) -o $@ $<
.cxx.o:
$(CXX) -c $(ALLCXXFLAGS) -o $@ $<
.rc.res:
2003-01-21 00:27:49 +01:00
$(LDPATH) $(WRC) $(WRCFLAGS) $(DIVINCL) -o $@ $<
2000-11-05 06:23:39 +01:00
.PHONY: all install uninstall clean distclean depend dummy
# 'all' target first in case the enclosing Makefile didn't define any target
all: Makefile
# Rules for makefile
Makefile: Makefile.in $(TOPSRCDIR)/configure
2002-09-10 02:42:43 +02:00
@echo $@ is older than $?, please rerun $(TOPSRCDIR)/configure
2000-11-05 06:23:39 +01:00
@exit 1
# Rules for cleaning
$(SUBDIRS:%=%/__clean__): dummy
cd `dirname $@` && $(MAKE) clean
$(EXTRASUBDIRS:%=%/__clean__): dummy
-cd `dirname $@` && $(RM) $(CLEAN_FILES)
clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
2003-10-28 22:13:54 +01:00
$(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS)
$(RM) $(DLLS:%=%.dbg.o) $(DLLS:%=%.spec.o) $(DLLS:%=%.so)
$(RM) $(EXES:%=%.dbg.o) $(EXES:%=%.spec.o) $(EXES:%=%.so) $(EXES:%.exe=%)
2002-12-12 23:26:18 +01:00
2000-11-05 06:23:39 +01:00
# Rules for installing
$(SUBDIRS:%=%/__install__): dummy
cd `dirname $@` && $(MAKE) install
$(SUBDIRS:%=%/__uninstall__): dummy
cd `dirname $@` && $(MAKE) uninstall
# Misc. rules
$(SUBDIRS): dummy
@cd $@ && $(MAKE)
dummy:
# End of global rules
2002-08-09 02:57:57 +02:00
--- wineapploader.in ---
#!/bin/sh
#
# Wrapper script to start a Winelib application once it is installed
#
# Copyright (C) 2002 Alexandre Julliard
# determine the app Winelib library name
appname=`basename "$0" .exe`.exe
#allow Wine to load Winelib application from the current directory
export WINEDLLPATH=$WINEDLLPATH:@winelibdir@
# first try explicit WINELOADER
if [ -x "$WINELOADER" ]; then exec "$WINELOADER" "$appname" "$@"; fi
# then default bin directory
if [ -x "@bindir@/wine" ]; then exec "@bindir@/wine" "$appname" "$@"; fi
# now try the directory containing $0
appdir=""
case "$0" in
*/*)
# $0 contains a path, use it
appdir=`dirname "$0"`
;;
*)
# no directory in $0, search in PATH
saved_ifs=$IFS
IFS=:
for d in $PATH
do
IFS=$saved_ifs
if [ -x "$d/$0" ]; then appdir="$d"; break; fi
done
;;
esac
if [ -x "$appdir/wine" ]; then exec "$appdir/wine" "$appname" "$@"; fi
# finally look in PATH
exec wine "$appname" "$@"
2000-11-05 06:23:39 +01:00
--- wrapper.c ---
/*
* Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers
*/
2001-10-08 22:30:18 +02:00
#ifndef STRICT
#define STRICT
#endif
2000-11-05 06:23:39 +01:00
#include <dlfcn.h>
#include <windows.h>
/*
* Describe the wrapped application
*/
/**
* This is either CUIEXE for a console based application or
* GUIEXE for a regular windows application.
*/
2002-09-09 21:17:52 +02:00
#define GUIEXE 0
#define CUIEXE 1
2000-11-05 06:23:39 +01:00
#define APP_TYPE ##WINEMAKER_APP_TYPE##
/**
2002-09-28 00:06:56 +02:00
* This is the name of the library containing the application,
* e.g. 'hello.dll' if the application is called 'hello.exe'.
2000-11-05 06:23:39 +01:00
*/
2002-09-13 19:43:25 +02:00
static char* appName = "##WINEMAKER_APP_NAME##";
2000-11-05 06:23:39 +01:00
/**
2002-06-01 04:55:48 +02:00
* This is the name of the application's Windows module. If left NULL
2000-11-05 06:23:39 +01:00
* then appName is used.
*/
static char* appModule = NULL;
/**
2002-06-01 04:55:48 +02:00
* This is the application's entry point. This is usually "WinMain" for a
2000-11-05 06:23:39 +01:00
* GUIEXE and 'main' for a CUIEXE application.
*/
static char* appInit = ##WINEMAKER_APP_INIT##;
/**
2002-06-01 04:55:48 +02:00
* This is either non-NULL for MFC-based applications and is the name of the
* MFC's module. This is the module in which we will take the 'WinMain'
2000-11-05 06:23:39 +01:00
* function.
*/
static char* mfcModule = ##WINEMAKER_APP_MFC##;
/*
* Implement the main.
*/
#if APP_TYPE == GUIEXE
typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow);
#else
typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);
#endif
#if APP_TYPE == GUIEXE
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
#else
2002-09-09 21:17:52 +02:00
int WINAPI main(int argc, char** argv, char** envp)
2000-11-05 06:23:39 +01:00
#endif
{
2002-09-09 21:17:52 +02:00
HINSTANCE hApp = 0, hMFC = 0, hMain = 0;
2000-11-05 06:23:39 +01:00
void* appMain;
int retcode;
/* Then if this application is MFC based, load the MFC module */
/* FIXME: I'm not sure this is really necessary */
if (mfcModule!=NULL) {
hMFC=LoadLibrary(mfcModule);
if (hMFC==NULL) {
char format[]="Could not load the MFC module %s (%d)";
char* msg;
msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11);
sprintf(msg,format,mfcModule,GetLastError());
MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
free(msg);
return 1;
}
2002-06-01 04:55:48 +02:00
/* MFC is a special case: the WinMain is in the MFC library,
2000-11-05 06:23:39 +01:00
* instead of the application's library.
*/
hMain=hMFC;
} else {
hMFC=NULL;
}
/* Load the application's module */
if (appModule==NULL) {
appModule=appName;
}
hApp=LoadLibrary(appModule);
if (hApp==NULL) {
char format[]="Could not load the application's module %s (%d)";
char* msg;
msg=(char*)malloc(strlen(format)+strlen(appModule)+11);
sprintf(msg,format,appModule,GetLastError());
MessageBox(NULL,msg,"LoadLibrary error",MB_OK);
free(msg);
return 1;
} else if (hMain==NULL) {
hMain=hApp;
}
/* Get the address of the application's entry point */
2002-09-09 21:17:52 +02:00
appMain=GetProcAddress(hMain, appInit);
2000-11-05 06:23:39 +01:00
if (appMain==NULL) {
char format[]="Could not get the address of %s (%d)";
char* msg;
msg=(char*)malloc(strlen(format)+strlen(appInit)+11);
sprintf(msg,format,appInit,GetLastError());
MessageBox(NULL,msg,"GetProcAddress error",MB_OK);
free(msg);
return 1;
}
/* And finally invoke the application's entry point */
#if APP_TYPE == GUIEXE
retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow);
#else
retcode=(*((MainFunc)appMain))(argc,argv,envp);
#endif
/* Cleanup and done */
FreeLibrary(hApp);
if (hMFC!=NULL) {
FreeLibrary(hMFC);
}
return retcode;
}