Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | # Copyright 2000 Francois Gouget for CodeWeavers |
| 4 | # fgouget@codeweavers.com |
| 5 | # |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 6 | my $version="0.5.2"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 7 | |
| 8 | use Cwd; |
| 9 | use File::Basename; |
| 10 | use File::Copy; |
| 11 | |
| 12 | |
| 13 | |
| 14 | ##### |
| 15 | # |
| 16 | # Options |
| 17 | # |
| 18 | ##### |
| 19 | |
| 20 | # The following constants define what we do with the case of filenames |
| 21 | |
| 22 | ## |
| 23 | # Never rename a file to lowercase |
| 24 | my $OPT_LOWER_NONE=0; |
| 25 | |
| 26 | ## |
| 27 | # Rename all files to lowercase |
| 28 | my $OPT_LOWER_ALL=1; |
| 29 | |
| 30 | ## |
| 31 | # Rename only files that are all uppercase to lowercase |
| 32 | my $OPT_LOWER_UPPERCASE=2; |
| 33 | |
| 34 | |
| 35 | # The following constants define whether to ask questions or not |
| 36 | |
| 37 | ## |
| 38 | # No (synonym of never) |
| 39 | my $OPT_ASK_NO=0; |
| 40 | |
| 41 | ## |
| 42 | # Yes (always) |
| 43 | my $OPT_ASK_YES=1; |
| 44 | |
| 45 | ## |
| 46 | # Skip the questions till the end of this scope |
| 47 | my $OPT_ASK_SKIP=-1; |
| 48 | |
| 49 | |
| 50 | # General options |
| 51 | |
| 52 | ## |
| 53 | # Make a backup of the files |
| 54 | my $opt_backup; |
| 55 | |
| 56 | ## |
| 57 | # Defines which files to rename |
| 58 | my $opt_lower; |
| 59 | |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 60 | ## |
| 61 | # If we don't find the file referenced by an include, lower it |
| 62 | my $opt_lower_include; |
| 63 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 64 | |
| 65 | # Options for the 'Source' method |
| 66 | |
| 67 | ## |
| 68 | # Specifies that we have only one target so that all sources relate |
| 69 | # to this target. By default this variable is left undefined which |
| 70 | # means winemaker should try to find out by itself what the targets |
| 71 | # are. If not undefined then this contains the name of the default |
| 72 | # target (without the extension). |
| 73 | my $opt_single_target; |
| 74 | |
| 75 | ## |
| 76 | # If '$opt_single_target' has been specified then this is the type of |
| 77 | # that target. Otherwise it specifies whether the default target type |
| 78 | # is guiexe or cuiexe. |
| 79 | my $opt_target_type; |
| 80 | |
| 81 | ## |
| 82 | # Contains the default set of flags to be used when creating a new target. |
| 83 | my $opt_flags; |
| 84 | |
| 85 | ## |
| 86 | # If true then winemaker should ask questions to the user as it goes |
| 87 | # along. |
| 88 | my $opt_is_interactive; |
| 89 | my $opt_ask_project_options; |
| 90 | my $opt_ask_target_options; |
| 91 | |
| 92 | ## |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 93 | # If false then winemaker should not generate any file, i.e. |
| 94 | # no makefiles, but also no .spec files, no configure.in, etc. |
| 95 | my $opt_no_generated_files; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 96 | |
| 97 | ## |
| 98 | # Specifies not to print the banner if set. |
| 99 | my $opt_no_banner; |
| 100 | |
| 101 | |
| 102 | |
| 103 | ##### |
| 104 | # |
| 105 | # Target modelization |
| 106 | # |
| 107 | ##### |
| 108 | |
| 109 | # The description of a target is stored in an array. The constants |
| 110 | # below identify what is stored at each index of the array. |
| 111 | |
| 112 | ## |
| 113 | # This is the name of the target. |
| 114 | my $T_NAME=0; |
| 115 | |
| 116 | ## |
| 117 | # Defines the type of target we want to build. See the TT_xxx |
| 118 | # constants below |
| 119 | my $T_TYPE=1; |
| 120 | |
| 121 | ## |
| 122 | # Defines the target's enty point, i.e. the function that is called |
| 123 | # on startup. |
| 124 | my $T_INIT=2; |
| 125 | |
| 126 | ## |
| 127 | # This is a bitfield containing flags refining the way the target |
| 128 | # should be handled. See the TF_xxx constants below |
| 129 | my $T_FLAGS=12; |
| 130 | |
| 131 | ## |
| 132 | # This is a reference to an array containing the list of the |
| 133 | # resp. C, C++, RC, other (.h, .hxx, etc.) source files. |
| 134 | my $T_SOURCES_C=3; |
| 135 | my $T_SOURCES_CXX=4; |
| 136 | my $T_SOURCES_RC=5; |
| 137 | my $T_SOURCES_MISC=6; |
| 138 | |
| 139 | ## |
| 140 | # This is a reference to an array containing the list of macro |
| 141 | # definitions |
| 142 | my $T_DEFINES=7; |
| 143 | |
| 144 | ## |
| 145 | # This is a reference to an array containing the list of directory |
| 146 | # names that constitute the include path |
| 147 | my $T_INCLUDE_PATH=8; |
| 148 | |
| 149 | ## |
| 150 | # Same as T_INCLUDE_PATH but for the library search path |
| 151 | my $T_LIBRARY_PATH=9; |
| 152 | |
| 153 | ## |
| 154 | # The list of libraries to link with |
| 155 | my $T_IMPORTS=10; |
| 156 | |
| 157 | ## |
| 158 | # The list of dependencies between targets |
| 159 | my $T_DEPENDS=11; |
| 160 | |
| 161 | |
| 162 | # The following constants define the recognized types of target |
| 163 | |
| 164 | ## |
| 165 | # This is not a real target. This type of target is used to collect |
| 166 | # the sources that don't seem to belong to any other target. Thus no |
| 167 | # real target is generated for them, we just put the sources of the |
| 168 | # fake target in the global source list. |
| 169 | my $TT_SETTINGS=0; |
| 170 | |
| 171 | ## |
| 172 | # For executables in the windows subsystem |
| 173 | my $TT_GUIEXE=1; |
| 174 | |
| 175 | ## |
| 176 | # For executables in the console subsystem |
| 177 | my $TT_CUIEXE=2; |
| 178 | |
| 179 | ## |
| 180 | # For dynamically linked libraries |
| 181 | my $TT_DLL=3; |
| 182 | |
| 183 | |
| 184 | # The following constants further refine how the target should be handled |
| 185 | |
| 186 | ## |
| 187 | # This target needs a wrapper |
| 188 | my $TF_WRAP=1; |
| 189 | |
| 190 | ## |
| 191 | # This target is a wrapper |
| 192 | my $TF_WRAPPER=2; |
| 193 | |
| 194 | ## |
| 195 | # This target is an MFC-based target |
| 196 | my $TF_MFC=4; |
| 197 | |
| 198 | ## |
| 199 | # Initialize a target: |
| 200 | # - set the target type to TT_SETTINGS, i.e. no real target will |
| 201 | # be generated. |
| 202 | sub target_init |
| 203 | { |
| 204 | my $target=$_[0]; |
| 205 | |
| 206 | @$target[$T_TYPE]=$TT_SETTINGS; |
| 207 | # leaving $T_INIT undefined |
| 208 | @$target[$T_FLAGS]=$opt_flags; |
| 209 | @$target[$T_SOURCES_C]=[]; |
| 210 | @$target[$T_SOURCES_CXX]=[]; |
| 211 | @$target[$T_SOURCES_RC]=[]; |
| 212 | @$target[$T_SOURCES_MISC]=[]; |
| 213 | @$target[$T_DEFINES]=[]; |
| 214 | @$target[$T_INCLUDE_PATH]=[]; |
| 215 | @$target[$T_LIBRARY_PATH]=[]; |
| 216 | @$target[$T_IMPORTS]=[]; |
| 217 | @$target[$T_DEPENDS]=[]; |
| 218 | } |
| 219 | |
| 220 | sub get_default_init |
| 221 | { |
| 222 | my $type=$_[0]; |
| 223 | if ($type == $TT_GUIEXE) { |
| 224 | return "WinMain"; |
| 225 | } elsif ($type == $TT_CUIEXE) { |
| 226 | return "main"; |
| 227 | } elsif ($type == $TT_DLL) { |
| 228 | return "DllMain"; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | |
| 233 | |
| 234 | ##### |
| 235 | # |
| 236 | # Project modelization |
| 237 | # |
| 238 | ##### |
| 239 | |
| 240 | # First we have the notion of project. A project is described by an |
| 241 | # array (since we don't have structs in perl). The constants below |
| 242 | # identify what is stored at each index of the array. |
| 243 | |
| 244 | ## |
| 245 | # This is the path in which this project is located. In other |
| 246 | # words, this is the path to the Makefile. |
| 247 | my $P_PATH=0; |
| 248 | |
| 249 | ## |
| 250 | # This index contains a reference to an array containing the project-wide |
| 251 | # settings. The structure of that arrray is actually identical to that of |
| 252 | # a regular target since it can also contain extra sources. |
| 253 | my $P_SETTINGS=1; |
| 254 | |
| 255 | ## |
| 256 | # This index contains a reference to an array of targets for this |
| 257 | # project. Each target describes how an executable or library is to |
| 258 | # be built. For each target this description takes the same form as |
| 259 | # that of the project: an array. So this entry is an array of arrays. |
| 260 | my $P_TARGETS=2; |
| 261 | |
| 262 | ## |
| 263 | # Initialize a project: |
| 264 | # - set the project's path |
| 265 | # - initialize the target list |
| 266 | # - create a default target (will be removed later if unnecessary) |
| 267 | sub project_init |
| 268 | { |
| 269 | my $project=$_[0]; |
| 270 | my $path=$_[1]; |
| 271 | |
| 272 | my $project_settings=[]; |
| 273 | target_init($project_settings); |
| 274 | |
| 275 | @$project[$P_PATH]=$path; |
| 276 | @$project[$P_SETTINGS]=$project_settings; |
| 277 | @$project[$P_TARGETS]=[]; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | |
| 282 | ##### |
| 283 | # |
| 284 | # Global variables |
| 285 | # |
| 286 | ##### |
| 287 | |
| 288 | my $usage; |
| 289 | my %warnings; |
| 290 | |
| 291 | my %templates; |
| 292 | |
| 293 | ## |
| 294 | # Contains the list of all projects. This list tells us what are |
| 295 | # the subprojects of the main Makefile and where we have to generate |
| 296 | # Makefiles. |
| 297 | my @projects=(); |
| 298 | |
| 299 | ## |
| 300 | # This is the main project, i.e. the one in the "." directory. |
| 301 | # It may well be empty in which case the main Makefile will only |
| 302 | # call out subprojects. |
| 303 | my @main_project; |
| 304 | |
| 305 | ## |
| 306 | # Contains the defaults for the include path, etc. |
| 307 | # We store the defaults as if this were a target except that we only |
| 308 | # exploit the defines, include path, library path, library list and misc |
| 309 | # sources fields. |
| 310 | my @global_settings; |
| 311 | |
| 312 | ## |
| 313 | # If one of the projects requires the MFc then we set this global variable |
| 314 | # to true so that configure asks the user to provide a path tothe MFC |
| 315 | my $needs_mfc=0; |
| 316 | |
| 317 | |
| 318 | |
| 319 | ##### |
| 320 | # |
| 321 | # Utility functions |
| 322 | # |
| 323 | ##### |
| 324 | |
| 325 | ## |
| 326 | # Cleans up a name to make it an acceptable Makefile |
| 327 | # variable name. |
| 328 | sub canonize |
| 329 | { |
| 330 | my $name=$_[0]; |
| 331 | |
| 332 | $name =~ tr/a-zA-Z0-9_/_/c; |
| 333 | return $name; |
| 334 | } |
| 335 | |
| 336 | ## |
| 337 | # Returns true is the specified pathname is absolute. |
| 338 | # Note: pathnames that start with a variable '$' or |
| 339 | # '~' are considered absolute. |
| 340 | sub is_absolute |
| 341 | { |
| 342 | my $path=$_[0]; |
| 343 | |
| 344 | return ($path =~ /^[\/~\$]/); |
| 345 | } |
| 346 | |
| 347 | ## |
| 348 | # Performs a binary search looking for the specified item |
| 349 | sub bsearch |
| 350 | { |
| 351 | my $array=$_[0]; |
| 352 | my $item=$_[1]; |
| 353 | my $last=@{$array}-1; |
| 354 | my $first=0; |
| 355 | |
| 356 | while ($first<=$last) { |
| 357 | my $index=int(($first+$last)/2); |
| 358 | my $cmp=@$array[$index] cmp $item; |
| 359 | if ($cmp<0) { |
| 360 | $first=$index+1; |
| 361 | } elsif ($cmp>0) { |
| 362 | $last=$index-1; |
| 363 | } else { |
| 364 | return $index; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | |
| 370 | |
| 371 | ##### |
| 372 | # |
| 373 | # 'Source'-based Project analysis |
| 374 | # |
| 375 | ##### |
| 376 | |
| 377 | ## |
| 378 | # Allows the user to specify makefile and target specific options |
| 379 | # - target: the structure in which to store the results |
| 380 | # - options: the string containing the options |
| 381 | sub source_set_options |
| 382 | { |
| 383 | my $target=$_[0]; |
| 384 | my $options=$_[1]; |
| 385 | |
| 386 | #FIXME: we must deal with escaping of stuff and all |
| 387 | foreach $option (split / /,$options) { |
| 388 | if (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-D/) { |
| 389 | push @{@$target[$T_DEFINES]},$option; |
| 390 | } elsif (@$target[$T_TYPE] == $TT_SETTINGS and $option =~ /^-I/) { |
| 391 | push @{@$target[$T_INCLUDE_PATH]},$option; |
| 392 | } elsif ($option =~ /^-L/) { |
| 393 | push @{@$target[$T_LIBRARY_PATH]},$option; |
| 394 | } elsif ($option =~ /^-l/) { |
| 395 | push @{@$target[$T_IMPORTS]},$'; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 396 | } elsif (@$target[$T_TYPE] != $TT_DLL and |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 397 | $option =~ /^--wrap/) { |
| 398 | @$target[$T_FLAGS]|=$TF_WRAP; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 399 | } elsif (@$target[$T_TYPE] != $TT_DLL and |
| 400 | $option =~ /^--no-wrap/) { |
| 401 | @$target[$T_FLAGS]&=~$TF_WRAP; |
| 402 | } elsif ($option =~ /^--mfc/) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 403 | @$target[$T_FLAGS]|=$TF_MFC; |
| 404 | if (@$target[$T_TYPE] != $TT_DLL) { |
| 405 | @$target[$T_FLAGS]|=$TF_WRAP; |
| 406 | } |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 407 | } elsif ($option =~ /^--no-mfc/) { |
| 408 | @$target[$T_FLAGS]&=~($TF_MFC|$TF_WRAP); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 409 | } else { |
| 410 | print STDERR "warning: unknown option \"$option\", ignoring it\n"; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | ## |
| 416 | # Scans the specified directory to: |
| 417 | # - see if we should create a Makefile in this directory. We normally do |
| 418 | # so if we find a project file and sources |
| 419 | # - get a list of targets for this directory |
| 420 | # - get the list of source files |
| 421 | sub source_scan_directory |
| 422 | { |
| 423 | # a reference to the parent's project |
| 424 | my $parent_project=$_[0]; |
| 425 | # the full relative path to the current directory, including a |
| 426 | # trailing '/', or an empty string if this is the top level directory |
| 427 | my $path=$_[1]; |
| 428 | # the name of this directory, including a trailing '/', or an empty |
| 429 | # string if this is the top level directory |
| 430 | my $dirname=$_[2]; |
| 431 | |
| 432 | # reference to the project for this directory. May not be used |
| 433 | my $project; |
| 434 | # list of targets found in the 'current' directory |
| 435 | my %targets; |
| 436 | # list of sources found in the current directory |
| 437 | my @sources_c=(); |
| 438 | my @sources_cxx=(); |
| 439 | my @sources_rc=(); |
| 440 | my @sources_misc=(); |
| 441 | # true if this directory contains a Windows project |
| 442 | my $has_win_project=0; |
| 443 | # If we don't find any executable/library then we might make up targets |
| 444 | # from the list of .dsp/.mak files we find since they usually have the |
| 445 | # same name as their target. |
| 446 | my @dsp_files=(); |
| 447 | my @mak_files=(); |
| 448 | |
| 449 | if (defined $opt_single_target or $dirname eq "") { |
| 450 | # Either there is a single target and thus a single project, |
| 451 | # or we are in the top level directory for which a project |
| 452 | # already exists |
| 453 | $project=$parent_project; |
| 454 | } else { |
| 455 | $project=[]; |
| 456 | project_init($project,$path); |
| 457 | } |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 458 | my $project_settings=@$project[$P_SETTINGS]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 459 | |
| 460 | # First find out what this directory contains: |
| 461 | # collect all sources, targets and subdirectories |
| 462 | my $directory=get_directory_contents($path); |
| 463 | foreach $dentry (@$directory) { |
| 464 | if ($dentry =~ /^\./) { |
| 465 | next; |
| 466 | } |
| 467 | my $fullentry="$path$dentry"; |
| 468 | if (-d "$fullentry") { |
| 469 | if ($dentry =~ /^(Release|Debug)/i) { |
| 470 | # These directories are often used to store the object files and the |
| 471 | # resulting executable/library. They should not contain anything else. |
| 472 | my @candidates=grep /\.(exe|dll)$/i, @{get_directory_contents("$fullentry")}; |
| 473 | foreach $candidate (@candidates) { |
| 474 | if ($candidate =~ s/\.exe$//i) { |
| 475 | $targets{$candidate}=1; |
| 476 | } elsif ($candidate =~ s/^(.*)\.dll$/lib$1.so/i) { |
| 477 | $targets{$candidate}=1; |
| 478 | } |
| 479 | } |
| 480 | } else { |
| 481 | # Recursively scan this directory. Any source file that cannot be |
| 482 | # attributed to a project in one of the subdirectories will be attributed |
| 483 | # to this project. |
| 484 | source_scan_directory($project,"$fullentry/","$dentry/"); |
| 485 | } |
| 486 | } elsif (-f "$fullentry") { |
| 487 | if ($dentry =~ s/\.exe$//i) { |
| 488 | $targets{$dentry}=1; |
| 489 | } elsif ($dentry =~ s/^(.*)\.dll$/lib$1.so/i) { |
| 490 | $targets{$dentry}=1; |
| 491 | } elsif ($dentry =~ /\.c$/i and $dentry !~ /\.spec\.c$/) { |
| 492 | push @sources_c,"$dentry"; |
| 493 | } elsif ($dentry =~ /\.(cpp|cxx)$/i) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 494 | if ($dentry =~ /^stdafx.cpp$/i) { |
| 495 | push @sources_misc,"$dentry"; |
| 496 | @$project_settings[$T_FLAGS]|=$TF_MFC|$TF_WRAP; |
| 497 | } else { |
| 498 | push @sources_cxx,"$dentry"; |
| 499 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 500 | } elsif ($dentry =~ /\.rc$/i) { |
| 501 | push @sources_rc,"$dentry"; |
| 502 | } elsif ($dentry =~ /\.(h|hxx|inl|rc2|dlg)$/i) { |
| 503 | push @sources_misc,"$dentry"; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 504 | if ($dentry =~ /^stdafx.h$/i) { |
| 505 | @$project_settings[$T_FLAGS]|=$TF_MFC|$TF_WRAP; |
| 506 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 507 | } elsif ($dentry =~ /\.dsp$/i) { |
| 508 | push @dsp_files,"$dentry"; |
| 509 | $has_win_project=1; |
| 510 | } elsif ($dentry =~ /\.mak$/i) { |
| 511 | push @mak_files,"$dentry"; |
| 512 | $has_win_project=1; |
| 513 | } elsif ($dentry =~ /^makefile/i) { |
| 514 | $has_win_project=1; |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | closedir(DIRECTORY); |
| 519 | |
| 520 | # If we have a single target then all we have to do is assign |
| 521 | # all the sources to it and we're done |
| 522 | # FIXME: does this play well with the --interactive mode? |
| 523 | if ($opt_single_target) { |
| 524 | my $target=@{@$project[$P_TARGETS]}[0]; |
| 525 | push @{@$target[$T_SOURCES_C]},map "$path$_",@sources_c; |
| 526 | push @{@$target[$T_SOURCES_CXX]},map "$path$_",@sources_cxx; |
| 527 | push @{@$target[$T_SOURCES_RC]},map "$path$_",@sources_rc; |
| 528 | push @{@$target[$T_SOURCES_MISC]},map "$path$_",@sources_misc; |
| 529 | return; |
| 530 | } |
| 531 | |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 532 | my $source_count=@sources_c+@sources_cxx+@sources_rc+ |
| 533 | @{@$project_settings[$T_SOURCES_C]}+ |
| 534 | @{@$project_settings[$T_SOURCES_CXX]}+ |
| 535 | @{@$project_settings[$T_SOURCES_RC]}; |
| 536 | if ($source_count == 0) { |
| 537 | # A project without real sources is not a project, get out! |
| 538 | if ($project!=$parent_project) { |
| 539 | $parent_settings=@$parent_project[$P_SETTINGS]; |
| 540 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc; |
| 541 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]}; |
| 542 | } |
| 543 | return; |
| 544 | } |
| 545 | #print "targets=",%targets,"\n"; |
| 546 | #print "target_count=$target_count\n"; |
| 547 | #print "has_win_project=$has_win_project\n"; |
| 548 | #print "dirname=$dirname\n"; |
| 549 | |
| 550 | my $target_count; |
| 551 | if (($has_win_project != 0) or ($dirname eq "")) { |
| 552 | # Deal with cases where we could not find any executable/library, and |
| 553 | # thus have no target, although we did find some sort of windows project. |
| 554 | $target_count=keys %targets; |
| 555 | if ($target_count == 0) { |
| 556 | # Try to come up with a target list based on .dsp/.mak files |
| 557 | my $prj_list; |
| 558 | if (@dsp_files > 0) { |
| 559 | $prj_list=\@dsp_files; |
| 560 | } else { |
| 561 | $prj_list=\@mak_files; |
| 562 | } |
| 563 | foreach $filename (@$prj_list) { |
| 564 | $filename =~ s/\.(dsp|mak)$//i; |
| 565 | if ($opt_target_type == $TT_DLL) { |
| 566 | $filename = "lib$filename.so"; |
| 567 | } |
| 568 | $targets{$filename}=1; |
| 569 | } |
| 570 | $target_count=keys %targets; |
| 571 | if ($target_count == 0) { |
| 572 | # Still nothing, try the name of the directory |
| 573 | my $name; |
| 574 | if ($dirname eq "") { |
| 575 | # Bad luck, this is the top level directory! |
| 576 | $name=(split /\//, cwd)[-1]; |
| 577 | } else { |
| 578 | $name=$dirname; |
| 579 | # Remove the trailing '/'. Also eliminate whatever is after the last |
| 580 | # '.' as it is likely to be meaningless (.orig, .new, ...) |
| 581 | $name =~ s+(/|\.[^.]*)$++; |
| 582 | if ($name eq "src") { |
| 583 | # 'src' is probably a subdirectory of the real project directory. |
| 584 | # Try again with the parent (if any). |
| 585 | my $parent=$path; |
| 586 | if ($parent =~ s+([^/]*)/[^/]*/$+$1+) { |
| 587 | $name=$parent; |
| 588 | } else { |
| 589 | $name=(split /\//, cwd)[-1]; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | $name =~ s+(/|\.[^.]*)$++; |
| 594 | if ($opt_target_type == $TT_DLL) { |
| 595 | $name = "lib$name.so"; |
| 596 | } |
| 597 | $targets{$name}=1; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | # Ask confirmation to the user if he wishes so |
| 602 | if ($opt_is_interactive == $OPT_ASK_YES) { |
| 603 | my $target_list=join " ",keys %targets; |
| 604 | print "\n*** In $path\n"; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 605 | print "* winemaker found the following list of (potential) targets\n"; |
| 606 | print "* $target_list\n"; |
| 607 | print "* Type enter to use it as is, your own comma-separated list of\n"; |
| 608 | print "* targets, 'none' to assign the source files to a parent directory,\n"; |
| 609 | print "* or 'ignore' to ignore everything in this directory tree.\n"; |
| 610 | print "* Target list:\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 611 | $target_list=<STDIN>; |
| 612 | chomp $target_list; |
| 613 | if ($target_list eq "") { |
| 614 | # Keep the target list as is, i.e. do nothing |
| 615 | } elsif ($target_list eq "none") { |
| 616 | # Empty the target list |
| 617 | undef %targets; |
| 618 | } elsif ($target_list eq "ignore") { |
| 619 | # Ignore this subtree altogether |
| 620 | return; |
| 621 | } else { |
| 622 | undef %targets; |
| 623 | foreach $target (split /,/,$target_list) { |
| 624 | $target =~ s+^\s*++; |
| 625 | $target =~ s+\s*$++; |
| 626 | # Also accept .exe and .dll as a courtesy |
| 627 | $target =~ s+(.*)\.dll$+lib$1.so+; |
| 628 | $target =~ s+\.exe$++; |
| 629 | $targets{$target}=1; |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | # If we have no project at this level, then transfer all |
| 636 | # the sources to the parent project |
| 637 | $target_count=keys %targets; |
| 638 | if ($target_count == 0) { |
| 639 | if ($project!=$parent_project) { |
| 640 | my $parent_settings=@$parent_project[$P_SETTINGS]; |
| 641 | push @{@$parent_settings[$T_SOURCES_C]},map "$dirname$_",@sources_c; |
| 642 | push @{@$parent_settings[$T_SOURCES_CXX]},map "$dirname$_",@sources_cxx; |
| 643 | push @{@$parent_settings[$T_SOURCES_RC]},map "$dirname$_",@sources_rc; |
| 644 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@sources_misc; |
| 645 | push @{@$parent_settings[$T_SOURCES_MISC]},map "$dirname$_",@{@$project_settings[$T_SOURCES_MISC]}; |
| 646 | } |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | # Otherwise add this project to the project list, except for |
| 651 | # the main project which is already in the list. |
| 652 | if ($dirname ne "") { |
| 653 | push @projects,$project; |
| 654 | } |
| 655 | |
| 656 | # Ask for project-wide options |
| 657 | if ($opt_ask_project_options == $OPT_ASK_YES) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 658 | my $flag_desc=""; |
| 659 | if ((@$project_settings[$T_FLAGS] & $TF_MFC)!=0) { |
| 660 | $flag_desc="mfc"; |
| 661 | } |
| 662 | if ((@$project_settings[$T_FLAGS] & $TF_WRAP)!=0) { |
| 663 | if ($flag_desc ne "") { |
| 664 | $flag_desc.=", "; |
| 665 | } |
| 666 | $flag_desc.="wrapped"; |
| 667 | } |
| 668 | print "* Type any project-wide options (-D/-I/-L/-l/--mfc/--wrap),\n"; |
| 669 | if (defined $flag_desc) { |
| 670 | print "* (currently $flag_desc)\n"; |
| 671 | } |
| 672 | print "* or 'skip' to skip the target specific options,\n"; |
| 673 | print "* or 'never' to not be asked this question again:\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 674 | my $options=<STDIN>; |
| 675 | chomp $options; |
| 676 | if ($options eq "skip") { |
| 677 | $opt_ask_target_options=$OPT_ASK_SKIP; |
| 678 | } elsif ($options eq "never") { |
| 679 | $opt_ask_project_options="never"; |
| 680 | } else { |
| 681 | source_set_options($project_settings,$options); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
| 685 | # - Create the targets |
| 686 | # - Check if we have both libraries and programs |
| 687 | # - Match each target with source files (sort in reverse |
| 688 | # alphabetical order to get the longest matches first) |
| 689 | my @local_imports=(); |
| 690 | my @local_depends=(); |
| 691 | my @program_list=(); |
| 692 | foreach $target_name (sort { $b cmp $a } keys %targets) { |
| 693 | # Create the target... |
| 694 | my $basename; |
| 695 | my $target=[]; |
| 696 | target_init($target); |
| 697 | @$target[$T_NAME]=$target_name; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 698 | @$target[$T_FLAGS]|=@$project_settings[$T_FLAGS]; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 699 | if ($target_name =~ /^lib(.*)\.so$/) { |
| 700 | @$target[$T_TYPE]=$TT_DLL; |
| 701 | @$target[$T_INIT]=get_default_init($TT_DLL); |
| 702 | @$target[$T_FLAGS]&=~$TF_WRAP; |
| 703 | $basename=$1; |
| 704 | push @local_depends,$target_name; |
| 705 | push @local_imports,$basename; |
| 706 | } else { |
| 707 | @$target[$T_TYPE]=$opt_target_type; |
| 708 | @$target[$T_INIT]=get_default_init($opt_target_type); |
| 709 | $basename=$target_name; |
| 710 | push @program_list,$target; |
| 711 | } |
| 712 | push @{@$project[$P_TARGETS]},$target; |
| 713 | |
| 714 | # Ask for target-specific options |
| 715 | if ($opt_ask_target_options == $OPT_ASK_YES) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 716 | my $flag_desc=""; |
| 717 | if ((@$target[$T_FLAGS] & $TF_MFC)!=0) { |
| 718 | $flag_desc=" (mfc"; |
| 719 | } |
| 720 | if ((@$target[$T_FLAGS] & $TF_WRAP)!=0) { |
| 721 | if ($flag_desc ne "") { |
| 722 | $flag_desc.=", "; |
| 723 | } else { |
| 724 | $flag_desc=" ("; |
| 725 | } |
| 726 | $flag_desc.="wrapped"; |
| 727 | } |
| 728 | if ($flag_desc ne "") { |
| 729 | $flag_desc.=")"; |
| 730 | } |
| 731 | print "* Specify any link option (-L/-l/--mfc/--wrap) specific to the target\n"; |
| 732 | print "* \"$target_name\"$flag_desc or 'never' to not be asked this question again:\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 733 | my $options=<STDIN>; |
| 734 | chomp $options; |
| 735 | if ($options eq "never") { |
| 736 | $opt_ask_target_options=$OPT_ASK_NO; |
| 737 | } else { |
| 738 | source_set_options($target,$options); |
| 739 | } |
| 740 | } |
| 741 | if (@$target[$T_FLAGS] & $TF_MFC) { |
| 742 | @$project_settings[$T_FLAGS]|=$TF_MFC; |
| 743 | push @{@$target[$T_LIBRARY_PATH]},"\$(MFC_LIBRARY_PATH)"; |
| 744 | push @{@$target[$T_IMPORTS]},"mfc"; |
| 745 | } |
| 746 | |
| 747 | # Match sources... |
| 748 | if ($target_count == 1) { |
| 749 | push @{@$target[$T_SOURCES_C]},@sources_c; |
| 750 | push @{@$target[$T_SOURCES_CXX]},@sources_cxx; |
| 751 | push @{@$target[$T_SOURCES_RC]},@sources_rc; |
| 752 | push @{@$target[$T_SOURCES_MISC]},@sources_misc; |
| 753 | @sources_c=(); |
| 754 | @sources_cxx=(); |
| 755 | @sources_rc=(); |
| 756 | @sources_misc=(); |
| 757 | } else { |
| 758 | foreach $source (@sources_c) { |
| 759 | if ($source =~ /^$basename/i) { |
| 760 | push @{@$target[$T_SOURCES_C]},$source; |
| 761 | $source=""; |
| 762 | } |
| 763 | } |
| 764 | foreach $source (@sources_cxx) { |
| 765 | if ($source =~ /^$basename/i) { |
| 766 | push @{@$target[$T_SOURCES_CXX]},$source; |
| 767 | $source=""; |
| 768 | } |
| 769 | } |
| 770 | foreach $source (@sources_rc) { |
| 771 | if ($source =~ /^$basename/i) { |
| 772 | push @{@$target[$T_SOURCES_RC]},$source; |
| 773 | $source=""; |
| 774 | } |
| 775 | } |
| 776 | foreach $source (@sources_misc) { |
| 777 | if ($source =~ /^$basename/i) { |
| 778 | push @{@$target[$T_SOURCES_MISC]},$source; |
| 779 | $source=""; |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | @$target[$T_SOURCES_C]=[sort @{@$target[$T_SOURCES_C]}]; |
| 784 | @$target[$T_SOURCES_CXX]=[sort @{@$target[$T_SOURCES_CXX]}]; |
| 785 | @$target[$T_SOURCES_RC]=[sort @{@$target[$T_SOURCES_RC]}]; |
| 786 | @$target[$T_SOURCES_MISC]=[sort @{@$target[$T_SOURCES_MISC]}]; |
| 787 | } |
| 788 | if ($opt_ask_target_options == $OPT_ASK_SKIP) { |
| 789 | $opt_ask_target_options=$OPT_ASK_YES; |
| 790 | } |
| 791 | |
| 792 | if (@$project_settings[$T_FLAGS] & $TF_MFC) { |
| 793 | push @{@$project_settings[$T_INCLUDE_PATH]},"\$(MFC_INCLUDE_PATH)"; |
| 794 | } |
| 795 | # The sources that did not match, if any, go to the extra |
| 796 | # source list of the project settings |
| 797 | foreach $source (@sources_c) { |
| 798 | if ($source ne "") { |
| 799 | push @{@$project_settings[$T_SOURCES_C]},$source; |
| 800 | } |
| 801 | } |
| 802 | @$project_settings[$T_SOURCES_C]=[sort @{@$project_settings[$T_SOURCES_C]}]; |
| 803 | foreach $source (@sources_cxx) { |
| 804 | if ($source ne "") { |
| 805 | push @{@$project_settings[$T_SOURCES_CXX]},$source; |
| 806 | } |
| 807 | } |
| 808 | @$project_settings[$T_SOURCES_CXX]=[sort @{@$project_settings[$T_SOURCES_CXX]}]; |
| 809 | foreach $source (@sources_rc) { |
| 810 | if ($source ne "") { |
| 811 | push @{@$project_settings[$T_SOURCES_RC]},$source; |
| 812 | } |
| 813 | } |
| 814 | @$project_settings[$T_SOURCES_RC]=[sort @{@$project_settings[$T_SOURCES_RC]}]; |
| 815 | foreach $source (@sources_misc) { |
| 816 | if ($source ne "") { |
| 817 | push @{@$project_settings[$T_SOURCES_MISC]},$source; |
| 818 | } |
| 819 | } |
| 820 | @$project_settings[$T_SOURCES_MISC]=[sort @{@$project_settings[$T_SOURCES_MISC]}]; |
| 821 | |
| 822 | # Finally if we are building both libraries and programs in |
| 823 | # this directory, then the programs should be linked with all |
| 824 | # the libraries |
| 825 | if (@local_imports > 0 and @program_list > 0) { |
| 826 | foreach $target (@program_list) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 827 | push @{@$target[$T_LIBRARY_PATH]},"-L."; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 828 | push @{@$target[$T_IMPORTS]},@local_imports; |
| 829 | push @{@$target[$T_DEPENDS]},@local_depends; |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | ## |
| 835 | # Scan the source directories in search of things to build |
| 836 | sub source_scan |
| 837 | { |
| 838 | my $main_target=@{$main_project[$P_TARGETS]}[0]; |
| 839 | |
| 840 | # If there's a single target then this is going to be the default target |
| 841 | if (defined $opt_single_target) { |
| 842 | if ($opt_target_type == $TT_DLL) { |
| 843 | @$main_target[$T_NAME]="lib$opt_single_target.so"; |
| 844 | } else { |
| 845 | @$main_target[$T_NAME]="$opt_single_target"; |
| 846 | } |
| 847 | @$main_target[$T_TYPE]=$opt_target_type; |
| 848 | } |
| 849 | |
| 850 | # The main directory is always going to be there |
| 851 | push @projects,\@main_project; |
| 852 | |
| 853 | # Now scan the directory tree looking for source files and, maybe, targets |
| 854 | print "Scanning the source directories...\n"; |
| 855 | source_scan_directory(\@main_project,"",""); |
| 856 | |
| 857 | @projects=sort { @$a[$P_PATH] cmp @$b[$P_PATH] } @projects; |
| 858 | } |
| 859 | |
| 860 | |
| 861 | |
| 862 | ##### |
| 863 | # |
| 864 | # 'vc.dsp'-based Project analysis |
| 865 | # |
| 866 | ##### |
| 867 | |
| 868 | #sub analyze_vc_dsp |
| 869 | #{ |
| 870 | # |
| 871 | #} |
| 872 | |
| 873 | |
| 874 | |
| 875 | ##### |
| 876 | # |
| 877 | # Creating the wrapper targets |
| 878 | # |
| 879 | ##### |
| 880 | |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 881 | sub postprocess_targets |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 882 | { |
| 883 | foreach $project (@projects) { |
| 884 | foreach $target (@{@$project[$P_TARGETS]}) { |
| 885 | if ((@$target[$T_FLAGS] & $TF_WRAP) != 0) { |
| 886 | my $wrapper=[]; |
| 887 | target_init($wrapper); |
| 888 | @$wrapper[$T_NAME]=@$target[$T_NAME]; |
| 889 | @$wrapper[$T_TYPE]=@$target[$T_TYPE]; |
| 890 | @$wrapper[$T_INIT]=get_default_init(@$target[$T_TYPE]); |
| 891 | @$wrapper[$T_FLAGS]=$TF_WRAPPER | (@$target[$T_FLAGS] & $TF_MFC); |
| 892 | push @{@$wrapper[$T_SOURCES_C]},"@$wrapper[$T_NAME]_wrapper.c"; |
| 893 | |
| 894 | my $index=bsearch(@$target[$T_SOURCES_C],"@$wrapper[$T_NAME]_wrapper.c"); |
| 895 | if (defined $index) { |
| 896 | splice(@{@$target[$T_SOURCES_C]},$index,1); |
| 897 | } |
| 898 | @$target[$T_NAME]="lib@$target[$T_NAME].so"; |
| 899 | @$target[$T_TYPE]=$TT_DLL; |
| 900 | |
| 901 | push @{@$project[$P_TARGETS]},$wrapper; |
| 902 | } |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 903 | if ((@$target[$T_FLAGS] & $TF_MFC) != 0) { |
| 904 | @{@$project[$P_SETTINGS]}[$T_FLAGS]|=$TF_MFC; |
| 905 | $needs_mfc=1; |
| 906 | } |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | |
| 912 | |
| 913 | ##### |
| 914 | # |
| 915 | # Source search |
| 916 | # |
| 917 | ##### |
| 918 | |
| 919 | ## |
| 920 | # Performs a directory traversal and renames the files so that: |
| 921 | # - they have the case desired by the user |
| 922 | # - their extension is of the appropriate case |
| 923 | # - they don't contain annoying characters like ' ', '$', '#', ... |
| 924 | sub fix_file_and_directory_names |
| 925 | { |
| 926 | my $dirname=$_[0]; |
| 927 | |
| 928 | if (opendir(DIRECTORY, "$dirname")) { |
| 929 | foreach $dentry (readdir DIRECTORY) { |
| 930 | if ($dentry =~ /^\./ or $dentry eq "CVS") { |
| 931 | next; |
| 932 | } |
| 933 | # Set $warn to 1 if the user should be warned of the renaming |
| 934 | my $warn=0; |
| 935 | |
| 936 | # autoconf and make don't support these characters well |
| 937 | my $new_name=$dentry; |
| 938 | $new_name =~ s/[ \$]/_/g; |
| 939 | |
| 940 | # Our Make.rules supports all-uppercase and all-lowercase extensions. |
| 941 | # The others must be fixed. |
| 942 | if (-f "$dirname/$new_name") { |
| 943 | if ($new_name =~ /\.cpp/i and $new_name !~ /\.(cpp|CPP)/) { |
| 944 | $new_name =~ s/\.cpp$/.cpp/i; |
| 945 | } |
| 946 | if ($new_name =~ s/\.cxx$/.cpp/i) { |
| 947 | $warn=1; |
| 948 | } |
| 949 | if ($new_name =~ /\.rc/i and $new_name !~ /\.(rc|RC)/) { |
| 950 | $new_name =~ s/\.rc$/.rc/i; |
| 951 | } |
| 952 | # And this last one is to avoid confusion then running make |
| 953 | if ($new_name =~ s/^makefile$/makefile.win/) { |
| 954 | $warn=1; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | # Adjust the case to the user's preferences |
| 959 | if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or |
| 960 | ($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/) |
| 961 | ) { |
| 962 | $new_name=lc $new_name; |
| 963 | } |
| 964 | |
| 965 | # And finally, perform the renaming |
| 966 | if ($new_name ne $dentry) { |
| 967 | if ($warn) { |
| 968 | print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n"; |
| 969 | } |
| 970 | if (!rename("$dirname/$dentry","$dirname/$new_name")) { |
| 971 | print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n"; |
| 972 | print STDERR " $!\n"; |
| 973 | $new_name=$dentry; |
| 974 | } |
| 975 | } |
| 976 | if (-d "$dirname/$new_name") { |
| 977 | fix_file_and_directory_names("$dirname/$new_name"); |
| 978 | } |
| 979 | } |
| 980 | closedir(DIRECTORY); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | |
| 985 | |
| 986 | ##### |
| 987 | # |
| 988 | # Source fixup |
| 989 | # |
| 990 | ##### |
| 991 | |
| 992 | ## |
| 993 | # This maps a directory name to a reference to an array listing |
| 994 | # its contents (files and directories) |
| 995 | my %directories; |
| 996 | |
| 997 | ## |
| 998 | # Retrieves the contents of the specified directory. |
| 999 | # We either get it from the directories hashtable which acts as a |
| 1000 | # cache, or use opendir, readdir, closedir and store the result |
| 1001 | # in the hashtable. |
| 1002 | sub get_directory_contents |
| 1003 | { |
| 1004 | my $dirname=$_[0]; |
| 1005 | my $directory; |
| 1006 | |
| 1007 | #print "getting the contents of $dirname\n"; |
| 1008 | |
| 1009 | # check for a cached version |
| 1010 | $dirname =~ s+/$++; |
| 1011 | if ($dirname eq "") { |
| 1012 | $dirname=cwd; |
| 1013 | } |
| 1014 | $directory=$directories{$dirname}; |
| 1015 | if (defined $directory) { |
| 1016 | #print "->@$directory\n"; |
| 1017 | return $directory; |
| 1018 | } |
| 1019 | |
| 1020 | # Read this directory |
| 1021 | if (opendir(DIRECTORY, "$dirname")) { |
| 1022 | my @files=readdir DIRECTORY; |
| 1023 | closedir(DIRECTORY); |
| 1024 | $directory=\@files; |
| 1025 | } else { |
| 1026 | # Return an empty list |
| 1027 | #print "error: cannot open $dirname\n"; |
| 1028 | my @files; |
| 1029 | $directory=\@files; |
| 1030 | } |
| 1031 | #print "->@$directory\n"; |
| 1032 | $directories{$dirname}=$directory; |
| 1033 | return $directory; |
| 1034 | } |
| 1035 | |
| 1036 | ## |
| 1037 | # Try to find a file for the specified filename. The attempt is |
| 1038 | # case-insensitive which is why it's not trivial. If a match is |
| 1039 | # found then we return the pathname with the correct case. |
| 1040 | sub search_from |
| 1041 | { |
| 1042 | my $dirname=$_[0]; |
| 1043 | my $path=$_[1]; |
| 1044 | my $real_path=""; |
| 1045 | |
| 1046 | if ($dirname eq "" or $dirname eq ".") { |
| 1047 | $dirname=cwd; |
| 1048 | } elsif ($dirname =~ m+^[^/]+) { |
| 1049 | $dirname=cwd . "/" . $dirname; |
| 1050 | } |
| 1051 | if ($dirname !~ m+/$+) { |
| 1052 | $dirname.="/"; |
| 1053 | } |
| 1054 | |
| 1055 | foreach $component (@$path) { |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1056 | #print " looking for $component in \"$dirname\"\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1057 | if ($component eq ".") { |
| 1058 | # Pass it as is |
| 1059 | $real_path.="./"; |
| 1060 | } elsif ($component eq "..") { |
| 1061 | # Go up one level |
| 1062 | $dirname=dirname($dirname) . "/"; |
| 1063 | $real_path.="../"; |
| 1064 | } else { |
| 1065 | my $directory=get_directory_contents $dirname; |
| 1066 | my $found; |
| 1067 | foreach $dentry (@$directory) { |
| 1068 | if ($dentry =~ /^$component$/i) { |
| 1069 | $dirname.="$dentry/"; |
| 1070 | $real_path.="$dentry/"; |
| 1071 | $found=1; |
| 1072 | last; |
| 1073 | } |
| 1074 | } |
| 1075 | if (!defined $found) { |
| 1076 | # Give up |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1077 | #print " could not find $component in $dirname\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1078 | return; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | $real_path=~ s+/$++; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1083 | #print " -> found $real_path\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1084 | return $real_path; |
| 1085 | } |
| 1086 | |
| 1087 | ## |
| 1088 | # Performs a case-insensitive search for the specified file in the |
| 1089 | # include path. |
| 1090 | # $line is the line number that should be referenced when an error occurs |
| 1091 | # $filename is the file we are looking for |
| 1092 | # $dirname is the directory of the file containing the '#include' directive |
| 1093 | # if '"' was used, it is an empty string otherwise |
| 1094 | # $project and $target specify part of the include path |
| 1095 | sub get_real_include_name |
| 1096 | { |
| 1097 | my $line=$_[0]; |
| 1098 | my $filename=$_[1]; |
| 1099 | my $dirname=$_[2]; |
| 1100 | my $project=$_[3]; |
| 1101 | my $target=$_[4]; |
| 1102 | |
| 1103 | if ($filename =~ /^([a-zA-Z]:)?[\/]/ or $filename =~ /^[a-zA-Z]:[\/]?/) { |
| 1104 | # This is not a relative path, we cannot make any check |
| 1105 | my $warning="path:$filename"; |
| 1106 | if (!defined $warnings{$warning}) { |
| 1107 | $warnings{$warning}="1"; |
| 1108 | print STDERR "warning: cannot check the case of absolute pathnames:\n"; |
| 1109 | print STDERR "$line: $filename\n"; |
| 1110 | } |
| 1111 | } else { |
| 1112 | # Here's how we proceed: |
| 1113 | # - split the filename we look for into its components |
| 1114 | # - then for each directory in the include path |
| 1115 | # - trace the directory components starting from that directory |
| 1116 | # - if we fail to find a match at any point then continue with |
| 1117 | # the next directory in the include path |
| 1118 | # - otherwise, rejoice, our quest is over. |
| 1119 | my @file_components=split /[\/\\]+/, $filename; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1120 | #print " Searching for $filename from @$project[$P_PATH]\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1121 | |
| 1122 | my $real_filename; |
| 1123 | if ($dirname ne "") { |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1124 | # This is an 'include ""' -> look in dirname first. |
| 1125 | #print " in $dirname (include \"\")\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1126 | $real_filename=search_from($dirname,\@file_components); |
| 1127 | if (defined $real_filename) { |
| 1128 | return $real_filename; |
| 1129 | } |
| 1130 | } |
| 1131 | my $project_settings=@$project[$P_SETTINGS]; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1132 | foreach $include (@{@$target[$T_INCLUDE_PATH]}, @{@$project_settings[$T_INCLUDE_PATH]}) { |
| 1133 | my $dirname=$include; |
| 1134 | $dirname=~ s+^-I++; |
| 1135 | if (!is_absolute($dirname)) { |
| 1136 | $dirname="@$project[$P_PATH]$dirname"; |
| 1137 | } else { |
| 1138 | $dirname=~ s+^\$\(TOPSRCDIR\)/++; |
| 1139 | } |
| 1140 | #print " in $dirname\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1141 | $real_filename=search_from("$dirname",\@file_components); |
| 1142 | if (defined $real_filename) { |
| 1143 | return $real_filename; |
| 1144 | } |
| 1145 | } |
| 1146 | my $dotdotpath=@$project[$P_PATH]; |
| 1147 | $dotdotpath =~ s/[^\/]+/../g; |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1148 | foreach $include (@{$global_settings[$T_INCLUDE_PATH]}) { |
| 1149 | my $dirname=$include; |
| 1150 | $dirname=~ s+^-I++; |
| 1151 | $dirname=~ s+^\$\(TOPSRCDIR\)\/++; |
| 1152 | #print " in $dirname (global setting)\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1153 | $real_filename=search_from("$dirname",\@file_components); |
| 1154 | if (defined $real_filename) { |
| 1155 | return $real_filename; |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | $filename =~ s+\\\\+/+g; # in include "" |
| 1160 | $filename =~ s+\\+/+g; # in include <> ! |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1161 | if ($opt_lower_include) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1162 | return lc "$filename"; |
| 1163 | } |
| 1164 | return $filename; |
| 1165 | } |
| 1166 | |
| 1167 | ## |
| 1168 | # 'Parses' a source file and fixes constructs that would not work with |
| 1169 | # Winelib. The parsing is rather simple and not all non-portable features |
| 1170 | # are corrected. The most important feature that is corrected is the case |
| 1171 | # and path separator of '#include' directives. This requires that each |
| 1172 | # source file be associated to a project & target so that the proper |
| 1173 | # include path is used. |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 1174 | # Also note that the include path is relative to the directory in which the |
| 1175 | # compiler is run, i.e. that of the project, not to that of the file. |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1176 | sub fix_file |
| 1177 | { |
| 1178 | my $filename=$_[0]; |
| 1179 | my $project=$_[1]; |
| 1180 | my $target=$_[2]; |
| 1181 | $filename="@$project[$P_PATH]$filename"; |
| 1182 | if (! -e $filename) { |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | my $is_rc=($filename =~ /\.(rc2?|dlg)$/i); |
| 1187 | my $dirname=dirname($filename); |
| 1188 | my $is_mfc=0; |
| 1189 | if (defined $target and (@$target[$T_FLAGS] & $TF_MFC)) { |
| 1190 | $is_mfc=1; |
| 1191 | } |
| 1192 | |
| 1193 | print " $filename\n"; |
| 1194 | #FIXME:assuming that because there is a .bak file, this is what we want is |
| 1195 | #probably flawed. Or is it??? |
| 1196 | if (! -e "$filename.bak") { |
| 1197 | if (!copy("$filename","$filename.bak")) { |
| 1198 | print STDERR "error: unable to make a backup of $filename:\n"; |
| 1199 | print STDERR " $!\n"; |
| 1200 | return; |
| 1201 | } |
| 1202 | } |
| 1203 | if (!open(FILEI,"$filename.bak")) { |
| 1204 | print STDERR "error: unable to open $filename.bak for reading:\n"; |
| 1205 | print STDERR " $!\n"; |
| 1206 | return; |
| 1207 | } |
| 1208 | if (!open(FILEO,">$filename")) { |
| 1209 | print STDERR "error: unable to open $filename for writing:\n"; |
| 1210 | print STDERR " $!\n"; |
| 1211 | return; |
| 1212 | } |
| 1213 | my $line=0; |
| 1214 | my $modified=0; |
| 1215 | my $rc_block_depth=0; |
| 1216 | my $rc_textinclude_state=0; |
| 1217 | while (<FILEI>) { |
| 1218 | $line++; |
| 1219 | $_ =~ s/\r\n$/\n/; |
| 1220 | if ($is_rc and !$is_mfc and /^(\s*\#\s*include\s*)\"afxres\.h\"/) { |
| 1221 | # VC6 automatically includes 'afxres.h', an MFC specific header, in |
| 1222 | # the RC files it generates (even in non-MFC projects). So we replace |
| 1223 | # it with 'winres.h' its very close standard cousin so that non MFC |
| 1224 | # projects can compile in Wine without the MFC sources. This does not |
| 1225 | # harm VC but it will put 'afxres.h' back the next time the file is |
| 1226 | # edited. |
| 1227 | my $warning="mfc:afxres.h"; |
| 1228 | if (!defined $warnings{$warning}) { |
| 1229 | $warnings{$warning}="1"; |
| 1230 | print STDERR "warning: In non-MFC projects, winemaker replaces the MFC specific header 'afxres.h' with 'winres.h'\n"; |
| 1231 | print STDERR "warning: the above warning is issued only once\n"; |
| 1232 | } |
| 1233 | print FILEO "/* winemaker: $1\"afxres.h\" */\n"; |
| 1234 | print FILEO "$1\"winres.h\"$'"; |
| 1235 | $modified=1; |
| 1236 | } elsif (/^(\s*\#\s*include\s*)([\"<])([^\"]+)([\">])/) { |
| 1237 | my $from_file=($2 eq "<"?"":$dirname); |
| 1238 | my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target); |
| 1239 | print FILEO "$1$2$real_include_name$4$'"; |
| 1240 | $modified|=($real_include_name ne $3); |
| 1241 | } elsif (/^(\s*\#\s*pragma\s*pack\s*\((\s*push\s*,?)?\s*)(\w*)(\s*\))/) { |
| 1242 | my $pragma_header=$1; |
| 1243 | my $size=$3; |
| 1244 | my $pragma_trailer=$4; |
| 1245 | #print "$pragma_header$size$pragma_trailer$'"; |
| 1246 | #print "pragma push: size=$size\n"; |
| 1247 | print FILEO "/* winemaker: $pragma_header$size$pragma_trailer */\n"; |
| 1248 | $line++; |
| 1249 | if ($size eq "pop") { |
| 1250 | print FILEO "#include <poppack.h>$'"; |
| 1251 | } elsif ($size eq "1") { |
| 1252 | print FILEO "#include <pshpack1.h>$'"; |
| 1253 | } elsif ($size eq "2") { |
| 1254 | print FILEO "#include <pshpack2.h>$'"; |
| 1255 | } elsif ($size eq "8") { |
| 1256 | print FILEO "#include <pshpack8.h>$'"; |
| 1257 | } elsif ($size eq "4" or $size eq "") { |
| 1258 | print FILEO "#include <pshpack4.h>$'"; |
| 1259 | } else { |
| 1260 | my $warning="pack:$size"; |
| 1261 | if (!defined $warnings{$warning}) { |
| 1262 | $warnings{$warning}="1"; |
| 1263 | print STDERR "warning: assuming that the value of $size is 4 in\n"; |
| 1264 | print STDERR "$line: $pragma_header$size$pragma_trailer\n"; |
| 1265 | print STDERR "warning: the above warning is issued only once\n"; |
| 1266 | } |
| 1267 | print FILEO "#include <pshpack4.h>$'"; |
| 1268 | $modified=1; |
| 1269 | } |
| 1270 | } elsif ($is_rc) { |
| 1271 | if ($rc_block_depth == 0 and /^(\w+\s+(BITMAP|CURSOR|FONT|FONTDIR|ICON|MESSAGETABLE|TEXT)\s+((DISCARDABLE|FIXED|IMPURE|LOADONCALL|MOVEABLE|PRELOAD|PURE)\s+)*)([\"<]?)([^\">\r\n]+)([\">]?)/) { |
| 1272 | my $from_file=($5 eq "<"?"":$dirname); |
| 1273 | my $real_include_name=get_real_include_name($line,$6,$from_file,$project,$target); |
| 1274 | print FILEO "$1$5$real_include_name$7$'"; |
| 1275 | $modified|=($real_include_name ne $6); |
| 1276 | } elsif (/^(\s*RCINCLUDE\s*)([\"<]?)([^\">\r\n]+)([\">]?)/) { |
| 1277 | my $from_file=($2 eq "<"?"":$dirname); |
| 1278 | my $real_include_name=get_real_include_name($line,$3,$from_file,$project,$target); |
| 1279 | print FILEO "$1$2$real_include_name$4$'"; |
| 1280 | $modified|=($real_include_name ne $3); |
| 1281 | } elsif ($is_rc and !$is_mfc and $rc_block_depth == 0 and /^\s*\d+\s+TEXTINCLUDE\s*/) { |
| 1282 | $rc_textinclude_state=1; |
| 1283 | print FILEO; |
| 1284 | } elsif ($rc_textinclude_state == 3 and /^(\s*\"\#\s*include\s*\"\")afxres\.h(\"\"\\r\\n\")/) { |
| 1285 | print FILEO "$1winres.h$2$'"; |
| 1286 | $modified=1; |
| 1287 | } elsif (/^\s*BEGIN(\W.*)?$/) { |
| 1288 | $rc_textinclude_state|=2; |
| 1289 | $rc_block_depth++; |
| 1290 | print FILEO; |
| 1291 | } elsif (/^\s*END(\W.*)?$/) { |
| 1292 | $rc_textinclude_state=0; |
| 1293 | if ($rc_block_depth>0) { |
| 1294 | $rc_block_depth--; |
| 1295 | } |
| 1296 | print FILEO; |
| 1297 | } else { |
| 1298 | print FILEO; |
| 1299 | } |
| 1300 | } else { |
| 1301 | print FILEO; |
| 1302 | } |
| 1303 | } |
| 1304 | close(FILEI); |
| 1305 | close(FILEO); |
| 1306 | if ($opt_backup == 0 or $modified == 0) { |
| 1307 | if (!unlink("$filename.bak")) { |
| 1308 | print STDERR "error: unable to delete $filename.bak:\n"; |
| 1309 | print STDERR " $!\n"; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | ## |
| 1315 | # Analyzes each source file in turn to find and correct issues |
| 1316 | # that would cause it not to compile. |
| 1317 | sub fix_source |
| 1318 | { |
| 1319 | print "Fixing the source files...\n"; |
| 1320 | foreach $project (@projects) { |
| 1321 | foreach $target (@$project[$P_SETTINGS],@{@$project[$P_TARGETS]}) { |
| 1322 | if (@$target[$T_FLAGS] & $TF_WRAPPER) { |
| 1323 | next; |
| 1324 | } |
| 1325 | foreach $source (@{@$target[$T_SOURCES_C]}, @{@$target[$T_SOURCES_CXX]}, @{@$target[$T_SOURCES_RC]}, @{@$target[$T_SOURCES_MISC]}) { |
| 1326 | fix_file($source,$project,$target); |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | ##### |
| 1335 | # |
| 1336 | # File generation |
| 1337 | # |
| 1338 | ##### |
| 1339 | |
| 1340 | ## |
| 1341 | # Generates a target's .spec file |
| 1342 | sub generate_spec_file |
| 1343 | { |
| 1344 | my $path=$_[0]; |
| 1345 | my $target=$_[1]; |
| 1346 | my $project_settings=$_[2]; |
| 1347 | |
| 1348 | my $basename=@$target[$T_NAME]; |
| 1349 | $basename =~ s+\.so$++; |
| 1350 | if (@$target[$T_FLAGS] & $TF_WRAP) { |
| 1351 | $basename =~ s+^lib++; |
| 1352 | } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) { |
| 1353 | $basename.="_wrapper"; |
| 1354 | } |
| 1355 | |
| 1356 | if (!open(FILEO,">$path$basename.spec")) { |
| 1357 | print STDERR "error: could not open \"$path$basename.spec\" for writing\n"; |
| 1358 | print STDERR " $!\n"; |
| 1359 | return; |
| 1360 | } |
| 1361 | |
| 1362 | my $canon=canonize($basename); |
| 1363 | print FILEO "name $canon\n"; |
| 1364 | print FILEO "type win32\n"; |
| 1365 | if (@$target[$T_TYPE] == $TT_GUIEXE) { |
| 1366 | print FILEO "mode guiexe\n"; |
| 1367 | } elsif (@$target[$T_TYPE] == $TT_CUIEXE) { |
| 1368 | print FILEO "mode cuiexe\n"; |
| 1369 | } else { |
| 1370 | print FILEO "mode dll\n"; |
| 1371 | } |
| 1372 | if (defined @$target[$T_INIT] and ((@$target[$T_FLAGS] & $TF_WRAP) == 0)) { |
| 1373 | print FILEO "init @$target[$T_INIT]\n"; |
| 1374 | } |
| 1375 | if (@{@$target[$T_SOURCES_RC]} > 0) { |
| 1376 | if (@{@$target[$T_SOURCES_RC]} > 1) { |
| 1377 | print STDERR "warning: the target $basename has more than one RC file. Modify the Makefile.in to remove redundant RC files, and fix the spec file\n"; |
| 1378 | } |
| 1379 | my $rcname=@{@$target[$T_SOURCES_RC]}[0]; |
| 1380 | $rcname =~ s+\.rc$++i; |
| 1381 | print FILEO "rsrc $rcname.res\n"; |
| 1382 | } |
| 1383 | print FILEO "\n"; |
| 1384 | # FIXME: we should try to remove duplicates in the import list |
| 1385 | foreach $library (@{$global_settings[$T_IMPORTS]}) { |
| 1386 | print FILEO "import $library\n"; |
| 1387 | } |
| 1388 | if (defined $project_settings) { |
| 1389 | foreach $library (@{@$project_settings[$T_IMPORTS]}) { |
| 1390 | print FILEO "import $library\n"; |
| 1391 | } |
| 1392 | } |
| 1393 | foreach $library (@{@$target[$T_IMPORTS]}) { |
| 1394 | print FILEO "import $library\n"; |
| 1395 | } |
| 1396 | |
| 1397 | # Don't forget to export the 'Main' function for wrapped executables, |
| 1398 | # except for MFC ones! |
| 1399 | if (@$target[$T_FLAGS] == $TF_WRAP) { |
| 1400 | if (@$target[$T_TYPE] == $TT_GUIEXE) { |
| 1401 | print FILEO "\n@ stdcall @$target[$T_INIT](long long ptr long) @$target[$T_INIT]\n"; |
| 1402 | } elsif (@$target[$T_TYPE] == $TT_CUIEXE) { |
| 1403 | print FILEO "\n@ stdcall @$target[$T_INIT](long ptr ptr) @$target[$T_INIT]\n"; |
| 1404 | } else { |
| 1405 | print FILEO "\n@ stdcall @$target[$T_INIT](ptr long ptr) @$target[$T_INIT]\n"; |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | close(FILEO); |
| 1410 | } |
| 1411 | |
| 1412 | ## |
| 1413 | # Generates a target's wrapper file |
| 1414 | sub generate_wrapper_file |
| 1415 | { |
| 1416 | my $path=$_[0]; |
| 1417 | my $target=$_[1]; |
| 1418 | |
| 1419 | if (!defined $templates{"wrapper.c"}) { |
| 1420 | print STDERR "winemaker: internal error: No template called 'wrapper.c'\n"; |
| 1421 | return; |
| 1422 | } |
| 1423 | |
| 1424 | if (!open(FILEO,">$path@$target[$T_NAME]_wrapper.c")) { |
| 1425 | print STDERR "error: unable to open \"$path$basename.c\" for writing:\n"; |
| 1426 | print STDERR " $!\n"; |
| 1427 | return; |
| 1428 | } |
| 1429 | my $app_name="\"@$target[$T_NAME]\""; |
| 1430 | my $app_type=(@$target[$T_TYPE]==$TT_GUIEXE?"GUIEXE":"CUIEXE"); |
| 1431 | my $app_init=(@$target[$T_TYPE]==$TT_GUIEXE?"\"WinMain\"":"\"main\""); |
| 1432 | my $app_mfc=(@$target[$T_FLAGS] & $TF_MFC?"\"mfc\"":NULL); |
| 1433 | foreach $line (@{$templates{"wrapper.c"}}) { |
| 1434 | $line =~ s/\#\#WINEMAKER_APP_NAME\#\#/$app_name/; |
| 1435 | $line =~ s/\#\#WINEMAKER_APP_TYPE\#\#/$app_type/; |
| 1436 | $line =~ s/\#\#WINEMAKER_APP_INIT\#\#/$app_init/; |
| 1437 | $line =~ s/\#\#WINEMAKER_APP_MFC\#\#/$app_mfc/; |
| 1438 | print FILEO $line; |
| 1439 | } |
| 1440 | close(FILEO); |
| 1441 | } |
| 1442 | |
| 1443 | ## |
| 1444 | # A convenience function to generate all the lists (defines, |
| 1445 | # C sources, C++ source, etc.) in the Makefile |
| 1446 | sub generate_list |
| 1447 | { |
| 1448 | my $name=$_[0]; |
| 1449 | my $last=$_[1]; |
| 1450 | my $list=$_[2]; |
| 1451 | my $data=$_[3]; |
| 1452 | |
| 1453 | if ($name) { |
| 1454 | printf FILEO "%-9s =",$name; |
| 1455 | } |
| 1456 | if (defined $list and @$list > 0) { |
| 1457 | foreach $item (@$list) { |
| 1458 | my $value; |
| 1459 | if (defined $data) { |
| 1460 | $value=&$data($item); |
| 1461 | } else { |
| 1462 | $value=$item; |
| 1463 | } |
| 1464 | if ($value ne "") { |
| 1465 | print FILEO " \\\n\t$value"; |
| 1466 | } |
| 1467 | } |
| 1468 | } |
| 1469 | if ($last) { |
| 1470 | print FILEO "\n\n"; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | ## |
| 1475 | # Generates a project's Makefile.in and all the target files |
| 1476 | sub generate_project_files |
| 1477 | { |
| 1478 | my $project=$_[0]; |
| 1479 | my $project_settings=@$project[$P_SETTINGS]; |
| 1480 | my @library_list=(); |
| 1481 | my @program_list=(); |
| 1482 | |
| 1483 | # Then sort the targets and separate the libraries from the programs |
| 1484 | foreach $target (sort { @$a[$T_NAME] cmp @$b[$T_NAME] } @{@$project[$P_TARGETS]}) { |
| 1485 | if (@$target[$T_TYPE] == $TT_DLL) { |
| 1486 | push @library_list,$target; |
| 1487 | } else { |
| 1488 | push @program_list,$target; |
| 1489 | } |
| 1490 | } |
| 1491 | @$project[$P_TARGETS]=[]; |
| 1492 | push @{@$project[$P_TARGETS]}, @library_list; |
| 1493 | push @{@$project[$P_TARGETS]}, @program_list; |
| 1494 | |
| 1495 | if (!open(FILEO,">@$project[$P_PATH]Makefile.in")) { |
| 1496 | print STDERR "error: could not open \"@$project[$P_PATH]/Makefile.in\" for writing\n"; |
| 1497 | print STDERR " $!\n"; |
| 1498 | return; |
| 1499 | } |
| 1500 | |
| 1501 | print FILEO "### Generic autoconf variables\n\n"; |
| 1502 | print FILEO "TOPSRCDIR = \@top_srcdir\@\n"; |
| 1503 | print FILEO "TOPOBJDIR = .\n"; |
| 1504 | print FILEO "SRCDIR = \@srcdir\@\n"; |
| 1505 | print FILEO "VPATH = \@srcdir\@\n"; |
| 1506 | print FILEO "\n"; |
| 1507 | if (@$project[$P_PATH] eq "") { |
| 1508 | # This is the main project. It is also responsible for recursively |
| 1509 | # calling the other projects |
| 1510 | generate_list("SUBDIRS",1,\@projects,sub |
| 1511 | { |
| 1512 | if ($_[0] != \@main_project) { |
| 1513 | my $subdir=@{$_[0]}[$P_PATH]; |
| 1514 | $subdir =~ s+/$++; |
| 1515 | return $subdir; |
| 1516 | } |
| 1517 | # Eliminating the main project by returning undefined! |
| 1518 | }); |
| 1519 | } |
| 1520 | if (@{@$project[$P_TARGETS]} > 0) { |
| 1521 | generate_list("LIBRARIES",1,\@library_list,sub |
| 1522 | { |
| 1523 | return @{$_[0]}[$T_NAME]; |
| 1524 | }); |
| 1525 | generate_list("PROGRAMS",1,\@program_list,sub |
| 1526 | { |
| 1527 | return @{$_[0]}[$T_NAME]; |
| 1528 | }); |
| 1529 | print FILEO "\n\n"; |
| 1530 | |
| 1531 | print FILEO "### Global settings\n\n"; |
| 1532 | # Make it so that the project-wide settings override the global settings |
| 1533 | generate_list("DEFINES",0,@$project_settings[$T_DEFINES],sub |
| 1534 | { |
| 1535 | return "$_[0]"; |
| 1536 | }); |
| 1537 | generate_list("",1,$global_settings[$T_DEFINES],sub |
| 1538 | { |
| 1539 | return "$_[0]"; |
| 1540 | }); |
| 1541 | generate_list("INCLUDE_PATH",$no_extra,@$project_settings[$T_INCLUDE_PATH],sub |
| 1542 | { |
| 1543 | return "$_[0]"; |
| 1544 | }); |
| 1545 | generate_list("",1,$global_settings[$T_INCLUDE_PATH],sub |
| 1546 | { |
| 1547 | if ($_[0] !~ /^-I/) { |
| 1548 | return "$_[0]"; |
| 1549 | } |
| 1550 | if (is_absolute($')) { |
| 1551 | return "$_[0]"; |
| 1552 | } |
| 1553 | return "\$(TOPSRCDIR)/$_[0]"; |
| 1554 | }); |
| 1555 | generate_list("LIBRARY_PATH",$no_extra,@$project_settings[$T_LIBRARY_PATH],sub |
| 1556 | { |
| 1557 | return "$_[0]"; |
| 1558 | }); |
| 1559 | generate_list("",1,$global_settings[$T_LIBRARY_PATH],sub |
| 1560 | { |
| 1561 | if ($_[0] !~ /^-L/) { |
| 1562 | return "$_[0]"; |
| 1563 | } |
| 1564 | if (is_absolute($')) { |
| 1565 | return "$_[0]"; |
| 1566 | } |
| 1567 | return "\$(TOPSRCDIR)/$_[0]"; |
| 1568 | }); |
| 1569 | generate_list("IMPORTS",$no_extra,@$project_settings[$T_IMPORTS],sub |
| 1570 | { |
| 1571 | return "$_[0]"; |
| 1572 | }); |
| 1573 | generate_list("",1,$global_settings[$T_IMPORTS],sub |
| 1574 | { |
| 1575 | return "$_[0]"; |
| 1576 | }); |
| 1577 | print FILEO "\n\n"; |
| 1578 | |
| 1579 | my $extra_source_count=@{@$project_settings[$T_SOURCES_C]}+ |
| 1580 | @{@$project_settings[$T_SOURCES_CXX]}+ |
| 1581 | @{@$project_settings[$T_SOURCES_RC]}; |
| 1582 | my $no_extra=($extra_source_count == 0); |
| 1583 | if (!$no_extra) { |
| 1584 | print FILEO "### Extra source lists\n\n"; |
| 1585 | generate_list("EXTRA_C_SRCS",1,@$project_settings[$T_SOURCES_C]); |
| 1586 | generate_list("EXTRA_CXX_SRCS",1,@$project_settings[$T_SOURCES_CXX]); |
| 1587 | generate_list("EXTRA_RC_SRCS",1,@$project_settings[$T_SOURCES_RC]); |
| 1588 | print FILEO "EXTRA_OBJS = \$(EXTRA_C_SRCS:.c=.o) \$(EXTRA_CXX_SRCS:.cpp=.o)\n"; |
| 1589 | print FILEO "\n\n"; |
| 1590 | } |
| 1591 | |
| 1592 | # Iterate over all the targets... |
| 1593 | foreach $target (@{@$project[$P_TARGETS]}) { |
| 1594 | print FILEO "\n### @$target[$T_NAME] sources and settings\n\n"; |
| 1595 | my $canon=canonize("@$target[$T_NAME]"); |
| 1596 | $canon =~ s+_so$++; |
| 1597 | generate_list("${canon}_C_SRCS",1,@$target[$T_SOURCES_C]); |
| 1598 | generate_list("${canon}_CXX_SRCS",1,@$target[$T_SOURCES_CXX]); |
| 1599 | generate_list("${canon}_RC_SRCS",1,@$target[$T_SOURCES_RC]); |
| 1600 | my $basename=@$target[$T_NAME]; |
| 1601 | $basename =~ s+\.so$++; |
| 1602 | if (@$target[$T_FLAGS] & $TF_WRAP) { |
| 1603 | $basename =~ s+^lib++; |
| 1604 | } elsif (@$target[$T_FLAGS] & $TF_WRAPPER) { |
| 1605 | $basename.="_wrapper"; |
| 1606 | } |
| 1607 | generate_list("${canon}_SPEC_SRCS",1,[ "$basename.spec"]); |
| 1608 | generate_list("${canon}_LIBRARY_PATH",1,@$target[$T_LIBRARY_PATH],sub |
| 1609 | { |
| 1610 | return "$_[0]"; |
| 1611 | }); |
| 1612 | generate_list("${canon}_IMPORTS",1,@$target[$T_IMPORTS],sub |
| 1613 | { |
| 1614 | return "$_[0]"; |
| 1615 | }); |
| 1616 | generate_list("${canon}_DEPENDS",1,@$target[$T_DEPENDS],sub |
| 1617 | { |
| 1618 | return "$_[0]"; |
| 1619 | }); |
| 1620 | print FILEO "${canon}_OBJS = \$(${canon}_SPEC_SRCS:.spec=.spec.o) \$(${canon}_C_SRCS:.c=.o) \$(${canon}_CXX_SRCS:.cpp=.o) \$(EXTRA_OBJS)\n"; |
| 1621 | print FILEO "\n\n"; |
| 1622 | } |
| 1623 | print FILEO "### Global source lists\n\n"; |
| 1624 | generate_list("C_SRCS",$no_extra,@$project[$P_TARGETS],sub |
| 1625 | { |
| 1626 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 1627 | $canon =~ s+_so$++; |
| 1628 | return "\$(${canon}_C_SRCS)"; |
| 1629 | }); |
| 1630 | if (!$no_extra) { |
| 1631 | generate_list("",1,[ "\$(EXTRA_C_SRCS)" ]); |
| 1632 | } |
| 1633 | generate_list("CXX_SRCS",$no_extra,@$project[$P_TARGETS],sub |
| 1634 | { |
| 1635 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 1636 | $canon =~ s+_so$++; |
| 1637 | return "\$(${canon}_CXX_SRCS)"; |
| 1638 | }); |
| 1639 | if (!$no_extra) { |
| 1640 | generate_list("",1,[ "\$(EXTRA_CXX_SRCS)" ]); |
| 1641 | } |
| 1642 | generate_list("RC_SRCS",$no_extra,@$project[$P_TARGETS],sub |
| 1643 | { |
| 1644 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 1645 | $canon =~ s+_so$++; |
| 1646 | return "\$(${canon}_RC_SRCS)"; |
| 1647 | }); |
| 1648 | if (!$no_extra) { |
| 1649 | generate_list("",1,@$project_settings[$T_SOURCES_RC]); |
| 1650 | } |
| 1651 | generate_list("SPEC_SRCS",1,@$project[$P_TARGETS],sub |
| 1652 | { |
| 1653 | my $canon=canonize(@{$_[0]}[$T_NAME]); |
| 1654 | $canon =~ s+_so$++; |
| 1655 | return "\$(${canon}_SPEC_SRCS)"; |
| 1656 | }); |
| 1657 | print FILEO "\n\n"; |
| 1658 | } |
| 1659 | |
| 1660 | print FILEO "### Generic autoconf targets\n\n"; |
| 1661 | if (@$project[$P_PATH] eq "") { |
| 1662 | print FILEO "all: \$(SUBDIRS) \$(LIBRARIES) \$(PROGRAMS)\n"; |
| 1663 | } else { |
| 1664 | print FILEO "all: \$(LIBRARIES) \$(PROGRAMS)\n"; |
| 1665 | } |
| 1666 | print FILEO "\n"; |
| 1667 | print FILEO "\@MAKE_RULES\@\n"; |
| 1668 | print FILEO "\n"; |
| 1669 | print FILEO "install::\n"; |
| 1670 | if (@$project[$P_PATH] eq "") { |
| 1671 | # This is the main project. It is also responsible for recursively |
| 1672 | # calling the other projects |
| 1673 | print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) install) || exit 1; done\n"; |
| 1674 | } |
| 1675 | if (@{@$project[$P_TARGETS]} > 0) { |
| 1676 | print FILEO "\tfor i in \$(PROGRAMS); do \$(INSTALL_PROGRAM) \$\$i \$(bindir); done\n"; |
| 1677 | print FILEO "\tfor i in \$(LIBRARIES); do \$(INSTALL_LIBRARY) \$\$i \$(libdir); done\n"; |
| 1678 | } |
| 1679 | print FILEO "\n"; |
| 1680 | print FILEO "uninstall::\n"; |
| 1681 | if (@$project[$P_PATH] eq "") { |
| 1682 | # This is the main project. It is also responsible for recursively |
| 1683 | # calling the other projects |
| 1684 | print FILEO "\tfor i in \$(SUBDIRS); do (cd \$\$i; \$(MAKE) uninstall) || exit 1; done\n"; |
| 1685 | } |
| 1686 | if (@{@$project[$P_TARGETS]} > 0) { |
| 1687 | print FILEO "\tfor i in \$(PROGRAMS); do \$(RM) \$(bindir)/\$\$i;done\n"; |
| 1688 | print FILEO "\tfor i in \$(LIBRARIES); do \$(RM) \$(libdir)/\$\$i;done\n"; |
| 1689 | } |
| 1690 | print FILEO "\n\n\n"; |
| 1691 | |
| 1692 | if (@{@$project[$P_TARGETS]} > 0) { |
| 1693 | print FILEO "### Target specific build rules\n\n"; |
| 1694 | foreach $target (@{@$project[$P_TARGETS]}) { |
| 1695 | my $canon=canonize("@$target[$T_NAME]"); |
| 1696 | $canon =~ s/_so$//; |
| 1697 | print FILEO "\$(${canon}_SPEC_SRCS:.spec=.spec.c): \$(${canon}_RC_SRCS:.rc=.res)\n"; |
| 1698 | print FILEO "\n"; |
| 1699 | print FILEO "@$target[$T_NAME]: \$(${canon}_OBJS) \$(${canon}_DEPENDS) \n"; |
| 1700 | if (@$target[$T_TYPE] eq $TT_DLL) { |
| 1701 | print FILEO "\t\$(LDSHARED) -shared -Wl,-soname,\$\@ -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_IMPORTS:%=-l%) \$(DLL_LINK) \$(LIBS)\n"; |
| 1702 | } else { |
| 1703 | print FILEO "\t\$(CC) -o \$\@ \$(${canon}_OBJS) \$(${canon}_LIBRARY_PATH) \$(${canon}_IMPORTS:%=-l%) \$(DLL_LINK) \$(LIBS)\n"; |
| 1704 | } |
| 1705 | print FILEO "\n"; |
| 1706 | } |
| 1707 | } |
| 1708 | close(FILEO); |
| 1709 | |
| 1710 | foreach $target (@{@$project[$P_TARGETS]}) { |
| 1711 | generate_spec_file(@$project[$P_PATH],$target,$project_settings); |
| 1712 | if (@$target[$T_FLAGS] & $TF_WRAPPER) { |
| 1713 | generate_wrapper_file(@$project[$P_PATH],$target); |
| 1714 | } |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | ## |
| 1719 | # Perform the replacements in the template configure files |
| 1720 | # Return 1 for success, 0 for failure |
| 1721 | sub generate_configure |
| 1722 | { |
| 1723 | my $filename=$_[0]; |
| 1724 | my $a_source_file=$_[1]; |
| 1725 | |
| 1726 | if (!defined $templates{$filename}) { |
| 1727 | if ($filename ne "configure") { |
| 1728 | print STDERR "winemaker: internal error: No template called '$filename'\n"; |
| 1729 | } |
| 1730 | return 0; |
| 1731 | } |
| 1732 | |
| 1733 | if (!open(FILEO,">$filename")) { |
| 1734 | print STDERR "error: unable to open \"$filename\" for writing:\n"; |
| 1735 | print STDERR " $!\n"; |
| 1736 | return 0; |
| 1737 | } |
| 1738 | foreach $line (@{$templates{$filename}}) { |
| 1739 | if ($line =~ /^\#\#WINEMAKER_PROJECTS\#\#$/) { |
| 1740 | foreach $project (@projects) { |
| 1741 | print FILEO "@$project[$P_PATH]Makefile\n"; |
| 1742 | } |
| 1743 | } else { |
| 1744 | $line =~ s+\#\#WINEMAKER_SOURCE\#\#+$a_source_file+; |
| 1745 | $line =~ s+\#\#WINEMAKER_NEEDS_MFC\#\#+$needs_mfc+; |
| 1746 | print FILEO $line; |
| 1747 | } |
| 1748 | } |
| 1749 | close(FILEO); |
| 1750 | return 1; |
| 1751 | } |
| 1752 | |
| 1753 | sub generate_generic |
| 1754 | { |
| 1755 | my $filename=$_[0]; |
| 1756 | |
| 1757 | if (!defined $templates{$filename}) { |
| 1758 | print STDERR "winemaker: internal error: No template called '$filename'\n"; |
| 1759 | return; |
| 1760 | } |
| 1761 | if (!open(FILEO,">$filename")) { |
| 1762 | print STDERR "error: unable to open \"$filename\" for writing:\n"; |
| 1763 | print STDERR " $!\n"; |
| 1764 | return; |
| 1765 | } |
| 1766 | foreach $line (@{$templates{$filename}}) { |
| 1767 | print FILEO $line; |
| 1768 | } |
| 1769 | close(FILEO); |
| 1770 | } |
| 1771 | |
| 1772 | ## |
| 1773 | # Generates the global files: |
| 1774 | # configure |
| 1775 | # configure.in |
| 1776 | # Make.rules.in |
| 1777 | sub generate_global_files |
| 1778 | { |
| 1779 | generate_generic("Make.rules.in"); |
| 1780 | |
| 1781 | # Get the name of a source file for configure.in |
| 1782 | my $a_source_file; |
| 1783 | search_a_file: foreach $project (@projects) { |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1784 | foreach $target (@{@$project[$P_TARGETS]}, @$project[$P_SETTINGS]) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1785 | $a_source_file=@{@$target[$T_SOURCES_C]}[0]; |
| 1786 | if (!defined $a_source_file) { |
| 1787 | $a_source_file=@{@$target[$T_SOURCES_CXX]}[0]; |
| 1788 | } |
| 1789 | if (!defined $a_source_file) { |
| 1790 | $a_source_file=@{@$target[$T_SOURCES_RC]}[0]; |
| 1791 | } |
| 1792 | if (defined $a_source_file) { |
| 1793 | $a_source_file="@$project[$P_PATH]$a_source_file"; |
| 1794 | last search_a_file; |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | generate_configure("configure.in",$a_source_file); |
| 1800 | unlink("configure"); |
| 1801 | if (generate_configure("configure",$a_source_file) == 0) { |
| 1802 | system("autoconf"); |
| 1803 | } |
| 1804 | # Add execute permission to configure for whoever has the right to read it |
| 1805 | my @st=stat("configure"); |
| 1806 | if (defined @st) { |
| 1807 | my $mode=$st[2]; |
| 1808 | $mode|=($mode & 0444) >>2; |
| 1809 | chmod($mode,"configure"); |
| 1810 | } else { |
| 1811 | print "warning: could not generate the configure script. You need to run autoconf\n"; |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | ## |
| 1816 | # |
| 1817 | sub generate_read_templates |
| 1818 | { |
| 1819 | my $file; |
| 1820 | |
| 1821 | while (<DATA>) { |
| 1822 | if (/^--- ((\w\.?)+) ---$/) { |
| 1823 | my $filename=$1; |
| 1824 | if (defined $templates{$filename}) { |
| 1825 | print STDERR "winemaker: internal error: There is more than one template for $filename\n"; |
| 1826 | undef $file; |
| 1827 | } else { |
| 1828 | $file=[]; |
| 1829 | $templates{$filename}=$file; |
| 1830 | } |
| 1831 | } elsif (defined $file) { |
| 1832 | push @$file, $_; |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | ## |
| 1838 | # This is where we finally generate files. In fact this method does not |
| 1839 | # do anything itself but calls the methods that do the actual work. |
| 1840 | sub generate |
| 1841 | { |
| 1842 | print "Generating project files...\n"; |
| 1843 | generate_read_templates(); |
| 1844 | generate_global_files(); |
| 1845 | |
| 1846 | foreach $project (@projects) { |
| 1847 | my $path=@$project[$P_PATH]; |
| 1848 | if ($path eq "") { |
| 1849 | $path="."; |
| 1850 | } else { |
| 1851 | $path =~ s+/$++; |
| 1852 | } |
| 1853 | print " $path\n"; |
| 1854 | generate_project_files($project); |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | ##### |
| 1861 | # |
| 1862 | # Option defaults |
| 1863 | # |
| 1864 | ##### |
| 1865 | |
| 1866 | $opt_backup=1; |
| 1867 | $opt_lower=$OPT_LOWER_UPPERCASE; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1868 | $opt_lower_include=1; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1869 | |
| 1870 | # $opt_single_target=<undefined> |
| 1871 | $opt_target_type=$TT_GUIEXE; |
| 1872 | $opt_flags=0; |
| 1873 | $opt_is_interactive=$OPT_ASK_NO; |
| 1874 | $opt_ask_project_options=$OPT_ASK_NO; |
| 1875 | $opt_ask_target_options=$OPT_ASK_NO; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1876 | $opt_no_generated_files=0; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1877 | $opt_no_banner=0; |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | ##### |
| 1882 | # |
| 1883 | # Main |
| 1884 | # |
| 1885 | ##### |
| 1886 | |
| 1887 | project_init(\@main_project,""); |
| 1888 | |
| 1889 | while (@ARGV>0) { |
| 1890 | my $arg=shift @ARGV; |
| 1891 | # General options |
| 1892 | if ($arg eq "--nobanner") { |
| 1893 | $opt_no_banner=1; |
| 1894 | } elsif ($arg eq "--backup") { |
| 1895 | $opt_backup=1; |
| 1896 | } elsif ($arg eq "--nobackup") { |
| 1897 | $opt_backup=0; |
| 1898 | } elsif ($arg eq "--single-target") { |
| 1899 | $opt_single_target=shift @ARGV; |
| 1900 | } elsif ($arg eq "--lower-none") { |
| 1901 | $opt_lower=$OPT_LOWER_NONE; |
| 1902 | } elsif ($arg eq "--lower-all") { |
| 1903 | $opt_lower=$OPT_LOWER_ALL; |
| 1904 | } elsif ($arg eq "--lower-uppercase") { |
| 1905 | $opt_lower=$OPT_LOWER_UPPERCASE; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1906 | } elsif ($arg eq "--lower-include") { |
| 1907 | $opt_lower_include=1; |
| 1908 | } elsif ($arg eq "--no-lower-include") { |
| 1909 | $opt_lower_include=0; |
| 1910 | } elsif ($arg eq "--generated-files") { |
| 1911 | $opt_no_generated_files=0; |
| 1912 | } elsif ($arg eq "--no-generated-files") { |
| 1913 | $opt_no_generated_files=1; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1914 | |
| 1915 | } elsif ($arg =~ /^-D/) { |
| 1916 | push @{$global_settings[$T_DEFINES]},$arg; |
| 1917 | } elsif ($arg =~ /^-I/) { |
| 1918 | push @{$global_settings[$T_INCLUDE_PATH]},$arg; |
| 1919 | } elsif ($arg =~ /^-L/) { |
| 1920 | push @{$global_settings[$T_LIBRARY_PATH]},$arg; |
| 1921 | } elsif ($arg =~ /^-l/) { |
| 1922 | push @{$global_settings[$T_IMPORTS]},$'; |
| 1923 | |
| 1924 | # 'Source'-based method options |
| 1925 | } elsif ($arg eq "--dll") { |
| 1926 | $opt_target_type=$TT_DLL; |
| 1927 | } elsif ($arg eq "--guiexe" or $arg eq "--windows") { |
| 1928 | $opt_target_type=$TT_GUIEXE; |
| 1929 | } elsif ($arg eq "--cuiexe" or $arg eq "--console") { |
| 1930 | $opt_target_type=$TT_CUIEXE; |
| 1931 | } elsif ($arg eq "--interactive") { |
| 1932 | $opt_is_interactive=$OPT_ASK_YES; |
| 1933 | $opt_ask_project_options=$OPT_ASK_YES; |
| 1934 | $opt_ask_target_options=$OPT_ASK_YES; |
| 1935 | } elsif ($arg eq "--wrap") { |
| 1936 | $opt_flags|=$TF_WRAP; |
| 1937 | } elsif ($arg eq "--nowrap") { |
| 1938 | $opt_flags&=~$TF_WRAP; |
| 1939 | } elsif ($arg eq "--mfc") { |
| 1940 | $opt_flags|=$TF_MFC|$TF_WRAP; |
| 1941 | $needs_mfc=1; |
| 1942 | } elsif ($arg eq "--nomfc") { |
| 1943 | $opt_flags&=~($TF_MFC|$TF_WRAP); |
| 1944 | $needs_mfc=0; |
| 1945 | |
| 1946 | # Catch errors |
| 1947 | } else { |
| 1948 | if ($arg ne "--help" and $arg ne "-h" and $arg ne "-?") { |
| 1949 | print STDERR "Unknown option: $arg\n"; |
| 1950 | } |
| 1951 | $usage=1; |
| 1952 | last; |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | if ($opt_no_banner == 0 or defined $usage) { |
| 1957 | print "Winemaker $version\n"; |
| 1958 | print "Copyright 2000 Francois Gouget <fgouget\@codeweavers.com> for CodeWeavers\n"; |
| 1959 | } |
| 1960 | |
| 1961 | if (defined $usage) { |
| 1962 | print STDERR "Usage: winemaker [--nobanner] [--backup|--nobackup]\n"; |
| 1963 | print STDERR " [--lower-none|--lower-all|--lower-uppercase]\n"; |
| 1964 | print STDERR " [--guiexe|--windows|--cuiexe|--console|--dll]\n"; |
| 1965 | print STDERR " [--wrap|--nowrap] [--mfc|--nomfc]\n"; |
| 1966 | print STDERR " [-Dmacro[=defn]] [-Idir] [-Ldir] [-llibrary]\n"; |
| 1967 | print STDERR " [--interactive] [--single-target name]\n"; |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1968 | print STDERR " [--generated-files|--no-generated-files]\n"; |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1969 | exit (2); |
| 1970 | } |
| 1971 | |
| 1972 | # Fix the file and directory names |
| 1973 | fix_file_and_directory_names("."); |
| 1974 | |
| 1975 | # Scan the sources to identify the projects and targets |
| 1976 | source_scan(); |
| 1977 | |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1978 | # Create targets for wrappers, etc. |
| 1979 | postprocess_targets(); |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1980 | |
| 1981 | # Fix the source files |
| 1982 | fix_source(); |
| 1983 | |
| 1984 | # Generate the Makefile and the spec file |
Francois Gouget | a106edb | 2000-11-10 22:29:11 +0000 | [diff] [blame^] | 1985 | if (! $opt_no_generated_files) { |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 1986 | generate(); |
| 1987 | } |
| 1988 | |
| 1989 | |
| 1990 | __DATA__ |
| 1991 | --- configure.in --- |
| 1992 | dnl Process this file with autoconf to produce a configure script. |
| 1993 | dnl Author: Michael Patra <micky@marie.physik.tu-berlin.de> |
| 1994 | dnl <patra@itp1.physik.tu-berlin.de> |
| 1995 | dnl Francois Gouget <fgouget@codeweavers.com> for CodeWeavers |
| 1996 | |
| 1997 | AC_REVISION([configure.in 1.00]) |
| 1998 | AC_INIT(##WINEMAKER_SOURCE##) |
| 1999 | |
| 2000 | NEEDS_MFC=##WINEMAKER_NEEDS_MFC## |
| 2001 | |
| 2002 | dnl **** Command-line arguments **** |
| 2003 | |
| 2004 | AC_SUBST(OPTIONS) |
| 2005 | |
| 2006 | dnl **** Check for some programs **** |
| 2007 | |
| 2008 | AC_PROG_MAKE_SET |
| 2009 | AC_PROG_CC |
| 2010 | AC_PROG_CXX |
| 2011 | AC_PROG_CPP |
| 2012 | AC_PATH_XTRA |
| 2013 | AC_PROG_RANLIB |
| 2014 | AC_PROG_LN_S |
| 2015 | AC_PATH_PROG(LDCONFIG, ldconfig, true, /sbin:/usr/sbin:$PATH) |
| 2016 | |
| 2017 | dnl **** Check for some libraries **** |
| 2018 | |
| 2019 | dnl Check for -lm for BeOS |
| 2020 | AC_CHECK_LIB(m,sqrt) |
| 2021 | dnl Check for -li386 for NetBSD and OpenBSD |
| 2022 | AC_CHECK_LIB(i386,i386_set_ldt) |
| 2023 | dnl Check for -lossaudio for NetBSD |
| 2024 | AC_CHECK_LIB(ossaudio,_oss_ioctl) |
| 2025 | dnl Check for -lw for Solaris |
| 2026 | AC_CHECK_LIB(w,iswalnum) |
| 2027 | dnl Check for -lnsl for Solaris |
| 2028 | AC_CHECK_FUNCS(gethostbyname,, AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl", AC_CHECK_LIB(socket, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl", , -lnsl), -lsocket)) |
| 2029 | dnl Check for -lsocket for Solaris |
| 2030 | AC_CHECK_FUNCS(connect,,AC_CHECK_LIB(socket,connect)) |
| 2031 | dnl Check for -lxpg4 for FreeBSD |
| 2032 | AC_CHECK_LIB(xpg4,setrunelocale) |
| 2033 | dnl Check for -lmmap for OS/2 |
| 2034 | AC_CHECK_LIB(mmap,mmap) |
| 2035 | dnl Check for openpty |
| 2036 | AC_CHECK_FUNCS(openpty,, |
| 2037 | AC_CHECK_LIB(util,openpty, |
| 2038 | AC_DEFINE(HAVE_OPENPTY) |
| 2039 | LIBS="$LIBS -lutil" |
| 2040 | )) |
| 2041 | |
| 2042 | AC_CHECK_HEADERS(dlfcn.h, |
| 2043 | AC_CHECK_FUNCS(dlopen, |
| 2044 | AC_DEFINE(HAVE_DL_API), |
| 2045 | AC_CHECK_LIB(dl,dlopen, |
| 2046 | AC_DEFINE(HAVE_DL_API) |
| 2047 | LIBS="$LIBS -ldl", |
| 2048 | ) |
| 2049 | ), |
| 2050 | ) |
| 2051 | AC_SUBST(XLIB) |
| 2052 | AC_SUBST(X_DLLS) |
| 2053 | X_DLLS="" |
| 2054 | AC_SUBST(XFILES) |
| 2055 | XFILES="" |
| 2056 | |
| 2057 | dnl **** Check which curses lib to use *** |
| 2058 | if test "$CURSES" = "yes" |
| 2059 | then |
| 2060 | AC_CHECK_HEADERS(ncurses.h) |
| 2061 | if test "$ac_cv_header_ncurses_h" = "yes" |
| 2062 | then |
| 2063 | AC_CHECK_LIB(ncurses,waddch) |
| 2064 | fi |
| 2065 | if test "$ac_cv_lib_ncurses_waddch" = "yes" |
| 2066 | then |
| 2067 | AC_CHECK_LIB(ncurses,resizeterm,AC_DEFINE(HAVE_RESIZETERM)) |
| 2068 | AC_CHECK_LIB(ncurses,getbkgd,AC_DEFINE(HAVE_GETBKGD)) |
| 2069 | else |
| 2070 | AC_CHECK_HEADERS(curses.h) |
| 2071 | if test "$ac_cv_header_curses_h" = "yes" |
| 2072 | then |
| 2073 | AC_CHECK_LIB(curses,waddch) |
| 2074 | if test "$ac_cv_lib_curses_waddch" = "yes" |
| 2075 | then |
| 2076 | AC_CHECK_LIB(curses,resizeterm,AC_DEFINE(HAVE_RESIZETERM)) |
| 2077 | AC_CHECK_LIB(curses,getbkgd,AC_DEFINE(HAVE_GETBKGD)) |
| 2078 | fi |
| 2079 | fi |
| 2080 | fi |
| 2081 | fi |
| 2082 | |
| 2083 | dnl **** If ln -s doesn't work, use cp instead **** |
| 2084 | if test "$ac_cv_prog_LN_S" = "ln -s"; then : ; else LN_S=cp ; fi |
| 2085 | |
| 2086 | dnl **** Check for gcc strength-reduce bug **** |
| 2087 | |
| 2088 | if test "x${GCC}" = "xyes" |
| 2089 | then |
| 2090 | AC_CACHE_CHECK( "for gcc strength-reduce bug", ac_cv_c_gcc_strength_bug, |
| 2091 | AC_TRY_RUN([ |
| 2092 | int main(void) { |
| 2093 | static int Array[[3]]; |
| 2094 | unsigned int B = 3; |
| 2095 | int i; |
| 2096 | for(i=0; i<B; i++) Array[[i]] = i - 3; |
| 2097 | exit( Array[[1]] != -2 ); |
| 2098 | }], |
| 2099 | ac_cv_c_gcc_strength_bug="no", |
| 2100 | ac_cv_c_gcc_strength_bug="yes", |
| 2101 | ac_cv_c_gcc_strength_bug="yes") ) |
| 2102 | if test "$ac_cv_c_gcc_strength_bug" = "yes" |
| 2103 | then |
| 2104 | CFLAGS="$CFLAGS -fno-strength-reduce" |
| 2105 | fi |
| 2106 | fi |
| 2107 | |
| 2108 | dnl **** Check for underscore on external symbols **** |
| 2109 | |
| 2110 | AC_CACHE_CHECK("whether external symbols need an underscore prefix", |
| 2111 | ac_cv_c_extern_prefix, |
| 2112 | [saved_libs=$LIBS |
| 2113 | LIBS="conftest_asm.s $LIBS" |
| 2114 | cat > conftest_asm.s <<EOF |
| 2115 | .globl _ac_test |
| 2116 | _ac_test: |
| 2117 | .long 0 |
| 2118 | EOF |
| 2119 | AC_TRY_LINK([extern int ac_test;],[if (ac_test) return 1], |
| 2120 | ac_cv_c_extern_prefix="yes",ac_cv_c_extern_prefix="no") |
| 2121 | LIBS=$saved_libs]) |
| 2122 | if test "$ac_cv_c_extern_prefix" = "yes" |
| 2123 | then |
| 2124 | AC_DEFINE(NEED_UNDERSCORE_PREFIX) |
| 2125 | fi |
| 2126 | |
| 2127 | dnl **** Check for working dll **** |
| 2128 | |
| 2129 | LDSHARED="" |
| 2130 | AC_CACHE_CHECK("whether we can build a Linux dll", |
| 2131 | ac_cv_c_dll_linux, |
| 2132 | [saved_cflags=$CFLAGS |
| 2133 | CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0" |
| 2134 | AC_TRY_LINK(,[return 1],ac_cv_c_dll_linux="yes",ac_cv_c_dll_linux="no") |
| 2135 | CFLAGS=$saved_cflags |
| 2136 | ]) |
| 2137 | if test "$ac_cv_c_dll_linux" = "yes" |
| 2138 | then |
| 2139 | LDSHARED="\$(CC) -shared -Wl,-soname,\$(SONAME),-rpath,\$(libdir)" |
| 2140 | else |
| 2141 | AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll, |
| 2142 | ac_cv_c_dll_unixware, |
| 2143 | [saved_cflags=$CFLAGS |
| 2144 | CFLAGS="$CFLAGS -fPIC -Wl,-G,-h,conftest.so.1.0" |
| 2145 | AC_TRY_LINK(,[return 1],ac_cv_c_dll_unixware="yes",ac_cv_c_dll_unixware="no") |
| 2146 | CFLAGS=$saved_cflags |
| 2147 | ]) |
| 2148 | if test "$ac_cv_c_dll_unixware" = "yes" |
| 2149 | then |
| 2150 | LDSHARED="\$(CC) -Wl,-G,-h,\$(libdir)/\$(SONAME)" |
| 2151 | else |
| 2152 | AC_CACHE_CHECK("whether we can build a NetBSD dll", |
| 2153 | ac_cv_c_dll_netbsd, |
| 2154 | [saved_cflags=$CFLAGS |
| 2155 | CFLAGS="$CFLAGS -fPIC -Bshareable -Bforcearchive" |
| 2156 | AC_TRY_LINK(,[return 1],ac_cv_c_dll_netbsd="yes",ac_cv_c_dll_netbsd="no") |
| 2157 | CFLAGS=$saved_cflags |
| 2158 | ]) |
| 2159 | if test "$ac_cv_c_dll_netbsd" = "yes" |
| 2160 | then |
| 2161 | LDSHARED="ld -Bshareable -Bforcearchive" |
| 2162 | fi |
| 2163 | fi |
| 2164 | fi |
| 2165 | if test "$ac_cv_c_dll_linux" = "no" -a "$ac_cv_c_dll_unixware" = "no" -a "$ac_cv_c_dll_netbsd" = "no" |
| 2166 | then |
| 2167 | AC_MSG_ERROR([Could not find how to build a dynamically linked library]) |
| 2168 | fi |
| 2169 | |
| 2170 | DLLFLAGS="-fPIC" |
| 2171 | DLL_LINK="\$(WINELIB_LIBRARY_PATH) \$(DLLS:%=-l%) \$(IMPORTS:%=-l%) -lwine -lwine_unicode" |
| 2172 | |
| 2173 | AC_SUBST(DLL_LINK) |
| 2174 | AC_SUBST(DLLFLAGS) |
| 2175 | AC_SUBST(LDSHARED) |
| 2176 | |
| 2177 | dnl *** check for the need to define __i386__ |
| 2178 | |
| 2179 | AC_CACHE_CHECK("whether we need to define __i386__",ac_cv_cpp_def_i386, |
| 2180 | AC_EGREP_CPP(yes,[#if (defined(i386) || defined(__i386)) && !defined(__i386__) |
| 2181 | yes |
| 2182 | #endif], |
| 2183 | ac_cv_cpp_def_i386="yes", ac_cv_cpp_def_i386="no")) |
| 2184 | if test "$ac_cv_cpp_def_i386" = "yes" |
| 2185 | then |
| 2186 | CFLAGS="$CFLAGS -D__i386__" |
| 2187 | fi |
| 2188 | |
| 2189 | dnl $GCC is set by autoconf |
| 2190 | GCC_NO_BUILTIN="" |
| 2191 | if test "$GCC" = "yes" |
| 2192 | then |
| 2193 | GCC_NO_BUILTIN="-fno-builtin" |
| 2194 | fi |
| 2195 | AC_SUBST(GCC_NO_BUILTIN) |
| 2196 | |
| 2197 | dnl **** Test Winelib-related features of the C++ compiler |
| 2198 | AC_LANG_CPLUSPLUS() |
| 2199 | if test "x${GCC}" = "xyes" |
| 2200 | then |
| 2201 | OLDCXXFLAGS="$CXXFLAGS"; |
| 2202 | CXXFLAGS="-fpermissive"; |
| 2203 | AC_CACHE_CHECK("for g++ -fpermissive option", has_gxx_permissive, |
| 2204 | AC_TRY_COMPILE(,[ |
| 2205 | for (int i=0;i<2;i++); |
| 2206 | i=0; |
| 2207 | ], |
| 2208 | [has_gxx_permissive="yes"], |
| 2209 | [has_gxx_permissive="no"]) |
| 2210 | ) |
| 2211 | CXXFLAGS="-fno-for-scope"; |
| 2212 | AC_CACHE_CHECK("for g++ -fno-for-scope option", has_gxx_no_for_scope, |
| 2213 | AC_TRY_COMPILE(,[ |
| 2214 | for (int i=0;i<2;i++); |
| 2215 | i=0; |
| 2216 | ], |
| 2217 | [has_gxx_no_for_scope="yes"], |
| 2218 | [has_gxx_no_for_scope="no"]) |
| 2219 | ) |
| 2220 | CXXFLAGS="$OLDCXXFLAGS"; |
| 2221 | if test "$has_gxx_permissive" = "yes" |
| 2222 | then |
| 2223 | CXXFLAGS="$CXXFLAGS -fpermissive" |
| 2224 | fi |
| 2225 | if test "$has_gxx_no_for_scope" = "yes" |
| 2226 | then |
| 2227 | CXXFLAGS="$CXXFLAGS -fno-for-scope" |
| 2228 | fi |
| 2229 | fi |
| 2230 | |
| 2231 | dnl **** Test Winelib-related features of the C compiler |
| 2232 | dnl none for now |
| 2233 | |
| 2234 | dnl **** Try to find where winelib is located **** |
| 2235 | |
| 2236 | dnl This section is implemented using custom code since autoconf does not |
| 2237 | dnl provide a standard method. Here is how other people have tried to |
| 2238 | dnl solve the same (or similar) problem. |
| 2239 | dnl See: http://www.geocrawler.com/archives/3/402/1999/4/50/2131449/ |
| 2240 | dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131443/ |
| 2241 | dnl ftp://ftp.slac.stanford.edu/users/langston/autoconf/smr_macros-0.09.tar.gz |
| 2242 | dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131452/ |
| 2243 | dnl or http://www.geocrawler.com/archives/3/402/1999/4/50/2131446/ |
| 2244 | |
| 2245 | WINELIB_INCLUDE_ROOT=""; |
| 2246 | WINELIB_INCLUDE_PATH=""; |
| 2247 | WINELIB_LIBRARY_ROOT=""; |
| 2248 | WINELIB_LIBRARY_PATH=""; |
| 2249 | WINELIB_TOOL_PATH=""; |
| 2250 | WINEBUILD=""; |
| 2251 | WRC=""; |
| 2252 | |
| 2253 | AC_ARG_WITH(winelib-root, |
| 2254 | [ --with-winelib-root=DIR take the Winelib includes, libraries and tools from this directory], |
| 2255 | [if test "$withval" != "no"; then |
| 2256 | WINELIB_ROOT="$withval"; |
| 2257 | WINELIB_INCLUDES=""; |
| 2258 | WINELIB_LIBRARIES=""; |
| 2259 | WINELIB_TOOLS=""; |
| 2260 | else |
| 2261 | WINELIB_ROOT=""; |
| 2262 | fi]) |
| 2263 | if test -n "$WINELIB_ROOT" |
| 2264 | then |
| 2265 | WINELIB_INCLUDE_ROOT="$WINELIB_ROOT/include"; |
| 2266 | WINELIB_LIBRARY_ROOT="$WINELIB_ROOT"; |
| 2267 | WINELIB_TOOL_PATH="$WINELIB_ROOT:$WINELIB_ROOT/bin:$WINELIB_ROOT/tools/wrc:$WINELIB_ROOT/tools/winebuild:$PATH"; |
| 2268 | fi |
| 2269 | |
| 2270 | AC_ARG_WITH(winelib-includes, |
| 2271 | [ --with-winelib-includes=DIR take the Winelib includes from this directory], |
| 2272 | [if test "$withval" != "no"; then |
| 2273 | WINELIB_INCLUDES="$withval"; |
| 2274 | else |
| 2275 | WINELIB_INCLUDES=""; |
| 2276 | fi]) |
| 2277 | if test -n "$WINELIB_INCLUDES" |
| 2278 | then |
| 2279 | WINELIB_INCLUDE_ROOT="$WINELIB_INCLUDES"; |
| 2280 | fi |
| 2281 | |
| 2282 | AC_ARG_WITH(winelib-libraries, |
| 2283 | [ --with-winelib-libraries=DIR take the Winelib libraries from this directory], |
| 2284 | [if test "$withval" != "no"; then |
| 2285 | WINELIB_LIBRARIES="$withval"; |
| 2286 | else |
| 2287 | WINELIB_LIBRARIES=""; |
| 2288 | fi]) |
| 2289 | if test -n "$WINELIB_LIBRARIES" |
| 2290 | then |
| 2291 | WINELIB_LIBRARY_ROOT="$WINELIB_LIBRARIES"; |
| 2292 | fi |
| 2293 | |
| 2294 | AC_ARG_WITH(winelib-tools, |
| 2295 | [ --with-winelib-tools=DIR take the Winelib tools from this directory], |
| 2296 | [if test "$withval" != "no"; then |
| 2297 | WINELIB_TOOLS="$withval"; |
| 2298 | else |
| 2299 | WINELIB_TOOLS=""; |
| 2300 | fi]) |
| 2301 | if test -n "$WINELIB_TOOLS" |
| 2302 | then |
| 2303 | WINELIB_TOOL_PATH="$WINELIB_TOOLS:$WINELIB_TOOLS/wrc:$WINELIB_TOOLS/winebuild"; |
| 2304 | fi |
| 2305 | |
| 2306 | if test -z "$WINELIB_INCLUDE_ROOT" |
| 2307 | then |
| 2308 | WINELIB_INCLUDE_ROOT="/usr/include/wine"; |
| 2309 | fi |
| 2310 | if test ! -f "$WINELIB_INCLUDE_ROOT/windows.h" |
| 2311 | then |
| 2312 | AC_MSG_ERROR([Could not find the Winelib includes]) |
| 2313 | fi |
| 2314 | WINELIB_INCLUDE_PATH="-I$WINELIB_INCLUDE_ROOT" |
| 2315 | |
| 2316 | if test -z "$WINELIB_LIBRARY_ROOT" |
| 2317 | then |
| 2318 | WINELIB_LIBRARY_ROOT="/usr/lib/wine"; |
| 2319 | fi |
| 2320 | if test ! -f "$WINELIB_LIBRARY_ROOT/libwine.so" |
| 2321 | then |
| 2322 | if test -f "$WINELIB_LIBRARY_ROOT/lib/libwine.so" |
| 2323 | then |
| 2324 | WINELIB_LIBRARY_ROOT="$WINELIB_LIBRARY_ROOT/lib"; |
| 2325 | else |
| 2326 | AC_MSG_ERROR([Could not find the Winelib libraries (libwine)]) |
| 2327 | fi |
| 2328 | fi |
| 2329 | if test -f "$WINELIB_LIBRARY_ROOT/libkernel32.so" |
| 2330 | then |
| 2331 | WINELIB_LIBRARY_PATH="-L$WINELIB_LIBRARY_ROOT"; |
| 2332 | else |
| 2333 | if test -f "$WINELIB_LIBRARY_ROOT/dlls/libkernel32.so" |
| 2334 | then |
| 2335 | WINELIB_LIBRARY_PATH="-L$WINELIB_LIBRARY_ROOT -L$WINELIB_LIBRARY_ROOT/dlls"; |
| 2336 | else |
| 2337 | AC_MSG_ERROR([Could not find the Winelib libraries (libkernel32)]) |
| 2338 | fi |
| 2339 | fi |
| 2340 | |
| 2341 | AC_PATH_PROG(WINEBUILD,winebuild,,$WINELIB_TOOL_PATH) |
| 2342 | if test -z "$WINEBUILD" |
| 2343 | then |
| 2344 | AC_MSG_ERROR([Could not find Winelib's winebuild tool]) |
| 2345 | fi |
| 2346 | AC_PATH_PROG(WRC,wrc,,$WINELIB_TOOL_PATH) |
| 2347 | if test -z "$WRC" |
| 2348 | then |
| 2349 | AC_MSG_ERROR([Could not find Winelib's wrc tool]) |
| 2350 | fi |
| 2351 | |
| 2352 | AC_SUBST(WINELIB_INCLUDE_ROOT) |
| 2353 | AC_SUBST(WINELIB_INCLUDE_PATH) |
| 2354 | AC_SUBST(WINELIB_LIBRARY_ROOT) |
| 2355 | AC_SUBST(WINELIB_LIBRARY_PATH) |
| 2356 | |
| 2357 | dnl **** Try to find where the MFC are located **** |
| 2358 | |
| 2359 | if test "x$NEEDS_MFC" = "x1" |
| 2360 | then |
| 2361 | ATL_INCLUDE_ROOT=""; |
| 2362 | ATL_INCLUDE_PATH=""; |
| 2363 | MFC_INCLUDE_ROOT=""; |
| 2364 | MFC_INCLUDE_PATH=""; |
| 2365 | MFC_LIBRARY_ROOT=""; |
| 2366 | MFC_LIBRARY_PATH=""; |
| 2367 | |
| 2368 | AC_ARG_WITH(mfc-root, |
| 2369 | [ --with-mfc-root=DIR take the MFC includes and libraries from this directory], |
| 2370 | [if test "$withval" != "no"; then |
| 2371 | MFC_ROOT="$withval"; |
| 2372 | ATL_INCLUDES=""; |
| 2373 | MFC_INCLUDES=""; |
| 2374 | MFC_LIBRARIES=""; |
| 2375 | else |
| 2376 | MFC_ROOT=""; |
| 2377 | fi]) |
| 2378 | if test -n "$MFC_ROOT" |
| 2379 | then |
| 2380 | ATL_INCLUDE_ROOT="$MFC_ROOT"; |
| 2381 | MFC_INCLUDE_ROOT="$MFC_ROOT"; |
| 2382 | MFC_LIBRARY_ROOT="$MFC_ROOT"; |
| 2383 | fi |
| 2384 | |
| 2385 | AC_ARG_WITH(atl-includes, |
| 2386 | [ --with-atl-includes=DIR take the ATL includes from this directory], |
| 2387 | [if test "$withval" != "no"; then |
| 2388 | ATL_INCLUDES="$withval"; |
| 2389 | else |
| 2390 | ATL_INCLUDES=""; |
| 2391 | fi]) |
| 2392 | if test -n "$ATL_INCLUDES" |
| 2393 | then |
| 2394 | ATL_INCLUDE_ROOT="$ATL_INCLUDES"; |
| 2395 | fi |
| 2396 | |
| 2397 | AC_ARG_WITH(mfc-includes, |
| 2398 | [ --with-mfc-includes=DIR take the MFC includes from this directory], |
| 2399 | [if test "$withval" != "no"; then |
| 2400 | MFC_INCLUDES="$withval"; |
| 2401 | else |
| 2402 | MFC_INCLUDES=""; |
| 2403 | fi]) |
| 2404 | if test -n "$MFC_INCLUDES" |
| 2405 | then |
| 2406 | MFC_INCLUDE_ROOT="$MFC_INCLUDES"; |
| 2407 | fi |
| 2408 | |
| 2409 | AC_ARG_WITH(mfc-libraries, |
| 2410 | [ --with-mfc-libraries=DIR take the MFC libraries from this directory], |
| 2411 | [if test "$withval" != "no"; then |
| 2412 | MFC_LIBRARIES="$withval"; |
| 2413 | else |
| 2414 | MFC_LIBRARIES=""; |
| 2415 | fi]) |
| 2416 | if test -n "$MFC_LIBRARIES" |
| 2417 | then |
| 2418 | MFC_LIBRARY_ROOT="$MFC_LIBRARIES"; |
| 2419 | fi |
| 2420 | |
| 2421 | dnl FIXME: We should have an include path and just iterate through it. |
| 2422 | dnl These tests become ugly. |
| 2423 | if test -z "$ATL_INCLUDE_ROOT" |
| 2424 | then |
| 2425 | ATL_INCLUDE_ROOT="/usr/include"; |
| 2426 | fi |
| 2427 | if test ! -f "$ATL_INCLUDE_ROOT/atlbase.h" |
| 2428 | then |
| 2429 | if test -f "$ATL_INCLUDE_ROOT/atl/atlbase.h" |
| 2430 | then |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 2431 | ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT/atl" |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2432 | else |
| 2433 | if test -f "$ATL_INCLUDE_ROOT/atl/include/atlbase.h" |
| 2434 | then |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 2435 | ATL_INCLUDE_ROOT="$ATL_INCLUDE_ROOT/atl/include" |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2436 | else |
| 2437 | AC_MSG_ERROR([Could not find the ATL includes]) |
| 2438 | fi |
| 2439 | fi |
| 2440 | fi |
| 2441 | ATL_INCLUDE_PATH="-I$ATL_INCLUDE_ROOT" |
| 2442 | |
| 2443 | if test -z "$MFC_INCLUDE_ROOT" |
| 2444 | then |
| 2445 | MFC_INCLUDE_ROOT="/usr/include"; |
| 2446 | fi |
| 2447 | if test ! -f "$MFC_INCLUDE_ROOT/afx.h" |
| 2448 | then |
| 2449 | if test -f "$MFC_INCLUDE_ROOT/mfc/afx.h" |
| 2450 | then |
| 2451 | MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT/mfc" |
| 2452 | else |
| 2453 | if test -f "$MFC_INCLUDE_ROOT/mfc/include/afx.h" |
| 2454 | then |
| 2455 | MFC_INCLUDE_ROOT="$MFC_INCLUDE_ROOT/mfc/include" |
| 2456 | else |
| 2457 | AC_MSG_ERROR([Could not find the MFC includes]) |
| 2458 | fi |
| 2459 | fi |
| 2460 | fi |
Francois Gouget | b430295 | 2000-11-07 20:27:16 +0000 | [diff] [blame] | 2461 | MFC_INCLUDE_PATH="-D_DLL -D_MT -I$ATL_INCLUDE_ROOT -I$MFC_INCLUDE_ROOT -I\$(WINELIB_INCLUDE_ROOT)/mixedcrt" |
Francois Gouget | 755bb92 | 2000-11-05 05:23:39 +0000 | [diff] [blame] | 2462 | |
| 2463 | if test -z "$MFC_LIBRARY_ROOT" |
| 2464 | then |
| 2465 | MFC_LIBRARY_ROOT="/usr/lib/mfc"; |
| 2466 | fi |
| 2467 | if test -f "$MFC_LIBRARY_ROOT/libmfc.so" |
| 2468 | then |
| 2469 | MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT"; |
| 2470 | else |
| 2471 | if test -f "$MFC_LIBRARY_ROOT/lib/libmfc.so" |
| 2472 | then |
| 2473 | MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT/lib"; |
| 2474 | else |
| 2475 | if test -f "$MFC_LIBRARY_ROOT/mfc/src/libmfc.so" |
| 2476 | then |
| 2477 | MFC_LIBRARY_ROOT="$MFC_LIBRARY_ROOT/mfc/src"; |
| 2478 | else |
| 2479 | AC_MSG_ERROR([Could not find the MFC library (libmfc)]) |
| 2480 | fi |
| 2481 | fi |
| 2482 | fi |
| 2483 | MFC_LIBRARY_PATH="-L$MFC_LIBRARY_ROOT" |
| 2484 | |
| 2485 | AC_SUBST(ATL_INCLUDE_ROOT) |
| 2486 | AC_SUBST(ATL_INCLUDE_PATH) |
| 2487 | AC_SUBST(MFC_INCLUDE_ROOT) |
| 2488 | AC_SUBST(MFC_INCLUDE_PATH) |
| 2489 | AC_SUBST(MFC_LIBRARY_ROOT) |
| 2490 | AC_SUBST(MFC_LIBRARY_PATH) |
| 2491 | fi |
| 2492 | |
| 2493 | dnl **** Generate output files **** |
| 2494 | |
| 2495 | MAKE_RULES=Make.rules |
| 2496 | AC_SUBST_FILE(MAKE_RULES) |
| 2497 | |
| 2498 | AC_OUTPUT([ |
| 2499 | Make.rules |
| 2500 | ##WINEMAKER_PROJECTS## |
| 2501 | ]) |
| 2502 | |
| 2503 | echo |
| 2504 | echo "Configure finished. Do 'make' to build the project." |
| 2505 | echo |
| 2506 | |
| 2507 | dnl Local Variables: |
| 2508 | dnl comment-start: "dnl " |
| 2509 | dnl comment-end: "" |
| 2510 | dnl comment-start-skip: "\\bdnl\\b\\s *" |
| 2511 | dnl compile-command: "autoconf" |
| 2512 | dnl End: |
| 2513 | --- Make.rules.in --- |
| 2514 | # Copyright 2000 Francois Gouget for CodeWeavers |
| 2515 | # fgouget@codeweavers.com |
| 2516 | # |
| 2517 | # Global rules shared by all makefiles -*-Makefile-*- |
| 2518 | # |
| 2519 | # Each individual makefile must define the following variables: |
| 2520 | # WINELIB_INCLUDE_ROOT: Winelib includes location |
| 2521 | # WINELIB_LIBRARY_ROOT: Winelib libraries location |
| 2522 | # TOPOBJDIR : top-level object directory |
| 2523 | # SRCDIR : source directory for this module |
| 2524 | # |
| 2525 | # Each individual makefile may define the following additional variables: |
| 2526 | # |
| 2527 | # SUBDIRS : subdirectories that contain a Makefile |
| 2528 | # LIBRARIES : libraries to be built |
| 2529 | # PROGRAMS : programs to be built |
| 2530 | # |
| 2531 | # CEXTRA : extra c flags (e.g. '-Wall') |
| 2532 | # CXXEXTRA : extra c++ flags (e.g. '-Wall') |
| 2533 | # WRCEXTRA : extra wrc flags (e.g. '-p _SysRes') |
| 2534 | # DEFINES : defines (e.g. -DSTRICT) |
| 2535 | # INCLUDE_PATH : additional include path |
| 2536 | # LIBRARY_PATH : additional library path |
| 2537 | # IMPORTS : additional libraries to link with |
| 2538 | # |
| 2539 | # C_SRCS : C sources for the module |
| 2540 | # CXX_SRCS : C++ sources for the module |
| 2541 | # RC_SRCS : resource source files |
| 2542 | # SPEC_SRCS : interface definition files |
| 2543 | |
| 2544 | |
| 2545 | # Where is Winelib |
| 2546 | |
| 2547 | WINELIB_INCLUDE_ROOT = @WINELIB_INCLUDE_ROOT@ |
| 2548 | WINELIB_INCLUDE_PATH = @WINELIB_INCLUDE_PATH@ |
| 2549 | WINELIB_LIBRARY_ROOT = @WINELIB_LIBRARY_ROOT@ |
| 2550 | WINELIB_LIBRARY_PATH = @WINELIB_LIBRARY_PATH@ |
| 2551 | |
| 2552 | # Where are the MFC |
| 2553 | |
| 2554 | ATL_INCLUDE_ROOT = @ATL_INCLUDE_ROOT@ |
| 2555 | ATL_INCLUDE_PATH = @ATL_INCLUDE_PATH@ |
| 2556 | MFC_INCLUDE_ROOT = @MFC_INCLUDE_ROOT@ |
| 2557 | MFC_INCLUDE_PATH = @MFC_INCLUDE_PATH@ |
| 2558 | MFC_LIBRARY_ROOT = @MFC_LIBRARY_ROOT@ |
| 2559 | MFC_LIBRARY_PATH = @MFC_LIBRARY_PATH@ |
| 2560 | |
| 2561 | # First some useful definitions |
| 2562 | |
| 2563 | SHELL = /bin/sh |
| 2564 | CC = @CC@ |
| 2565 | CPP = @CPP@ |
| 2566 | CFLAGS = @CFLAGS@ |
| 2567 | CXXFLAGS = @CXXFLAGS@ |
| 2568 | OPTIONS = @OPTIONS@ -D_REENTRANT -DWINELIB |
| 2569 | X_CFLAGS = @X_CFLAGS@ |
| 2570 | X_LIBS = @X_LIBS@ |
| 2571 | XLIB = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ |
| 2572 | DLL_LINK = @DLL_LINK@ |
| 2573 | LIBS = @LIBS@ $(LIBRARY_PATH) |
| 2574 | YACC = @YACC@ |
| 2575 | LEX = @LEX@ |
| 2576 | LEXLIB = @LEXLIB@ |
| 2577 | LN_S = @LN_S@ |
| 2578 | DIVINCL = -I$(SRCDIR) $(WINELIB_INCLUDE_PATH) $(INCLUDE_PATH) |
| 2579 | ALLCFLAGS = $(DIVINCL) $(CFLAGS) $(CEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES) |
| 2580 | ALLCXXFLAGS = $(DIVINCL) $(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(X_CFLAGS) $(DEFINES) |
| 2581 | LDCOMBINE = ld -r |
| 2582 | LDSHARED = @LDSHARED@ |
| 2583 | RM = rm -f |
| 2584 | MV = mv |
| 2585 | MKDIR = mkdir -p |
| 2586 | WINEBUILD = @WINEBUILD@ |
| 2587 | WRC = @WRC@ |
| 2588 | WRCFLAGS = -r -L |
| 2589 | @SET_MAKE@ |
| 2590 | |
| 2591 | # Installation infos |
| 2592 | |
| 2593 | INSTALL = @INSTALL@ |
| 2594 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ |
| 2595 | INSTALL_DATA = @INSTALL_DATA@ |
| 2596 | prefix = @prefix@ |
| 2597 | exec_prefix = @exec_prefix@ |
| 2598 | bindir = @bindir@ |
| 2599 | libdir = @libdir@ |
| 2600 | infodir = @infodir@ |
| 2601 | mandir = @mandir@ |
| 2602 | prog_manext = 1 |
| 2603 | conf_manext = 5 |
| 2604 | CLEAN_FILES = *.o *.a *.so \\\#*\\\# *~ *% .\\\#* *.orig *.rej \ |
| 2605 | *.spec.c y.tab.c y.tab.h lex.yy.c core |
| 2606 | |
| 2607 | OBJS = $(SPEC_SRCS:.spec=.spec.o) $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o) |
| 2608 | |
| 2609 | # DLL list |
| 2610 | |
| 2611 | X_DLLS = \ |
| 2612 | ddraw \ |
| 2613 | x11drv |
| 2614 | |
| 2615 | DLLS = \ |
| 2616 | @X_DLLS@ \ |
| 2617 | advapi32 \ |
| 2618 | avifil32 \ |
| 2619 | comctl32 \ |
| 2620 | comdlg32 \ |
| 2621 | crtdll \ |
| 2622 | dciman32 \ |
| 2623 | dinput \ |
| 2624 | dplay \ |
| 2625 | dplayx \ |
| 2626 | dsound \ |
| 2627 | gdi32 \ |
| 2628 | imagehlp \ |
| 2629 | imm32 \ |
| 2630 | joystick.drv \ |
| 2631 | kernel32 \ |
| 2632 | lz32 \ |
| 2633 | mcianim.drv \ |
| 2634 | mciavi.drv \ |
| 2635 | mcicda.drv \ |
| 2636 | mciseq.drv \ |
| 2637 | mciwave.drv \ |
| 2638 | midimap.drv \ |
| 2639 | mpr \ |
| 2640 | msacm.drv \ |
| 2641 | msacm32 \ |
| 2642 | msnet32 \ |
| 2643 | msvfw32 \ |
| 2644 | odbc32 \ |
| 2645 | ole32 \ |
| 2646 | oleaut32 \ |
| 2647 | olecli32 \ |
| 2648 | oledlg \ |
| 2649 | olepro32 \ |
| 2650 | olesvr32 \ |
| 2651 | psapi \ |
| 2652 | rasapi32 \ |
| 2653 | riched32 \ |
| 2654 | rpcrt4 \ |
| 2655 | serialui \ |
| 2656 | shell32 \ |
| 2657 | shfolder \ |
| 2658 | shlwapi \ |
| 2659 | tapi32 \ |
| 2660 | ttydrv \ |
| 2661 | urlmon \ |
| 2662 | user32 \ |
| 2663 | version \ |
| 2664 | w32skrnl \ |
| 2665 | wineoss.drv \ |
| 2666 | wineps \ |
| 2667 | wininet \ |
| 2668 | winmm \ |
| 2669 | winspool.drv \ |
| 2670 | wnaspi32 \ |
| 2671 | wow32 \ |
| 2672 | ws2_32 \ |
| 2673 | wsock32 |
| 2674 | |
| 2675 | # Implicit rules |
| 2676 | |
| 2677 | .SUFFIXES: .C .cpp .CPP .cxx .CXX .rc .RC .res .spec .spec.c .spec.o |
| 2678 | |
| 2679 | .c.o: |
| 2680 | $(CC) -c $(ALLCFLAGS) -o $@ $< |
| 2681 | |
| 2682 | .C.o: |
| 2683 | $(CC) -c $(ALLCFLAGS) -o $@ $< |
| 2684 | |
| 2685 | .cpp.o: |
| 2686 | $(CXX) -c $(ALLCXXFLAGS) -o $@ $< |
| 2687 | |
| 2688 | .CPP.o: |
| 2689 | $(CXX) -c $(ALLCXXFLAGS) -o $@ $< |
| 2690 | |
| 2691 | .cxx.o: |
| 2692 | $(CXX) -c $(ALLCXXFLAGS) -o $@ $< |
| 2693 | |
| 2694 | .CXX.o: |
| 2695 | $(CXX) -c $(ALLCXXFLAGS) -o $@ $< |
| 2696 | |
| 2697 | .spec.spec.c: |
| 2698 | $(WINEBUILD) @DLLFLAGS@ -o $@ -spec $< |
| 2699 | |
| 2700 | .spec.c.spec.o: |
| 2701 | $(CC) -c $(ALLCFLAGS) @GCC_NO_BUILTIN@ -o $@ $< |
| 2702 | |
| 2703 | .rc.res: |
| 2704 | $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $< |
| 2705 | |
| 2706 | .RC.res: |
| 2707 | $(WRC) $(WRCFLAGS) $(WRCEXTRA) $(DIVINCL) -o $@ $< |
| 2708 | |
| 2709 | .PHONY: all install uninstall clean distclean depend dummy |
| 2710 | |
| 2711 | # 'all' target first in case the enclosing Makefile didn't define any target |
| 2712 | |
| 2713 | all: Makefile |
| 2714 | |
| 2715 | # Rules for makefile |
| 2716 | |
| 2717 | Makefile: Makefile.in $(TOPSRCDIR)/configure |
| 2718 | @echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure |
| 2719 | @exit 1 |
| 2720 | |
| 2721 | # Rules for cleaning |
| 2722 | |
| 2723 | $(SUBDIRS:%=%/__clean__): dummy |
| 2724 | cd `dirname $@` && $(MAKE) clean |
| 2725 | |
| 2726 | $(EXTRASUBDIRS:%=%/__clean__): dummy |
| 2727 | -cd `dirname $@` && $(RM) $(CLEAN_FILES) |
| 2728 | |
| 2729 | clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__) |
| 2730 | $(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(LIBRARIES) $(PROGRAMS) |
| 2731 | |
| 2732 | # Rules for installing |
| 2733 | |
| 2734 | $(SUBDIRS:%=%/__install__): dummy |
| 2735 | cd `dirname $@` && $(MAKE) install |
| 2736 | |
| 2737 | $(SUBDIRS:%=%/__uninstall__): dummy |
| 2738 | cd `dirname $@` && $(MAKE) uninstall |
| 2739 | |
| 2740 | # Misc. rules |
| 2741 | |
| 2742 | $(SUBDIRS): dummy |
| 2743 | @cd $@ && $(MAKE) |
| 2744 | |
| 2745 | dummy: |
| 2746 | |
| 2747 | # End of global rules |
| 2748 | --- wrapper.c --- |
| 2749 | /* |
| 2750 | * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers |
| 2751 | */ |
| 2752 | |
| 2753 | #include <dlfcn.h> |
| 2754 | #include <windows.h> |
| 2755 | |
| 2756 | |
| 2757 | |
| 2758 | /* |
| 2759 | * Describe the wrapped application |
| 2760 | */ |
| 2761 | |
| 2762 | /** |
| 2763 | * This is either CUIEXE for a console based application or |
| 2764 | * GUIEXE for a regular windows application. |
| 2765 | */ |
| 2766 | #define APP_TYPE ##WINEMAKER_APP_TYPE## |
| 2767 | |
| 2768 | /** |
| 2769 | * This is the application library's base name, i.e. 'hello' if the |
| 2770 | * library is called 'libhello.so'. |
| 2771 | */ |
| 2772 | static char* appName = ##WINEMAKER_APP_NAME##; |
| 2773 | |
| 2774 | /** |
| 2775 | * This is the name of the application's Windows module. If left NULL |
| 2776 | * then appName is used. |
| 2777 | */ |
| 2778 | static char* appModule = NULL; |
| 2779 | |
| 2780 | /** |
| 2781 | * This is the application's entry point. This is usually "WinMain" for a |
| 2782 | * GUIEXE and 'main' for a CUIEXE application. |
| 2783 | */ |
| 2784 | static char* appInit = ##WINEMAKER_APP_INIT##; |
| 2785 | |
| 2786 | /** |
| 2787 | * This is either non-NULL for MFC-based applications and is the name of the |
| 2788 | * MFC's module. This is the module in which we will take the 'WinMain' |
| 2789 | * function. |
| 2790 | */ |
| 2791 | static char* mfcModule = ##WINEMAKER_APP_MFC##; |
| 2792 | |
| 2793 | |
| 2794 | |
| 2795 | /* |
| 2796 | * Implement the main. |
| 2797 | */ |
| 2798 | |
| 2799 | #if APP_TYPE == GUIEXE |
| 2800 | typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 2801 | PSTR szCmdLine, int iCmdShow); |
| 2802 | #else |
| 2803 | typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp); |
| 2804 | #endif |
| 2805 | |
| 2806 | #if APP_TYPE == GUIEXE |
| 2807 | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 2808 | PSTR szCmdLine, int iCmdShow) |
| 2809 | #else |
| 2810 | int WINAPI Main(int argc, char** argv, char** envp) |
| 2811 | #endif |
| 2812 | { |
| 2813 | void* appLibrary; |
| 2814 | HINSTANCE hApp,hMFC,hMain; |
| 2815 | void* appMain; |
| 2816 | char* libName; |
| 2817 | int retcode; |
| 2818 | |
| 2819 | /* Load the application's library */ |
| 2820 | libName=(char*)malloc(strlen(appName)+5+3+1); |
| 2821 | /* FIXME: we should get the wrapper's path and use that as the base for |
| 2822 | * the library |
| 2823 | */ |
| 2824 | sprintf(libName,"./lib%s.so",appName); |
| 2825 | appLibrary=dlopen(libName,RTLD_NOW); |
| 2826 | if (appLibrary==NULL) { |
| 2827 | sprintf(libName,"lib%s.so",appName); |
| 2828 | appLibrary=dlopen(libName,RTLD_NOW); |
| 2829 | } |
| 2830 | if (appLibrary==NULL) { |
| 2831 | char format[]="Could not load the %s library:\r\n%s"; |
| 2832 | char* error; |
| 2833 | char* msg; |
| 2834 | |
| 2835 | error=dlerror(); |
| 2836 | msg=(char*)malloc(strlen(format)+strlen(libName)+strlen(error)); |
| 2837 | sprintf(msg,format,libName,error); |
| 2838 | MessageBox(NULL,msg,"dlopen error",MB_OK); |
| 2839 | free(msg); |
| 2840 | return 1; |
| 2841 | } |
| 2842 | |
| 2843 | /* Then if this application is MFC based, load the MFC module */ |
| 2844 | /* FIXME: I'm not sure this is really necessary */ |
| 2845 | if (mfcModule!=NULL) { |
| 2846 | hMFC=LoadLibrary(mfcModule); |
| 2847 | if (hMFC==NULL) { |
| 2848 | char format[]="Could not load the MFC module %s (%d)"; |
| 2849 | char* msg; |
| 2850 | |
| 2851 | msg=(char*)malloc(strlen(format)+strlen(mfcModule)+11); |
| 2852 | sprintf(msg,format,mfcModule,GetLastError()); |
| 2853 | MessageBox(NULL,msg,"LoadLibrary error",MB_OK); |
| 2854 | free(msg); |
| 2855 | return 1; |
| 2856 | } |
| 2857 | /* MFC is a special case: the WinMain is in the MFC library, |
| 2858 | * instead of the application's library. |
| 2859 | */ |
| 2860 | hMain=hMFC; |
| 2861 | } else { |
| 2862 | hMFC=NULL; |
| 2863 | } |
| 2864 | |
| 2865 | /* Load the application's module */ |
| 2866 | if (appModule==NULL) { |
| 2867 | appModule=appName; |
| 2868 | } |
| 2869 | hApp=LoadLibrary(appModule); |
| 2870 | if (hApp==NULL) { |
| 2871 | char format[]="Could not load the application's module %s (%d)"; |
| 2872 | char* msg; |
| 2873 | |
| 2874 | msg=(char*)malloc(strlen(format)+strlen(appModule)+11); |
| 2875 | sprintf(msg,format,appModule,GetLastError()); |
| 2876 | MessageBox(NULL,msg,"LoadLibrary error",MB_OK); |
| 2877 | free(msg); |
| 2878 | return 1; |
| 2879 | } else if (hMain==NULL) { |
| 2880 | hMain=hApp; |
| 2881 | } |
| 2882 | |
| 2883 | /* Get the address of the application's entry point */ |
| 2884 | appMain=(WinMainFunc*)GetProcAddress(hMain, appInit); |
| 2885 | if (appMain==NULL) { |
| 2886 | char format[]="Could not get the address of %s (%d)"; |
| 2887 | char* msg; |
| 2888 | |
| 2889 | msg=(char*)malloc(strlen(format)+strlen(appInit)+11); |
| 2890 | sprintf(msg,format,appInit,GetLastError()); |
| 2891 | MessageBox(NULL,msg,"GetProcAddress error",MB_OK); |
| 2892 | free(msg); |
| 2893 | return 1; |
| 2894 | } |
| 2895 | |
| 2896 | /* And finally invoke the application's entry point */ |
| 2897 | #if APP_TYPE == GUIEXE |
| 2898 | retcode=(*((WinMainFunc)appMain))(hApp,hPrevInstance,szCmdLine,iCmdShow); |
| 2899 | #else |
| 2900 | retcode=(*((MainFunc)appMain))(argc,argv,envp); |
| 2901 | #endif |
| 2902 | |
| 2903 | /* Cleanup and done */ |
| 2904 | FreeLibrary(hApp); |
| 2905 | if (hMFC!=NULL) { |
| 2906 | FreeLibrary(hMFC); |
| 2907 | } |
| 2908 | dlclose(appLibrary); |
| 2909 | free(libName); |
| 2910 | |
| 2911 | return retcode; |
| 2912 | } |