1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_tools.hxx" 26 27 // global includes 28 #include <stdio.h> 29 30 // local includes 31 #include "bootstrp/mkcreate.hxx" 32 #include "bootstrp/inimgr.hxx" 33 #include "bootstrp/appdef.hxx" 34 #include <tools/geninfo.hxx> 35 #include <tools/iparser.hxx> 36 #include "bootstrp/prj.hxx" 37 38 char const *NoBuildProject[] = { 39 "solenv", 40 "EndOf_NoBuildProject" 41 }; 42 43 char const *LimitedPath[] = { 44 "jurt\\com\\sun\\star", 45 "r_tools", 46 "ridljar", 47 "setup2", 48 "connectivity", 49 "EndOf_LimitedPath" 50 }; 51 52 // 53 // class SourceDirectory 54 // 55 56 /*****************************************************************************/ 57 SourceDirectory::SourceDirectory( const ByteString &rDirectoryName, 58 sal_uInt16 nOperatingSystem, SourceDirectory *pParentDirectory ) 59 /*****************************************************************************/ 60 : ByteString( rDirectoryName ), 61 pParent( pParentDirectory ), 62 pSubDirectories( NULL ), 63 nOSType( nOperatingSystem ), 64 nDepth( 0 ), 65 pDependencies( NULL ), 66 pCodedDependencies( NULL ), 67 pCodedIdentifier( NULL ) 68 { 69 if ( pParent ) { 70 if ( !pParent->pSubDirectories ) 71 pParent->pSubDirectories = new SourceDirectoryList(); 72 pParent->pSubDirectories->InsertSorted( this ); 73 nDepth = pParent->nDepth + 1; 74 } 75 } 76 77 /*****************************************************************************/ 78 SourceDirectory::~SourceDirectory() 79 /*****************************************************************************/ 80 { 81 delete pSubDirectories; 82 } 83 84 /*****************************************************************************/ 85 CodedDependency *SourceDirectory::AddCodedDependency( 86 const ByteString &rCodedIdentifier, sal_uInt16 nOperatingSystems ) 87 /*****************************************************************************/ 88 { 89 CodedDependency *pReturn = NULL; 90 91 if ( !pCodedDependencies ) { 92 pCodedDependencies = new SByteStringList(); 93 pReturn = new CodedDependency( rCodedIdentifier, nOperatingSystems ); 94 pCodedDependencies->PutString(( ByteString * ) pReturn ); 95 } 96 else { 97 sal_uIntPtr nPos = 98 pCodedDependencies->IsString( (ByteString *) (& rCodedIdentifier) ); 99 if ( nPos == NOT_THERE ) { 100 pReturn = 101 new CodedDependency( rCodedIdentifier, nOperatingSystems ); 102 pCodedDependencies->PutString(( ByteString * ) pReturn ); 103 } 104 else { 105 pReturn = 106 ( CodedDependency * ) pCodedDependencies->GetObject( nPos ); 107 pReturn->TryToMerge( rCodedIdentifier, nOperatingSystems ); 108 } 109 } 110 return pReturn; 111 } 112 113 /*****************************************************************************/ 114 CodedDependency *SourceDirectory::AddCodedIdentifier( 115 const ByteString &rCodedIdentifier, sal_uInt16 nOperatingSystems ) 116 /*****************************************************************************/ 117 { 118 CodedDependency *pReturn = NULL; 119 120 if ( !pCodedIdentifier ) { 121 pCodedIdentifier = new SByteStringList(); 122 pReturn = new CodedDependency( rCodedIdentifier, nOperatingSystems ); 123 pCodedIdentifier->PutString(( ByteString * ) pReturn ); 124 } 125 else { 126 sal_uIntPtr nPos = 127 pCodedIdentifier->IsString( ( ByteString *) (& rCodedIdentifier) ); 128 if ( nPos == NOT_THERE ) { 129 pReturn = 130 new CodedDependency( rCodedIdentifier, nOperatingSystems ); 131 pCodedIdentifier->PutString(( ByteString * ) pReturn ); 132 } 133 else { 134 pReturn = 135 ( CodedDependency * ) pCodedIdentifier->GetObject( nPos ); 136 pReturn->TryToMerge( rCodedIdentifier, nOperatingSystems ); 137 } 138 } 139 if ( pParent && pParent->nDepth > 1 ) 140 pParent->AddCodedIdentifier( rCodedIdentifier, nOperatingSystems ); 141 142 return pReturn; 143 } 144 145 /*****************************************************************************/ 146 ByteString SourceDirectory::GetFullPath() 147 /*****************************************************************************/ 148 { 149 ByteString sFullPath; 150 if ( pParent ) { 151 sFullPath = pParent->GetFullPath(); 152 sFullPath += ByteString( PATH_SEPARATOR ); 153 } 154 sFullPath += *this; 155 156 return sFullPath; 157 } 158 159 /*****************************************************************************/ 160 SourceDirectory *SourceDirectory::GetRootDirectory() 161 /*****************************************************************************/ 162 { 163 if ( !pParent ) 164 return this; 165 166 return pParent->GetRootDirectory(); 167 } 168 169 /*****************************************************************************/ 170 SourceDirectory *SourceDirectory::GetSubDirectory( 171 const ByteString &rDirectoryPath, sal_uInt16 nOperatingSystem ) 172 /*****************************************************************************/ 173 { 174 ByteString sSearch; 175 176 sal_Bool bSubs = sal_True; 177 sal_uIntPtr nIndex = 0; 178 179 while ( bSubs && ByteString( LimitedPath[ nIndex ]) != "EndOf_LimitedPath" ) { 180 SourceDirectory *pActDir = this; 181 ByteString sLimitation( LimitedPath[ nIndex ]); 182 183 sal_Bool bBreak = sal_False; 184 for ( sal_uIntPtr i = sLimitation.GetTokenCount( '\\' ); i > 0 && !bBreak; i-- ) { 185 if (( !pActDir ) || ( *pActDir != sLimitation.GetToken(( sal_uInt16 )( i - 1 ), '\\' ))) 186 bBreak = sal_True; 187 else 188 pActDir = pActDir->pParent; 189 } 190 bSubs = bBreak; 191 nIndex++; 192 } 193 194 if ( !bSubs ) 195 { 196 sSearch = rDirectoryPath; 197 } 198 else 199 sSearch = rDirectoryPath.GetToken( 0, PATH_SEPARATOR ); 200 201 SourceDirectory *pSubDirectory = NULL; 202 203 if ( pSubDirectories ) 204 pSubDirectory = pSubDirectories->Search( sSearch ); 205 206 if ( !pSubDirectory ) 207 pSubDirectory = new SourceDirectory( 208 sSearch, nOperatingSystem, this ); 209 210 pSubDirectory->nOSType |= nOperatingSystem; 211 212 if ( sSearch.Len() == rDirectoryPath.Len()) 213 return pSubDirectory; 214 215 ByteString sPath = rDirectoryPath.Copy( sSearch.Len() + 1 ); 216 217 return pSubDirectory->GetSubDirectory( sPath, nOperatingSystem ); 218 } 219 220 /*****************************************************************************/ 221 SourceDirectory *SourceDirectory::GetDirectory( 222 const ByteString &rDirectoryName, sal_uInt16 nOperatingSystem ) 223 /*****************************************************************************/ 224 { 225 ByteString sDirectoryName( rDirectoryName ); 226 #ifdef UNX 227 sDirectoryName.SearchAndReplaceAll( "\\", "/" ); 228 #endif 229 230 SourceDirectory *pRoot = GetRootDirectory(); 231 232 if ( sDirectoryName.Search( *pRoot ) != 0 ) 233 return NULL; 234 235 if ( sDirectoryName.Len() == pRoot->Len()) 236 return pRoot; 237 238 if ( sDirectoryName.GetChar( pRoot->Len()) == PATH_SEPARATOR ) { 239 ByteString sSub = sDirectoryName.Copy( pRoot->Len() + 1 ); 240 return pRoot->GetSubDirectory( sSub, nOperatingSystem ); 241 } 242 243 return NULL; 244 } 245 246 /*****************************************************************************/ 247 SourceDirectory *SourceDirectory::Insert( const ByteString &rDirectoryName, 248 sal_uInt16 nOperatingSystem ) 249 /*****************************************************************************/ 250 { 251 SourceDirectory *pSubDirectory = NULL; 252 if ( pSubDirectories ) 253 pSubDirectory = pSubDirectories->Search( rDirectoryName ); 254 255 if ( !pSubDirectory ) 256 pSubDirectory = new SourceDirectory( 257 rDirectoryName, nOperatingSystem, this ); 258 259 return pSubDirectory; 260 } 261 262 /*****************************************************************************/ 263 Dependency *SourceDirectory::ResolvesDependency( 264 CodedDependency *pCodedDependency ) 265 /*****************************************************************************/ 266 { 267 if ( !pCodedIdentifier ) 268 return NULL; 269 270 sal_uIntPtr nPos = pCodedIdentifier->IsString( pCodedDependency ); 271 if ( nPos != NOT_THERE ) { 272 CodedDependency *pIdentifier = 273 ( CodedDependency * ) pCodedIdentifier->GetObject( nPos ); 274 sal_uInt16 nResult = 275 pIdentifier->GetOperatingSystem() & 276 pCodedDependency->GetOperatingSystem(); 277 Dependency *pReturn = new Dependency( *this, nResult ); 278 nResult ^= pCodedDependency->GetOperatingSystem(); 279 pCodedDependency->SetOperatingSystem( nResult ); 280 return pReturn; 281 } 282 return NULL; 283 } 284 285 286 /*****************************************************************************/ 287 void SourceDirectory::ResolveDependencies() 288 /*****************************************************************************/ 289 { 290 if ( !pSubDirectories ) 291 return; 292 293 for ( sal_uIntPtr i = 0; i < pSubDirectories->Count(); i++ ) { 294 SourceDirectory *pActDirectory = 295 ( SourceDirectory * ) pSubDirectories->GetObject( i ); 296 if ( pActDirectory->pSubDirectories ) 297 pActDirectory->ResolveDependencies(); 298 299 if ( pActDirectory->pCodedDependencies ) { 300 while ( pActDirectory->pCodedDependencies->Count()) 301 { 302 CodedDependency *pCodedDependency = ( CodedDependency * ) 303 pActDirectory->pCodedDependencies->GetObject(( sal_uIntPtr ) 0 ); 304 305 for ( 306 sal_uIntPtr k = 0; 307 ( k < pSubDirectories->Count()) && 308 ( pCodedDependency->GetOperatingSystem() != OS_NONE ); 309 k++ 310 ) { 311 Dependency *pDependency = 312 ((SourceDirectory *) pSubDirectories->GetObject( k ))-> 313 ResolvesDependency( pCodedDependency ); 314 if ( pDependency ) 315 { 316 if ( !pActDirectory->pDependencies ) 317 pActDirectory->pDependencies = new SByteStringList(); 318 pActDirectory->pDependencies->PutString( pDependency ); 319 } 320 } 321 if ( pCodedDependency->GetOperatingSystem()) { 322 if ( !pCodedDependencies ) 323 pCodedDependencies = new SByteStringList(); 324 pCodedDependencies->PutString( pCodedDependency ); 325 } 326 else 327 delete pCodedDependency; 328 pActDirectory->pCodedDependencies->Remove(( sal_uIntPtr ) 0 ); 329 } 330 } 331 } 332 } 333 334 /*****************************************************************************/ 335 ByteString SourceDirectory::GetTarget() 336 /*****************************************************************************/ 337 { 338 ByteString sReturn; 339 340 if ( !pDependencies ) 341 return sReturn; 342 343 sal_uIntPtr k = 0; 344 while ( k < pDependencies->Count()) { 345 if ( *this == *pDependencies->GetObject( k )) 346 delete pDependencies->Remove( k ); 347 else 348 k++; 349 } 350 351 if ( !pDependencies->Count()) { 352 delete pDependencies; 353 pDependencies = NULL; 354 return sReturn; 355 } 356 357 sal_Bool bDependsOnPlatform = sal_False; 358 for ( sal_uIntPtr i = 0; i < pDependencies->Count(); i++ ) 359 if ((( Dependency * ) pDependencies->GetObject( i ))-> 360 GetOperatingSystem() != OS_ALL ) 361 bDependsOnPlatform = sal_True; 362 363 ByteString sTarget( *this ); 364 sTarget.SearchAndReplaceAll( "\\", "$/" ); 365 if ( !bDependsOnPlatform ) { 366 sReturn = sTarget; 367 sReturn += " :"; 368 for ( sal_uIntPtr i = 0; i < pDependencies->Count(); i++ ) { 369 ByteString sDependency( *pDependencies->GetObject( i )); 370 sDependency.SearchAndReplaceAll( "\\", "$/" ); 371 sReturn += " "; 372 sReturn += sDependency; 373 } 374 } 375 else { 376 ByteString sUNX( ".IF \"$(GUI)\" == \"UNX\"\n" ); 377 sUNX += sTarget; 378 sUNX += " :"; 379 sal_Bool bUNX = sal_False; 380 381 ByteString sWNT( ".IF \"$(GUI)\" == \"WNT\"\n" ); 382 sWNT += sTarget; 383 sWNT += " :"; 384 sal_Bool bWNT = sal_False; 385 386 ByteString sOS2( ".IF \"$(GUI)\" == \"OS2\"\n" ); 387 sOS2 += sTarget; 388 sOS2 += " :"; 389 sal_Bool bOS2 = sal_False; 390 391 for ( sal_uIntPtr i = 0; i < pDependencies->Count(); i++ ) { 392 Dependency *pDependency = 393 ( Dependency * ) pDependencies->GetObject( i ); 394 ByteString sDependency( *pDependency ); 395 sDependency.SearchAndReplaceAll( "\\", "$/" ); 396 397 if ( pDependency->GetOperatingSystem() & OS_UNX ) { 398 sUNX += " "; 399 sUNX += sDependency; 400 bUNX = sal_True; 401 } 402 if ( pDependency->GetOperatingSystem() & OS_WIN32 ) { 403 sWNT += " "; 404 sWNT += sDependency; 405 bWNT = sal_True; 406 } 407 if ( pDependency->GetOperatingSystem() & OS_OS2 ) { 408 sOS2 += " "; 409 sOS2 += sDependency; 410 bOS2 = sal_True; 411 } 412 } 413 414 if ( bUNX ) { 415 sReturn += sUNX; 416 sReturn += "\n.ENDIF\n"; 417 } 418 if ( bWNT ) { 419 sReturn += sWNT; 420 sReturn += "\n.ENDIF\n"; 421 } 422 if ( bOS2 ) { 423 sReturn += sOS2; 424 sReturn += "\n.ENDIF\n"; 425 } 426 } 427 sReturn.EraseTrailingChars( '\n' ); 428 return sReturn; 429 } 430 431 /*****************************************************************************/ 432 ByteString SourceDirectory::GetSubDirsTarget() 433 /*****************************************************************************/ 434 { 435 ByteString sReturn; 436 437 if ( pSubDirectories ) { 438 sal_Bool bDependsOnPlatform = sal_False; 439 for ( sal_uIntPtr i = 0; i < pSubDirectories->Count(); i++ ) 440 if ((( SourceDirectory * ) pSubDirectories->GetObject( i ))-> 441 GetOperatingSystems() != OS_ALL ) 442 bDependsOnPlatform = sal_True; 443 444 if ( !bDependsOnPlatform ) { 445 sReturn = "RC_SUBDIRS = "; 446 447 for ( sal_uIntPtr i = 0; i < pSubDirectories->Count(); i++ ) { 448 ByteString sSubDirectory( *pSubDirectories->GetObject( i )); 449 sSubDirectory.SearchAndReplaceAll( "\\", "$/" ); 450 sReturn += " \\\n\t"; 451 sReturn += sSubDirectory; 452 } 453 sReturn += "\n"; 454 } 455 else { 456 ByteString sUNX( ".IF \"$(GUI)\" == \"UNX\"\n" ); 457 sUNX += "RC_SUBDIRS = "; 458 sal_Bool bUNX = sal_False; 459 460 ByteString sWNT( ".IF \"$(GUI)\" == \"WNT\"\n" ); 461 sWNT += "RC_SUBDIRS = "; 462 sal_Bool bWNT = sal_False; 463 464 ByteString sOS2( ".IF \"$(GUI)\" == \"OS2\"\n" ); 465 sOS2 += "RC_SUBDIRS = "; 466 sal_Bool bOS2 = sal_False; 467 468 for ( sal_uIntPtr i = 0; i < pSubDirectories->Count(); i++ ) { 469 SourceDirectory *pDirectory = 470 ( SourceDirectory * ) pSubDirectories->GetObject( i ); 471 ByteString sDirectory( *pDirectory ); 472 sDirectory.SearchAndReplaceAll( "\\", "$/" ); 473 474 if ( pDirectory->GetOperatingSystems() & OS_UNX ) { 475 sUNX += " \\\n\t"; 476 sUNX += sDirectory; 477 bUNX = sal_True; 478 } 479 if ( pDirectory->GetOperatingSystems() & OS_WIN32 ) { 480 sWNT += " \\\n\t"; 481 sWNT += sDirectory; 482 bWNT = sal_True; 483 } 484 if ( pDirectory->GetOperatingSystems() & OS_OS2 ) { 485 sOS2 += " \\\n\t"; 486 sOS2 += sDirectory; 487 bOS2 = sal_True; 488 } 489 } 490 if ( bUNX ) { 491 sReturn += sUNX; 492 sReturn += "\n.ENDIF\n"; 493 } 494 if ( bWNT ) { 495 sReturn += sWNT; 496 sReturn += "\n.ENDIF\n"; 497 } 498 if ( bOS2 ) { 499 sReturn += sOS2; 500 sReturn += "\n.ENDIF\n"; 501 } 502 } 503 } 504 return sReturn; 505 } 506 507 /*****************************************************************************/ 508 sal_uInt16 SourceDirectory::GetOSType( const ByteString &sDependExt ) 509 /*****************************************************************************/ 510 { 511 sal_uInt16 nOSType = 0; 512 if ( sDependExt == "" ) 513 nOSType |= OS_ALL; 514 else if ( sDependExt == "N" || sDependExt == "W" ) 515 nOSType |= OS_WIN32; 516 else if ( sDependExt == "U" ) 517 nOSType |= OS_UNX; 518 else if ( sDependExt == "P" ) 519 nOSType |= OS_OS2; 520 return nOSType; 521 } 522 523 /*****************************************************************************/ 524 SourceDirectory *SourceDirectory::CreateRootDirectory( 525 const ByteString &rRoot, const ByteString &rVersion, sal_Bool bAll ) 526 /*****************************************************************************/ 527 { 528 IniManager aIniManager; 529 aIniManager.Update(); 530 531 ByteString sDefLst( GetDefStandList()); 532 ByteString sStandLst( aIniManager.ToLocal( sDefLst )); 533 String s = String( sStandLst, gsl_getSystemTextEncoding()); 534 InformationParser aParser; 535 // fprintf( stderr, 536 // "Reading database %s ...\n", sStandLst.GetBuffer()); 537 GenericInformationList *pVerList = aParser.Execute( 538 s ); 539 540 /* 541 ByteString sPath( rVersion ); 542 #ifndef UNX 543 sPath += ByteString( "/settings/solarlist" ); 544 #else 545 sPath += ByteString( "/settings/unxsolarlist" ); 546 #endif 547 ByteString sSolarList( _SOLARLIST ); 548 549 GenericInformation *pInfo = pVerList->GetInfo( sPath, sal_True ); 550 if ( pInfo ) { 551 ByteString aIniRoot( GetIniRoot() ); 552 DirEntry aIniEntry( String( aIniRoot, RTL_TEXTENCODING_ASCII_US )); 553 aIniEntry += DirEntry( String( pInfo->GetValue(), RTL_TEXTENCODING_ASCII_US )).GetBase( PATH_SEPARATOR ); 554 sSolarList = ByteString( aIniEntry.GetFull(), RTL_TEXTENCODING_ASCII_US ); 555 } 556 557 sSolarList = aIniManager.ToLocal( sSolarList ); 558 fprintf( stderr, 559 "Reading directory information %s ...\n", sSolarList.GetBuffer()); 560 */ 561 562 ByteString sVersion( rVersion ); 563 Star aStar( pVerList, sVersion, sal_True, rRoot.GetBuffer()); 564 // fprintf( stderr, 565 // "Creating virtual directory tree ...\n" ); 566 567 568 SourceDirectory *pSourceRoot = new SourceDirectory( rRoot, OS_ALL ); 569 570 for ( sal_uIntPtr i = 0; i < aStar.Count(); i++ ) { 571 Prj *pPrj = aStar.GetObject( i ); 572 573 sal_Bool bBuildable = sal_True; 574 sal_uIntPtr nIndex = 0; 575 576 while ( bBuildable && ByteString( NoBuildProject[ nIndex ]) != "EndOf_NoBuildProject" ) { 577 bBuildable = ( ByteString( NoBuildProject[ nIndex ]) != pPrj->GetProjectName()); 578 nIndex ++; 579 } 580 581 if ( bBuildable ) { 582 SourceDirectory *pProject = pSourceRoot->Insert( pPrj->GetProjectName(), OS_ALL ); 583 584 SByteStringList *pPrjDependencies = pPrj->GetDependencies( sal_False ); 585 if ( pPrjDependencies ) 586 for ( sal_uIntPtr x = 0; x < pPrjDependencies->Count(); x++ ) 587 pProject->AddCodedDependency( *pPrjDependencies->GetObject( x ), OS_ALL ); 588 589 pProject->AddCodedIdentifier( pPrj->GetProjectName(), OS_ALL ); 590 591 for ( sal_uIntPtr j = 0; j < pPrj->Count(); j++ ) { 592 CommandData *pData = pPrj->GetObject( j ); 593 if ( bAll || ( pData->GetCommandType() == COMMAND_NMAKE )) { 594 ByteString sDirPath( rRoot ); 595 sDirPath += ByteString( PATH_SEPARATOR ); 596 sDirPath += pData->GetPath(); 597 SourceDirectory *pDirectory = 598 pSourceRoot->InsertFull( sDirPath, pData->GetOSType()); 599 SByteStringList *pDependencies = pData->GetDependencies(); 600 if ( pDependencies ) { 601 for ( sal_uIntPtr k = 0; k < pDependencies->Count(); k++ ) { 602 ByteString sDependency(*pDependencies->GetObject( k )); 603 ByteString sDependExt(sDependency.GetToken( 1, '.' )); 604 sDependExt.ToUpperAscii(); 605 pDirectory->AddCodedDependency( 606 sDependency.GetToken( 0, '.' ), GetOSType( sDependExt )); 607 } 608 } 609 ByteString sIdentifier = pData->GetLogFile(); 610 ByteString sIdExt = sIdentifier.GetToken( 1, '.' ); 611 sIdExt.ToUpperAscii(); 612 pDirectory->AddCodedIdentifier( sIdentifier.GetToken( 0, '.' ), GetOSType( sIdExt )); 613 } 614 } 615 } 616 } 617 delete pVerList; 618 return pSourceRoot; 619 } 620 621 /*****************************************************************************/ 622 sal_Bool SourceDirectory::RemoveDirectoryTreeAndAllDependencies() 623 /*****************************************************************************/ 624 { 625 if ( !pParent ) 626 return sal_False; 627 628 SourceDirectoryList *pParentContent = pParent->pSubDirectories; 629 sal_uIntPtr i = 0; 630 while ( i < pParentContent->Count()) { 631 SourceDirectory *pCandidate = 632 ( SourceDirectory * )pParentContent->GetObject( i ); 633 if ( pCandidate == this ) { 634 pParentContent->Remove( i ); 635 } 636 else { 637 if ( pCandidate->pDependencies ) { 638 sal_uIntPtr nPos = pCandidate->pDependencies->IsString( this ); 639 if ( nPos != NOT_THERE ) 640 delete pCandidate->pDependencies->Remove( nPos ); 641 } 642 i++; 643 } 644 } 645 delete this; 646 return sal_True; 647 } 648 649 /*****************************************************************************/ 650 sal_Bool SourceDirectory::CreateRecursiveMakefile( sal_Bool bAllChilds ) 651 /*****************************************************************************/ 652 { 653 if ( !pSubDirectories ) 654 return sal_True; 655 656 fprintf( stdout, "%s", GetFullPath().GetBuffer()); 657 658 String aTmpStr( GetFullPath(), gsl_getSystemTextEncoding()); 659 DirEntry aEntry( aTmpStr ); 660 if ( !aEntry.Exists()) { 661 fprintf( stdout, " ... no directory!n" ); 662 return sal_False; 663 } 664 665 sal_uIntPtr j = 0; 666 while( j < pSubDirectories->Count()) { 667 String sSubDirectory( 668 (( SourceDirectory * ) pSubDirectories->GetObject( j ))-> 669 GetFullPath(), 670 gsl_getSystemTextEncoding() 671 ); 672 DirEntry aSubDirectory( sSubDirectory ); 673 if ( !aSubDirectory.Exists()) 674 (( SourceDirectory * ) pSubDirectories->GetObject( j ))-> 675 RemoveDirectoryTreeAndAllDependencies(); 676 else 677 j++; 678 } 679 680 DirEntry aRCFile( String( "makefile.rc", gsl_getSystemTextEncoding())); 681 DirEntry aRCEntry( aEntry ); 682 aRCEntry += aRCFile; 683 684 DirEntry aMKFile( String( "makefile.mk", gsl_getSystemTextEncoding())); 685 DirEntry aMKEntry( aEntry ); 686 aMKEntry += aMKFile; 687 688 sal_Bool bMakefileMk = sal_False; 689 if ( aMKEntry.Exists()) { 690 if ( nDepth == 1 && *this == ByteString( "api" )) 691 fprintf( stdout, " ... makefile.mk exists, ignoring (hack: prj == api)!" ); 692 else { 693 fprintf( stdout, " ... makefile.mk exists, including!" ); 694 bMakefileMk = sal_True; 695 } 696 } 697 698 SvFileStream aMakefile( aRCEntry.GetFull(), STREAM_STD_WRITE | STREAM_TRUNC ); 699 if ( !aMakefile.IsOpen()) { 700 fprintf( stdout, " ... failed!\n" ); 701 return sal_False; 702 } 703 704 ByteString sHeader( 705 "#*************************************************************************\n" 706 "#\n" 707 "# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n" 708 "#\n" 709 "# Copyright 2000, 2010 Oracle and/or its affiliates.\n" 710 "#\n" 711 "# OpenOffice.org - a multi-platform office productivity suite\n" 712 "#\n" 713 "# This file is part of OpenOffice.org.\n" 714 "#\n" 715 "# OpenOffice.org is free software: you can redistribute it and/or modify\n" 716 "# it under the terms of the GNU Lesser General Public License version 3\n" 717 "# only, as published by the Free Software Foundation.\n" 718 "#\n" 719 "# OpenOffice.org is distributed in the hope that it will be useful,\n" 720 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 721 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 722 "# GNU Lesser General Public License version 3 for more details\n" 723 "# (a copy is included in the LICENSE file that accompanied this code).\n" 724 "#\n" 725 "# You should have received a copy of the GNU Lesser General Public License\n" 726 "# version 3 along with OpenOffice.org. If not, see\n" 727 "# <http://www.openoffice.org/license.html>\n" 728 "# for a copy of the LGPLv3 License.\n" 729 "#\n" 730 "#*************************************************************************\n" 731 "\n" 732 ); 733 if ( !bMakefileMk ) { 734 if ( nDepth == 0 ) { 735 sHeader += ByteString( 736 "\n" 737 "# \n" 738 "# mark this makefile as a recursive one\n" 739 "# \n" 740 "\n" 741 "MAKEFILERC=yes\n" 742 "\n" 743 "# \n" 744 "# implementation of cvs checkout\n" 745 "# \n" 746 "\n" 747 ".IF \"$(checkout)\"==\"\"\n" 748 "all_target: ALLTAR\n" 749 ".ELSE\t# \"$(checkout)\"==\"\"\n" 750 ".IF \"$(checkout)\"==\"true\"\n" 751 "% : $(NULL)\n" 752 "\t_cvs co $@\n" 753 ".ELSE\t# \"$(checkout)\"==\"true\"\n" 754 "% : $(NULL)\n" 755 "\t_cvs co -r$(checkout) $@\n" 756 ".ENDIF\t# \"$(checkout)\"==\"true\"\n" 757 "all_subdirs : $(RC_SUBDIRS)\n" 758 ".ENDIF\t# \"$(checkout)\"==\"\"\n" 759 ); 760 } 761 else { 762 sHeader += ByteString( 763 "\n" 764 "# \n" 765 "# mark this makefile as a recursive one\n" 766 "# \n" 767 "\n" 768 "MAKEFILERC=yes\n" 769 ); 770 if ( nDepth == 1 ) 771 sHeader += ByteString( 772 ".IF \"$(build_deliver)\"==\"true\"\n" 773 "all_target:\t\t\\\n" 774 "\tTG_DELIVER\t\\\n" 775 "\tALLTAR\n" 776 ".ELSE # \"$(build_deliver)\"==\"true\"\n" 777 "all_target: ALLTAR\n" 778 ".ENDIF # \"$(build_deliver)\"==\"true\"\n" 779 ); 780 else 781 sHeader += ByteString( 782 "all_target: ALLTAR\n" 783 ); 784 } 785 } 786 else { 787 if ( nDepth == 1 ) 788 sHeader += ByteString( 789 ".IF \"$(build_deliver)\"==\"true\"\n" 790 "all_target:\t\t\\\n" 791 "\tTG_DELIVER\t\\\n" 792 "\tALLTAR\n" 793 ".ELSE # \"$(build_deliver)\"==\"true\"\n" 794 "all_target: ALLTAR\n" 795 ".ENDIF # \"$(build_deliver)\"==\"true\"\n" 796 ); 797 } 798 sHeader += ByteString( 799 "\n" 800 "# \n" 801 "# macro RC_SUBDIRS handles iteration over\n" 802 "# all mandatory sub directories\n" 803 "# \n" 804 ); 805 806 aMakefile.WriteLine( sHeader ); 807 aMakefile.WriteLine( GetSubDirsTarget()); 808 809 if ( nDepth == 0 ) { 810 ByteString sBootstrapTarget( 811 "# \n" 812 "# bootstrap target\n" 813 "# \n\n" 814 "bootstrap .PHONY :\n" 815 "\t@config_office/bootstrap\n\n" 816 ); 817 aMakefile.WriteLine( sBootstrapTarget ); 818 ByteString sConfigureTarget( 819 "# \n" 820 "# configure target\n" 821 "# \n\n" 822 "configure .PHONY SETDIR=config_office :\n" 823 "\t@configure\n" 824 ); 825 aMakefile.WriteLine( sConfigureTarget ); 826 } 827 else if ( nDepth == 1 ) { 828 ByteString sDeliverTarget( 829 "# \n" 830 "# deliver target to handle\n" 831 "# project dependencies\n" 832 "# \n\n" 833 "TG_DELIVER : $(RC_SUBDIRS)\n" 834 "\t$(DELIVER)\n" 835 ); 836 aMakefile.WriteLine( sDeliverTarget ); 837 } 838 839 if ( bMakefileMk ) { 840 ByteString sInclude( 841 "# \n" 842 "# local makefile\n" 843 "# \n" 844 "\n" 845 ".INCLUDE : makefile.mk\n" 846 ); 847 848 if ( nDepth != 1 ) 849 sInclude += ByteString( 850 "\n" 851 "all_rc_target: ALLTAR\n" 852 ); 853 854 aMakefile.WriteLine( sInclude ); 855 } 856 857 ByteString sComment( 858 "# \n" 859 "# single directory targets for\n" 860 "# dependency handling between directories\n" 861 "# \n" 862 ); 863 aMakefile.WriteLine( sComment ); 864 865 for ( sal_uIntPtr i = 0; i < pSubDirectories->Count(); i++ ) { 866 ByteString sTarget( 867 (( SourceDirectory * )pSubDirectories->GetObject( i ))-> 868 GetTarget() 869 ); 870 if ( sTarget.Len()) 871 aMakefile.WriteLine( sTarget ); 872 } 873 874 ByteString sFooter( 875 "\n" 876 ); 877 if ( !bMakefileMk ) { 878 sFooter += ByteString( 879 "# \n" 880 "# central target makefile\n" 881 "# \n" 882 "\n" 883 ); 884 if ( nDepth != 0 ) { 885 sFooter += ByteString( 886 ".INCLUDE : target.mk\n" 887 ); 888 } 889 else { 890 sFooter += ByteString( 891 ".IF \"$(checkout)\"==\"\"\n" 892 ".INCLUDE : target.mk\n" 893 ".ENDIF\t#\"$(checkout)\"==\"\"\n" 894 ); 895 } 896 } 897 sFooter += ByteString( 898 "\n" 899 "#*************************************************************************\n" 900 ); 901 aMakefile.WriteLine( sFooter ); 902 903 aMakefile.Close(); 904 905 fprintf( stdout, "\n" ); 906 907 sal_Bool bSuccess = sal_True; 908 if ( bAllChilds ) 909 for ( sal_uIntPtr k = 0; k < pSubDirectories->Count(); k++ ) 910 if ( !(( SourceDirectory * ) pSubDirectories->GetObject( k ))-> 911 CreateRecursiveMakefile( sal_True )) 912 bSuccess = sal_False; 913 914 return bSuccess; 915 } 916 917 // 918 // class SourceDirectoryList 919 // 920 921 /*****************************************************************************/ 922 SourceDirectoryList::~SourceDirectoryList() 923 /*****************************************************************************/ 924 { 925 for ( sal_uIntPtr i = 0; i < Count(); i++ ) 926 delete GetObject( i ); 927 } 928 929 /*****************************************************************************/ 930 SourceDirectory *SourceDirectoryList::Search( 931 const ByteString &rDirectoryName ) 932 /*****************************************************************************/ 933 { 934 sal_uIntPtr nPos = IsString( ( ByteString * ) (&rDirectoryName) ); 935 if ( nPos != LIST_ENTRY_NOTFOUND ) 936 return ( SourceDirectory * ) GetObject( nPos ); 937 938 return NULL; 939 } 940 941 942