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