1cdf0e10cSrcweir: 2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 47e90fac2SAndrew Rist#************************************************************** 57e90fac2SAndrew Rist# 67e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 77e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 87e90fac2SAndrew Rist# distributed with this work for additional information 97e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 107e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 117e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 127e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 137e90fac2SAndrew Rist# 147e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 157e90fac2SAndrew Rist# 167e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 177e90fac2SAndrew Rist# software distributed under the License is distributed on an 187e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 197e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 207e90fac2SAndrew Rist# specific language governing permissions and limitations 217e90fac2SAndrew Rist# under the License. 227e90fac2SAndrew Rist# 237e90fac2SAndrew Rist#************************************************************** 247e90fac2SAndrew Rist 257e90fac2SAndrew Rist 26cdf0e10cSrcweir# 27cdf0e10cSrcweiruse XML::Parser; 28cdf0e10cSrcweir# ------------------------------------------------------------------------ 29cdf0e10cSrcweir# Other global stuff 30cdf0e10cSrcweir$is_debug=0; 31cdf0e10cSrcweirmy $path = $ENV{'INPATH'} . "/"; 32cdf0e10cSrcweirmy $quot = '"'; 33cdf0e10cSrcweirmy %template_hash=(); 34cdf0e10cSrcweirmy %vcproj_hash=(); 35cdf0e10cSrcweir# ------------------------------------------------------------------------ 36cdf0e10cSrcweir# Global stuff for parsing the *.vcproj files (XML::Parser) 37cdf0e10cSrcweir# 38cdf0e10cSrcweirmy $ConfigurationGlobal = 1; # Release = 1, Debug=0 39cdf0e10cSrcweirmy $Configuration = undef; 40cdf0e10cSrcweirmy %configelements = (); 41cdf0e10cSrcweirmy %files = (); 42cdf0e10cSrcweirmy %files2copy = (); 43cdf0e10cSrcweirmy %files_special = (); 44cdf0e10cSrcweirmy $Release = 1; 45cdf0e10cSrcweir # Release = 1, Debug = 0, undef = 2 46cdf0e10cSrcweirmy $file_tmp = ""; # temporary storage for file name 47cdf0e10cSrcweirmy $CustomSection = 0; 48cdf0e10cSrcweir# ------------------------------------------------------------------------ 49cdf0e10cSrcweir# ------------------------------------------------------------------------ 50cdf0e10cSrcweir# e.g. %object_hash with Key = blabla.cpp 51cdf0e10cSrcweir# contains a Hash: 52cdf0e10cSrcweir# Header: "..\\common\\unicode\\utypes.h ..\\common\\unicode\\uset.h" 53cdf0e10cSrcweir# CFlags: Common (set in templates file) or special sequence 54cdf0e10cSrcweir# CDefs: Common (set in templates file) or special sequence 55cdf0e10cSrcweir# ------------------------------------------------------------------------ 56cdf0e10cSrcweirmy $configfile = shift; 57cdf0e10cSrcweirmy $sourcePath = shift; 58cdf0e10cSrcweirif ( !$configfile ) { 59cdf0e10cSrcweir $configfile = "createmak.cfg"; 60cdf0e10cSrcweir} 61cdf0e10cSrcweirif ( !$sourcePath ) { 62cdf0e10cSrcweir $inpath = $ENV{"INPATH"}; 63cdf0e10cSrcweir $sourcePath = $inpath . "\\misc\\build\\icu\\source"; 64cdf0e10cSrcweir} 65cdf0e10cSrcweir$dir = ""; 66cdf0e10cSrcweir$header = ""; 67cdf0e10cSrcweir$sep = "\\\\"; 68cdf0e10cSrcweir 69cdf0e10cSrcweir%project_by_id =(); 70cdf0e10cSrcweir%project_by_name = (); 71cdf0e10cSrcweir%project_dependencies = (); 72cdf0e10cSrcweirmy @builddeps = prepare_allinone_all_mak(\%project_by_id,\%project_by_name,\%project_dependencies,$sourcePath); 73cdf0e10cSrcweir 74cdf0e10cSrcweirfillTemplateHash($configfile); 75cdf0e10cSrcweir 76cdf0e10cSrcweircreate_allinone_all_mak(\@builddeps,\%project_by_id,$sourcePath); 77cdf0e10cSrcweirmy @dirs = (); 78cdf0e10cSrcweirforeach $projectname(keys %project_by_name) 79cdf0e10cSrcweir{ 80cdf0e10cSrcweir my $dir = $project_by_name{$projectname}[1]; 81cdf0e10cSrcweir $dir =~ /\.\.\\(.+)\\(.+)\.vcproj/; 82cdf0e10cSrcweir my $dir1 = $1; 83cdf0e10cSrcweir my $dir2 = $2; 84cdf0e10cSrcweir if ( $dir1 !~ /$dir2$/ ) { 85cdf0e10cSrcweir $dir1 .= "\.$dir2"; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir print "$dir1 - $dir2\n" if ($is_debug); 88cdf0e10cSrcweir push @dirs, $dir1; 89cdf0e10cSrcweir} 90cdf0e10cSrcweir 91cdf0e10cSrcweir# set nonpro switch (linking against debug runtime if nonpro=1) 92cdf0e10cSrcweirmy $nonpro = ($ENV{"PROEXT"} ne ".pro"); 93cdf0e10cSrcweirprint "Non Product Build" if ($nonpro); 94cdf0e10cSrcweir 95cdf0e10cSrcweirforeach $dir(@dirs) 96cdf0e10cSrcweir{ 97cdf0e10cSrcweir next if ($dir eq "data.makedata"); # very special don't overwrite this file 98cdf0e10cSrcweir # ------------------------------------------------------------------------ 99cdf0e10cSrcweir # Reset global stuff for parsing the *.vcproj files (XML::Parser) 100cdf0e10cSrcweir # 101cdf0e10cSrcweir $Configuration = $ConfigurationGlobal; # Release = 1, Debug=0 102cdf0e10cSrcweir %configelements = (); 103cdf0e10cSrcweir %files = (); 104cdf0e10cSrcweir # contains all relevant *.c,*.cpp,*.h,*.rc files 105cdf0e10cSrcweir %files2copy = (); 106cdf0e10cSrcweir %files_special = (); 107cdf0e10cSrcweir $Release = 2; 108cdf0e10cSrcweir # Release = 1, Debug = 0, undef = 2 109cdf0e10cSrcweir $file_tmp = ""; # temporary storage for file name 110cdf0e10cSrcweir $CustomSection = 0; 111cdf0e10cSrcweir # ------------------------------------------------------------------------ 112cdf0e10cSrcweir 113cdf0e10cSrcweir my $extra_mak = ""; 114cdf0e10cSrcweir ($dir, $extra_mak) = handle_extra_mak_files($dir); # handle e.g. tools/genrb.derb entires 115cdf0e10cSrcweir 116cdf0e10cSrcweir my @mak=(); # Array for make file *.mak 117cdf0e10cSrcweir my %deps=(); 118cdf0e10cSrcweir my %object_hash=(); 119cdf0e10cSrcweir my %collected_header=(); 120cdf0e10cSrcweir my %collect_header_target_hash=(); 121cdf0e10cSrcweir my %collect_object_target_hash=(); 122cdf0e10cSrcweir my $vcproj_file = ""; 123cdf0e10cSrcweir my $resource_file = ""; 124cdf0e10cSrcweir 125cdf0e10cSrcweir # $dir : common,i18n,... 126cdf0e10cSrcweir chomp $dir; 127cdf0e10cSrcweir next if ( $dir eq "" ); 128cdf0e10cSrcweir my $fullpath = $sourcePath . "\\" . $dir; 129cdf0e10cSrcweir if ( $extra_mak eq "" ) { 130cdf0e10cSrcweir if ($dir =~ /(.+)+\\(.+)$/) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir $vcproj_file = $fullpath ."\\$2.vcproj"; 133cdf0e10cSrcweir } else 134cdf0e10cSrcweir { 135cdf0e10cSrcweir $vcproj_file = $fullpath ."\\$dir.vcproj"; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } else 138cdf0e10cSrcweir { 139cdf0e10cSrcweir $vcproj_file = $fullpath . "\\" . $extra_mak . ".vcproj"; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir 143cdf0e10cSrcweir # Parse the *.vcproj file 144cdf0e10cSrcweir my $parser = new XML::Parser(ErrorContext => 2); 145cdf0e10cSrcweir $parser->setHandlers(Start => \&start_handler, 146cdf0e10cSrcweir Char => \&char_handler); 147cdf0e10cSrcweir $parser->parsefile($vcproj_file); 148cdf0e10cSrcweir if ( $file_tmp ) { 149cdf0e10cSrcweir # save a file which hasn't been saved yet 150cdf0e10cSrcweir $files{ $file_tmp } = 1; # save it now 151cdf0e10cSrcweir $file_tmp = ""; # has been saved now reset it 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir # is there a resource file? 155cdf0e10cSrcweir foreach $i (keys %files) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir if ($i =~ /\.rc/) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir $resource_file = $i; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir # Fill hash %deps for dependencies for all files in directory ($testdir) 163cdf0e10cSrcweir # %files contains all relevant files from *.vcproj 164cdf0e10cSrcweir 165cdf0e10cSrcweir getAllFilesDeps($fullpath,\%deps,\%files); 166cdf0e10cSrcweir my $includedir = $configelements{"Release"}{"OutputDirectory"}; # e.g. OutputDirectory = ..\..\lib 167cdf0e10cSrcweir $includedir =~ s/lib/include/; 168cdf0e10cSrcweir foreach $file( sort keys %deps) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir $file =~ /(.+)\.(.+)/; 171cdf0e10cSrcweir my $name = $1; 172cdf0e10cSrcweir my $ext = $2; 173cdf0e10cSrcweir next if (!defined $name); 174cdf0e10cSrcweir $object = "\$(INTDIR)\\" . "$name.obj"; 175cdf0e10cSrcweir $collect_object_target_hash{$object}=1; 176cdf0e10cSrcweir 177cdf0e10cSrcweir createMakDepSection($dir,$name,$ext,$deps{$file},\@mak,\%files_special); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir my %all_target_hash=(); 180cdf0e10cSrcweir foreach $header(sort keys %files2copy) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir my $dir; 183cdf0e10cSrcweir my $file; 184cdf0e10cSrcweir #$pathdepth = "..\\.."; 185cdf0e10cSrcweir $file = $header; 186cdf0e10cSrcweir $header =~ s/^\.\\//; 187cdf0e10cSrcweir $inputpath = $file; 188cdf0e10cSrcweir $target = $includedir . "\\" . $header; 189cdf0e10cSrcweir $target =~ /.+\\(.+)\\.+$/; 190cdf0e10cSrcweir $targetpath = $configelements{"Release"}{"CommandLine"}; 191cdf0e10cSrcweir chomp $targetpath; 192cdf0e10cSrcweir # set %all_target_hash and @mak 193cdf0e10cSrcweir createCopySection($file,$inputpath,$target,$targetpath,\@mak,\%all_target_hash); 194cdf0e10cSrcweir $collect_header_target_hash{$target}=1; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir my $test = $configelements{"Release"}{"OutputFile"}; 197cdf0e10cSrcweir $all_target_hash{$test}=1; 198cdf0e10cSrcweir 199cdf0e10cSrcweir # set name of the *.mak file 200cdf0e10cSrcweir my $mak_file=""; 201cdf0e10cSrcweir if ( $extra_mak eq "" ) { 202cdf0e10cSrcweir $mak_file = $vcproj_file; 203cdf0e10cSrcweir $mak_file =~ s/vcproj/mak/; 204cdf0e10cSrcweir } else 205cdf0e10cSrcweir { 206cdf0e10cSrcweir # extra_mak eg. derb, stringperf 207cdf0e10cSrcweir $mak_file = $fullpath . "\\$extra_mak" . "\.mak"; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir # generate the content of the *.mak file 211cdf0e10cSrcweir # in @mak array 212cdf0e10cSrcweir print "extra_mak=$extra_mak\n" if ($is_debug); 213cdf0e10cSrcweir print "mak_file=$mak_file\n" if ($is_debug); 214cdf0e10cSrcweir open(MAKFILE, ">$mak_file") || die "Can't open $mak_file\n"; 215cdf0e10cSrcweir print_all_target($fullpath, \%all_target_hash); 216cdf0e10cSrcweir 217cdf0e10cSrcweir # $extra_mak handles further *.mak files in a directory 218cdf0e10cSrcweir print_flags($dir,$extra_mak,'CFlags',$nonpro); # depends on directory 219cdf0e10cSrcweir print_simple_flag("Rules"); 220cdf0e10cSrcweir print_simple_flag("Link"); 221cdf0e10cSrcweir print_common_linkflags(); 222cdf0e10cSrcweir# print_flags($fullpath,$extra_mak,'LinkFlags'); # depends on directory 223cdf0e10cSrcweir# print_lib32_objs($fullpath,$extra_mak,\%collect_object_target_hash,$resource_file); 224cdf0e10cSrcweir print_flags($dir,$extra_mak,'LinkFlags'); # depends on directory 225cdf0e10cSrcweir print_lib32_objs($dir,$extra_mak,\%collect_object_target_hash,$resource_file); 226cdf0e10cSrcweir 227cdf0e10cSrcweir # write @mak array into the *.mak file 228cdf0e10cSrcweir foreach $line(@mak) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir print MAKFILE $line; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir $|=1; 233cdf0e10cSrcweir print "."; # user entertainment 234cdf0e10cSrcweir $|=0; 235cdf0e10cSrcweir} 236cdf0e10cSrcweirprint "\ndone\n"; 237cdf0e10cSrcweirexit; 238cdf0e10cSrcweir 239cdf0e10cSrcweir############################################################################ 240cdf0e10cSrcweirsub getKey #01.04.2008 09:46 241cdf0e10cSrcweir############################################################################ 242cdf0e10cSrcweir { 243cdf0e10cSrcweir my $line = shift; 244cdf0e10cSrcweir $line =~ /\[(.+)\]/; 245cdf0e10cSrcweir return $1; 246cdf0e10cSrcweir} ##getKey 247cdf0e10cSrcweir 248cdf0e10cSrcweir############################################################################ 249cdf0e10cSrcweirsub fillTemplateHash #01.04.2008 10:48 250cdf0e10cSrcweir############################################################################ 251cdf0e10cSrcweir { 252cdf0e10cSrcweir my $file = shift; 253cdf0e10cSrcweir open (TEMPLATE, "< $file") || die "Can't open template file $file\n"; 254cdf0e10cSrcweir my $key = ""; 255cdf0e10cSrcweir while ( $line=<TEMPLATE> ) { 256cdf0e10cSrcweir if ( $line =~ /\[.+\]/ ) { 257cdf0e10cSrcweir print $line if ($is_debug); 258cdf0e10cSrcweir if ( $key ne "" ) { 259cdf0e10cSrcweir $template_hash{$key}=[@cmdlines]; 260cdf0e10cSrcweir @cmdlines=""; 261cdf0e10cSrcweir $key=""; 262cdf0e10cSrcweir } 263cdf0e10cSrcweir $key = getKey( $line ); 264cdf0e10cSrcweir } else 265cdf0e10cSrcweir { 266cdf0e10cSrcweir push @cmdlines, $line; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir } # while 269cdf0e10cSrcweir} ##fillTemplateHash 270cdf0e10cSrcweir 271cdf0e10cSrcweir############################################################################ 272cdf0e10cSrcweirsub createCopySection #01.04.2008 11:37 273cdf0e10cSrcweir############################################################################ 274cdf0e10cSrcweir { 275cdf0e10cSrcweir my $header = shift; 276cdf0e10cSrcweir my $inputpath = shift; 277cdf0e10cSrcweir my $target = shift; 278cdf0e10cSrcweir my $targetpath = shift; 279cdf0e10cSrcweir my $ref_make_file = shift; # Array written later to make file *.mak 280cdf0e10cSrcweir my $ref_all_target_hash = shift; # reference to fill all_target_hash; 281cdf0e10cSrcweir if ( $target !~ /\\include/ && $target !~ /\\bin/) { 282cdf0e10cSrcweir return; # $target contains nonsense 283cdf0e10cSrcweir } 284cdf0e10cSrcweir if ( !$targetpath ) { 285cdf0e10cSrcweir # $targetpath is empty! (Due to missing entry in *.vcproj file) 286cdf0e10cSrcweir # Generate $targetpath here from $target 287cdf0e10cSrcweir my $t = $target; 288cdf0e10cSrcweir $t =~ /(.+)\\(.+)$/; 289cdf0e10cSrcweir $targetpath = "copy \"\$(InputPath)\" " . $1; 290cdf0e10cSrcweir chomp $targetpath; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir $targetpath =~ s/\r$//; # remove x0A from EOL if the is one 293cdf0e10cSrcweir my @template = @{$template_hash{"Copy"}}; 294cdf0e10cSrcweir my $line = ""; 295cdf0e10cSrcweir foreach $line(@template) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir $line =~ s/<HEADER>/$header/g; 298cdf0e10cSrcweir $line =~ s/<INPUTPATH>/$inputpath/g; 299cdf0e10cSrcweir $line =~ s/<TARGET>/$target/g; 300cdf0e10cSrcweir $line =~ s/<TARGETPATH>/$targetpath/; 301cdf0e10cSrcweir push @{$ref_make_file}, $line; # from template 302cdf0e10cSrcweir $$ref_all_target_hash{$target} = 1; # "\"$target\" "; 303cdf0e10cSrcweir # save for target ALL: 304cdf0e10cSrcweir } 305cdf0e10cSrcweir} ##createCopySection 306cdf0e10cSrcweir 307cdf0e10cSrcweir############################################################################ 308cdf0e10cSrcweirsub createMakDepSection #01.04.2008 13:36 309cdf0e10cSrcweir############################################################################ 310cdf0e10cSrcweir { 311cdf0e10cSrcweir # creates the dependency section in the make file 312cdf0e10cSrcweir my $dir = shift; 313cdf0e10cSrcweir my $source = shift; 314cdf0e10cSrcweir my $extension = shift; 315cdf0e10cSrcweir my $ref_header_list = shift; 316cdf0e10cSrcweir my $ref_make_file = shift; # Array written later to make file *.mak 317cdf0e10cSrcweir my $ref_special_file = shift; # hash for special files (compiler flags, include paths) 318cdf0e10cSrcweir my $header_list = ""; 319cdf0e10cSrcweir my $special_flag = 0; 320cdf0e10cSrcweir 321cdf0e10cSrcweir return if ( !defined $source ); 322cdf0e10cSrcweir foreach $header(@{$ref_header_list}) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir if ( ($header =~ /^\.\.\\.+/) && (-e $header )) { 325cdf0e10cSrcweir $header_list = $header_list . " " . $header; # this header is located in an other directory 326cdf0e10cSrcweir } else 327cdf0e10cSrcweir { 328cdf0e10cSrcweir $header_list = $header_list . " .\\" . $header; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir #special handling 333cdf0e10cSrcweir # compile this file with other compiler switches 334cdf0e10cSrcweir my $file = $source . "\." . $extension; 335cdf0e10cSrcweir $dir =~ s/\\/_/; 336cdf0e10cSrcweir my @template = @{$template_hash{"CFlags_$dir"}}; 337cdf0e10cSrcweir if ( defined $$ref_special_file{"AdditionalIncludeDirectories"}{$file} ) { 338cdf0e10cSrcweir $special_flag = 1; 339cdf0e10cSrcweir my $includepath = $$ref_special_file{"AdditionalIncludeDirectories"}{$file}; 340cdf0e10cSrcweir $includepath =~ s/\;/\/I /g; # subst ; with /I for multiple paths 341cdf0e10cSrcweir $line = "CPP_SWITCH_INCLUDE=/I $includepath\n"; 342cdf0e10cSrcweir push @{$ref_make_file}, $line; 343cdf0e10cSrcweir foreach $line(@template) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir if ( $line =~ /CPP_PROJ/) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir $line =~ s/CPP_PROJ=/CPPX_PROJ=/; 348cdf0e10cSrcweir $line =~ s/\$\(CDEFS\)/\$\(CDEFS\) \$\(CPP_SWITCH_INCLUDE\)/; # include $(CPP_SWITCH_INCLUDE) 349cdf0e10cSrcweir push @{$ref_make_file}, $line; 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir if ( $$ref_special_file{"DisableLanguageExtensions"}{$file} ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir # FALSE = /Ze 356cdf0e10cSrcweir $special_flag = 1; 357cdf0e10cSrcweir foreach $line(@template) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir if ( $line =~ /CPP_PROJ/) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir $line =~ s/CPP_PROJ=/CPPX_PROJ=/; 362cdf0e10cSrcweir $line =~ s/-Za/-Ze/; 363cdf0e10cSrcweir if ( $nonpro ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir # if non product link against debug libraries 366cdf0e10cSrcweir $line =~ s/-MD/-MDd/; 367cdf0e10cSrcweir $line =~ s/-MT/-MTd/; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir push @{$ref_make_file}, $line; 370cdf0e10cSrcweir } 371cdf0e10cSrcweir } 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir @template = @{$template_hash{"Deps"}}; 375cdf0e10cSrcweir my $line = ""; 376cdf0e10cSrcweir foreach $line(@template) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir $line =~ s/<SOURCEFILE>/$source/g; 379cdf0e10cSrcweir $line =~ s/<EXT>/$extension/g; 380cdf0e10cSrcweir $line =~ s/<HEADER_LIST>/$header_list/g; 381cdf0e10cSrcweir push @{$ref_make_file}, $line; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir if ( $special_flag ) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir pop @{$ref_make_file}; # remove empty line 387cdf0e10cSrcweir push @{$ref_make_file},"\t\$(CPP) @<<\n"; 388cdf0e10cSrcweir push @{$ref_make_file},"\t\$(CPPX_PROJ) \$(SOURCE)\n"; 389cdf0e10cSrcweir push @{$ref_make_file},"<<\n\n"; 390cdf0e10cSrcweir $special_flag = 0; 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir} ##createMakDepSection 394cdf0e10cSrcweir 395cdf0e10cSrcweir 396cdf0e10cSrcweir############################################################################ 397cdf0e10cSrcweirsub getFilenameFromPath #10.04.2008 13:03 398cdf0e10cSrcweir############################################################################ 399cdf0e10cSrcweir{ 400cdf0e10cSrcweir my $path = shift; 401cdf0e10cSrcweir $path =~ /.+\\(.+)$/; 402cdf0e10cSrcweir return $1; 403cdf0e10cSrcweir} ##getFilenameFromPath 404cdf0e10cSrcweir 405cdf0e10cSrcweir############################################################################ 406cdf0e10cSrcweirsub getAllFilesDeps #08.04.2008 09:39 407cdf0e10cSrcweir############################################################################ 408cdf0e10cSrcweir{ 409cdf0e10cSrcweir my $path = shift; 410cdf0e10cSrcweir my $ref_deps = shift; 411cdf0e10cSrcweir my $ref_allfiles = shift; # contains all relevant files from *.vcproj 412cdf0e10cSrcweir my %local_header_hash=(); # contains all local header 413cdf0e10cSrcweir 414cdf0e10cSrcweir my @all_files = keys %{$ref_allfiles}; 415cdf0e10cSrcweir 416cdf0e10cSrcweir # collect lokal header names in %header_hash 417cdf0e10cSrcweir foreach $file(@all_files) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir if ( $file =~ /.+\.h/ ) { 420cdf0e10cSrcweir chomp $file; 421cdf0e10cSrcweir $local_header_hash{$file} = 1; 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir foreach $file(@all_files) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir my @header_deps=(); 428cdf0e10cSrcweir my $skip = 0; 429cdf0e10cSrcweir 430cdf0e10cSrcweir $file =~ s/^\.\\//; # remove leading .\ 431cdf0e10cSrcweir 432cdf0e10cSrcweir # exclude sub directories and several file extensions 433cdf0e10cSrcweir # *.dep,*.h,*.in,*.mak,*.pl,*.txt,*.vcproj.*.rc and origs of patch files (*.*~) and 434cdf0e10cSrcweir # .cvsignore (files beginning with .) 435cdf0e10cSrcweir next if ( (-d "$path$sep$file") || ($file =~ /.+(_|\~|dep|h|in|mak|pl|txt|vcproj|rc)$/) || ($file =~ /^\.+./)); 436cdf0e10cSrcweir parse_header_deps($path,$file,\@header_deps,\%local_header_hash); 437cdf0e10cSrcweir handle_dep_to_other_directory($path,$file,\@header_deps,$$ref_vcproj{$file}) if ($$ref_vcproj{$file}); 438cdf0e10cSrcweir $$ref_deps{$file}=[@header_deps]; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir} ##getAllFilesDeps 441cdf0e10cSrcweir 442cdf0e10cSrcweir ############################################################################ 443cdf0e10cSrcweir sub parse_header_deps #14.06.2006 18:04 444cdf0e10cSrcweir ############################################################################ 445cdf0e10cSrcweir { 446cdf0e10cSrcweir # get includes from c/cpp file 447cdf0e10cSrcweir # call create_deps(path,file,\$link_obj) 448cdf0e10cSrcweir # 449cdf0e10cSrcweir my $path = shift; 450cdf0e10cSrcweir my $cfile = shift; 451cdf0e10cSrcweir my $ref_header_deps = shift; 452cdf0e10cSrcweir my $ref_local_header_hash = shift; 453cdf0e10cSrcweir 454cdf0e10cSrcweir my $fullpath = $path . $sep . $cfile; 455cdf0e10cSrcweir my $unicodedep=""; 456cdf0e10cSrcweir open(IN, "<$fullpath") || die "can't open $fullpath\n"; 457cdf0e10cSrcweir while ( $line = <IN> ) { 458cdf0e10cSrcweir next if ($line !~ /^.?\#include.+/); # handle include lines only 459cdf0e10cSrcweir if ($line =~ /.+?\s(.+)/) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir $header = $1; 462cdf0e10cSrcweir if ( ($header !~ /^<.+/) && ($header !~ /.+\.c.+$/) ) { 463cdf0e10cSrcweir # no <stdio> etc. header 464cdf0e10cSrcweir $header =~ s/\s+\/\*.+\*\///; # delete <blanks>/* ... */ 465cdf0e10cSrcweir $header =~ s/\s+\/\/.+//; # delete <blanks>//...... 466cdf0e10cSrcweir $header =~ s/\//\\/; # subst. / with \ 467cdf0e10cSrcweir $header =~ s/^\"/\".\\/; 468cdf0e10cSrcweir $header =~ s/\"//g; 469cdf0e10cSrcweir $header =~ s/\.\\//; 470cdf0e10cSrcweir my $test = $$ref_local_header_hash{$header}; 471cdf0e10cSrcweir my $header_fullpath = $path . "\\" . $header; 472cdf0e10cSrcweir if ( $test || (($header =~ /\\/) && (-e $header_fullpath))) { 473cdf0e10cSrcweir push @{$ref_header_deps}, $header; 474cdf0e10cSrcweir } 475cdf0e10cSrcweir } 476cdf0e10cSrcweir } 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } ##parse_header_deps 479cdf0e10cSrcweir 480cdf0e10cSrcweir############################################################################ 481cdf0e10cSrcweirsub handle_dep_to_other_directory #16.04.2008 15:11 482cdf0e10cSrcweir############################################################################ 483cdf0e10cSrcweir{ 484cdf0e10cSrcweir # there has been an additional include directoy detected 485cdf0e10cSrcweir # now try to find out which header (parsed from c/cpp-file) 486cdf0e10cSrcweir # comes from this directory by checking: does it exist there? 487cdf0e10cSrcweir my $path = shift; 488cdf0e10cSrcweir my $file = shift; 489cdf0e10cSrcweir my $ref_header_deps = shift; 490cdf0e10cSrcweir my $path_additional = shift; 491cdf0e10cSrcweir my $search_path = $path . "\\" . $path_additional; 492cdf0e10cSrcweir my $counter = 0; 493cdf0e10cSrcweir foreach $header(@{$ref_header_deps}) 494cdf0e10cSrcweir { 495cdf0e10cSrcweir my $full_path = $search_path . "\\" . $header; 496cdf0e10cSrcweir if ( -e "$full_path" ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir $$ref_header_deps[$counter] = $path_additional . "\\" . $header; 499cdf0e10cSrcweir } 500cdf0e10cSrcweir $counter++ 501cdf0e10cSrcweir } 502cdf0e10cSrcweir} ##handle_dep_to_other_directory 503cdf0e10cSrcweir 504cdf0e10cSrcweir############################################################################ 505cdf0e10cSrcweirsub print_lib32_objs #18.04.2008 12:54 506cdf0e10cSrcweir############################################################################ 507cdf0e10cSrcweir { 508cdf0e10cSrcweir # generate Link section 509cdf0e10cSrcweir my $path = shift; 510cdf0e10cSrcweir my $extra_mak = shift; 511cdf0e10cSrcweir my $ref_objecthash = shift; 512cdf0e10cSrcweir my $resource_file = shift; 513cdf0e10cSrcweir # output link objects 514cdf0e10cSrcweir print MAKFILE "LINK32_OBJS= \\\n"; 515cdf0e10cSrcweir # print objects 516cdf0e10cSrcweir foreach $object(sort keys %{$ref_objecthash}) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir print MAKFILE "\t$object \\\n"; 519cdf0e10cSrcweir } 520cdf0e10cSrcweir 521cdf0e10cSrcweir # print *.res if *.rc exists 522cdf0e10cSrcweir if ( $resource_file ne "" ) { 523cdf0e10cSrcweir my $res_file = $resource_file; 524cdf0e10cSrcweir $res_file =~ s/\.rc/\.res/; 525cdf0e10cSrcweir $res_file =~ /(.+)\\(.+)$/; 526cdf0e10cSrcweir $res_file = $2; 527cdf0e10cSrcweir print MAKFILE "\t\$(INTDIR)\\$res_file \\\n"; 528cdf0e10cSrcweir } 529cdf0e10cSrcweir 530cdf0e10cSrcweir # add import libs and res files 531cdf0e10cSrcweir print_flags($path,$extra_mak,"AdditionalLinkObjects"); 532cdf0e10cSrcweir my $outfile = $configelements{"Release"}{"OutputFile"}; 533cdf0e10cSrcweir 534cdf0e10cSrcweir # section for linking 535cdf0e10cSrcweir print_link_template($path,$outfile); 536cdf0e10cSrcweir 537cdf0e10cSrcweir # section for creating res files 538cdf0e10cSrcweir # setting for rsc, res target etc. 539cdf0e10cSrcweir print "resource_file=$resource_file\n" if ($is_debug); 540cdf0e10cSrcweir print_rsc_template($resource_file) if ($resource_file); 541cdf0e10cSrcweir print_simple_flag("Special_extra_uconv") if ($outfile =~ /uconv/); 542cdf0e10cSrcweir} ##print_lib32_objs 543cdf0e10cSrcweir 544cdf0e10cSrcweir############################################################################ 545cdf0e10cSrcweirsub print_all_target #26.06.2008 13:27 546cdf0e10cSrcweir############################################################################ 547cdf0e10cSrcweir { 548cdf0e10cSrcweir my $path = shift; 549cdf0e10cSrcweir my $ref_all_target_hash = shift; 550cdf0e10cSrcweir my $filename = getFilenameFromPath($path); 551cdf0e10cSrcweir my $outdir = $configelements{"Release"}{"OutputDirectory"}; 552cdf0e10cSrcweir print MAKFILE "NULL=\n"; 553cdf0e10cSrcweir print MAKFILE "OUTDIR=$outdir\n"; 554cdf0e10cSrcweir print MAKFILE "OutDir=$outdir\n"; 555cdf0e10cSrcweir print MAKFILE "INTDIR=.\\Release\n\n"; 556cdf0e10cSrcweir print MAKFILE "ALL: "; 557cdf0e10cSrcweir foreach $target(sort keys %{$ref_all_target_hash}) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir if ( $target =~ /\.exe/ ) { 560cdf0e10cSrcweir my $out = $target; 561cdf0e10cSrcweir $out =~ s/.\\Release/\.\.\\\.\.\\\.\.\\bin/; 562cdf0e10cSrcweir $out =~ s/\$\(OutDir\)/\.\.\\\.\.\\\.\.\\bin/; 563cdf0e10cSrcweir $out =~ s/\//\\/; # convert / to \ 564cdf0e10cSrcweir $target = $out; 565cdf0e10cSrcweir } 566cdf0e10cSrcweir print MAKFILE "\"$target\" "; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569cdf0e10cSrcweir # Append [Target_<dir>] item e.g. ../../icuxy36.dll 570cdf0e10cSrcweir my $targetkey = "Target_" . $filename; 571cdf0e10cSrcweir my @target = (); 572cdf0e10cSrcweir if ( exists $template_hash{$targetkey} ) { 573cdf0e10cSrcweir @target = @{$template_hash{$targetkey}}; 574cdf0e10cSrcweir } 575cdf0e10cSrcweir my $additional_target=""; 576cdf0e10cSrcweir foreach $additional_target(@target) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir print MAKFILE $additional_target if ($additional_target ne ""); 579cdf0e10cSrcweir } 580cdf0e10cSrcweir print MAKFILE "\n\n"; 581cdf0e10cSrcweir print MAKFILE "\"\$(OUTDIR)\" : \n"; 582cdf0e10cSrcweir print MAKFILE "\tif not exist \"\$(OUTDIR)/\$(NULL)\" mkdir \"\$(OUTDIR)\"\n\n"; 583cdf0e10cSrcweir print MAKFILE "!IF \"\$(OUTDIR)\" != \"\$(INTDIR)\"\n"; 584cdf0e10cSrcweir print MAKFILE "\"\$(INTDIR)\" : \n"; 585cdf0e10cSrcweir print MAKFILE "\tif not exist \"\$(INTDIR)/\$(NULL)\" mkdir \"\$(INTDIR)\"\n"; 586cdf0e10cSrcweir print MAKFILE "!ENDIF\n"; 587cdf0e10cSrcweir print MAKFILE "\n\n"; 588cdf0e10cSrcweir} ##print_all_target 589cdf0e10cSrcweir 590cdf0e10cSrcweir############################################################################ 591cdf0e10cSrcweirsub print_simple_flag #18.04.2008 13:39 592cdf0e10cSrcweir############################################################################ 593cdf0e10cSrcweir{ 594cdf0e10cSrcweir my $simple_flag = shift; 595cdf0e10cSrcweir my @template = @{$template_hash{$simple_flag}}; 596cdf0e10cSrcweir foreach $line(@template) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir print MAKFILE $line; 599cdf0e10cSrcweir } 600cdf0e10cSrcweir} ##print_rules 601cdf0e10cSrcweir 602cdf0e10cSrcweir############################################################################ 603cdf0e10cSrcweirsub print_link_template #18.04.2008 13:39 604cdf0e10cSrcweir############################################################################ 605cdf0e10cSrcweir{ 606cdf0e10cSrcweir my $dir = shift; 607cdf0e10cSrcweir my $outfile = shift; 608cdf0e10cSrcweir my $manifest; 609cdf0e10cSrcweir # set resource id for manifest file 610cdf0e10cSrcweir if ( $outfile =~ /\.exe/ ) { 611cdf0e10cSrcweir $manifest = 1; 612cdf0e10cSrcweir } else 613cdf0e10cSrcweir { 614cdf0e10cSrcweir $manifest = 2; 615cdf0e10cSrcweir } 616cdf0e10cSrcweir my @template = (); 617cdf0e10cSrcweir if ($dir =~ /stubdata/ ) { 618cdf0e10cSrcweir @template = @{$template_hash{"Special_stubdata"}}; 619cdf0e10cSrcweir } else 620cdf0e10cSrcweir { 621cdf0e10cSrcweir @template = @{$template_hash{"LinkTemplate"}}; 622cdf0e10cSrcweir } 623cdf0e10cSrcweir 624cdf0e10cSrcweir print MAKFILE "\n"; # insert blank line 625cdf0e10cSrcweir foreach $line(@template) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir $line =~ s/<OUTFILE>/$outfile/; 628cdf0e10cSrcweir $line =~ s/<MANIFEST>/$manifest/; 629cdf0e10cSrcweir print MAKFILE $line; 630cdf0e10cSrcweir } 631cdf0e10cSrcweir 632cdf0e10cSrcweir # insert special stuff for 633cdf0e10cSrcweir # extras/uconv/uconv.mak 634cdf0e10cSrcweir if ( $dir =~ /uconv/ ) { 635cdf0e10cSrcweir print_flags($dir,"","Special"); 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir # for *.exe files an additional 639cdf0e10cSrcweir # copy section is required to get 640cdf0e10cSrcweir # the stuff into the global bin directory 641cdf0e10cSrcweir my %dummy = (); 642cdf0e10cSrcweir my @mak = (); 643cdf0e10cSrcweir if( $manifest ==1 ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir # source,inputpath,target,action 646cdf0e10cSrcweir my $out = $outfile; 647cdf0e10cSrcweir $out =~ s/.\\.*Release/\.\.\\\.\.\\\.\.\\bin/; 648cdf0e10cSrcweir $out =~ s/\$\(OutDir\)/\.\.\\\.\.\\\.\.\\bin/; 649cdf0e10cSrcweir $out =~ s/\//\\/; # subst / with \ 650cdf0e10cSrcweir $outfile =~ s/\//\\/; # subst / with \ 651cdf0e10cSrcweir createCopySection($outfile,$outfile,$out,"copy \"\$(InputPath)\" .\\..\\..\\..\\bin",\@mak,\%dummy); 652cdf0e10cSrcweir foreach $line(@mak) 653cdf0e10cSrcweir { 654cdf0e10cSrcweir print MAKFILE $line; 655cdf0e10cSrcweir } 656cdf0e10cSrcweir } 657cdf0e10cSrcweir} ##print_rules 658cdf0e10cSrcweir 659cdf0e10cSrcweir############################################################################ 660cdf0e10cSrcweirsub print_rsc_template #04.11.2008 14:48 661cdf0e10cSrcweir############################################################################ 662cdf0e10cSrcweir { 663cdf0e10cSrcweir # print resource compiler setting + resource target 664cdf0e10cSrcweir my $resourcefile = shift; 665cdf0e10cSrcweir # skip this if no res file required 666cdf0e10cSrcweir 667cdf0e10cSrcweir return if (!$resourcefile); 668cdf0e10cSrcweir $resfile = $resourcefile; 669cdf0e10cSrcweir #remove file extension (.res) 670cdf0e10cSrcweir $resfile =~ /(.+)\\(.+)\.(.+)/; 671cdf0e10cSrcweir $resfile = $2; 672cdf0e10cSrcweir 673cdf0e10cSrcweir my @template = @{$template_hash{"RSC_Template"}}; 674cdf0e10cSrcweir print MAKFILE "\n"; # insert blank line 675cdf0e10cSrcweir foreach $line(@template) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir $line =~ s/<FILE>/$resourcefile/; 678cdf0e10cSrcweir $line =~ s/<FILEOUT>/$resfile/; 679cdf0e10cSrcweir print MAKFILE $line; 680cdf0e10cSrcweir } 681cdf0e10cSrcweir} ##print_rsc_template 682cdf0e10cSrcweir 683cdf0e10cSrcweir############################################################################ 684cdf0e10cSrcweirsub print_flags #18.04.2008 14:19 685cdf0e10cSrcweir############################################################################ 686cdf0e10cSrcweir{ 687cdf0e10cSrcweir # CFlags, LinkFlags 688cdf0e10cSrcweir my $dir = shift; 689cdf0e10cSrcweir my $extra_mak = shift; # eg. derb.mak, stringperf.mak 690cdf0e10cSrcweir my $flag = shift; 691cdf0e10cSrcweir my $nonpro = shift; 692cdf0e10cSrcweir my @template = (); 693cdf0e10cSrcweir my $switch = ""; 694cdf0e10cSrcweir $dir =~ s/\\/_/g if ($dir); # change \ to _ 695cdf0e10cSrcweir $switch = "$flag" . "_" . "$dir" if ($dir); 696cdf0e10cSrcweir handle_CFlags() if ($flag eq "CFlags"); # get and print Preprocessor defines 697cdf0e10cSrcweir $switch .= "\." . $extra_mak if ( $extra_mak ne "" ) ; 698cdf0e10cSrcweir if ( exists $template_hash{$switch} ) { 699cdf0e10cSrcweir @template = @{$template_hash{$switch}}; 700cdf0e10cSrcweir foreach $line(@template) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir if ( $nonpro ) 703cdf0e10cSrcweir { 704cdf0e10cSrcweir # if non product link against debug libraries 705cdf0e10cSrcweir $line =~ s/-MD/-MDd/; 706cdf0e10cSrcweir $line =~ s/-MT/-MTd/; 707cdf0e10cSrcweir } 708cdf0e10cSrcweir print MAKFILE $line; 709cdf0e10cSrcweir } 710cdf0e10cSrcweir } 711cdf0e10cSrcweir} ##print_flags 712cdf0e10cSrcweir 713cdf0e10cSrcweir############################################################################ 714cdf0e10cSrcweirsub handle_CFlags #28.01.2009 11:20 715cdf0e10cSrcweir############################################################################ 716cdf0e10cSrcweir { 717cdf0e10cSrcweir 718cdf0e10cSrcweir my $ppdefs = $configelements{"Release"}{"PreprocessorDefinitions"}; 719cdf0e10cSrcweir my $ppinc = $configelements{"Release"}{"AdditionalIncludeDirectories"}; 720cdf0e10cSrcweir my @template = @{$template_hash{"General_CFlags"}}; 721cdf0e10cSrcweir $ppdefs =~ s/;/ -D/g; # subst ; with -D switch 722cdf0e10cSrcweir $ppdefs = "-D" . $ppdefs; 723cdf0e10cSrcweir $ppinc =~ s/(;|,)/ -I/g; # subst ; with -I switch 724cdf0e10cSrcweir $ppinc = "-I" . $ppinc; 725cdf0e10cSrcweir print "ppdefs=$ppdefs\n" if ($is_debug); 726cdf0e10cSrcweir print "ppinc =$ppinc\n" if ($is_debug); 727cdf0e10cSrcweir foreach $line(@template) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir $line =~ s/<AddIncDirs>/$ppinc/; 730cdf0e10cSrcweir $line =~ s/<PreProcDefs>/$ppdefs/; 731cdf0e10cSrcweir print MAKFILE $line; 732cdf0e10cSrcweir } 733cdf0e10cSrcweir} ##handle_CFlags 734cdf0e10cSrcweir 735cdf0e10cSrcweir############################################################################ 736cdf0e10cSrcweirsub print_common_linkflags #21.11.2008 11:47 737cdf0e10cSrcweir############################################################################ 738cdf0e10cSrcweir { 739cdf0e10cSrcweir my @template = @{$template_hash{"CommonLinkFlags"}}; 740cdf0e10cSrcweir my $outfile = $configelements{"Release"}{"OutputFile"}; 741cdf0e10cSrcweir my $pdbfile = $configelements{"Release"}{"ProgramDatabaseFile"}; 742cdf0e10cSrcweir $pdbfile =~ s/\//\\/; # subst / with \ 743cdf0e10cSrcweir $outfile =~ s/\//\\/; # subst / with \ 744cdf0e10cSrcweir print "PATH=$path OUTFILE=$outfile\n" if ($is_debug); 745cdf0e10cSrcweir foreach $line(@template) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir $line =~ s/<OUTFILE>/$outfile/; 748cdf0e10cSrcweir $line =~ s/<PDBFILE>/$pdbfile/; 749cdf0e10cSrcweir print MAKFILE $line; 750cdf0e10cSrcweir } 751cdf0e10cSrcweir} ##print_common_linkflags 752cdf0e10cSrcweir 753cdf0e10cSrcweir############################################################################ 754cdf0e10cSrcweirsub handle_extra_mak_files #25.08.2008 14:32 755cdf0e10cSrcweir############################################################################ 756cdf0e10cSrcweir{ 757cdf0e10cSrcweir # extract extra filename for *.mak file 758cdf0e10cSrcweir # e.g input: tools\genrb.derb 759cdf0e10cSrcweir # output: derb 760cdf0e10cSrcweir my $direntry = shift; 761cdf0e10cSrcweir my $out = ""; 762cdf0e10cSrcweir my $dir = ""; 763cdf0e10cSrcweir if ( $direntry =~ /(.+)\.(.+)$/ ) { 764cdf0e10cSrcweir $dir = $1; 765cdf0e10cSrcweir $out = $2; 766cdf0e10cSrcweir } else 767cdf0e10cSrcweir { 768cdf0e10cSrcweir $dir = $direntry; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir return ($dir,$out); 771cdf0e10cSrcweir} ##handle_extra_mak_files 772cdf0e10cSrcweir 773cdf0e10cSrcweir############################################################################ 774cdf0e10cSrcweirsub prepare_allinone_all_mak 775cdf0e10cSrcweir############################################################################ 776cdf0e10cSrcweir{ 777cdf0e10cSrcweir # Read in allinone.sln 778cdf0e10cSrcweir # Fills hashes and returns an array with build order 779cdf0e10cSrcweir # uses topographical sorting 780cdf0e10cSrcweir 781cdf0e10cSrcweir my $href_project_by_id = shift; 782cdf0e10cSrcweir my $href_project_by_name = shift; 783cdf0e10cSrcweir my $href_project_dependencies = shift; 784cdf0e10cSrcweir my $sourcePath = shift; 785cdf0e10cSrcweir 786cdf0e10cSrcweir my $allslnfile = $sourcePath . "\\allinone\\allinone.sln"; 787cdf0e10cSrcweir my @projectdeps; 788cdf0e10cSrcweir my $projectname; 789cdf0e10cSrcweir my $projectpath; 790cdf0e10cSrcweir my $projectid; 791cdf0e10cSrcweir 792cdf0e10cSrcweir # fill hash tables 793cdf0e10cSrcweir open (SLN, "< $allslnfile") || die "Can't open $allslnfile\n"; 794cdf0e10cSrcweir while ($line = <SLN>) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir my @project = (); 797cdf0e10cSrcweir if ( $line =~ /^Project\(/ ) { 798cdf0e10cSrcweir @project = split( /,/, $line); 799cdf0e10cSrcweir if ( $#project ) { 800cdf0e10cSrcweir $projectname = ""; 801cdf0e10cSrcweir $projectpath = ""; 802cdf0e10cSrcweir $projectid = ""; 803cdf0e10cSrcweir @projectdeps = (); 804cdf0e10cSrcweir my @subarray = (); 805cdf0e10cSrcweir @subarray = split( /=/, $project[0]); 806cdf0e10cSrcweir $projectname = $subarray[1]; 807cdf0e10cSrcweir $projectname =~ s/\"//g; # remove " 808cdf0e10cSrcweir $projectpath = $project[1]; 809cdf0e10cSrcweir $projectid = $project[2]; 810cdf0e10cSrcweir $projectid =~ s/\"//g; # remove " 811cdf0e10cSrcweir $projectid =~ s/.+\{//g; # remove til { 812cdf0e10cSrcweir $projectid =~ s/\}\n//g; # remove }<CR> 813cdf0e10cSrcweir my @pnp = ($projectname,$projectpath); 814cdf0e10cSrcweir my @pip = ($projectid,$projectpath); 815cdf0e10cSrcweir $$href_project_by_id{$projectid}=[@pnp]; 816cdf0e10cSrcweir $$href_project_by_name{$projectname} =[@pip]; 817cdf0e10cSrcweir } 818cdf0e10cSrcweir } # $line =~ /^Project\(/ 819cdf0e10cSrcweir if ( $line =~ /ProjectSection\(/ ) { 820cdf0e10cSrcweir $psect = 1; 821cdf0e10cSrcweir next; 822cdf0e10cSrcweir } 823cdf0e10cSrcweir if ( $line =~ /EndProjectSection/ ) { 824cdf0e10cSrcweir $psect = 0; 825cdf0e10cSrcweir $$href_project_dependencies{$projectid}=[@projectdeps]; 826cdf0e10cSrcweir next; 827cdf0e10cSrcweir } 828cdf0e10cSrcweir if ( $psect ) { 829cdf0e10cSrcweir my @tarray = split(/=/, $line); 830cdf0e10cSrcweir $depends_on_id = $tarray[0]; 831cdf0e10cSrcweir $depends_on_id =~ s/.+\{//g; 832cdf0e10cSrcweir $depends_on_id =~ s/\}.+//g; 833cdf0e10cSrcweir print "+$depends_on_id-\n" if ($is_debug); 834cdf0e10cSrcweir 835cdf0e10cSrcweir push @projectdeps, $depends_on_id; 836cdf0e10cSrcweir } 837cdf0e10cSrcweir } 838cdf0e10cSrcweir ######################################## 839cdf0e10cSrcweir # sort here and generate build order 840cdf0e10cSrcweir ######################################## 841cdf0e10cSrcweir $objektzahl=0; 842cdf0e10cSrcweir %hashindex=(); 843cdf0e10cSrcweir 844cdf0e10cSrcweir foreach $projectid(keys %{$href_project_by_id}) 845cdf0e10cSrcweir { 846cdf0e10cSrcweir if ( $$href_project_dependencies{$projectid} ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir @deps = @{$$href_project_dependencies{$projectid}}; 849cdf0e10cSrcweir } else 850cdf0e10cSrcweir { 851cdf0e10cSrcweir @deps = (); 852cdf0e10cSrcweir } 853cdf0e10cSrcweir for $counter(0..$#deps) 854cdf0e10cSrcweir { 855cdf0e10cSrcweir $v = find_or_create_element($deps[$counter]); 856cdf0e10cSrcweir $n = find_or_create_element($projectid); 857cdf0e10cSrcweir push @{$nachfolgerliste[$v]},$n; 858cdf0e10cSrcweir } 859cdf0e10cSrcweir } 860cdf0e10cSrcweir 861cdf0e10cSrcweir for $n (0..$objektzahl-1) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir $vorgaengerzahl[$n]=0; 864cdf0e10cSrcweir } 865cdf0e10cSrcweir for $v (0..$objektzahl-1) 866cdf0e10cSrcweir { 867cdf0e10cSrcweir for $n (@{$nachfolgerliste[$v]}) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir ++$vorgaengerzahl[$n]; 870cdf0e10cSrcweir } 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir @hilfsliste=(); 874cdf0e10cSrcweir for $n (0..$objektzahl-1) 875cdf0e10cSrcweir { 876cdf0e10cSrcweir push(@hilfsliste,$n) if ($vorgaengerzahl[$n]==0) 877cdf0e10cSrcweir } 878cdf0e10cSrcweir 879cdf0e10cSrcweir $ausgabe=0; 880cdf0e10cSrcweir @builddep =(); 881cdf0e10cSrcweir while (defined($v=pop(@hilfsliste))) 882cdf0e10cSrcweir { 883cdf0e10cSrcweir push @builddep, $name[$v]; # save build order by project_id; 884cdf0e10cSrcweir ++$ausgabe; 885cdf0e10cSrcweir for $n (@{$nachfolgerliste[$v]}) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir --$vorgaengerzahl[$n]; 888cdf0e10cSrcweir push(@hilfsliste,$n) if ($vorgaengerzahl[$n]==0); 889cdf0e10cSrcweir } 890cdf0e10cSrcweir } # while 891cdf0e10cSrcweir die "Cyclic dependencies found! Stopping now.\n" if $ausgabe<$objektzahl; 892cdf0e10cSrcweir ############################################################## 893cdf0e10cSrcweir # End of sorting stuff 894cdf0e10cSrcweir ############################################################## 895cdf0e10cSrcweir 896cdf0e10cSrcweir return @builddep; 897cdf0e10cSrcweir ############################################################### 898cdf0e10cSrcweir ########################### 899cdf0e10cSrcweir # sub for sorting only 900cdf0e10cSrcweir ########################### 901cdf0e10cSrcweir sub find_or_create_element 902cdf0e10cSrcweir { 903cdf0e10cSrcweir my ($str)=@_; 904cdf0e10cSrcweir my ($idx)=$hashindex{$str}; 905cdf0e10cSrcweir if (!defined($idx)) { # new element ... 906cdf0e10cSrcweir $idx=$objektzahl++; 907cdf0e10cSrcweir $hashindex{$str}=$idx; 908cdf0e10cSrcweir $name[$idx]=$str; 909cdf0e10cSrcweir @{$nachfolgerliste[$idx]}=(); 910cdf0e10cSrcweir } 911cdf0e10cSrcweir return $idx; 912cdf0e10cSrcweir } # find_or_create_element 913cdf0e10cSrcweir} # prepare_allinone_all_mak 914cdf0e10cSrcweir 915cdf0e10cSrcweir############################################################################ 916cdf0e10cSrcweirsub create_allinone_all_mak #09.02.2009 09:22 917cdf0e10cSrcweir############################################################################ 918cdf0e10cSrcweir{ 919cdf0e10cSrcweir my $ref_buildorder = shift; 920cdf0e10cSrcweir my $href_project_by_id = shift; 921cdf0e10cSrcweir my $sourcePath = shift; 922cdf0e10cSrcweir my $allmakfile = $sourcePath . "\\allinone\\all.mak"; 923cdf0e10cSrcweir open (ALLMAK, ">$allmakfile") || die "Can't write to $allmakfile \n"; 924cdf0e10cSrcweir print ALLMAK "ALL: "; 925cdf0e10cSrcweir foreach $proj(@{$ref_buildorder}) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir print ALLMAK $$href_project_by_id{$proj}[0]; 928cdf0e10cSrcweir } 929cdf0e10cSrcweir print ALLMAK "\n\n"; 930cdf0e10cSrcweir 931cdf0e10cSrcweir foreach $proj( @{$ref_buildorder} ) 932cdf0e10cSrcweir { 933cdf0e10cSrcweir print "$proj $$href_project_by_id{$proj}[0] $$href_project_by_id{$proj}[1]\n"; 934cdf0e10cSrcweir my $prjdir = $$href_project_by_id{$proj}[1]; 935cdf0e10cSrcweir $prjdir =~ /(.+)\\(.+)$/; 936cdf0e10cSrcweir $prjdir = $1; 937cdf0e10cSrcweir $prjname = $2; 938cdf0e10cSrcweir $prjdir =~ s/^.+\"//; 939cdf0e10cSrcweir $prjname =~ s/\"$//; 940cdf0e10cSrcweir $prjname =~ s/vcproj/mak/; 941cdf0e10cSrcweir $allinonehelpstring = $prjdir; 942cdf0e10cSrcweir $allinonehelpstring =~ s/^\.+\\//; # remove ..\ 943cdf0e10cSrcweir my $backcount = ""; 944*a893be29SPedro Giffuni while ($allinonehelpstring=~ /.+\\/g) # counts the occurring \ 945cdf0e10cSrcweir { 946cdf0e10cSrcweir $backcount .= "..\\"; 947cdf0e10cSrcweir } 948cdf0e10cSrcweir $allinonedir = $backcount . "..\\allinone"; 949cdf0e10cSrcweir 950cdf0e10cSrcweir # write all.mak 951cdf0e10cSrcweir $$href_project_by_id{$proj}[0] =~ s/^\s+//; 952cdf0e10cSrcweir if ( $$href_project_by_id{$proj}[0] ne "makedata" ) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir my @template = @{$template_hash{"AllInOnePrj"}}; 955cdf0e10cSrcweir foreach $line(@template) 956cdf0e10cSrcweir { 957cdf0e10cSrcweir $line =~ s/<PRJ>/$$href_project_by_id{$proj}[0]/; 958cdf0e10cSrcweir $line =~ s/<PRJDIR>/$prjdir/; 959cdf0e10cSrcweir $line =~ s/<PRJMAK>/$prjname/; 960cdf0e10cSrcweir $line =~ s/<ALLINONEDIR>/$allinonedir/; 961cdf0e10cSrcweir print ALLMAK $line; 962cdf0e10cSrcweir } 963cdf0e10cSrcweir } else 964cdf0e10cSrcweir { 965cdf0e10cSrcweir #special code snippet 966cdf0e10cSrcweir print ALLMAK "makedata : \n"; 967cdf0e10cSrcweir print ALLMAK " cd \"..\\data\"\n"; 968cdf0e10cSrcweir print ALLMAK " nmake /f makedata.mak icumake=\$(MAKEDIR)\\..\\data cfg=Release\n"; 969cdf0e10cSrcweir print ALLMAK " cd \"..\\allinone\"\n\n"; 970cdf0e10cSrcweir } 971cdf0e10cSrcweir } 972cdf0e10cSrcweir close ALLMAK; 973cdf0e10cSrcweir} ##create_allinone_all_mak 974cdf0e10cSrcweir 975cdf0e10cSrcweir############################################################################ 976cdf0e10cSrcweir 977cdf0e10cSrcweir# ------------------------------------------------------------------------ 978cdf0e10cSrcweir# XML parser handling 979cdf0e10cSrcweir# ------------------------------------------------------------------------ 980cdf0e10cSrcweir 981cdf0e10cSrcweir############################################################################ 982cdf0e10cSrcweirsub start_handler 983cdf0e10cSrcweir############################################################################ 984cdf0e10cSrcweir{ 985cdf0e10cSrcweir my $p = shift; # pointer to parser 986cdf0e10cSrcweir my $el = shift; # element 987cdf0e10cSrcweir 988cdf0e10cSrcweir # Deal with attributes 989cdf0e10cSrcweir 990cdf0e10cSrcweir my $CompilerSection = 0; 991cdf0e10cSrcweir my $LinkerSection = 0; 992cdf0e10cSrcweir my $ConfigSection = ($el eq "Configuration"); 993cdf0e10cSrcweir 994cdf0e10cSrcweir while (@_) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir # shift if ( $el eq "FileConfiguration" ); 997cdf0e10cSrcweir my $att = shift; 998cdf0e10cSrcweir my $val = shift; 999cdf0e10cSrcweir $CustomSection = 0; 1000cdf0e10cSrcweir if ($special_file && defined $att & $att ne "Name") 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir print "$special_file - $att - $val\n"; 1003cdf0e10cSrcweir my @param = ($att,$val); 1004cdf0e10cSrcweir $files_special{ $special_file } = [@param]; # files with special compiler switch 1005cdf0e10cSrcweir @test = @{$files_special{ $special_file }}; 1006cdf0e10cSrcweir print "test=@test\n"; 1007cdf0e10cSrcweir $special_file=""; 1008cdf0e10cSrcweir } 1009cdf0e10cSrcweir if ( $ConfigSection && $att eq "Name" && $val eq "Release|Win32" ) { 1010cdf0e10cSrcweir $Release = 1; 1011cdf0e10cSrcweir $config = "Release"; # Release 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir if ( $ConfigSection && $att eq "Name" && $val eq "Debug|Win32" ) { 1014cdf0e10cSrcweir $Release = 0; # Debug 1015cdf0e10cSrcweir $config = "Debug"; 1016cdf0e10cSrcweir } 1017cdf0e10cSrcweir if ( $att eq "Name" && $val eq "VCCLCompilerTool" ) { 1018cdf0e10cSrcweir $CompilerSection = 1; 1019cdf0e10cSrcweir } 1020cdf0e10cSrcweir if ( $att eq "Name" && $val eq "VCLinkerTool" ) { 1021cdf0e10cSrcweir $LinkerSection = 1; 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir if ( $att eq "Name" && $val eq "VCCustomBuildTool" ) { 1024cdf0e10cSrcweir $CustomSection = 1; 1025cdf0e10cSrcweir } 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir # For Configuration Infos like compiler defines etc. 1028cdf0e10cSrcweir if ( $att eq "PreprocessorDefinitions" && $CompilerSection ) { 1029cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1030cdf0e10cSrcweir } 1031cdf0e10cSrcweir if ( $att eq "AdditionalIncludeDirectories" && $CompilerSection ) { 1032cdf0e10cSrcweir #$configelements{$config}{$att} = $val; 1033cdf0e10cSrcweir if ( ($file_tmp ne "") && ($val ne "") ) { 1034cdf0e10cSrcweir $files{ $file_tmp } = 1; # save it now 1035cdf0e10cSrcweir $file_tmp =~ s/^\.\\//; # remove leading .\ 1036cdf0e10cSrcweir $files_special{"AdditionalIncludeDirectories"}{$file_tmp} = $val; 1037cdf0e10cSrcweir print "Include $val: $file_tmp\n" if ($is_debug); 1038cdf0e10cSrcweir $file_tmp = ""; # has been saved now reset it 1039cdf0e10cSrcweir } else 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1042cdf0e10cSrcweir } 1043cdf0e10cSrcweir } 1044cdf0e10cSrcweir if ( ($att eq "DisableLanguageExtensions") && $CompilerSection ) { 1045cdf0e10cSrcweir #$configelements{$config}{$att} = $val; 1046cdf0e10cSrcweir if ( ($file_tmp ne "") && ($val ne "")) { 1047cdf0e10cSrcweir $files{ $file_tmp } = 1; # save it now 1048cdf0e10cSrcweir $file_tmp =~ s/^\.\\//; # remove leading .\ 1049cdf0e10cSrcweir $files_special{"DisableLanguageExtensions"}{$file_tmp} = $val; 1050cdf0e10cSrcweir print "-Ze: $file_tmp\n" if ($is_debug); 1051cdf0e10cSrcweir $file_tmp = ""; # has been saved now reset it 1052cdf0e10cSrcweir } 1053cdf0e10cSrcweir } 1054cdf0e10cSrcweir if ( $att eq "OutputDirectory" ) { 1055cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1056cdf0e10cSrcweir } 1057cdf0e10cSrcweir if ( $att eq "OutputFile" && $LinkerSection ) { 1058cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1059cdf0e10cSrcweir } 1060cdf0e10cSrcweir if ( $att eq "ProgramDatabaseFile" ) { 1061cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1062cdf0e10cSrcweir } 1063cdf0e10cSrcweir if ( $att eq "ImportLibrary" && $LinkerSection ) { 1064cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir if ($att eq "CommandLine") { 1067cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1068cdf0e10cSrcweir } 1069cdf0e10cSrcweir if (($att eq "PreprocessorDefinitions") && $ConfigSection) { 1070cdf0e10cSrcweir $configelements{$config}{$att} = $val; 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir # Is the file in the step before a header 1074cdf0e10cSrcweir # which has to be copied into the global 1075cdf0e10cSrcweir # include path? 1076cdf0e10cSrcweir if ( $file_tmp ne "" ) 1077cdf0e10cSrcweir { 1078cdf0e10cSrcweir $config = "Release"; 1079cdf0e10cSrcweir if ( ($att eq "CommandLine") && ($el eq "Tool") ) 1080cdf0e10cSrcweir { 1081cdf0e10cSrcweir if ( $file_tmp =~ /.+\.h$/ ) { 1082cdf0e10cSrcweir $files2copy{ $file_tmp } = $val; # unicode + layout header to copy 1083cdf0e10cSrcweir $file_tmp = ""; # has been saved now reset it 1084cdf0e10cSrcweir } 1085cdf0e10cSrcweir } 1086cdf0e10cSrcweir } # if $file_tmp 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir # For files 1089cdf0e10cSrcweir if ( $att eq "RelativePath" ) { 1090cdf0e10cSrcweir if ( $file_tmp ) { 1091cdf0e10cSrcweir # no special file (include dir / compiler switch) 1092cdf0e10cSrcweir $files{ $file_tmp } = 1; # save it now 1093cdf0e10cSrcweir $file_tmp = ""; # has been saved now reset it 1094cdf0e10cSrcweir } 1095cdf0e10cSrcweir # store temporary the file name 1096cdf0e10cSrcweir $file_tmp = $val if ($val !~ /\.mk$/); # no *.mk files 1097cdf0e10cSrcweir } 1098cdf0e10cSrcweir } # while @_ 1099cdf0e10cSrcweir} # End start_handler 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir############################################################################ 1102cdf0e10cSrcweirsub char_handler 1103cdf0e10cSrcweir############################################################################ 1104cdf0e10cSrcweir{ 1105cdf0e10cSrcweir} # End char_handler 1106