Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2 | use strict; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 3 | |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 4 | # Copyright 2000-2004 Francois Gouget for CodeWeavers |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 5 | # Copyright 2004 Dimitrie O. Paun |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 6 | # Copyright 2009 André Hentschel |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 7 | # |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 8 | # This library is free software; you can redistribute it and/or |
| 9 | # modify it under the terms of the GNU Lesser General Public |
| 10 | # License as published by the Free Software Foundation; either |
| 11 | # version 2.1 of the License, or (at your option) any later version. |
| 12 | # |
| 13 | # This library is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | # Lesser General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU Lesser General Public |
| 19 | # License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 21 | # |
| 22 | |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 23 | my $version="0.7.4"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 24 | |
| 25 | use Cwd; |
| 26 | use File::Basename; |
| 27 | use File::Copy; |
| 28 | |
| 29 | |
| 30 | |
| 31 | ##### |
| 32 | # |
| 33 | # Options |
| 34 | # |
| 35 | ##### |
| 36 | |
| 37 | # The following constants define what we do with the case of filenames |
| 38 | |
| 39 | ## |
| 40 | # Never rename a file to lowercase |
| 41 | my $OPT_LOWER_NONE=0; |
| 42 | |
| 43 | ## |
| 44 | # Rename all files to lowercase |
| 45 | my $OPT_LOWER_ALL=1; |
| 46 | |
| 47 | ## |
| 48 | # Rename only files that are all uppercase to lowercase |
| 49 | my $OPT_LOWER_UPPERCASE=2; |
| 50 | |
| 51 | |
| 52 | # The following constants define whether to ask questions or not |
| 53 | |
| 54 | ## |
| 55 | # No (synonym of never) |
| 56 | my $OPT_ASK_NO=0; |
| 57 | |
| 58 | ## |
| 59 | # Yes (always) |
| 60 | my $OPT_ASK_YES=1; |
| 61 | |
| 62 | ## |
| 63 | # Skip the questions till the end of this scope |
| 64 | my $OPT_ASK_SKIP=-1; |
| 65 | |
| 66 | |
André Hentschel | 2100cb6 | 2009-05-01 11:37:01 +0200 | [diff] [blame] | 67 | # The following constants define the architecture |
| 68 | |
| 69 | ## |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 70 | # Default Architecture will be choosen |
| 71 | my $OPT_ARCH_DEFAULT=0; |
| 72 | |
| 73 | ## |
André Hentschel | 2100cb6 | 2009-05-01 11:37:01 +0200 | [diff] [blame] | 74 | # 32-Bit Target |
| 75 | my $OPT_ARCH_32=32; |
| 76 | |
| 77 | ## |
| 78 | # 64-Bit Target |
| 79 | my $OPT_ARCH_64=64; |
| 80 | |
| 81 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 82 | # General options |
| 83 | |
| 84 | ## |
François Gouget | c1f016b | 2001-01-10 22:43:21 +0000 | [diff] [blame] | 85 | # This is the directory in which winemaker will operate. |
| 86 | my $opt_work_dir; |
| 87 | |
| 88 | ## |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 89 | # This is the file in which winemaker will operate if a project file is specified. |
| 90 | my $opt_work_file; |
| 91 | |
| 92 | ## |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 93 | # Make a backup of the files |
| 94 | my $opt_backup; |
| 95 | |
| 96 | ## |
| 97 | # Defines which files to rename |
| 98 | my $opt_lower; |
| 99 | |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 100 | ## |
| 101 | # If we don't find the file referenced by an include, lower it |
| 102 | my $opt_lower_include; |
| 103 | |
Bill Medland | ce4e0a6 | 2001-09-24 01:11:50 +0000 | [diff] [blame] | 104 | ## |
| 105 | # If true then winemaker should not attempt to fix the source. This is |
| 106 | # useful if the source is known to be already in a suitable form and is |
| 107 | # readonly |
| 108 | my $opt_no_source_fix; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 109 | |
| 110 | # Options for the 'Source' method |
| 111 | |
| 112 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 113 | # Specifies that we have only one target so that all sources relate |
| 114 | # to this target. By default this variable is left undefined which |
| 115 | # means winemaker should try to find out by itself what the targets |
| 116 | # are. If not undefined then this contains the name of the default |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 117 | # target (without the extension). |
| 118 | my $opt_single_target; |
| 119 | |
| 120 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 121 | # If '$opt_single_target' has been specified then this is the type of |
| 122 | # that target. Otherwise it specifies whether the default target type |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 123 | # is guiexe or cuiexe. |
| 124 | my $opt_target_type; |
| 125 | |
| 126 | ## |
| 127 | # Contains the default set of flags to be used when creating a new target. |
| 128 | my $opt_flags; |
| 129 | |
| 130 | ## |
André Hentschel | 2100cb6 | 2009-05-01 11:37:01 +0200 | [diff] [blame] | 131 | # Contains 32 for 32-Bit-Targets and 64 for 64-Bit-Targets |
| 132 | my $opt_arch; |
| 133 | |
| 134 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 135 | # If true then winemaker should ask questions to the user as it goes |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 136 | # along. |
| 137 | my $opt_is_interactive; |
| 138 | my $opt_ask_project_options; |
| 139 | my $opt_ask_target_options; |
| 140 | |
| 141 | ## |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 142 | # If false then winemaker should not generate the makefiles. |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 143 | my $opt_no_generated_files; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 144 | |
| 145 | ## |
| 146 | # Specifies not to print the banner if set. |
| 147 | my $opt_no_banner; |
| 148 | |
| 149 | |
| 150 | |
| 151 | ##### |
| 152 | # |
| 153 | # Target modelization |
| 154 | # |
| 155 | ##### |
| 156 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 157 | # The description of a target is stored in an array. The constants |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 158 | # below identify what is stored at each index of the array. |
| 159 | |
| 160 | ## |
| 161 | # This is the name of the target. |
| 162 | my $T_NAME=0; |
| 163 | |
| 164 | ## |
| 165 | # Defines the type of target we want to build. See the TT_xxx |
| 166 | # constants below |
| 167 | my $T_TYPE=1; |
| 168 | |
| 169 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 170 | # This is a bitfield containing flags refining the way the target |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 171 | # should be handled. See the TF_xxx constants below |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 172 | my $T_FLAGS=2; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 173 | |
| 174 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 175 | # This is a reference to an array containing the list of the |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 176 | # resp. C, C++, RC, other (.h, .hxx, etc.) source files. |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 177 | my $T_SOURCES_C=3; |
| 178 | my $T_SOURCES_CXX=4; |
| 179 | my $T_SOURCES_RC=5; |
| 180 | my $T_SOURCES_MISC=6; |
| 181 | |
| 182 | ## |
| 183 | # This is a reference to an array containing the list of |
| 184 | # C compiler options |
| 185 | my $T_CEXTRA=7; |
| 186 | |
| 187 | ## |
| 188 | # This is a reference to an array containing the list of |
| 189 | # C++ compiler options |
| 190 | my $T_CXXEXTRA=8; |
| 191 | |
| 192 | ## |
| 193 | # This is a reference to an array containing the list of |
| 194 | # RC compiler options |
| 195 | my $T_RCEXTRA=9; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 196 | |
| 197 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 198 | # This is a reference to an array containing the list of macro |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 199 | # definitions |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 200 | my $T_DEFINES=10; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 201 | |
| 202 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 203 | # This is a reference to an array containing the list of directory |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 204 | # names that constitute the include path |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 205 | my $T_INCLUDE_PATH=11; |
| 206 | |
| 207 | ## |
| 208 | # Flags for the linker |
| 209 | my $T_LDFLAGS=12; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 210 | |
| 211 | ## |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 212 | # Same as T_INCLUDE_PATH but for the dll search path |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 213 | my $T_DLL_PATH=13; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 214 | |
| 215 | ## |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 216 | # The list of Windows dlls to import |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 217 | my $T_DLLS=14; |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 218 | |
| 219 | ## |
| 220 | # Same as T_INCLUDE_PATH but for the library search path |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 221 | my $T_LIBRARY_PATH=15; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 222 | |
| 223 | ## |
| 224 | # The list of Unix libraries to link with |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 225 | my $T_LIBRARIES=16; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 226 | |
| 227 | ## |
| 228 | # The list of dependencies between targets |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 229 | my $T_DEPENDS=17; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 230 | |
| 231 | |
| 232 | # The following constants define the recognized types of target |
| 233 | |
| 234 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 235 | # This is not a real target. This type of target is used to collect |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 236 | # the sources that don't seem to belong to any other target. Thus no |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 237 | # real target is generated for them, we just put the sources of the |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 238 | # fake target in the global source list. |
| 239 | my $TT_SETTINGS=0; |
| 240 | |
| 241 | ## |
| 242 | # For executables in the windows subsystem |
| 243 | my $TT_GUIEXE=1; |
| 244 | |
| 245 | ## |
| 246 | # For executables in the console subsystem |
| 247 | my $TT_CUIEXE=2; |
| 248 | |
| 249 | ## |
| 250 | # For dynamically linked libraries |
| 251 | my $TT_DLL=3; |
| 252 | |
| 253 | |
| 254 | # The following constants further refine how the target should be handled |
| 255 | |
| 256 | ## |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 257 | # This target is an MFC-based target |
| 258 | my $TF_MFC=4; |
| 259 | |
| 260 | ## |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 261 | # User has specified --nomfc option for this target or globally |
| 262 | my $TF_NOMFC=8; |
| 263 | |
| 264 | ## |
| 265 | # --nodlls option: Do not use standard DLL set |
| 266 | my $TF_NODLLS=16; |
| 267 | |
| 268 | ## |
Francois Gouget | 15487bc | 2004-02-02 23:02:32 +0000 | [diff] [blame] | 269 | # --nomsvcrt option: Do not link with msvcrt |
| 270 | my $TF_NOMSVCRT=32; |
| 271 | |
| 272 | ## |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 273 | # Initialize a target: |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 274 | # - set the target type to TT_SETTINGS, i.e. no real target will |
| 275 | # be generated. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 276 | sub target_init($) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 277 | { |
| 278 | my $target=$_[0]; |
| 279 | |
| 280 | @$target[$T_TYPE]=$TT_SETTINGS; |
| 281 | # leaving $T_INIT undefined |
| 282 | @$target[$T_FLAGS]=$opt_flags; |
| 283 | @$target[$T_SOURCES_C]=[]; |
| 284 | @$target[$T_SOURCES_CXX]=[]; |
| 285 | @$target[$T_SOURCES_RC]=[]; |
| 286 | @$target[$T_SOURCES_MISC]=[]; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 287 | @$target[$T_CEXTRA]=[]; |
| 288 | @$target[$T_CXXEXTRA]=[]; |
| 289 | @$target[$T_RCEXTRA]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 290 | @$target[$T_DEFINES]=[]; |
| 291 | @$target[$T_INCLUDE_PATH]=[]; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 292 | @$target[$T_LDFLAGS]=[]; |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 293 | @$target[$T_DLL_PATH]=[]; |
| 294 | @$target[$T_DLLS]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 295 | @$target[$T_LIBRARY_PATH]=[]; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 296 | @$target[$T_LIBRARIES]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 299 | |
| 300 | |
| 301 | ##### |
| 302 | # |
| 303 | # Project modelization |
| 304 | # |
| 305 | ##### |
| 306 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 307 | # First we have the notion of project. A project is described by an |
| 308 | # array (since we don't have structs in perl). The constants below |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 309 | # identify what is stored at each index of the array. |
| 310 | |
| 311 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 312 | # This is the path in which this project is located. In other |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 313 | # words, this is the path to the Makefile. |
| 314 | my $P_PATH=0; |
| 315 | |
| 316 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 317 | # This index contains a reference to an array containing the project-wide |
| 318 | # settings. The structure of that arrray is actually identical to that of |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 319 | # a regular target since it can also contain extra sources. |
| 320 | my $P_SETTINGS=1; |
| 321 | |
| 322 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 323 | # This index contains a reference to an array of targets for this |
| 324 | # project. Each target describes how an executable or library is to |
| 325 | # be built. For each target this description takes the same form as |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 326 | # that of the project: an array. So this entry is an array of arrays. |
| 327 | my $P_TARGETS=2; |
| 328 | |
| 329 | ## |
| 330 | # Initialize a project: |
| 331 | # - set the project's path |
| 332 | # - initialize the target list |
| 333 | # - create a default target (will be removed later if unnecessary) |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 334 | sub project_init($$$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 335 | { |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 336 | my ($project, $path, $global_settings)=@_; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 337 | |
| 338 | my $project_settings=[]; |
| 339 | target_init($project_settings); |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 340 | @$project_settings[$T_DEFINES]=[@{@$global_settings[$T_DEFINES]}]; |
| 341 | @$project_settings[$T_INCLUDE_PATH]=[@{@$global_settings[$T_INCLUDE_PATH]}]; |
| 342 | @$project_settings[$T_DLL_PATH]=[@{@$global_settings[$T_DLL_PATH]}]; |
| 343 | @$project_settings[$T_DLLS]=[@{@$global_settings[$T_DLLS]}]; |
| 344 | @$project_settings[$T_LIBRARY_PATH]=[@{@$global_settings[$T_LIBRARY_PATH]}]; |
| 345 | @$project_settings[$T_LIBRARIES]=[@{@$global_settings[$T_LIBRARIES]}]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 346 | |
| 347 | @$project[$P_PATH]=$path; |
| 348 | @$project[$P_SETTINGS]=$project_settings; |
| 349 | @$project[$P_TARGETS]=[]; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | |
| 354 | ##### |
| 355 | # |
| 356 | # Global variables |
| 357 | # |
| 358 | ##### |
| 359 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 360 | my %warnings; |
| 361 | |
| 362 | my %templates; |
| 363 | |
| 364 | ## |
Michael Jung | dc75406 | 2004-12-13 12:00:59 +0000 | [diff] [blame] | 365 | # This maps a directory name to a reference to an array listing |
| 366 | # its contents (files and directories) |
| 367 | my %directories; |
| 368 | |
| 369 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 370 | # Contains the list of all projects. This list tells us what are |
| 371 | # the subprojects of the main Makefile and where we have to generate |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 372 | # Makefiles. |
| 373 | my @projects=(); |
| 374 | |
| 375 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 376 | # This is the main project, i.e. the one in the "." directory. |
| 377 | # It may well be empty in which case the main Makefile will only |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 378 | # call out subprojects. |
| 379 | my @main_project; |
| 380 | |
| 381 | ## |
| 382 | # Contains the defaults for the include path, etc. |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 383 | # We store the defaults as if this were a target except that we only |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 384 | # exploit the defines, include path, library path, library list and misc |
| 385 | # sources fields. |
| 386 | my @global_settings; |
| 387 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 388 | |
| 389 | |
| 390 | ##### |
| 391 | # |
| 392 | # Utility functions |
| 393 | # |
| 394 | ##### |
| 395 | |
| 396 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 397 | # Cleans up a name to make it an acceptable Makefile |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 398 | # variable name. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 399 | sub canonize($) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 400 | { |
| 401 | my $name=$_[0]; |
| 402 | |
| 403 | $name =~ tr/a-zA-Z0-9_/_/c; |
| 404 | return $name; |
| 405 | } |
| 406 | |
| 407 | ## |
| 408 | # Returns true is the specified pathname is absolute. |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 409 | # Note: pathnames that start with a variable '$' or |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 410 | # '~' are considered absolute. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 411 | sub is_absolute($) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 412 | { |
| 413 | my $path=$_[0]; |
| 414 | |
| 415 | return ($path =~ /^[\/~\$]/); |
| 416 | } |
| 417 | |
| 418 | ## |
Francois Gouget | bebac0a | 2004-10-30 02:11:19 +0000 | [diff] [blame] | 419 | # Retrieves the contents of the specified directory. |
| 420 | # We either get it from the directories hashtable which acts as a |
| 421 | # cache, or use opendir, readdir, closedir and store the result |
| 422 | # in the hashtable. |
| 423 | sub get_directory_contents($) |
| 424 | { |
| 425 | my $dirname=$_[0]; |
| 426 | my $directory; |
| 427 | |
| 428 | #print "getting the contents of $dirname\n"; |
| 429 | |
| 430 | # check for a cached version |
| 431 | $dirname =~ s+/$++; |
| 432 | if ($dirname eq "") { |
| 433 | $dirname=cwd; |
| 434 | } |
| 435 | $directory=$directories{$dirname}; |
| 436 | if (defined $directory) { |
| 437 | #print "->@$directory\n"; |
| 438 | return $directory; |
| 439 | } |
| 440 | |
| 441 | # Read this directory |
| 442 | if (opendir(DIRECTORY, "$dirname")) { |
| 443 | my @files=readdir DIRECTORY; |
| 444 | closedir(DIRECTORY); |
| 445 | $directory=\@files; |
| 446 | } else { |
| 447 | # Return an empty list |
| 448 | #print "error: cannot open $dirname\n"; |
| 449 | my @files; |
| 450 | $directory=\@files; |
| 451 | } |
| 452 | #print "->@$directory\n"; |
| 453 | $directories{$dirname}=$directory; |
| 454 | return $directory; |
| 455 | } |
| 456 | |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 457 | ## |
| 458 | # Removes a directory from the cache. |
| 459 | # This is needed if one of its files or subdirectory has been renamed. |
| 460 | sub clear_directory_cache($) |
| 461 | { |
| 462 | my ($dirname)=@_; |
| 463 | delete $directories{$dirname}; |
| 464 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 465 | |
| 466 | |
| 467 | ##### |
| 468 | # |
| 469 | # 'Source'-based Project analysis |
| 470 | # |
| 471 | ##### |
| 472 | |
| 473 | ## |
| 474 | # Allows the user to specify makefile and target specific options |
| 475 | # - target: the structure in which to store the results |
| 476 | # - options: the string containing the options |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 477 | sub source_set_options($$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 478 | { |
| 479 | my $target=$_[0]; |
| 480 | my $options=$_[1]; |
| 481 | |
| 482 | #FIXME: we must deal with escaping of stuff and all |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 483 | foreach my $option (split / /,$options) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 484 | if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) { |
| 485 | push @{@$target[$T_DEFINES]},$option; |
| 486 | } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) { |
| 487 | push @{@$target[$T_INCLUDE_PATH]},$option; |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 488 | } elsif ($option =~ /^-P/) { |
| 489 | push @{@$target[$T_DLL_PATH]},"-L$'"; |
| 490 | } elsif ($option =~ /^-i/) { |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 491 | push @{@$target[$T_DLLS]},"$'"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 492 | } elsif ($option =~ /^-L/) { |
| 493 | push @{@$target[$T_LIBRARY_PATH]},$option; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 494 | } elsif ($option =~ /^-l/) { |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 495 | push @{@$target[$T_LIBRARIES]},"$'"; |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 496 | } elsif ($option =~ /^--mfc/) { |
| 497 | @$target[$T_FLAGS]|=$TF_MFC; |
| 498 | @$target[$T_FLAGS]&=~$TF_NOMFC; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 499 | } elsif ($option =~ /^--nomfc/) { |
| 500 | @$target[$T_FLAGS]&=~$TF_MFC; |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 501 | @$target[$T_FLAGS]|=$TF_NOMFC; |
| 502 | } elsif ($option =~ /^--nodlls/) { |
| 503 | @$target[$T_FLAGS]|=$TF_NODLLS; |
Francois Gouget | 15487bc | 2004-02-02 23:02:32 +0000 | [diff] [blame] | 504 | } elsif ($option =~ /^--nomsvcrt/) { |
| 505 | @$target[$T_FLAGS]|=$TF_NOMSVCRT; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 506 | } else { |
Francois Gouget | 3af251e | 2000-11-30 20:36:04 +0000 | [diff] [blame] | 507 | print STDERR "error: unknown option \"$option\"\n"; |
| 508 | return 0; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 509 | } |
| 510 | } |
Francois Gouget | 3af251e | 2000-11-30 20:36:04 +0000 | [diff] [blame] | 511 | return 1; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | ## |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 515 | # Scans the specified project file to: |
| 516 | # - get a list of targets for this project |
| 517 | # - get some settings |
| 518 | # - get the list of source files |
| 519 | sub source_scan_project_file($$$); |
| 520 | sub source_scan_project_file($$$) |
| 521 | { |
| 522 | # a reference to the parent's project |
| 523 | my $parent_project=$_[0]; |
| 524 | # 0 if it is a single project, 1 if it is part of a workspace |
| 525 | my $is_sub_project=$_[1]; |
| 526 | # the name of the project file, with complete path, or without if in |
| 527 | # the same directory |
| 528 | my $filename=$_[2]; |
| 529 | |
| 530 | # reference to the project for this file. May not be used |
| 531 | my $project; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 532 | # list of sources found in the current file |
| 533 | my @sources_c=(); |
| 534 | my @sources_cxx=(); |
| 535 | my @sources_rc=(); |
| 536 | my @sources_misc=(); |
| 537 | # some more settings |
| 538 | my $path=dirname($filename); |
| 539 | my $prj_target_cflags; |
André Hentschel | e1e9dc3 | 2009-08-13 16:43:37 +0200 | [diff] [blame] | 540 | my $prj_target_defines; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 541 | my $prj_target_ldflags; |
| 542 | my $prj_target_libs; |
| 543 | my $prj_name; |
| 544 | my $found_cfg=0; |
| 545 | my $prj_cfg; |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 546 | my $prj_target_type=$TT_GUIEXE; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 547 | my @prj_target_options; |
| 548 | |
| 549 | if (!($path=~/\/$/)) { |
| 550 | $path.="/"; |
| 551 | } |
| 552 | |
| 553 | if (defined $opt_single_target or $is_sub_project == 0) { |
| 554 | # Either there is a single target and thus a single project, |
| 555 | # or we are a single project-file for which a project |
| 556 | # already exists |
| 557 | $project=$parent_project; |
| 558 | } else { |
| 559 | $project=[]; |
| 560 | project_init($project, $path, \@global_settings); |
| 561 | } |
| 562 | my $project_settings=@$project[$P_SETTINGS]; |
| 563 | |
| 564 | if ($filename =~ /.dsp$/i) { |
| 565 | # First find out what this project file contains: |
| 566 | # collect all sources, find targets and settings |
| 567 | if (!open(FILEI,$filename)) { |
| 568 | print STDERR "error: unable to open $filename for reading:\n"; |
| 569 | print STDERR " $!\n"; |
| 570 | return; |
| 571 | } |
| 572 | my $sfilet; |
| 573 | while (<FILEI>) { |
| 574 | # Remove any trailing CtrlZ, which isn't strictly in the file |
| 575 | if (/\x1A/) { |
| 576 | s/\x1A//; |
| 577 | last if (/^$/) |
| 578 | } |
| 579 | |
| 580 | # Remove any trailing CrLf |
| 581 | s/\r\n$/\n/; |
| 582 | if (!/\n$/) { |
| 583 | # Make sure all lines are '\n' terminated |
| 584 | $_ .= "\n"; |
| 585 | } |
| 586 | |
| 587 | if (/^\# Microsoft Developer Studio Project File - Name=\"([^\"]+)/) { |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 588 | $prj_name="$1"; |
André Hentschel | 5f059ed | 2009-11-21 18:13:44 +0100 | [diff] [blame] | 589 | $prj_name=~s/\s+/_/g; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 590 | #print $prj_name; |
| 591 | next; |
| 592 | } elsif (/^# TARGTYPE/) { |
| 593 | if (/[[:space:]]0x0101$/) { |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 594 | # Application |
| 595 | $prj_target_type=$TT_GUIEXE; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 596 | }elsif (/[[:space:]]0x0102$/) { |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 597 | # Dynamic-Link Library |
| 598 | $prj_target_type=$TT_DLL; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 599 | }elsif (/[[:space:]]0x0103$/) { |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 600 | # Console Application |
| 601 | $prj_target_type=$TT_CUIEXE; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 602 | }elsif (/[[:space:]]0x0104$/) { |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 603 | # Static Library |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 604 | } |
| 605 | next; |
| 606 | } elsif (/^# ADD CPP(.*)/ && $found_cfg==1) { |
| 607 | $prj_target_cflags=$1; |
| 608 | @prj_target_options=split(" /", $prj_target_cflags); |
| 609 | $prj_target_cflags=""; |
| 610 | foreach ( @prj_target_options ) { |
| 611 | if ($_ eq "") { |
| 612 | # empty |
| 613 | } elsif (/nologo/) { |
| 614 | # Suppress Startup Banner and Information Messages |
| 615 | } elsif (/^W0$/) { |
| 616 | # Turns off all warning messages |
| 617 | $prj_target_cflags.="-w "; |
| 618 | } elsif (/^W[123]$/) { |
| 619 | # Warning Level |
| 620 | $prj_target_cflags.="-W "; |
| 621 | } elsif (/^W4$/) { |
| 622 | # Warning Level |
| 623 | $prj_target_cflags.="-Wall "; |
| 624 | } elsif (/^WX$/) { |
| 625 | # Warnings As Errors |
| 626 | $prj_target_cflags.="-Werror "; |
| 627 | } elsif (/^Gm$/) { |
| 628 | # Enable Minimal Rebuild |
| 629 | } elsif (/^GX$/) { |
| 630 | # Enable Exception Handling |
| 631 | $prj_target_cflags.="-fexceptions "; |
| 632 | } elsif (/^Z[d7iI]$/) { |
| 633 | # Debug Info |
| 634 | $prj_target_cflags.="-g "; |
| 635 | } elsif (/^Od$/) { |
| 636 | # Disable Optimizations |
| 637 | $prj_target_cflags.="-O0 "; |
| 638 | } elsif (/^O1$/) { |
| 639 | # Minimize Size |
| 640 | $prj_target_cflags.="-Os "; |
| 641 | } elsif (/^O2$/) { |
| 642 | # Maximize Speed |
| 643 | $prj_target_cflags.="-O2 "; |
| 644 | } elsif (/^Ob0$/) { |
| 645 | # Disables inline Expansion |
| 646 | $prj_target_cflags.="-fno-inline "; |
| 647 | } elsif (/^Ob1$/) { |
André Hentschel | e1cdd97 | 2009-04-25 16:27:42 +0200 | [diff] [blame] | 648 | #In-line Function Expansion |
| 649 | $prj_target_cflags.="-finline-functions "; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 650 | } elsif (/^Ob2$/) { |
| 651 | # auto In-line Function Expansion |
| 652 | $prj_target_cflags.="-finline-functions "; |
André Hentschel | e1cdd97 | 2009-04-25 16:27:42 +0200 | [diff] [blame] | 653 | } elsif (/^Ox$/) { |
| 654 | # Use maximum optimization |
| 655 | $prj_target_cflags.="-O3 "; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 656 | } elsif (/^Oy$/) { |
| 657 | # Frame-Pointer Omission |
| 658 | $prj_target_cflags.="-fomit-frame-pointer "; |
André Hentschel | dc31d87 | 2009-04-25 16:41:48 +0200 | [diff] [blame] | 659 | } elsif (/^Oy-$/) { |
| 660 | # Frame-Pointer Omission |
| 661 | $prj_target_cflags.="-fno-omit-frame-pointer "; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 662 | } elsif (/^GZ$/) { |
| 663 | # Catch Release-Build Errors in Debug Build |
| 664 | } elsif (/^M[DLT]d?$/) { |
| 665 | # Use Multithreaded Run-Time Library |
| 666 | } elsif (/^D\s*\"(.*)\"/) { |
| 667 | # Preprocessor Definitions |
André Hentschel | e1e9dc3 | 2009-08-13 16:43:37 +0200 | [diff] [blame] | 668 | $prj_target_defines.="-D".$1." "; |
André Hentschel | abc68c1 | 2009-05-19 21:01:55 +0200 | [diff] [blame] | 669 | } elsif (/^I\s*\"(.*)\"/) { |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 670 | # Additional Include Directories |
André Hentschel | abc68c1 | 2009-05-19 21:01:55 +0200 | [diff] [blame] | 671 | $sfilet=$1; |
| 672 | $sfilet=~s/\\/\//g; |
| 673 | push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$sfilet." "; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 674 | } elsif (/^U\s*\"(.*)\"/) { |
| 675 | # Undefines a previously defined symbol |
| 676 | $prj_target_cflags.="-U".$1." "; |
| 677 | } elsif (/^Fp/) { |
| 678 | # Name .PCH File |
| 679 | } elsif (/^F[Rr]/) { |
| 680 | # Create .SBR File |
| 681 | } elsif (/^YX$/) { |
| 682 | # Automatic Use of Precompiled Headers |
| 683 | } elsif (/^FD$/) { |
| 684 | # Generate File Dependencies |
| 685 | } elsif (/^c$/) { |
| 686 | # Compile Without Linking |
| 687 | # this option is always present and is already specified in the suffix rules |
| 688 | } elsif (/^GB$/) { |
| 689 | # Blend Optimization |
| 690 | $prj_target_cflags.="-mcpu=pentiumpro -D_M_IX86=500 "; |
| 691 | } elsif (/^G6$/) { |
| 692 | # Pentium Pro Optimization |
| 693 | $prj_target_cflags.="-march=pentiumpro -D_M_IX86=600 "; |
| 694 | } elsif (/^G5$/) { |
| 695 | # Pentium Optimization |
| 696 | $prj_target_cflags.="-mcpu=pentium -D_M_IX86=500 "; |
| 697 | } elsif (/^G3$/) { |
| 698 | # 80386 Optimization |
| 699 | $prj_target_cflags.="-mcpu=i386 -D_M_IX86=300 "; |
| 700 | } elsif (/^G4$/) { |
| 701 | # 80486 Optimization |
| 702 | $prj_target_cflags.="-mcpu=i486 -D_M_IX86=400 "; |
| 703 | } elsif (/^Yc/) { |
| 704 | # Create Precompiled Header |
| 705 | } elsif (/^Yu/) { |
| 706 | # Use Precompiled Header |
| 707 | } elsif (/^Za$/) { |
| 708 | # Disable Language Extensions |
| 709 | $prj_target_cflags.="-ansi "; |
| 710 | } elsif (/^Ze$/) { |
| 711 | # Enable Microsoft Extensions |
| 712 | } elsif (/^Zm[[:digit:]]+$/) { |
| 713 | # Specify Memory Allocation Limit |
| 714 | } elsif (/^Zp1?$/) { |
| 715 | # Packs structures on 1-byte boundaries |
| 716 | $prj_target_cflags.="-fpack-struct "; |
| 717 | } elsif (/^Zp(2|4|8|16)$/) { |
| 718 | # Struct Member Alignment |
| 719 | $prj_target_cflags.="-fpack-struct=".$1; |
| 720 | } else { |
| 721 | print "C compiler option $_ not implemented\n"; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | #print "\nOptions: $prj_target_cflags\n"; |
| 726 | next; |
| 727 | } elsif (/^# ADD LINK32(.*)/ && $found_cfg==1) { |
| 728 | $prj_target_ldflags=$1; |
| 729 | @prj_target_options=split(" /", $prj_target_ldflags); |
| 730 | $prj_target_ldflags=""; |
| 731 | $prj_target_libs=$prj_target_options[0]; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 732 | $prj_target_libs=~s/\\/\//g; |
| 733 | $prj_target_libs=~s/\.lib//g; |
André Hentschel | b09d6d0 | 2009-04-21 20:32:34 +0200 | [diff] [blame] | 734 | $prj_target_libs=~s/\s+/ -l/g; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 735 | shift (@prj_target_options); |
| 736 | foreach ( @prj_target_options ) { |
| 737 | if ($_ eq "") { |
| 738 | # empty |
| 739 | } elsif (/^base:(.*)/) { |
| 740 | # Base Address |
| 741 | $prj_target_ldflags.="--image-base ".$1." "; |
| 742 | } elsif (/^debug$/) { |
| 743 | # Generate Debug Info |
| 744 | } elsif (/^dll$/) { |
| 745 | # Build a DLL |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 746 | $prj_target_type=$TT_DLL; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 747 | } elsif (/^incremental:[[:alpha:]]+$/) { |
| 748 | # Link Incrmentally |
| 749 | } elsif (/^implib:/) { |
| 750 | # Name import library |
| 751 | } elsif (/^libpath:\"(.*)\"/) { |
| 752 | # Additional Libpath |
| 753 | push @{@$project_settings[$T_DLL_PATH]},"-L$1"; |
| 754 | } elsif (/^machine:[[:alnum:]]+$/) { |
| 755 | # Specify Target Platform |
| 756 | } elsif (/^map/) { |
| 757 | # Generate Mapfile |
| 758 | if (/^map:(.*)/) { |
| 759 | $prj_target_ldflags.="-Map ".$1." "; |
| 760 | } else { |
| 761 | $prj_target_ldflags.="-Map ".$prj_name.".map "; |
| 762 | } |
| 763 | } elsif (/^nologo$/) { |
| 764 | # Suppress Startup Banner and Information Messages |
| 765 | } elsif (/^out:/) { |
| 766 | # Output File Name |
| 767 | # may use it as Target? |
| 768 | } elsif (/^pdbtype:/) { |
| 769 | # Program Database Storage |
| 770 | } elsif (/^subsystem:/) { |
| 771 | # Specify Subsystem |
| 772 | } elsif (/^version:[[:digit:].]+$/) { |
| 773 | # Version Information |
| 774 | } else { |
| 775 | print "Linker option $_ not implemented\n"; |
| 776 | } |
| 777 | } |
| 778 | next; |
| 779 | } elsif (/^LIB32=/ && $found_cfg==1) { |
| 780 | #$libflag = 1; |
| 781 | next; |
| 782 | } elsif (/^SOURCE=(.*)$/) { |
| 783 | my @components=split /[\/\\]+/, $1; |
| 784 | $sfilet=search_from($path, \@components); |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 785 | if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) { |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 786 | push @sources_c,$sfilet; |
| 787 | } elsif ($sfilet =~ /\.(cpp|cxx)$/i) { |
| 788 | if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) { |
| 789 | push @sources_misc,$sfilet; |
| 790 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
| 791 | } else { |
| 792 | push @sources_cxx,$sfilet; |
| 793 | } |
| 794 | } elsif ($sfilet =~ /\.rc$/i) { |
| 795 | push @sources_rc,$sfilet; |
| 796 | } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) { |
| 797 | push @sources_misc,$sfilet; |
| 798 | if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) { |
| 799 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
| 800 | } |
| 801 | } |
| 802 | next; |
| 803 | |
| 804 | } elsif (/^# (Begin|End) Source File/) { |
| 805 | # Source-Files already handled |
| 806 | next; |
| 807 | } elsif (/^# (Begin|End) Group/) { |
| 808 | # Groups are ignored |
| 809 | next; |
| 810 | } elsif (/^# (Begin|End) Custom Build/) { |
| 811 | # Custom Builds are ignored |
| 812 | next; |
| 813 | } elsif (/^# ADD LIB32 /) { |
| 814 | #"ARFLAGS=rus" |
| 815 | next; |
| 816 | } elsif (/^# Begin Target$/) { |
| 817 | # Targets are ignored |
| 818 | next; |
| 819 | } elsif (/^# End Target$/) { |
| 820 | # Targets are ignored |
| 821 | next; |
| 822 | } elsif (/^!/) { |
| 823 | if ($found_cfg == 1) { |
| 824 | $found_cfg=0; |
| 825 | } |
| 826 | if (/if (.*)\(CFG\)" == "(.*)"/i) { |
| 827 | if ($2 eq $prj_cfg) { |
| 828 | $found_cfg=1; |
| 829 | } |
| 830 | } |
| 831 | next; |
| 832 | } elsif (/^CFG=(.*)/i) { |
| 833 | $prj_cfg=$1; |
| 834 | next; |
| 835 | } |
| 836 | else { # Line recognized |
| 837 | # print "|\n"; |
| 838 | } |
| 839 | } |
| 840 | close(FILEI); |
| 841 | |
| 842 | push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs; |
| 843 | push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags; |
| 844 | push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags; |
André Hentschel | e1e9dc3 | 2009-08-13 16:43:37 +0200 | [diff] [blame] | 845 | push @{@$project_settings[$T_DEFINES]},$prj_target_defines; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 846 | push @{@$project_settings[$T_LDFLAGS]},$prj_target_ldflags; |
| 847 | } elsif ($filename =~ /.vcproj$/i) { |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 848 | # Import XML::LibXML, you need the libxml package (deb: libxml-libxml-perl, rpm: perl-libxml-perl) |
| 849 | require XML::LibXML; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 850 | |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 851 | my $xmlparser = XML::LibXML->new(); |
| 852 | my $project_xml = $xmlparser->parse_file($filename); |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 853 | my $sfilet; |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 854 | my $configt; |
| 855 | |
| 856 | foreach my $vc_project ($project_xml->findnodes('/VisualStudioProject')) { |
| 857 | foreach my $vc_project_attr ($vc_project->attributes) { |
| 858 | if ($vc_project_attr->getName eq "Name") { |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 859 | $prj_name=$vc_project_attr->getValue; |
André Hentschel | 5f059ed | 2009-11-21 18:13:44 +0100 | [diff] [blame] | 860 | $prj_name=~s/\s+/_/g; |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 861 | last; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | for (my $flevel = 0; $flevel <= 5; $flevel++) { |
| 867 | foreach my $vc_file ($project_xml->findnodes('/VisualStudioProject/Files/'.('Filter/' x $flevel).'File')) { |
| 868 | foreach my $vc_file_attr ($vc_file->attributes) { |
| 869 | if ($vc_file_attr->getName eq "RelativePath") { |
| 870 | $sfilet = $vc_file_attr->getValue; |
| 871 | $sfilet=~s/\\\\/\\/g; #remove double backslash |
| 872 | $sfilet=~s/^\.\\//; #remove starting 'this directory' |
| 873 | $sfilet=~s/\\/\//g; #make slashes out of backslashes |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 874 | if ($sfilet =~ /\.c$/i and $sfilet !~ /\.(dbg|spec)\.c$/) { |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 875 | push @sources_c,$sfilet; |
| 876 | } elsif ($sfilet =~ /\.(cpp|cxx)$/i) { |
| 877 | if ($sfilet =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) { |
| 878 | push @sources_misc,$sfilet; |
| 879 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
| 880 | } else { |
| 881 | push @sources_cxx,$sfilet; |
| 882 | } |
| 883 | } elsif ($sfilet =~ /\.rc$/i) { |
| 884 | push @sources_rc,$sfilet; |
| 885 | } elsif ($sfilet =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) { |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 886 | push @sources_misc,$sfilet; |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 887 | if ($sfilet =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) { |
| 888 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
| 889 | } |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | } |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 895 | |
| 896 | my @vc_configurations = $project_xml->findnodes('/VisualStudioProject/Configurations/Configuration'); |
| 897 | my $vc_configuration = $vc_configurations[0]; |
| 898 | foreach my $vc_configuration_attr ($vc_configuration->attributes) { |
| 899 | if ($vc_configuration_attr->getName eq "ConfigurationType") { |
| 900 | if ($vc_configuration_attr->getValue==1) { |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 901 | $prj_target_type=$TT_GUIEXE; # Application |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 902 | } elsif ($vc_configuration_attr->getValue==2) { |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 903 | $prj_target_type=$TT_DLL; # Dynamic-Link Library |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 904 | } |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 905 | } |
| 906 | } |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 907 | |
| 908 | foreach my $vc_configuration_tools ($vc_configuration->findnodes('Tool')) { |
| 909 | my @find_tool = $vc_configuration_tools->attributes; |
André Hentschel | c9cea6f | 2009-08-10 17:44:09 +0200 | [diff] [blame] | 910 | if ($find_tool[0]->getValue eq "VCCLCompilerTool") { |
| 911 | foreach my $vc_compiler_tool ($vc_configuration_tools->attributes) { |
| 912 | if ($vc_compiler_tool->getName eq "Optimization") {$prj_target_cflags.="-O".$vc_compiler_tool->getValue." ";} |
| 913 | if ($vc_compiler_tool->getName eq "WarningLevel") { |
| 914 | if ($vc_compiler_tool->getValue==0) { |
| 915 | $prj_target_cflags.="-w "; |
| 916 | } elsif ($vc_compiler_tool->getValue<4) { |
| 917 | $prj_target_cflags.="-W "; |
| 918 | } elsif ($vc_compiler_tool->getValue==4) { |
| 919 | $prj_target_cflags.="-Wall "; |
| 920 | } elsif ($vc_compiler_tool->getValue eq "X") { |
| 921 | $prj_target_cflags.="-Werror "; |
| 922 | } |
| 923 | } |
| 924 | if ($vc_compiler_tool->getName eq "PreprocessorDefinitions") { |
| 925 | $configt=$vc_compiler_tool->getValue; |
| 926 | $configt=~s/;/ -D/g; |
André Hentschel | e1e9dc3 | 2009-08-13 16:43:37 +0200 | [diff] [blame] | 927 | $prj_target_defines.="-D".$configt." "; |
André Hentschel | c9cea6f | 2009-08-10 17:44:09 +0200 | [diff] [blame] | 928 | } |
| 929 | if ($vc_compiler_tool->getName eq "AdditionalIncludeDirectories") { |
| 930 | $configt=$vc_compiler_tool->getValue; |
| 931 | $configt=~s/\\/\//g; |
| 932 | $configt=~s/;/ -I/g; |
| 933 | push @{@$project_settings[$T_INCLUDE_PATH]},"-I".$configt; |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 934 | } |
| 935 | } |
André Hentschel | c9cea6f | 2009-08-10 17:44:09 +0200 | [diff] [blame] | 936 | } |
| 937 | if ($find_tool[0]->getValue eq "VCLinkerTool") { |
| 938 | foreach my $vc_linker_tool ($vc_configuration_tools->attributes) { |
| 939 | if ($vc_linker_tool->getName eq "AdditionalDependencies") { |
| 940 | $prj_target_libs=" ".$vc_linker_tool->getValue; |
| 941 | $prj_target_libs=~s/\\/\//g; |
| 942 | $prj_target_libs=~s/\.lib//g; |
| 943 | $prj_target_libs=~s/\s+/ -l/g; |
| 944 | } |
André Hentschel | 89ec1f1 | 2009-05-30 16:58:30 +0200 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | } |
| 948 | |
André Hentschel | c9cea6f | 2009-08-10 17:44:09 +0200 | [diff] [blame] | 949 | push @{@$project_settings[$T_LIBRARIES]},$prj_target_libs; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 950 | push @{@$project_settings[$T_CEXTRA]},$prj_target_cflags; |
| 951 | push @{@$project_settings[$T_CXXEXTRA]},$prj_target_cflags; |
André Hentschel | e1e9dc3 | 2009-08-13 16:43:37 +0200 | [diff] [blame] | 952 | push @{@$project_settings[$T_DEFINES]},$prj_target_defines; |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 953 | } |
| 954 | |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 955 | # Add this project to the project list, except for |
| 956 | # the main project which is already in the list. |
| 957 | if ($is_sub_project == 1) { |
| 958 | push @projects,$project; |
| 959 | } |
| 960 | |
| 961 | # Ask for project-wide options |
| 962 | if ($opt_ask_project_options == $OPT_ASK_YES) { |
| 963 | my $flag_desc=""; |
| 964 | if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) { |
| 965 | $flag_desc="mfc"; |
| 966 | } |
| 967 | print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n"; |
| 968 | if (defined $flag_desc) { |
| 969 | print "* (currently $flag_desc)\n"; |
| 970 | } |
| 971 | print "* or 'skip' to skip the target specific options,\n"; |
| 972 | print "* or 'never' to not be asked this question again:\n"; |
| 973 | while (1) { |
| 974 | my $options=<STDIN>; |
| 975 | chomp $options; |
| 976 | if ($options eq "skip") { |
| 977 | $opt_ask_target_options=$OPT_ASK_SKIP; |
| 978 | last; |
| 979 | } elsif ($options eq "never") { |
| 980 | $opt_ask_project_options=$OPT_ASK_NO; |
| 981 | last; |
| 982 | } elsif (source_set_options($project_settings,$options)) { |
| 983 | last; |
| 984 | } |
| 985 | print "Please re-enter the options:\n"; |
| 986 | } |
| 987 | } |
| 988 | |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 989 | my @local_dlls=(); |
| 990 | my @local_depends=(); |
| 991 | my @exe_list=(); |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 992 | |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 993 | # Create the target... |
| 994 | my $target=[]; |
| 995 | target_init($target); |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 996 | |
André Hentschel | ebde805 | 2010-05-10 19:59:01 +0200 | [diff] [blame] | 997 | if ($prj_target_type!=$TT_DLL) { |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 998 | $prj_name=lc($prj_name.".exe"); |
| 999 | @$target[$T_TYPE]=$opt_target_type; |
| 1000 | push @exe_list,$target; |
| 1001 | push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows"); |
| 1002 | } else { |
| 1003 | $prj_name=lc($prj_name.".dll"); |
| 1004 | @$target[$T_TYPE]=$TT_DLL; |
| 1005 | push @local_depends,"$prj_name.so"; |
| 1006 | push @local_dlls,$prj_name; |
| 1007 | my $canon=canonize($prj_name); |
| 1008 | push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)"); |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 1009 | } |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 1010 | |
| 1011 | @$target[$T_NAME]=$prj_name; |
| 1012 | @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS]; |
| 1013 | |
| 1014 | # This is the default link list of Visual Studio |
| 1015 | my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32); |
| 1016 | my @std_libraries=qw(uuid); |
| 1017 | if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) { |
| 1018 | @$target[$T_DLLS]=\@std_imports; |
| 1019 | @$target[$T_LIBRARIES]=\@std_libraries; |
| 1020 | } else { |
| 1021 | @$target[$T_DLLS]=[]; |
| 1022 | @$target[$T_LIBRARIES]=[]; |
| 1023 | } |
| 1024 | if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) { |
| 1025 | push @{@$target[$T_LDFLAGS]},"-mno-cygwin"; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 1026 | if ($opt_arch != $OPT_ARCH_DEFAULT) { |
| 1027 | push @{@$target[$T_LDFLAGS]},"-m$opt_arch"; |
| 1028 | } |
André Hentschel | c0bd291 | 2009-08-29 13:10:01 +0200 | [diff] [blame] | 1029 | } |
| 1030 | push @{@$project[$P_TARGETS]},$target; |
| 1031 | |
| 1032 | # Ask for target-specific options |
| 1033 | if ($opt_ask_target_options == $OPT_ASK_YES) { |
| 1034 | my $flag_desc=""; |
| 1035 | if ((@$target[$T_FLAGS] & $TF_MFC)!=0) { |
| 1036 | $flag_desc=" (mfc"; |
| 1037 | } |
| 1038 | if ($flag_desc ne "") { |
| 1039 | $flag_desc.=")"; |
| 1040 | } |
| 1041 | print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n"; |
| 1042 | print "* \"$prj_name\"$flag_desc or 'never' to not be asked this question again:\n"; |
| 1043 | while (1) { |
| 1044 | my $options=<STDIN>; |
| 1045 | chomp $options; |
| 1046 | if ($options eq "never") { |
| 1047 | $opt_ask_target_options=$OPT_ASK_NO; |
| 1048 | last; |
| 1049 | } elsif (source_set_options($target,$options)) { |
| 1050 | last; |
| 1051 | } |
| 1052 | print "Please re-enter the options:\n"; |
| 1053 | } |
| 1054 | } |
| 1055 | if (@$target[$T_FLAGS] & $TF_MFC) { |
| 1056 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
| 1057 | push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)"; |
| 1058 | push @{@$target[$T_DLLS]},"mfc.dll"; |
| 1059 | # FIXME: Link with the MFC in the Unix sense, until we |
| 1060 | # start exporting the functions properly. |
| 1061 | push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)"; |
| 1062 | push @{@$target[$T_LIBRARIES]},"mfc"; |
| 1063 | } |
| 1064 | |
| 1065 | # Match sources... |
| 1066 | push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c; |
| 1067 | @$project_settings[$T_SOURCES_C]=[]; |
| 1068 | @sources_c=(); |
| 1069 | push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx; |
| 1070 | @$project_settings[$T_SOURCES_CXX]=[]; |
| 1071 | @sources_cxx=(); |
| 1072 | push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc; |
| 1073 | @$project_settings[$T_SOURCES_RC]=[]; |
| 1074 | @sources_rc=(); |
| 1075 | push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc; |
| 1076 | @$project_settings[$T_SOURCES_MISC]=[]; |
| 1077 | @sources_misc=(); |
| 1078 | |
| 1079 | @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}]; |
| 1080 | @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}]; |
| 1081 | @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}]; |
| 1082 | @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}]; |
| 1083 | |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 1084 | if ($opt_ask_target_options == $OPT_ASK_SKIP) { |
| 1085 | $opt_ask_target_options=$OPT_ASK_YES; |
| 1086 | } |
| 1087 | |
| 1088 | if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) { |
| 1089 | push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin"; |
| 1090 | push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin"; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 1091 | if ($opt_arch != $OPT_ARCH_DEFAULT) { |
| 1092 | push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch"; |
| 1093 | push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch"; |
| 1094 | } |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (@$project_settings[$T_FLAGS] & $TF_MFC) { |
| 1098 | push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)"; |
| 1099 | } |
| 1100 | # The sources that did not match, if any, go to the extra |
| 1101 | # source list of the project settings |
| 1102 | foreach my $source (@sources_c) { |
| 1103 | if ($source ne "") { |
| 1104 | push @{@$project_settings[$T_SOURCES_C]},$source; |
| 1105 | } |
| 1106 | } |
| 1107 | @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}]; |
| 1108 | foreach my $source (@sources_cxx) { |
| 1109 | if ($source ne "") { |
| 1110 | push @{@$project_settings[$T_SOURCES_CXX]},$source; |
| 1111 | } |
| 1112 | } |
| 1113 | @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}]; |
| 1114 | foreach my $source (@sources_rc) { |
| 1115 | if ($source ne "") { |
| 1116 | push @{@$project_settings[$T_SOURCES_RC]},$source; |
| 1117 | } |
| 1118 | } |
| 1119 | @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}]; |
| 1120 | foreach my $source (@sources_misc) { |
| 1121 | if ($source ne "") { |
| 1122 | push @{@$project_settings[$T_SOURCES_MISC]},$source; |
| 1123 | } |
| 1124 | } |
| 1125 | @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}]; |
| 1126 | } |
| 1127 | |
| 1128 | ## |
André Hentschel | df5c417 | 2009-04-02 18:53:24 +0200 | [diff] [blame] | 1129 | # Scans the specified workspace file to find the project files |
| 1130 | sub source_scan_workspace_file($); |
| 1131 | sub source_scan_workspace_file($) |
| 1132 | { |
| 1133 | my $filename=$_[0]; |
| 1134 | my $path=dirname($filename); |
| 1135 | my @components; |
| 1136 | |
| 1137 | if (! -e $filename) { |
| 1138 | return; |
| 1139 | } |
| 1140 | |
| 1141 | if (!open(FILEIWS,$filename)) { |
| 1142 | print STDERR "error: unable to open $filename for reading:\n"; |
| 1143 | print STDERR " $!\n"; |
| 1144 | return; |
| 1145 | } |
| 1146 | |
| 1147 | my $prj_name; |
| 1148 | my $prj_path; |
| 1149 | |
| 1150 | if ($filename =~ /.dsw$/i) { |
| 1151 | while (<FILEIWS>) { |
| 1152 | # Remove any trailing CrLf |
| 1153 | s/\r\n$/\n/; |
| 1154 | |
| 1155 | # catch a project definition |
André Hentschel | 925b144 | 2009-05-01 11:37:13 +0200 | [diff] [blame] | 1156 | if (/^Project:\s\"(.*)\"=(.*)\s-/) { |
André Hentschel | df5c417 | 2009-04-02 18:53:24 +0200 | [diff] [blame] | 1157 | $prj_name=$1; |
| 1158 | $prj_path=$2; |
André Hentschel | 1199d05 | 2009-04-25 15:47:59 +0200 | [diff] [blame] | 1159 | @components=split /[\/\\]+/, $prj_path; |
André Hentschel | df5c417 | 2009-04-02 18:53:24 +0200 | [diff] [blame] | 1160 | $prj_path=search_from($path, \@components); |
| 1161 | print "Name: $prj_name\nPath: $prj_path\n"; |
| 1162 | source_scan_project_file(\@main_project,1,$prj_path); |
| 1163 | next; |
| 1164 | } elsif (/^#/) { |
| 1165 | # ignore Comments |
| 1166 | } elsif (/\w:/) { |
| 1167 | print STDERR "unknown section $_\n"; |
| 1168 | } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) { |
| 1169 | print "\nFileversion: $3\n"; |
| 1170 | } |
| 1171 | } |
| 1172 | close(FILEIWS); |
| 1173 | } elsif ($filename =~ /.sln$/i) { |
| 1174 | while (<FILEIWS>) { |
| 1175 | # Remove any trailing CrLf |
| 1176 | s/\r\n$/\n/; |
| 1177 | |
| 1178 | # catch a project definition |
| 1179 | if (/^Project(.*)=\s*"(.*)",\s*"(.*)",\s*"(.*)"/) { |
| 1180 | $prj_name=$2; |
| 1181 | $prj_path=$3; |
| 1182 | @components=split /[\/\\]+/, $3; |
| 1183 | $prj_path=search_from($path, \@components); |
| 1184 | print "Name: $prj_name\nPath: $prj_path\n"; |
| 1185 | source_scan_project_file(\@main_project,1,$prj_path); |
| 1186 | next; |
| 1187 | } elsif (/^Microsoft(.*)Studio(.*)File,\sFormat Version\s(.*)/) { |
| 1188 | print "\nFileversion: $3\n"; |
| 1189 | } |
| 1190 | } |
| 1191 | close(FILEIWS); |
| 1192 | } |
| 1193 | |
| 1194 | @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects; |
| 1195 | } |
| 1196 | |
| 1197 | ## |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1198 | # Scans the specified directory to: |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1199 | # - see if we should create a Makefile in this directory. We normally do |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1200 | # so if we find a project file and sources |
| 1201 | # - get a list of targets for this directory |
| 1202 | # - get the list of source files |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1203 | sub source_scan_directory($$$$); |
| 1204 | sub source_scan_directory($$$$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1205 | { |
| 1206 | # a reference to the parent's project |
| 1207 | my $parent_project=$_[0]; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1208 | # the full relative path to the current directory, including a |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1209 | # trailing '/', or an empty string if this is the top level directory |
| 1210 | my $path=$_[1]; |
| 1211 | # the name of this directory, including a trailing '/', or an empty |
| 1212 | # string if this is the top level directory |
| 1213 | my $dirname=$_[2]; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1214 | # if set then no targets will be looked for and the sources will all |
Francois Gouget | 3266b88 | 2001-03-03 00:17:11 +0000 | [diff] [blame] | 1215 | # end up in the parent_project's 'misc' bucket |
| 1216 | my $no_target=$_[3]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1217 | |
| 1218 | # reference to the project for this directory. May not be used |
| 1219 | my $project; |
| 1220 | # list of targets found in the 'current' directory |
| 1221 | my %targets; |
| 1222 | # list of sources found in the current directory |
| 1223 | my @sources_c=(); |
| 1224 | my @sources_cxx=(); |
| 1225 | my @sources_rc=(); |
| 1226 | my @sources_misc=(); |
| 1227 | # true if this directory contains a Windows project |
| 1228 | my $has_win_project=0; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1229 | # true if this directory contains headers |
| 1230 | my $has_headers=0; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1231 | # If we don't find any executable/library then we might make up targets |
| 1232 | # from the list of .dsp/.mak files we find since they usually have the |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1233 | # same name as their target. |
André Hentschel | bb8f2c4 | 2010-05-10 19:58:12 +0200 | [diff] [blame] | 1234 | my @prj_files=(); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1235 | my @mak_files=(); |
| 1236 | |
| 1237 | if (defined $opt_single_target or $dirname eq "") { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1238 | # Either there is a single target and thus a single project, |
| 1239 | # or we are in the top level directory for which a project |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1240 | # already exists |
| 1241 | $project=$parent_project; |
| 1242 | } else { |
| 1243 | $project=[]; |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 1244 | project_init($project, $path, \@global_settings); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1245 | } |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1246 | my $project_settings=@$project[$P_SETTINGS]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1247 | |
| 1248 | # First find out what this directory contains: |
| 1249 | # collect all sources, targets and subdirectories |
| 1250 | my $directory=get_directory_contents($path); |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1251 | foreach my $dentry (@$directory) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1252 | if ($dentry =~ /^\./) { |
| 1253 | next; |
| 1254 | } |
| 1255 | my $fullentry="$path$dentry"; |
| 1256 | if (-d "$fullentry") { |
| 1257 | if ($dentry =~ /^(Release|Debug)/i) { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1258 | # These directories are often used to store the object files and the |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1259 | # resulting executable/library. They should not contain anything else. |
| 1260 | my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")}; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1261 | foreach my $candidate (@candidates) { |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1262 | $targets{$candidate}=1; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1263 | } |
Francois Gouget | 4ec1059 | 2000-12-02 20:12:45 +0000 | [diff] [blame] | 1264 | } elsif ($dentry =~ /^include/i) { |
| 1265 | # This directory must contain headers we're going to need |
| 1266 | push @{@$project_settings[$T_INCLUDE_PATH]},"-I$dentry"; |
Francois Gouget | 3266b88 | 2001-03-03 00:17:11 +0000 | [diff] [blame] | 1267 | source_scan_directory($project,"$fullentry/","$dentry/",1); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1268 | } else { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1269 | # Recursively scan this directory. Any source file that cannot be |
| 1270 | # attributed to a project in one of the subdirectories will be |
Francois Gouget | 3266b88 | 2001-03-03 00:17:11 +0000 | [diff] [blame] | 1271 | # attributed to this project. |
| 1272 | source_scan_directory($project,"$fullentry/","$dentry/",$no_target); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1273 | } |
| 1274 | } elsif (-f "$fullentry") { |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1275 | if ($dentry =~ /\.(exe|dll)$/i) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1276 | $targets{$dentry}=1; |
Francois Gouget | 1dd5325 | 2003-10-28 21:13:54 +0000 | [diff] [blame] | 1277 | } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.(dbg|spec)\.c$/) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1278 | push @sources_c,"$dentry"; |
| 1279 | } elsif ($dentry =~ /\.(cpp|cxx)$/i) { |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 1280 | if ($dentry =~ /^stdafx.cpp$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1281 | push @sources_misc,"$dentry"; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 1282 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1283 | } else { |
| 1284 | push @sources_cxx,"$dentry"; |
| 1285 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1286 | } elsif ($dentry =~ /\.rc$/i) { |
| 1287 | push @sources_rc,"$dentry"; |
Francois Gouget | 3c6c20f | 2001-03-23 19:07:59 +0000 | [diff] [blame] | 1288 | } elsif ($dentry =~ /\.(h|hxx|hpp|inl|rc2|dlg)$/i) { |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1289 | $has_headers=1; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1290 | push @sources_misc,"$dentry"; |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 1291 | if ($dentry =~ /^stdafx.h$/i && !(@$project_settings[$T_FLAGS] & $TF_NOMFC)) { |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 1292 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1293 | } |
André Hentschel | bb8f2c4 | 2010-05-10 19:58:12 +0200 | [diff] [blame] | 1294 | } elsif ($dentry =~ /\.(dsp|vcproj)$/i) { |
| 1295 | push @prj_files,"$dentry"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1296 | $has_win_project=1; |
| 1297 | } elsif ($dentry =~ /\.mak$/i) { |
| 1298 | push @mak_files,"$dentry"; |
| 1299 | $has_win_project=1; |
| 1300 | } elsif ($dentry =~ /^makefile/i) { |
| 1301 | $has_win_project=1; |
| 1302 | } |
| 1303 | } |
| 1304 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1305 | |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1306 | if ($has_headers) { |
| 1307 | push @{@$project_settings[$T_INCLUDE_PATH]},"-I."; |
| 1308 | } |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1309 | # If we have a single target then all we have to do is assign |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1310 | # all the sources to it and we're done |
| 1311 | # FIXME: does this play well with the --interactive mode? |
| 1312 | if ($opt_single_target) { |
| 1313 | my $target=@{@$project[$P_TARGETS]}[0]; |
| 1314 | push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c; |
| 1315 | push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx; |
| 1316 | push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc; |
| 1317 | push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc; |
| 1318 | return; |
| 1319 | } |
Francois Gouget | 3266b88 | 2001-03-03 00:17:11 +0000 | [diff] [blame] | 1320 | if ($no_target) { |
| 1321 | my $parent_settings=@$parent_project[$P_SETTINGS]; |
| 1322 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_c; |
| 1323 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_cxx; |
| 1324 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_rc; |
| 1325 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc; |
Francois Gouget | 647bb8f | 2001-04-20 18:26:35 +0000 | [diff] [blame] | 1326 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]}; |
Francois Gouget | 3266b88 | 2001-03-03 00:17:11 +0000 | [diff] [blame] | 1327 | return; |
| 1328 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1329 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1330 | my $source_count=@sources_c+@sources_cxx+@sources_rc+ |
| 1331 | @{@$project_settings[$T_SOURCES_C]}+ |
| 1332 | @{@$project_settings[$T_SOURCES_CXX]}+ |
| 1333 | @{@$project_settings[$T_SOURCES_RC]}; |
| 1334 | if ($source_count == 0) { |
| 1335 | # A project without real sources is not a project, get out! |
| 1336 | if ($project!=$parent_project) { |
Francois Gouget | 3266b88 | 2001-03-03 00:17:11 +0000 | [diff] [blame] | 1337 | my $parent_settings=@$parent_project[$P_SETTINGS]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1338 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc; |
| 1339 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]}; |
| 1340 | } |
| 1341 | return; |
| 1342 | } |
| 1343 | #print "targets=",%targets,"\n"; |
| 1344 | #print "target_count=$target_count\n"; |
| 1345 | #print "has_win_project=$has_win_project\n"; |
| 1346 | #print "dirname=$dirname\n"; |
| 1347 | |
| 1348 | my $target_count; |
| 1349 | if (($has_win_project != 0) or ($dirname eq "")) { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1350 | # Deal with cases where we could not find any executable/library, and |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1351 | # thus have no target, although we did find some sort of windows project. |
| 1352 | $target_count=keys %targets; |
| 1353 | if ($target_count == 0) { |
| 1354 | # Try to come up with a target list based on .dsp/.mak files |
| 1355 | my $prj_list; |
André Hentschel | bb8f2c4 | 2010-05-10 19:58:12 +0200 | [diff] [blame] | 1356 | if (@prj_files > 0) { |
André Hentschel | 1a8fdf0 | 2010-05-11 20:03:04 +0200 | [diff] [blame] | 1357 | print "Projectfile found! You might want to try using it directly.\n"; |
André Hentschel | bb8f2c4 | 2010-05-10 19:58:12 +0200 | [diff] [blame] | 1358 | $prj_list=\@prj_files; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1359 | } else { |
André Hentschel | bb8f2c4 | 2010-05-10 19:58:12 +0200 | [diff] [blame] | 1360 | $prj_list=\@mak_files; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1361 | } |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1362 | foreach my $filename (@$prj_list) { |
André Hentschel | bb8f2c4 | 2010-05-10 19:58:12 +0200 | [diff] [blame] | 1363 | $filename =~ s/\.(dsp|vcproj|mak)$//i; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1364 | if ($opt_target_type == $TT_DLL) { |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1365 | $filename = "$filename.dll"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1366 | } |
| 1367 | $targets{$filename}=1; |
| 1368 | } |
| 1369 | $target_count=keys %targets; |
| 1370 | if ($target_count == 0) { |
| 1371 | # Still nothing, try the name of the directory |
| 1372 | my $name; |
| 1373 | if ($dirname eq "") { |
| 1374 | # Bad luck, this is the top level directory! |
| 1375 | $name=(split /\//, cwd)[-1]; |
| 1376 | } else { |
| 1377 | $name=$dirname; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1378 | # Remove the trailing '/'. Also eliminate whatever is after the last |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1379 | # '.' as it is likely to be meaningless (.orig, .new, ...) |
| 1380 | $name =~ s+(/|\.[^.]*)$++; |
| 1381 | if ($name eq "src") { |
| 1382 | # 'src' is probably a subdirectory of the real project directory. |
| 1383 | # Try again with the parent (if any). |
| 1384 | my $parent=$path; |
| 1385 | if ($parent =~ s+([^/]*)/[^/]*/$+$1+) { |
| 1386 | $name=$parent; |
| 1387 | } else { |
| 1388 | $name=(split /\//, cwd)[-1]; |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | $name =~ s+(/|\.[^.]*)$++; |
| 1393 | if ($opt_target_type == $TT_DLL) { |
André Hentschel | 6a5be43 | 2009-04-23 20:41:32 +0200 | [diff] [blame] | 1394 | $name = canonize($name).".dll"; |
Jeff Smith | caa74b6 | 2003-01-02 19:27:23 +0000 | [diff] [blame] | 1395 | } else { |
André Hentschel | 6a5be43 | 2009-04-23 20:41:32 +0200 | [diff] [blame] | 1396 | $name = canonize($name).".exe"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1397 | } |
| 1398 | $targets{$name}=1; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | # Ask confirmation to the user if he wishes so |
| 1403 | if ($opt_is_interactive == $OPT_ASK_YES) { |
| 1404 | my $target_list=join " ",keys %targets; |
Francois Gouget | fb5b590 | 2000-11-30 20:34:39 +0000 | [diff] [blame] | 1405 | print "\n*** In ",($path?$path:"./"),"\n"; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1406 | print "* winemaker found the following list of (potential) targets\n"; |
| 1407 | print "* $target_list\n"; |
| 1408 | print "* Type enter to use it as is, your own comma-separated list of\n"; |
| 1409 | print "* targets, 'none' to assign the source files to a parent directory,\n"; |
| 1410 | print "* or 'ignore' to ignore everything in this directory tree.\n"; |
| 1411 | print "* Target list:\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1412 | $target_list=<STDIN>; |
| 1413 | chomp $target_list; |
| 1414 | if ($target_list eq "") { |
| 1415 | # Keep the target list as is, i.e. do nothing |
| 1416 | } elsif ($target_list eq "none") { |
| 1417 | # Empty the target list |
| 1418 | undef %targets; |
| 1419 | } elsif ($target_list eq "ignore") { |
| 1420 | # Ignore this subtree altogether |
| 1421 | return; |
| 1422 | } else { |
| 1423 | undef %targets; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1424 | foreach my $target (split /,/,$target_list) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1425 | $target =~ s+^\s*++; |
| 1426 | $target =~ s+\s*$++; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1427 | $targets{$target}=1; |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1433 | # If we have no project at this level, then transfer all |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1434 | # the sources to the parent project |
| 1435 | $target_count=keys %targets; |
| 1436 | if ($target_count == 0) { |
| 1437 | if ($project!=$parent_project) { |
| 1438 | my $parent_settings=@$parent_project[$P_SETTINGS]; |
| 1439 | push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c; |
| 1440 | push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx; |
| 1441 | push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc; |
| 1442 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc; |
| 1443 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]}; |
| 1444 | } |
| 1445 | return; |
| 1446 | } |
| 1447 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1448 | # Otherwise add this project to the project list, except for |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1449 | # the main project which is already in the list. |
| 1450 | if ($dirname ne "") { |
| 1451 | push @projects,$project; |
| 1452 | } |
| 1453 | |
| 1454 | # Ask for project-wide options |
| 1455 | if ($opt_ask_project_options == $OPT_ASK_YES) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1456 | my $flag_desc=""; |
| 1457 | if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) { |
| 1458 | $flag_desc="mfc"; |
| 1459 | } |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 1460 | print "* Type any project-wide options (-D/-I/-P/-i/-L/-l/--mfc),\n"; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1461 | if (defined $flag_desc) { |
| 1462 | print "* (currently $flag_desc)\n"; |
| 1463 | } |
| 1464 | print "* or 'skip' to skip the target specific options,\n"; |
| 1465 | print "* or 'never' to not be asked this question again:\n"; |
Francois Gouget | 3af251e | 2000-11-30 20:36:04 +0000 | [diff] [blame] | 1466 | while (1) { |
| 1467 | my $options=<STDIN>; |
| 1468 | chomp $options; |
| 1469 | if ($options eq "skip") { |
| 1470 | $opt_ask_target_options=$OPT_ASK_SKIP; |
| 1471 | last; |
| 1472 | } elsif ($options eq "never") { |
| 1473 | $opt_ask_project_options=$OPT_ASK_NO; |
| 1474 | last; |
| 1475 | } elsif (source_set_options($project_settings,$options)) { |
| 1476 | last; |
| 1477 | } |
| 1478 | print "Please re-enter the options:\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | # - Create the targets |
| 1483 | # - Check if we have both libraries and programs |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1484 | # - Match each target with source files (sort in reverse |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1485 | # alphabetical order to get the longest matches first) |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 1486 | my @local_dlls=(); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1487 | my @local_depends=(); |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 1488 | my @exe_list=(); |
Martin Wilck | 4ae4d66 | 2002-09-18 18:30:29 +0000 | [diff] [blame] | 1489 | foreach my $target_name (map (lc, (sort { $b cmp $a } keys %targets))) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1490 | # Create the target... |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1491 | my $target=[]; |
| 1492 | target_init($target); |
| 1493 | @$target[$T_NAME]=$target_name; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1494 | @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS]; |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1495 | if ($target_name =~ /\.dll$/) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1496 | @$target[$T_TYPE]=$TT_DLL; |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1497 | push @local_depends,"$target_name.so"; |
| 1498 | push @local_dlls,$target_name; |
Francois Gouget | a286c20 | 2005-01-11 10:39:10 +0000 | [diff] [blame] | 1499 | my $canon=canonize($target_name); |
| 1500 | push @{@$target[$T_LDFLAGS]},("-shared","\$(${canon}_MODULE:%=%.spec)"); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1501 | } else { |
| 1502 | @$target[$T_TYPE]=$opt_target_type; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 1503 | push @exe_list,$target; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1504 | push @{@$target[$T_LDFLAGS]},(@$target[$T_TYPE] == $TT_CUIEXE ? "-mconsole" : "-mwindows"); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1505 | } |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1506 | my $basename=$target_name; |
| 1507 | $basename=~ s/\.(dll|exe)$//i; |
André Hentschel | 8052c1a | 2009-02-05 17:36:39 +0100 | [diff] [blame] | 1508 | # This is the default link list of Visual Studio |
| 1509 | my @std_imports=qw(odbc32 ole32 oleaut32 winspool odbccp32); |
Francois Gouget | b1ff875 | 2004-01-30 22:55:00 +0000 | [diff] [blame] | 1510 | my @std_libraries=qw(uuid); |
Martin Wilck | 90d6528 | 2002-09-13 17:43:25 +0000 | [diff] [blame] | 1511 | if ((@$target[$T_FLAGS] & $TF_NODLLS) == 0) { |
Jeff Smith | c327246 | 2002-12-15 03:00:40 +0000 | [diff] [blame] | 1512 | @$target[$T_DLLS]=\@std_imports; |
Francois Gouget | b1ff875 | 2004-01-30 22:55:00 +0000 | [diff] [blame] | 1513 | @$target[$T_LIBRARIES]=\@std_libraries; |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 1514 | } else { |
| 1515 | @$target[$T_DLLS]=[]; |
Francois Gouget | b1ff875 | 2004-01-30 22:55:00 +0000 | [diff] [blame] | 1516 | @$target[$T_LIBRARIES]=[]; |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 1517 | } |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1518 | if ((@$target[$T_FLAGS] & $TF_NOMSVCRT) == 0) { |
| 1519 | push @{@$target[$T_LDFLAGS]},"-mno-cygwin"; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 1520 | if ($opt_arch != $OPT_ARCH_DEFAULT) { |
| 1521 | push @{@$target[$T_LDFLAGS]},"-m$opt_arch"; |
| 1522 | } |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1523 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1524 | push @{@$project[$P_TARGETS]},$target; |
| 1525 | |
| 1526 | # Ask for target-specific options |
| 1527 | if ($opt_ask_target_options == $OPT_ASK_YES) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1528 | my $flag_desc=""; |
| 1529 | if ((@$target[$T_FLAGS] & $TF_MFC)!=0) { |
| 1530 | $flag_desc=" (mfc"; |
| 1531 | } |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1532 | if ($flag_desc ne "") { |
| 1533 | $flag_desc.=")"; |
| 1534 | } |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 1535 | print "* Specify any link option (-P/-i/-L/-l/--mfc) specific to the target\n"; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1536 | print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n"; |
Francois Gouget | 3af251e | 2000-11-30 20:36:04 +0000 | [diff] [blame] | 1537 | while (1) { |
| 1538 | my $options=<STDIN>; |
| 1539 | chomp $options; |
| 1540 | if ($options eq "never") { |
| 1541 | $opt_ask_target_options=$OPT_ASK_NO; |
| 1542 | last; |
| 1543 | } elsif (source_set_options($target,$options)) { |
| 1544 | last; |
| 1545 | } |
| 1546 | print "Please re-enter the options:\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | if (@$target[$T_FLAGS] & $TF_MFC) { |
| 1550 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 1551 | push @{@$target[$T_DLL_PATH]},"\$(MFC_LIBRARY_PATH)"; |
| 1552 | push @{@$target[$T_DLLS]},"mfc.dll"; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1553 | # FIXME: Link with the MFC in the Unix sense, until we |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 1554 | # start exporting the functions properly. |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 1555 | push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)"; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 1556 | push @{@$target[$T_LIBRARIES]},"mfc"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | # Match sources... |
| 1560 | if ($target_count == 1) { |
Francois Gouget | 4ec1059 | 2000-12-02 20:12:45 +0000 | [diff] [blame] | 1561 | push @{@$target[$T_SOURCES_C]},@{@$project_settings[$T_SOURCES_C]},@sources_c; |
| 1562 | @$project_settings[$T_SOURCES_C]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1563 | @sources_c=(); |
Francois Gouget | 4ec1059 | 2000-12-02 20:12:45 +0000 | [diff] [blame] | 1564 | |
| 1565 | push @{@$target[$T_SOURCES_CXX]},@{@$project_settings[$T_SOURCES_CXX]},@sources_cxx; |
| 1566 | @$project_settings[$T_SOURCES_CXX]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1567 | @sources_cxx=(); |
Francois Gouget | 4ec1059 | 2000-12-02 20:12:45 +0000 | [diff] [blame] | 1568 | |
| 1569 | push @{@$target[$T_SOURCES_RC]},@{@$project_settings[$T_SOURCES_RC]},@sources_rc; |
| 1570 | @$project_settings[$T_SOURCES_RC]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1571 | @sources_rc=(); |
Francois Gouget | 4ec1059 | 2000-12-02 20:12:45 +0000 | [diff] [blame] | 1572 | |
| 1573 | push @{@$target[$T_SOURCES_MISC]},@{@$project_settings[$T_SOURCES_MISC]},@sources_misc; |
| 1574 | # No need for sorting these sources |
| 1575 | @$project_settings[$T_SOURCES_MISC]=[]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1576 | @sources_misc=(); |
| 1577 | } else { |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1578 | foreach my $source (@sources_c) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1579 | if ($source =~ /^$basename/i) { |
| 1580 | push @{@$target[$T_SOURCES_C]},$source; |
| 1581 | $source=""; |
| 1582 | } |
| 1583 | } |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1584 | foreach my $source (@sources_cxx) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1585 | if ($source =~ /^$basename/i) { |
| 1586 | push @{@$target[$T_SOURCES_CXX]},$source; |
| 1587 | $source=""; |
| 1588 | } |
| 1589 | } |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1590 | foreach my $source (@sources_rc) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1591 | if ($source =~ /^$basename/i) { |
| 1592 | push @{@$target[$T_SOURCES_RC]},$source; |
| 1593 | $source=""; |
| 1594 | } |
| 1595 | } |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1596 | foreach my $source (@sources_misc) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1597 | if ($source =~ /^$basename/i) { |
| 1598 | push @{@$target[$T_SOURCES_MISC]},$source; |
| 1599 | $source=""; |
| 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}]; |
| 1604 | @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}]; |
| 1605 | @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}]; |
| 1606 | @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}]; |
| 1607 | } |
| 1608 | if ($opt_ask_target_options == $OPT_ASK_SKIP) { |
| 1609 | $opt_ask_target_options=$OPT_ASK_YES; |
| 1610 | } |
| 1611 | |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 1612 | if ((@$project_settings[$T_FLAGS] & $TF_NOMSVCRT) == 0) { |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 1613 | push @{@$project_settings[$T_CEXTRA]},"-mno-cygwin"; |
| 1614 | push @{@$project_settings[$T_CXXEXTRA]},"-mno-cygwin"; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 1615 | if ($opt_arch != $OPT_ARCH_DEFAULT) { |
| 1616 | push @{@$project_settings[$T_CEXTRA]},"-m$opt_arch"; |
| 1617 | push @{@$project_settings[$T_CXXEXTRA]},"-m$opt_arch"; |
| 1618 | } |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1621 | if (@$project_settings[$T_FLAGS] & $TF_MFC) { |
| 1622 | push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)"; |
| 1623 | } |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1624 | # The sources that did not match, if any, go to the extra |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1625 | # source list of the project settings |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1626 | foreach my $source (@sources_c) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1627 | if ($source ne "") { |
| 1628 | push @{@$project_settings[$T_SOURCES_C]},$source; |
| 1629 | } |
| 1630 | } |
| 1631 | @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}]; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1632 | foreach my $source (@sources_cxx) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1633 | if ($source ne "") { |
| 1634 | push @{@$project_settings[$T_SOURCES_CXX]},$source; |
| 1635 | } |
| 1636 | } |
| 1637 | @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}]; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1638 | foreach my $source (@sources_rc) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1639 | if ($source ne "") { |
| 1640 | push @{@$project_settings[$T_SOURCES_RC]},$source; |
| 1641 | } |
| 1642 | } |
| 1643 | @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}]; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1644 | foreach my $source (@sources_misc) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1645 | if ($source ne "") { |
| 1646 | push @{@$project_settings[$T_SOURCES_MISC]},$source; |
| 1647 | } |
| 1648 | } |
| 1649 | @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}]; |
| 1650 | |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1651 | # Finally if we are building both libraries and programs in |
| 1652 | # this directory, then the programs should be linked with all |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1653 | # the libraries |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 1654 | if (@local_dlls > 0 and @exe_list > 0) { |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1655 | foreach my $target (@exe_list) { |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 1656 | push @{@$target[$T_DLL_PATH]},"-L."; |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1657 | push @{@$target[$T_DLLS]},@local_dlls; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | ## |
| 1663 | # Scan the source directories in search of things to build |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1664 | sub source_scan() |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1665 | { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1666 | # If there's a single target then this is going to be the default target |
| 1667 | if (defined $opt_single_target) { |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 1668 | # Create the main target |
| 1669 | my $main_target=[]; |
| 1670 | target_init($main_target); |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 1671 | @$main_target[$T_NAME]=$opt_single_target; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1672 | @$main_target[$T_TYPE]=$opt_target_type; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 1673 | |
| 1674 | # Add it to the list |
| 1675 | push @{$main_project[$P_TARGETS]},$main_target; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | # The main directory is always going to be there |
| 1679 | push @projects,\@main_project; |
| 1680 | |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 1681 | if (defined $opt_work_dir) { |
| 1682 | # Now scan the directory tree looking for source files and, maybe, targets |
| 1683 | print "Scanning the source directories...\n"; |
| 1684 | source_scan_directory(\@main_project,"","",0); |
| 1685 | @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects; |
| 1686 | } elsif (defined $opt_work_file) { |
| 1687 | if ($opt_work_file =~ /.dsp$/i or $opt_work_file =~ /.vcproj$/i) { |
| 1688 | source_scan_project_file(\@main_project,0,$opt_work_file); |
André Hentschel | df5c417 | 2009-04-02 18:53:24 +0200 | [diff] [blame] | 1689 | } elsif ($opt_work_file =~ /.dsw$/i or $opt_work_file =~ /.sln$/i) { |
| 1690 | source_scan_workspace_file($opt_work_file); |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 1691 | } |
| 1692 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1695 | ##### |
| 1696 | # |
| 1697 | # Source search |
| 1698 | # |
| 1699 | ##### |
| 1700 | |
| 1701 | ## |
| 1702 | # Performs a directory traversal and renames the files so that: |
| 1703 | # - they have the case desired by the user |
| 1704 | # - their extension is of the appropriate case |
| 1705 | # - they don't contain annoying characters like ' ', '$', '#', ... |
Francois Gouget | a6eecca | 2005-02-21 18:29:44 +0000 | [diff] [blame] | 1706 | # But only perform these changes for source files and directories. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1707 | sub fix_file_and_directory_names($); |
| 1708 | sub fix_file_and_directory_names($) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1709 | { |
| 1710 | my $dirname=$_[0]; |
| 1711 | |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1712 | my $directory=get_directory_contents($dirname); |
| 1713 | foreach my $dentry (@$directory) |
| 1714 | { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1715 | if ($dentry =~ /^\./ or $dentry eq "CVS") { |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1716 | next; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1717 | } |
| 1718 | # Set $warn to 1 if the user should be warned of the renaming |
Francois Gouget | a6eecca | 2005-02-21 18:29:44 +0000 | [diff] [blame] | 1719 | my $warn; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1720 | my $new_name=$dentry; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1721 | |
Francois Gouget | a6eecca | 2005-02-21 18:29:44 +0000 | [diff] [blame] | 1722 | if (-f "$dirname/$dentry") |
| 1723 | { |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1724 | # Don't rename Winemaker's makefiles |
| 1725 | next if ($dentry eq "Makefile" and |
| 1726 | `head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/); |
Francois Gouget | a6eecca | 2005-02-21 18:29:44 +0000 | [diff] [blame] | 1727 | |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1728 | # Leave non-source files alone |
| 1729 | next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i); |
Francois Gouget | a6eecca | 2005-02-21 18:29:44 +0000 | [diff] [blame] | 1730 | |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1731 | # Only all lowercase extensions are supported (because of |
| 1732 | # rules like '.c.o:'. |
| 1733 | $new_name =~ s/\.C$/.c/; |
| 1734 | $new_name =~ s/\.cpp$/.cpp/i; |
| 1735 | $warn=1 if ($new_name =~ s/\.cxx$/.cpp/i); |
| 1736 | $new_name =~ s/\.rc$/.rc/i; |
| 1737 | # And this last one is to avoid confusion then running make |
| 1738 | $warn=1 if ($new_name =~ s/^makefile$/makefile.win/i); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | # Adjust the case to the user's preferences |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1742 | if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1743 | ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/) |
| 1744 | ) { |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1745 | $new_name=lc $new_name; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Francois Gouget | a6eecca | 2005-02-21 18:29:44 +0000 | [diff] [blame] | 1748 | # autoconf and make don't support these characters well |
| 1749 | $new_name =~ s/[ \$]/_/g; |
| 1750 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1751 | # And finally, perform the renaming |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1752 | if ($new_name ne $dentry) |
| 1753 | { |
| 1754 | if ($warn) { |
| 1755 | print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n"; |
| 1756 | } |
| 1757 | if (!rename("$dirname/$dentry","$dirname/$new_name")) { |
| 1758 | print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n"; |
| 1759 | print STDERR " $!\n"; |
| 1760 | $new_name=$dentry; |
| 1761 | } |
| 1762 | else |
| 1763 | { |
| 1764 | clear_directory_cache($dirname); |
| 1765 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1766 | } |
| 1767 | if (-d "$dirname/$new_name") { |
Francois Gouget | d4fddfb | 2009-02-25 10:32:36 +0100 | [diff] [blame] | 1768 | fix_file_and_directory_names("$dirname/$new_name"); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1769 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | ##### |
| 1776 | # |
| 1777 | # Source fixup |
| 1778 | # |
| 1779 | ##### |
| 1780 | |
| 1781 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1782 | # Try to find a file for the specified filename. The attempt is |
| 1783 | # case-insensitive which is why it's not trivial. If a match is |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1784 | # found then we return the pathname with the correct case. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1785 | sub search_from($$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1786 | { |
| 1787 | my $dirname=$_[0]; |
| 1788 | my $path=$_[1]; |
| 1789 | my $real_path=""; |
| 1790 | |
André Hentschel | 70fbe97 | 2009-04-24 17:40:32 +0200 | [diff] [blame] | 1791 | if ($dirname eq "" or $dirname eq "." or $dirname eq "./") { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1792 | $dirname=cwd; |
Francois Gouget | a286c20 | 2005-01-11 10:39:10 +0000 | [diff] [blame] | 1793 | } elsif ($dirname !~ m+^/+) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1794 | $dirname=cwd . "/" . $dirname; |
| 1795 | } |
| 1796 | if ($dirname !~ m+/$+) { |
| 1797 | $dirname.="/"; |
| 1798 | } |
| 1799 | |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1800 | foreach my $component (@$path) { |
André Hentschel | a021e83 | 2009-04-29 19:42:24 +0200 | [diff] [blame] | 1801 | $component=~s/^\"//; |
| 1802 | $component=~s/\"$//; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1803 | #print " looking for $component in \"$dirname\"\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1804 | if ($component eq ".") { |
| 1805 | # Pass it as is |
| 1806 | $real_path.="./"; |
| 1807 | } elsif ($component eq "..") { |
| 1808 | # Go up one level |
| 1809 | $dirname=dirname($dirname) . "/"; |
| 1810 | $real_path.="../"; |
| 1811 | } else { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1812 | # The file/directory may have been renamed before. Also try to |
Francois Gouget | 3fafafa | 2001-04-23 18:16:13 +0000 | [diff] [blame] | 1813 | # match the renamed file. |
| 1814 | my $renamed=$component; |
| 1815 | $renamed =~ s/[ \$]/_/g; |
| 1816 | if ($renamed eq $component) { |
| 1817 | undef $renamed; |
| 1818 | } |
| 1819 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1820 | my $directory=get_directory_contents $dirname; |
| 1821 | my $found; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1822 | foreach my $dentry (@$directory) { |
Simon C. Ion | 7b5cbdb | 2008-12-19 18:23:45 -0600 | [diff] [blame] | 1823 | if ($dentry =~ /^\Q$component\E$/i or |
Francois Gouget | 3fafafa | 2001-04-23 18:16:13 +0000 | [diff] [blame] | 1824 | (defined $renamed and $dentry =~ /^$renamed$/i) |
| 1825 | ) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1826 | $dirname.="$dentry/"; |
| 1827 | $real_path.="$dentry/"; |
| 1828 | $found=1; |
| 1829 | last; |
| 1830 | } |
| 1831 | } |
| 1832 | if (!defined $found) { |
| 1833 | # Give up |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1834 | #print " could not find $component in $dirname\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1835 | return; |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | $real_path=~ s+/$++; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1840 | #print " -> found $real_path\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1841 | return $real_path; |
| 1842 | } |
| 1843 | |
| 1844 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1845 | # Performs a case-insensitive search for the specified file in the |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1846 | # include path. |
| 1847 | # $line is the line number that should be referenced when an error occurs |
| 1848 | # $filename is the file we are looking for |
| 1849 | # $dirname is the directory of the file containing the '#include' directive |
| 1850 | # if '"' was used, it is an empty string otherwise |
| 1851 | # $project and $target specify part of the include path |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1852 | sub get_real_include_name($$$$$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1853 | { |
| 1854 | my $line=$_[0]; |
| 1855 | my $filename=$_[1]; |
| 1856 | my $dirname=$_[2]; |
| 1857 | my $project=$_[3]; |
| 1858 | my $target=$_[4]; |
| 1859 | |
| 1860 | if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) { |
| 1861 | # This is not a relative path, we cannot make any check |
| 1862 | my $warning="path:$filename"; |
| 1863 | if (!defined $warnings{$warning}) { |
| 1864 | $warnings{$warning}="1"; |
| 1865 | print STDERR "warning: cannot check the case of absolute pathnames:\n"; |
| 1866 | print STDERR "$line: $filename\n"; |
| 1867 | } |
| 1868 | } else { |
| 1869 | # Here's how we proceed: |
| 1870 | # - split the filename we look for into its components |
| 1871 | # - then for each directory in the include path |
| 1872 | # - trace the directory components starting from that directory |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1873 | # - if we fail to find a match at any point then continue with |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1874 | # the next directory in the include path |
| 1875 | # - otherwise, rejoice, our quest is over. |
| 1876 | my @file_components=split /[\/\\]+/, $filename; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1877 | #print " Searching for $filename from @$project[$P_PATH]\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1878 | |
| 1879 | my $real_filename; |
| 1880 | if ($dirname ne "") { |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1881 | # This is an 'include ""' -> look in dirname first. |
| 1882 | #print " in $dirname (include \"\")\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1883 | $real_filename=search_from($dirname,\@file_components); |
| 1884 | if (defined $real_filename) { |
| 1885 | return $real_filename; |
| 1886 | } |
| 1887 | } |
| 1888 | my $project_settings=@$project[$P_SETTINGS]; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1889 | foreach my $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) { |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1890 | my $dirname=$include; |
| 1891 | $dirname=~ s+^-I++; |
André Hentschel | abc68c1 | 2009-05-19 21:01:55 +0200 | [diff] [blame] | 1892 | $dirname=~ s+\s$++; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1893 | if (!is_absolute($dirname)) { |
| 1894 | $dirname="@$project[$P_PATH]$dirname"; |
| 1895 | } else { |
Francois Gouget | 647bb8f | 2001-04-20 18:26:35 +0000 | [diff] [blame] | 1896 | $dirname=~ s+^\$\(TOPSRCDIR\)/++; |
| 1897 | $dirname=~ s+^\$\(SRCDIR\)/+@$project[$P_PATH]+; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1898 | } |
| 1899 | #print " in $dirname\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1900 | $real_filename=search_from("$dirname",\@file_components); |
| 1901 | if (defined $real_filename) { |
| 1902 | return $real_filename; |
| 1903 | } |
| 1904 | } |
| 1905 | my $dotdotpath=@$project[$P_PATH]; |
| 1906 | $dotdotpath =~ s/[^\/]+/../g; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1907 | foreach my $include (@{$global_settings[$T_INCLUDE_PATH]}) { |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1908 | my $dirname=$include; |
| 1909 | $dirname=~ s+^-I++; |
| 1910 | $dirname=~ s+^\$\(TOPSRCDIR\)\/++; |
Francois Gouget | 647bb8f | 2001-04-20 18:26:35 +0000 | [diff] [blame] | 1911 | $dirname=~ s+^\$\(SRCDIR\)\/+@$project[$P_PATH]+; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1912 | #print " in $dirname (global setting)\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1913 | $real_filename=search_from("$dirname",\@file_components); |
| 1914 | if (defined $real_filename) { |
| 1915 | return $real_filename; |
| 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | $filename =~ s+\\\\+/+g; # in include "" |
| 1920 | $filename =~ s+\\+/+g; # in include <> ! |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 1921 | if ($opt_lower_include) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1922 | return lc "$filename"; |
| 1923 | } |
| 1924 | return $filename; |
| 1925 | } |
| 1926 | |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1927 | sub print_pack($$$) |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 1928 | { |
| 1929 | my $indent=$_[0]; |
| 1930 | my $size=$_[1]; |
| 1931 | my $trailer=$_[2]; |
| 1932 | |
| 1933 | if ($size =~ /^(1|2|4|8)$/) { |
| 1934 | print FILEO "$indent#include <pshpack$size.h>$trailer"; |
| 1935 | } else { |
| 1936 | print FILEO "$indent/* winemaker:warning: Unknown size \"$size\". Defaulting to 4 */\n"; |
| 1937 | print FILEO "$indent#include <pshpack4.h>$trailer"; |
| 1938 | } |
| 1939 | } |
| 1940 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1941 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1942 | # 'Parses' a source file and fixes constructs that would not work with |
| 1943 | # Winelib. The parsing is rather simple and not all non-portable features |
| 1944 | # are corrected. The most important feature that is corrected is the case |
| 1945 | # and path separator of '#include' directives. This requires that each |
| 1946 | # source file be associated to a project & target so that the proper |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1947 | # include path is used. |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1948 | # Also note that the include path is relative to the directory in which the |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1949 | # compiler is run, i.e. that of the project, not to that of the file. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 1950 | sub fix_file($$$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1951 | { |
| 1952 | my $filename=$_[0]; |
| 1953 | my $project=$_[1]; |
| 1954 | my $target=$_[2]; |
| 1955 | $filename="@$project[$P_PATH]$filename"; |
| 1956 | if (! -e $filename) { |
| 1957 | return; |
| 1958 | } |
| 1959 | |
| 1960 | my $is_rc=($filename =~ /\.(rc2?|dlg)$/i); |
| 1961 | my $dirname=dirname($filename); |
| 1962 | my $is_mfc=0; |
| 1963 | if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) { |
| 1964 | $is_mfc=1; |
| 1965 | } |
| 1966 | |
| 1967 | print " $filename\n"; |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 1968 | #FIXME:assuming that because there is a .bak file, this is what we want is |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1969 | #probably flawed. Or is it??? |
| 1970 | if (! -e "$filename.bak") { |
| 1971 | if (!copy("$filename","$filename.bak")) { |
| 1972 | print STDERR "error: unable to make a backup of $filename:\n"; |
| 1973 | print STDERR " $!\n"; |
| 1974 | return; |
| 1975 | } |
| 1976 | } |
| 1977 | if (!open(FILEI,"$filename.bak")) { |
| 1978 | print STDERR "error: unable to open $filename.bak for reading:\n"; |
| 1979 | print STDERR " $!\n"; |
| 1980 | return; |
| 1981 | } |
| 1982 | if (!open(FILEO,">$filename")) { |
| 1983 | print STDERR "error: unable to open $filename for writing:\n"; |
| 1984 | print STDERR " $!\n"; |
| 1985 | return; |
| 1986 | } |
| 1987 | my $line=0; |
| 1988 | my $modified=0; |
| 1989 | my $rc_block_depth=0; |
| 1990 | my $rc_textinclude_state=0; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 1991 | my @pack_stack; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1992 | while (<FILEI>) { |
Bill Medland | 987ea46 | 2001-07-12 22:21:44 +0000 | [diff] [blame] | 1993 | # Remove any trailing CtrlZ, which isn't strictly in the file |
| 1994 | if (/\x1A/) { |
| 1995 | s/\x1A//; |
| 1996 | last if (/^$/) |
| 1997 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1998 | $line++; |
François Gouget | a62703e | 2001-02-12 01:22:58 +0000 | [diff] [blame] | 1999 | s/\r\n$/\n/; |
| 2000 | if (!/\n$/) { |
| 2001 | # Make sure all files are '\n' terminated |
| 2002 | $_ .= "\n"; |
| 2003 | } |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2004 | if ($is_rc and !$is_mfc and /^(\s*)(\#\s*include\s*)\"afxres\.h\"/) { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2005 | # VC6 automatically includes 'afxres.h', an MFC specific header, in |
| 2006 | # the RC files it generates (even in non-MFC projects). So we replace |
André Hentschel | 47b1bff | 2009-04-02 18:53:12 +0200 | [diff] [blame] | 2007 | # it with 'winresrc.h' its very close standard cousin so that non MFC |
François Gouget | a62703e | 2001-02-12 01:22:58 +0000 | [diff] [blame] | 2008 | # projects can compile in Wine without the MFC sources. |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2009 | my $warning="mfc:afxres.h"; |
| 2010 | if (!defined $warnings{$warning}) { |
| 2011 | $warnings{$warning}="1"; |
André Hentschel | 47b1bff | 2009-04-02 18:53:12 +0200 | [diff] [blame] | 2012 | print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winresrc.h'\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2013 | print STDERR "warning: the above warning is issued only once\n"; |
| 2014 | } |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2015 | print FILEO "$1/* winemaker: $2\"afxres.h\" */\n"; |
André Hentschel | 47b1bff | 2009-04-02 18:53:12 +0200 | [diff] [blame] | 2016 | print FILEO "$1/* winemaker:warning: 'afxres.h' is an MFC specific header. Replacing it with 'winresrc.h' */\n"; |
| 2017 | print FILEO "$1$2\"winresrc.h\"$'"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2018 | $modified=1; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2019 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2020 | } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) { |
| 2021 | my $from_file=($2 eq "<"?"":$dirname); |
| 2022 | my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target); |
| 2023 | print FILEO "$1$2$real_include_name$4$'"; |
| 2024 | $modified|=($real_include_name ne $3); |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2025 | |
| 2026 | } elsif (s/^(\s*)(\#\s*pragma\s+pack\s*\(\s*)//) { |
| 2027 | # Pragma pack handling |
| 2028 | # |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2029 | # pack_stack is an array of references describing the stack of |
| 2030 | # pack directives currently in effect. Each directive if described |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2031 | # by a reference to an array containing: |
| 2032 | # - "push" for pack(push,...) directives, "" otherwise |
| 2033 | # - the directive's identifier at index 1 |
Francois Gouget | 42a61d7 | 2008-05-06 15:54:52 +0200 | [diff] [blame] | 2034 | # - the directive's alignment value at index 2 |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2035 | # |
| 2036 | # Don't believe a word of what the documentation says: it's all wrong. |
| 2037 | # The code below is based on the actual behavior of Visual C/C++ 6. |
| 2038 | my $pack_indent=$1; |
| 2039 | my $pack_header=$2; |
| 2040 | if (/^(\))/) { |
| 2041 | # pragma pack() |
| 2042 | # Pushes the default stack alignment |
| 2043 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2044 | print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n"; |
| 2045 | print_pack($pack_indent,4,$'); |
| 2046 | push @pack_stack, [ "", "", 4 ]; |
| 2047 | |
| 2048 | } elsif (/^(pop\s*(,\s*\d+\s*)?\))/) { |
| 2049 | # pragma pack(pop) |
| 2050 | # pragma pack(pop,n) |
| 2051 | # Goes up the stack until it finds a pack(push,...), and pops it |
| 2052 | # Ignores any pack(n) entry |
| 2053 | # Issues a warning if the pack is of the form pack(push,label) |
| 2054 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2055 | my $pack_comment=$'; |
Francois Gouget | 647bb8f | 2001-04-20 18:26:35 +0000 | [diff] [blame] | 2056 | $pack_comment =~ s/^\s*//; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2057 | if ($pack_comment ne "") { |
| 2058 | print FILEO "$pack_indent$pack_comment"; |
| 2059 | } |
| 2060 | while (1) { |
| 2061 | my $alignment=pop @pack_stack; |
| 2062 | if (!defined $alignment) { |
| 2063 | print FILEO "$pack_indent/* winemaker:warning: No pack(push,...) found. All the stack has been popped */\n"; |
| 2064 | last; |
| 2065 | } |
| 2066 | if (@$alignment[1]) { |
| 2067 | print FILEO "$pack_indent/* winemaker:warning: Anonymous pop of pack(push,@$alignment[1]) (@$alignment[2]) */\n"; |
| 2068 | } |
| 2069 | print FILEO "$pack_indent#include <poppack.h>\n"; |
| 2070 | if (@$alignment[0]) { |
| 2071 | last; |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | } elsif (/^(pop\s*,\s*(\w+)\s*(,\s*\d+\s*)?\))/) { |
| 2076 | # pragma pack(pop,label[,n]) |
| 2077 | # Goes up the stack until finding a pack(push,...) and pops it. |
| 2078 | # 'n', if specified, is ignored. |
| 2079 | # Ignores any pack(n) entry |
| 2080 | # Issues a warning if the label of the pack does not match, |
| 2081 | # or if it is in fact a pack(push,n) |
| 2082 | my $label=$2; |
| 2083 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2084 | my $pack_comment=$'; |
Francois Gouget | 647bb8f | 2001-04-20 18:26:35 +0000 | [diff] [blame] | 2085 | $pack_comment =~ s/^\s*//; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2086 | if ($pack_comment ne "") { |
| 2087 | print FILEO "$pack_indent$pack_comment"; |
| 2088 | } |
| 2089 | while (1) { |
| 2090 | my $alignment=pop @pack_stack; |
| 2091 | if (!defined $alignment) { |
| 2092 | print FILEO "$pack_indent/* winemaker:warning: No pack(push,$label) found. All the stack has been popped */\n"; |
| 2093 | last; |
| 2094 | } |
| 2095 | if (@$alignment[1] and @$alignment[1] ne $label) { |
| 2096 | print FILEO "$pack_indent/* winemaker:warning: Push/pop mismatch: \"@$alignment[1]\" (@$alignment[2]) != \"$label\" */\n"; |
| 2097 | } |
| 2098 | print FILEO "$pack_indent#include <poppack.h>\n"; |
| 2099 | if (@$alignment[0]) { |
| 2100 | last; |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | } elsif (/^(push\s*\))/) { |
| 2105 | # pragma pack(push) |
| 2106 | # Push the current alignment |
| 2107 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2108 | if (@pack_stack > 0) { |
| 2109 | my $alignment=$pack_stack[$#pack_stack]; |
| 2110 | print_pack($pack_indent,@$alignment[2],$'); |
| 2111 | push @pack_stack, [ "push", "", @$alignment[2] ]; |
| 2112 | } else { |
| 2113 | print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n"; |
| 2114 | print_pack($pack_indent,4,$'); |
| 2115 | push @pack_stack, [ "push", "", 4 ]; |
| 2116 | } |
| 2117 | |
| 2118 | } elsif (/^((push\s*,\s*)?(\d+)\s*\))/) { |
| 2119 | # pragma pack([push,]n) |
| 2120 | # Push new alignment n |
| 2121 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2122 | print_pack($pack_indent,$3,"$'"); |
| 2123 | push @pack_stack, [ ($2 ? "push" : ""), "", $3 ]; |
| 2124 | |
| 2125 | } elsif (/^((\w+)\s*\))/) { |
| 2126 | # pragma pack(label) |
| 2127 | # label must in fact be a macro that resolves to an integer |
| 2128 | # Then behaves like 'pragma pack(n)' |
| 2129 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2130 | print FILEO "$pack_indent/* winemaker:warning: Assuming $2 == 4 */\n"; |
| 2131 | print_pack($pack_indent,4,$'); |
| 2132 | push @pack_stack, [ "", "", 4 ]; |
| 2133 | |
| 2134 | } elsif (/^(push\s*,\s*(\w+)\s*(,\s*(\d+)\s*)?\))/) { |
| 2135 | # pragma pack(push,label[,n]) |
| 2136 | # Pushes a new label on the stack. It is possible to push the same |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2137 | # label multiple times. If 'n' is omitted then the alignment is |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2138 | # unchanged. Otherwise it becomes 'n'. |
| 2139 | print FILEO "$pack_indent/* winemaker: $pack_header$1 */\n"; |
| 2140 | my $size; |
| 2141 | if (defined $4) { |
| 2142 | $size=$4; |
| 2143 | } elsif (@pack_stack > 0) { |
| 2144 | my $alignment=$pack_stack[$#pack_stack]; |
| 2145 | $size=@$alignment[2]; |
| 2146 | } else { |
| 2147 | print FILEO "$pack_indent/* winemaker:warning: Using 4 as the default alignment */\n"; |
| 2148 | $size=4; |
| 2149 | } |
| 2150 | print_pack($pack_indent,$size,$'); |
| 2151 | push @pack_stack, [ "push", $2, $size ]; |
| 2152 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2153 | } else { |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2154 | # pragma pack(??? -> What's that? |
| 2155 | print FILEO "$pack_indent/* winemaker:warning: Unknown type of pragma pack directive */\n"; |
| 2156 | print FILEO "$pack_indent$pack_header$_"; |
| 2157 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2158 | } |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2159 | $modified=1; |
| 2160 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2161 | } elsif ($is_rc) { |
Francois Gouget | 647bb8f | 2001-04-20 18:26:35 +0000 | [diff] [blame] | 2162 | 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]+)([\">]?)/) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2163 | my $from_file=($5 eq "<"?"":$dirname); |
| 2164 | my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target); |
| 2165 | print FILEO "$1$5$real_include_name$7$'"; |
| 2166 | $modified|=($real_include_name ne $6); |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2167 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2168 | } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) { |
| 2169 | my $from_file=($2 eq "<"?"":$dirname); |
| 2170 | my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target); |
| 2171 | print FILEO "$1$2$real_include_name$4$'"; |
| 2172 | $modified|=($real_include_name ne $3); |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2173 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2174 | } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) { |
| 2175 | $rc_textinclude_state=1; |
| 2176 | print FILEO; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2177 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2178 | } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) { |
André Hentschel | 47b1bff | 2009-04-02 18:53:12 +0200 | [diff] [blame] | 2179 | print FILEO "$1winresrc.h$2$'"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2180 | $modified=1; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2181 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2182 | } elsif (/^\s*BEGIN(\W.*)?$/) { |
| 2183 | $rc_textinclude_state|=2; |
| 2184 | $rc_block_depth++; |
| 2185 | print FILEO; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2186 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2187 | } elsif (/^\s*END(\W.*)?$/) { |
| 2188 | $rc_textinclude_state=0; |
| 2189 | if ($rc_block_depth>0) { |
| 2190 | $rc_block_depth--; |
| 2191 | } |
| 2192 | print FILEO; |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2193 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2194 | } else { |
| 2195 | print FILEO; |
| 2196 | } |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2197 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2198 | } else { |
| 2199 | print FILEO; |
| 2200 | } |
| 2201 | } |
Francois Gouget | c1159be | 2001-04-18 17:39:42 +0000 | [diff] [blame] | 2202 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2203 | close(FILEI); |
| 2204 | close(FILEO); |
| 2205 | if ($opt_backup == 0 or $modified == 0) { |
| 2206 | if (!unlink("$filename.bak")) { |
| 2207 | print STDERR "error: unable to delete $filename.bak:\n"; |
| 2208 | print STDERR " $!\n"; |
| 2209 | } |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2214 | # Analyzes each source file in turn to find and correct issues |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2215 | # that would cause it not to compile. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2216 | sub fix_source() |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2217 | { |
| 2218 | print "Fixing the source files...\n"; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2219 | foreach my $project (@projects) { |
| 2220 | foreach my $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) { |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2221 | foreach my $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2222 | fix_file($source,$project,$target); |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | ##### |
| 2231 | # |
| 2232 | # File generation |
| 2233 | # |
| 2234 | ##### |
| 2235 | |
| 2236 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2237 | # A convenience function to generate all the lists (defines, |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2238 | # C sources, C++ source, etc.) in the Makefile |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2239 | sub generate_list($$$;$) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2240 | { |
| 2241 | my $name=$_[0]; |
| 2242 | my $last=$_[1]; |
| 2243 | my $list=$_[2]; |
| 2244 | my $data=$_[3]; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2245 | my $first=$name; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2246 | |
| 2247 | if ($name) { |
Francois Gouget | fb5b590 | 2000-11-30 20:34:39 +0000 | [diff] [blame] | 2248 | printf FILEO "%-22s=",$name; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2249 | } |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2250 | if (defined $list) { |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2251 | foreach my $item (@$list) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2252 | my $value; |
| 2253 | if (defined $data) { |
| 2254 | $value=&$data($item); |
| 2255 | } else { |
| 2256 | $value=$item; |
| 2257 | } |
| 2258 | if ($value ne "") { |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2259 | if ($first) { |
| 2260 | print FILEO " $value"; |
| 2261 | $first=0; |
| 2262 | } else { |
| 2263 | print FILEO " \\\n\t\t\t$value"; |
| 2264 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | } |
| 2268 | if ($last) { |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2269 | print FILEO "\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | ## |
Francois Gouget | a286c20 | 2005-01-11 10:39:10 +0000 | [diff] [blame] | 2274 | # Generates a project's Makefile and all the target files |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2275 | sub generate_project_files($) |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2276 | { |
| 2277 | my $project=$_[0]; |
| 2278 | my $project_settings=@$project[$P_SETTINGS]; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2279 | my @dll_list=(); |
| 2280 | my @exe_list=(); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2281 | |
| 2282 | # Then sort the targets and separate the libraries from the programs |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2283 | foreach my $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2284 | if (@$target[$T_TYPE] == $TT_DLL) { |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2285 | push @dll_list,$target; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2286 | } else { |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2287 | push @exe_list,$target; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2288 | } |
| 2289 | } |
| 2290 | @$project[$P_TARGETS]=[]; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2291 | push @{@$project[$P_TARGETS]}, @dll_list; |
| 2292 | push @{@$project[$P_TARGETS]}, @exe_list; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2293 | |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2294 | if (!open(FILEO,">@$project[$P_PATH]Makefile")) { |
| 2295 | print STDERR "error: could not open \"@$project[$P_PATH]/Makefile\" for writing\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2296 | print STDERR " $!\n"; |
| 2297 | return; |
| 2298 | } |
| 2299 | |
André Hentschel | f711704 | 2009-04-23 19:07:42 +0200 | [diff] [blame] | 2300 | print FILEO "### Generated by Winemaker $version\n"; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2301 | print FILEO "\n\n"; |
| 2302 | |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2303 | generate_list("SRCDIR",1,[ "." ]); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2304 | if (@$project[$P_PATH] eq "") { |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2305 | # This is the main project. It is also responsible for recursively |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2306 | # calling the other projects |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2307 | generate_list("SUBDIRS",1,\@projects,sub |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2308 | { |
| 2309 | if ($_[0] != \@main_project) { |
| 2310 | my $subdir=@{$_[0]}[$P_PATH]; |
| 2311 | $subdir =~ s+/$++; |
| 2312 | return $subdir; |
| 2313 | } |
| 2314 | # Eliminating the main project by returning undefined! |
| 2315 | }); |
| 2316 | } |
| 2317 | if (@{@$project[$P_TARGETS]} > 0) { |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2318 | generate_list("DLLS",1,\@dll_list,sub |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2319 | { |
| 2320 | return @{$_[0]}[$T_NAME]; |
| 2321 | }); |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2322 | generate_list("EXES",1,\@exe_list,sub |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2323 | { |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 2324 | return "@{$_[0]}[$T_NAME]"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2325 | }); |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2326 | print FILEO "\n\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2327 | |
Francois Gouget | d19aa5b | 2002-09-11 01:09:58 +0000 | [diff] [blame] | 2328 | print FILEO "### Common settings\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2329 | # Make it so that the project-wide settings override the global settings |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2330 | generate_list("CEXTRA",1,@$project_settings[$T_CEXTRA]); |
| 2331 | generate_list("CXXEXTRA",1,@$project_settings[$T_CXXEXTRA]); |
| 2332 | generate_list("RCEXTRA",1,@$project_settings[$T_RCEXTRA]); |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 2333 | generate_list("DEFINES",1,@$project_settings[$T_DEFINES]); |
Francois Gouget | d19aa5b | 2002-09-11 01:09:58 +0000 | [diff] [blame] | 2334 | generate_list("INCLUDE_PATH",1,@$project_settings[$T_INCLUDE_PATH]); |
| 2335 | generate_list("DLL_PATH",1,@$project_settings[$T_DLL_PATH]); |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 2336 | generate_list("DLL_IMPORTS",1,@$project_settings[$T_DLLS]); |
Francois Gouget | d19aa5b | 2002-09-11 01:09:58 +0000 | [diff] [blame] | 2337 | generate_list("LIBRARY_PATH",1,@$project_settings[$T_LIBRARY_PATH]); |
| 2338 | generate_list("LIBRARIES",1,@$project_settings[$T_LIBRARIES]); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2339 | print FILEO "\n\n"; |
| 2340 | |
| 2341 | my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+ |
| 2342 | @{@$project_settings[$T_SOURCES_CXX]}+ |
| 2343 | @{@$project_settings[$T_SOURCES_RC]}; |
Francois Gouget | d19aa5b | 2002-09-11 01:09:58 +0000 | [diff] [blame] | 2344 | my $no_extra=($extra_source_count == 0); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2345 | if (!$no_extra) { |
| 2346 | print FILEO "### Extra source lists\n\n"; |
| 2347 | generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]); |
| 2348 | generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]); |
| 2349 | generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]); |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2350 | print FILEO "\n"; |
| 2351 | generate_list("EXTRA_OBJS",1,["\$(EXTRA_C_SRCS:.c=.o)","\$(EXTRA_CXX_SRCS:.cpp=.o)"]); |
| 2352 | print FILEO "\n\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2353 | } |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2354 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2355 | # Iterate over all the targets... |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2356 | foreach my $target (@{@$project[$P_TARGETS]}) { |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2357 | print FILEO "### @$target[$T_NAME] sources and settings\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2358 | my $canon=canonize("@$target[$T_NAME]"); |
| 2359 | $canon =~ s+_so$++; |
Jeff Smith | caa74b6 | 2003-01-02 19:27:23 +0000 | [diff] [blame] | 2360 | |
| 2361 | generate_list("${canon}_MODULE",1,[@$target[$T_NAME]]); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2362 | generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]); |
| 2363 | generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]); |
| 2364 | generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]); |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2365 | generate_list("${canon}_LDFLAGS",1,@$target[$T_LDFLAGS]); |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 2366 | generate_list("${canon}_DLL_PATH",1,@$target[$T_DLL_PATH]); |
Gregg Mattinson | 2aad72c | 2002-07-19 03:15:20 +0000 | [diff] [blame] | 2367 | generate_list("${canon}_DLLS",1,@$target[$T_DLLS]); |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2368 | generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH]); |
| 2369 | generate_list("${canon}_LIBRARIES",1,@$target[$T_LIBRARIES]); |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2370 | print FILEO "\n"; |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2371 | generate_list("${canon}_OBJS",1,["\$(${canon}_C_SRCS:.c=.o)","\$(${canon}_CXX_SRCS:.cpp=.o)","\$(${canon}_RC_SRCS:.rc=.res)"]); |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2372 | print FILEO "\n\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2373 | } |
| 2374 | print FILEO "### Global source lists\n\n"; |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2375 | generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2376 | { |
| 2377 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 2378 | $canon =~ s+_so$++; |
| 2379 | return "\$(${canon}_C_SRCS)"; |
| 2380 | }); |
| 2381 | if (!$no_extra) { |
| 2382 | generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]); |
| 2383 | } |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2384 | generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2385 | { |
| 2386 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 2387 | $canon =~ s+_so$++; |
| 2388 | return "\$(${canon}_CXX_SRCS)"; |
| 2389 | }); |
| 2390 | if (!$no_extra) { |
| 2391 | generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]); |
| 2392 | } |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2393 | generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2394 | { |
| 2395 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 2396 | $canon =~ s+_so$++; |
| 2397 | return "\$(${canon}_RC_SRCS)"; |
| 2398 | }); |
| 2399 | if (!$no_extra) { |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2400 | generate_list("",1,[ "\$(EXTRA_RC_SRCS)" ]); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2401 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2402 | } |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2403 | print FILEO "\n\n"; |
| 2404 | print FILEO "### Tools\n\n"; |
| 2405 | print FILEO "CC = winegcc\n"; |
| 2406 | print FILEO "CXX = wineg++\n"; |
| 2407 | print FILEO "RC = wrc\n"; |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2408 | print FILEO "\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2409 | |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2410 | print FILEO "### Generic targets\n\n"; |
Francois Gouget | 27c3b59 | 2001-05-29 20:50:58 +0000 | [diff] [blame] | 2411 | print FILEO "all:"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2412 | if (@$project[$P_PATH] eq "") { |
Francois Gouget | 27c3b59 | 2001-05-29 20:50:58 +0000 | [diff] [blame] | 2413 | print FILEO " \$(SUBDIRS)"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2414 | } |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2415 | if (@{@$project[$P_TARGETS]} > 0) { |
Francois Gouget | 635eb3c | 2002-09-26 03:20:59 +0000 | [diff] [blame] | 2416 | print FILEO " \$(DLLS:%=%.so) \$(EXES:%=%.so)"; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2417 | } |
| 2418 | print FILEO "\n\n"; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2419 | print FILEO "### Build rules\n"; |
| 2420 | print FILEO "\n"; |
| 2421 | print FILEO ".PHONY: all clean dummy\n"; |
| 2422 | print FILEO "\n"; |
| 2423 | print FILEO "\$(SUBDIRS): dummy\n"; |
| 2424 | print FILEO "\t\@cd \$\@ && \$(MAKE)\n"; |
| 2425 | print FILEO "\n"; |
| 2426 | print FILEO "# Implicit rules\n"; |
| 2427 | print FILEO "\n"; |
| 2428 | print FILEO ".SUFFIXES: .cpp .rc .res\n"; |
| 2429 | print FILEO "DEFINCL = \$(INCLUDE_PATH) \$(DEFINES) \$(OPTIONS)\n"; |
| 2430 | print FILEO "\n"; |
| 2431 | print FILEO ".c.o:\n"; |
| 2432 | print FILEO "\t\$(CC) -c \$(CFLAGS) \$(CEXTRA) \$(DEFINCL) -o \$\@ \$<\n"; |
| 2433 | print FILEO "\n"; |
| 2434 | print FILEO ".cpp.o:\n"; |
| 2435 | print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n"; |
| 2436 | print FILEO "\n"; |
| 2437 | print FILEO ".cxx.o:\n"; |
| 2438 | print FILEO "\t\$(CXX) -c \$(CXXFLAGS) \$(CXXEXTRA) \$(DEFINCL) -o \$\@ \$<\n"; |
| 2439 | print FILEO "\n"; |
| 2440 | print FILEO ".rc.res:\n"; |
| 2441 | print FILEO "\t\$(RC) \$(RCFLAGS) \$(RCEXTRA) \$(DEFINCL) -fo\$@ \$<\n"; |
| 2442 | print FILEO "\n"; |
| 2443 | print FILEO "# Rules for cleaning\n"; |
| 2444 | print FILEO "\n"; |
Alexandre Julliard | 8b84ac8 | 2005-09-29 10:42:43 +0000 | [diff] [blame] | 2445 | print FILEO "CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \\\n"; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2446 | print FILEO " \\\\\\#*\\\\\\# *~ *% .\\\\\\#*\n"; |
| 2447 | print FILEO "\n"; |
| 2448 | print FILEO "clean:: \$(SUBDIRS:%=%/__clean__) \$(EXTRASUBDIRS:%=%/__clean__)\n"; |
| 2449 | print FILEO "\t\$(RM) \$(CLEAN_FILES) \$(RC_SRCS:.rc=.res) \$(C_SRCS:.c=.o) \$(CXX_SRCS:.cpp=.o)\n"; |
Alexandre Julliard | 8b84ac8 | 2005-09-29 10:42:43 +0000 | [diff] [blame] | 2450 | print FILEO "\t\$(RM) \$(DLLS:%=%.so) \$(EXES:%=%.so) \$(EXES:%.exe=%)\n"; |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2451 | print FILEO "\n"; |
| 2452 | print FILEO "\$(SUBDIRS:%=%/__clean__): dummy\n"; |
| 2453 | print FILEO "\tcd `dirname \$\@` && \$(MAKE) clean\n"; |
| 2454 | print FILEO "\n"; |
| 2455 | print FILEO "\$(EXTRASUBDIRS:%=%/__clean__): dummy\n"; |
| 2456 | print FILEO "\t-cd `dirname \$\@` && \$(RM) \$(CLEAN_FILES)\n"; |
| 2457 | print FILEO "\n"; |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2458 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2459 | if (@{@$project[$P_TARGETS]} > 0) { |
Francois Gouget | a286c20 | 2005-01-11 10:39:10 +0000 | [diff] [blame] | 2460 | print FILEO "### Target specific build rules\n"; |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 2461 | print FILEO "DEFLIB = \$(LIBRARY_PATH) \$(LIBRARIES) \$(DLL_PATH) \$(DLL_IMPORTS:%=-l%)\n\n"; |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2462 | foreach my $target (@{@$project[$P_TARGETS]}) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2463 | my $canon=canonize("@$target[$T_NAME]"); |
| 2464 | $canon =~ s/_so$//; |
Martin Wilck | 90d6528 | 2002-09-13 17:43:25 +0000 | [diff] [blame] | 2465 | |
Alexandre Julliard | 8b84ac8 | 2005-09-29 10:42:43 +0000 | [diff] [blame] | 2466 | print FILEO "\$(${canon}_MODULE).so: \$(${canon}_OBJS)\n"; |
Francois Gouget | 8d0e1e7 | 2001-03-04 01:03:55 +0000 | [diff] [blame] | 2467 | if (@{@$target[$T_SOURCES_CXX]} > 0 or @{@$project_settings[$T_SOURCES_CXX]} > 0) { |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2468 | print FILEO "\t\$(CXX)"; |
Francois Gouget | 8d0e1e7 | 2001-03-04 01:03:55 +0000 | [diff] [blame] | 2469 | } else { |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2470 | print FILEO "\t\$(CC)"; |
Francois Gouget | 8d0e1e7 | 2001-03-04 01:03:55 +0000 | [diff] [blame] | 2471 | } |
Alexandre Julliard | 8b84ac8 | 2005-09-29 10:42:43 +0000 | [diff] [blame] | 2472 | print FILEO " \$(${canon}_LDFLAGS) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(DEFLIB) \$(${canon}_DLLS:%=-l%) \$(${canon}_LIBRARIES:%=-l%)\n"; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2473 | print FILEO "\n\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | close(FILEO); |
Francois Gouget | 35246cb | 2001-05-07 18:19:57 +0000 | [diff] [blame] | 2477 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2480 | |
| 2481 | ## |
Alexandre Julliard | 7cae558 | 2002-06-01 02:55:48 +0000 | [diff] [blame] | 2482 | # This is where we finally generate files. In fact this method does not |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2483 | # do anything itself but calls the methods that do the actual work. |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2484 | sub generate() |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2485 | { |
| 2486 | print "Generating project files...\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2487 | |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2488 | foreach my $project (@projects) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2489 | my $path=@$project[$P_PATH]; |
| 2490 | if ($path eq "") { |
| 2491 | $path="."; |
| 2492 | } else { |
| 2493 | $path =~ s+/$++; |
| 2494 | } |
| 2495 | print " $path\n"; |
| 2496 | generate_project_files($project); |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | ##### |
| 2503 | # |
| 2504 | # Option defaults |
| 2505 | # |
| 2506 | ##### |
| 2507 | |
| 2508 | $opt_backup=1; |
| 2509 | $opt_lower=$OPT_LOWER_UPPERCASE; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2510 | $opt_lower_include=1; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2511 | |
Francois Gouget | c7201ce | 2004-03-03 02:19:20 +0000 | [diff] [blame] | 2512 | $opt_work_dir=undef; |
| 2513 | $opt_single_target=undef; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2514 | $opt_target_type=$TT_GUIEXE; |
| 2515 | $opt_flags=0; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 2516 | $opt_arch=$OPT_ARCH_DEFAULT; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2517 | $opt_is_interactive=$OPT_ASK_NO; |
| 2518 | $opt_ask_project_options=$OPT_ASK_NO; |
| 2519 | $opt_ask_target_options=$OPT_ASK_NO; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2520 | $opt_no_generated_files=0; |
Bill Medland | ce4e0a6 | 2001-09-24 01:11:50 +0000 | [diff] [blame] | 2521 | $opt_no_source_fix=0; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2522 | $opt_no_banner=0; |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | ##### |
| 2527 | # |
| 2528 | # Main |
| 2529 | # |
| 2530 | ##### |
| 2531 | |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2532 | sub print_banner() |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2533 | { |
| 2534 | print "Winemaker $version\n"; |
| 2535 | print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n"; |
André Hentschel | 0c53d2e | 2009-04-23 19:07:54 +0200 | [diff] [blame] | 2536 | print "Copyright 2004 Dimitrie O. Paun\n"; |
| 2537 | print "Copyright 2009 André Hentschel\n"; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Francois Gouget | e3d26a3 | 2002-09-06 18:36:19 +0000 | [diff] [blame] | 2540 | sub usage() |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2541 | { |
| 2542 | print_banner(); |
Bill Medland | ce4e0a6 | 2001-09-24 01:11:50 +0000 | [diff] [blame] | 2543 | print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup] [--nosource-fix]\n"; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2544 | print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n"; |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2545 | print STDERR " [--lower-include|--nolower-include] [--mfc|--nomfc]\n"; |
Martin Wilck | 90d6528 | 2002-09-13 17:43:25 +0000 | [diff] [blame] | 2546 | print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n"; |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 2547 | print STDERR " [-Dmacro[=defn]] [-Idir] [-Pdir] [-idll] [-Ldir] [-llibrary]\n"; |
Francois Gouget | 15487bc | 2004-02-02 23:02:32 +0000 | [diff] [blame] | 2548 | print STDERR " [--nodlls] [--nomsvcrt] [--interactive] [--single-target name]\n"; |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2549 | print STDERR " [--generated-files|--nogenerated-files]\n"; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 2550 | print STDERR " [--wine32]\n"; |
André Hentschel | df5c417 | 2009-04-02 18:53:24 +0200 | [diff] [blame] | 2551 | print STDERR " work_directory|project_file|workspace_file\n"; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2552 | print STDERR "\nWinemaker is designed to recursively convert all the Windows sources found in\n"; |
André Hentschel | d26857c | 2009-08-29 13:11:12 +0200 | [diff] [blame] | 2553 | print STDERR "the specified directory or project-file, so that they can be compiled with Winelib.\n"; |
| 2554 | print STDERR "During this process it will modify and rename some of the corresponding files.\n"; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2555 | print STDERR "\tPlease read the manual page before use.\n"; |
| 2556 | exit (2); |
| 2557 | } |
| 2558 | |
Martin Wilck | 90d6528 | 2002-09-13 17:43:25 +0000 | [diff] [blame] | 2559 | target_init(\@global_settings); |
| 2560 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2561 | while (@ARGV>0) { |
| 2562 | my $arg=shift @ARGV; |
| 2563 | # General options |
| 2564 | if ($arg eq "--nobanner") { |
| 2565 | $opt_no_banner=1; |
| 2566 | } elsif ($arg eq "--backup") { |
| 2567 | $opt_backup=1; |
| 2568 | } elsif ($arg eq "--nobackup") { |
| 2569 | $opt_backup=0; |
| 2570 | } elsif ($arg eq "--single-target") { |
| 2571 | $opt_single_target=shift @ARGV; |
| 2572 | } elsif ($arg eq "--lower-none") { |
| 2573 | $opt_lower=$OPT_LOWER_NONE; |
| 2574 | } elsif ($arg eq "--lower-all") { |
| 2575 | $opt_lower=$OPT_LOWER_ALL; |
| 2576 | } elsif ($arg eq "--lower-uppercase") { |
| 2577 | $opt_lower=$OPT_LOWER_UPPERCASE; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2578 | } elsif ($arg eq "--lower-include") { |
| 2579 | $opt_lower_include=1; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2580 | } elsif ($arg eq "--nolower-include") { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2581 | $opt_lower_include=0; |
Bill Medland | ce4e0a6 | 2001-09-24 01:11:50 +0000 | [diff] [blame] | 2582 | } elsif ($arg eq "--nosource-fix") { |
| 2583 | $opt_no_source_fix=1; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2584 | } elsif ($arg eq "--generated-files") { |
| 2585 | $opt_no_generated_files=0; |
Francois Gouget | 82747b7 | 2000-11-25 01:38:39 +0000 | [diff] [blame] | 2586 | } elsif ($arg eq "--nogenerated-files") { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2587 | $opt_no_generated_files=1; |
André Hentschel | 65900b4 | 2010-04-21 20:22:13 +0200 | [diff] [blame] | 2588 | } elsif ($arg eq "--wine32") { |
| 2589 | $opt_arch=$OPT_ARCH_32; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2590 | } elsif ($arg =~ /^-D/) { |
| 2591 | push @{$global_settings[$T_DEFINES]},$arg; |
| 2592 | } elsif ($arg =~ /^-I/) { |
| 2593 | push @{$global_settings[$T_INCLUDE_PATH]},$arg; |
Francois Gouget | 89a0c02 | 2001-07-30 18:44:48 +0000 | [diff] [blame] | 2594 | } elsif ($arg =~ /^-P/) { |
| 2595 | push @{$global_settings[$T_DLL_PATH]},"-L$'"; |
| 2596 | } elsif ($arg =~ /^-i/) { |
Dimitrie O. Paun | 905658c | 2004-02-27 21:24:20 +0000 | [diff] [blame] | 2597 | push @{$global_settings[$T_DLLS]},$'; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2598 | } elsif ($arg =~ /^-L/) { |
| 2599 | push @{$global_settings[$T_LIBRARY_PATH]},$arg; |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2600 | } elsif ($arg =~ /^-l/) { |
| 2601 | push @{$global_settings[$T_LIBRARIES]},$'; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2602 | |
| 2603 | # 'Source'-based method options |
| 2604 | } elsif ($arg eq "--dll") { |
| 2605 | $opt_target_type=$TT_DLL; |
| 2606 | } elsif ($arg eq "--guiexe" or $arg eq "--windows") { |
| 2607 | $opt_target_type=$TT_GUIEXE; |
| 2608 | } elsif ($arg eq "--cuiexe" or $arg eq "--console") { |
| 2609 | $opt_target_type=$TT_CUIEXE; |
| 2610 | } elsif ($arg eq "--interactive") { |
| 2611 | $opt_is_interactive=$OPT_ASK_YES; |
| 2612 | $opt_ask_project_options=$OPT_ASK_YES; |
| 2613 | $opt_ask_target_options=$OPT_ASK_YES; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2614 | } elsif ($arg eq "--mfc") { |
Francois Gouget | be85959 | 2000-11-15 22:12:20 +0000 | [diff] [blame] | 2615 | $opt_flags|=$TF_MFC; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2616 | } elsif ($arg eq "--nomfc") { |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 2617 | $opt_flags&=~$TF_MFC; |
| 2618 | $opt_flags|=$TF_NOMFC; |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 2619 | } elsif ($arg eq "--nodlls") { |
| 2620 | $opt_flags|=$TF_NODLLS; |
Francois Gouget | 15487bc | 2004-02-02 23:02:32 +0000 | [diff] [blame] | 2621 | } elsif ($arg eq "--nomsvcrt") { |
| 2622 | $opt_flags|=$TF_NOMSVCRT; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2623 | |
| 2624 | # Catch errors |
| 2625 | } else { |
| 2626 | if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") { |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 2627 | if (!defined $opt_work_dir and !defined $opt_work_file) { |
| 2628 | if (-f $arg) { |
| 2629 | $opt_work_file=$arg; |
| 2630 | } |
| 2631 | else { |
| 2632 | $opt_work_dir=$arg; |
| 2633 | } |
| 2634 | } else { |
| 2635 | print STDERR "error: the work directory, \"$arg\", has already been specified (was \"$opt_work_dir\")\n"; |
| 2636 | usage(); |
| 2637 | } |
François Gouget | c1f016b | 2001-01-10 22:43:21 +0000 | [diff] [blame] | 2638 | } else { |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 2639 | usage(); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2640 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 2644 | if (!defined $opt_work_dir and !defined $opt_work_file) { |
| 2645 | print STDERR "error: you must specify the directory or project file containing the sources to be converted\n"; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2646 | usage(); |
André Hentschel | dc21b4f | 2009-04-02 18:53:14 +0200 | [diff] [blame] | 2647 | } elsif (defined $opt_work_dir and !chdir $opt_work_dir) { |
François Gouget | c1f016b | 2001-01-10 22:43:21 +0000 | [diff] [blame] | 2648 | print STDERR "error: could not chdir to the work directory\n"; |
| 2649 | print STDERR " $!\n"; |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2650 | usage(); |
François Gouget | c1f016b | 2001-01-10 22:43:21 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
François Gouget | 38b3ac5 | 2001-01-11 20:17:42 +0000 | [diff] [blame] | 2653 | if ($opt_no_banner == 0) { |
| 2654 | print_banner(); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2655 | } |
| 2656 | |
Francois Gouget | 786a2cd | 2009-02-25 10:33:48 +0100 | [diff] [blame] | 2657 | project_init(\@main_project, "", \@global_settings); |
Martin Wilck | 3aa9e8c | 2002-09-10 00:20:27 +0000 | [diff] [blame] | 2658 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2659 | # Fix the file and directory names |
| 2660 | fix_file_and_directory_names("."); |
| 2661 | |
| 2662 | # Scan the sources to identify the projects and targets |
| 2663 | source_scan(); |
| 2664 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2665 | # Fix the source files |
Bill Medland | ce4e0a6 | 2001-09-24 01:11:50 +0000 | [diff] [blame] | 2666 | if (! $opt_no_source_fix) { |
| 2667 | fix_source(); |
| 2668 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2669 | |
| 2670 | # Generate the Makefile and the spec file |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame] | 2671 | if (! $opt_no_generated_files) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2672 | generate(); |
| 2673 | } |