xref: /trunk/main/tools/bootstrp/mkcreate.cxx (revision 76f5c358)
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 /*****************************************************************************/
SourceDirectory(const ByteString & rDirectoryName,sal_uInt16 nOperatingSystem,SourceDirectory * pParentDirectory)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 /*****************************************************************************/
~SourceDirectory()78 SourceDirectory::~SourceDirectory()
79 /*****************************************************************************/
80 {
81 	delete pSubDirectories;
82 }
83 
84 /*****************************************************************************/
AddCodedDependency(const ByteString & rCodedIdentifier,sal_uInt16 nOperatingSystems)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 /*****************************************************************************/
AddCodedIdentifier(const ByteString & rCodedIdentifier,sal_uInt16 nOperatingSystems)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 /*****************************************************************************/
GetFullPath()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 /*****************************************************************************/
GetRootDirectory()160 SourceDirectory *SourceDirectory::GetRootDirectory()
161 /*****************************************************************************/
162 {
163 	if ( !pParent )
164 		return this;
165 
166 	return pParent->GetRootDirectory();
167 }
168 
169 /*****************************************************************************/
GetSubDirectory(const ByteString & rDirectoryPath,sal_uInt16 nOperatingSystem)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 /*****************************************************************************/
GetDirectory(const ByteString & rDirectoryName,sal_uInt16 nOperatingSystem)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 /*****************************************************************************/
Insert(const ByteString & rDirectoryName,sal_uInt16 nOperatingSystem)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 /*****************************************************************************/
ResolvesDependency(CodedDependency * pCodedDependency)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 /*****************************************************************************/
ResolveDependencies()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 /*****************************************************************************/
GetTarget()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 /*****************************************************************************/
GetSubDirsTarget()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 /*****************************************************************************/
GetOSType(const ByteString & sDependExt)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 /*****************************************************************************/
CreateRootDirectory(const ByteString & rRoot,const ByteString & rVersion,sal_Bool bAll)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 /*****************************************************************************/
RemoveDirectoryTreeAndAllDependencies()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 /*****************************************************************************/
CreateRecursiveMakefile(sal_Bool bAllChilds)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 		"#  Licensed to the Apache Software Foundation (ASF) under one\n"
708 		"#  or more contributor license agreements.  See the NOTICE file\n"
709 		"#  distributed with this work for additional information\n"
710 		"#  regarding copyright ownership.  The ASF licenses this file\n"
711 		"#  to you under the Apache License, Version 2.0 (the\n"
712 		"#  "License"); you may not use this file except in compliance\n"
713 		"#  with the License.  You may obtain a copy of the License at\n"
714 		"#  \n"
715 		"#    http://www.apache.org/licenses/LICENSE-2.0\n"
716 		"#  \n"
717 		"#  Unless required by applicable law or agreed to in writing,\n"
718 		"#  software distributed under the License is distributed on an\n"
719 		"#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n"
720 		"#  KIND, either express or implied.  See the License for the\n"
721 		"#  specific language governing permissions and limitations\n"
722 		"#  under the License.\n"
723 		"#  \n"
724 		"#**************************************************************\n"
725 		"\n"
726 	);
727 	if ( !bMakefileMk ) {
728 		if ( nDepth == 0 ) {
729 		 	sHeader += ByteString(
730 				"\n"
731 				"# \n"
732 				"# mark this makefile as a recursive one\n"
733 				"# \n"
734 				"\n"
735 				"MAKEFILERC=yes\n"
736 				"\n"
737 				"# \n"
738 				"# implementation of cvs checkout\n"
739 				"# \n"
740 				"\n"
741 				".IF \"$(checkout)\"==\"\"\n"
742 				"all_target: ALLTAR\n"
743 				".ELSE\t# \"$(checkout)\"==\"\"\n"
744 				".IF \"$(checkout)\"==\"true\"\n"
745 				"% : $(NULL)\n"
746 				"\t_cvs co $@\n"
747 				".ELSE\t# \"$(checkout)\"==\"true\"\n"
748 				"% : $(NULL)\n"
749 				"\t_cvs co -r$(checkout) $@\n"
750 				".ENDIF\t# \"$(checkout)\"==\"true\"\n"
751 				"all_subdirs : $(RC_SUBDIRS)\n"
752 				".ENDIF\t# \"$(checkout)\"==\"\"\n"
753 			);
754 		}
755 		else {
756 		 	sHeader += ByteString(
757 				"\n"
758 				"# \n"
759 				"# mark this makefile as a recursive one\n"
760 				"# \n"
761 				"\n"
762 				"MAKEFILERC=yes\n"
763 			);
764 			if ( nDepth == 1 )
765 				sHeader += ByteString(
766 					".IF \"$(build_deliver)\"==\"true\"\n"
767 					"all_target:\t\t\\\n"
768 					"\tTG_DELIVER\t\\\n"
769 					"\tALLTAR\n"
770 					".ELSE # \"$(build_deliver)\"==\"true\"\n"
771 					"all_target: ALLTAR\n"
772 					".ENDIF # \"$(build_deliver)\"==\"true\"\n"
773 				);
774 			else
775 				sHeader += ByteString(
776 					"all_target: ALLTAR\n"
777 				);
778 		}
779 	}
780 	else {
781 		if ( nDepth == 1 )
782 			sHeader += ByteString(
783 				".IF \"$(build_deliver)\"==\"true\"\n"
784 				"all_target:\t\t\\\n"
785 				"\tTG_DELIVER\t\\\n"
786 				"\tALLTAR\n"
787 				".ELSE # \"$(build_deliver)\"==\"true\"\n"
788 				"all_target: ALLTAR\n"
789 				".ENDIF # \"$(build_deliver)\"==\"true\"\n"
790 			);
791 	}
792 	sHeader += ByteString(
793 		"\n"
794 		"# \n"
795 		"# macro RC_SUBDIRS handles iteration over\n"
796 		"# all mandatory sub directories\n"
797 		"# \n"
798 	);
799 
800 	aMakefile.WriteLine( sHeader );
801 	aMakefile.WriteLine( GetSubDirsTarget());
802 
803 	if ( nDepth == 0 ) {
804 		ByteString sBootstrapTarget(
805 			"# \n"
806 			"# bootstrap target\n"
807 			"# \n\n"
808 			"bootstrap .PHONY :\n"
809     		"\t@config_office/bootstrap\n\n"
810 		);
811 		aMakefile.WriteLine( sBootstrapTarget );
812 		ByteString sConfigureTarget(
813 			"# \n"
814 			"# configure target\n"
815 			"# \n\n"
816 			"configure .PHONY SETDIR=config_office :\n"
817     		"\t@configure\n"
818 		);
819 		aMakefile.WriteLine( sConfigureTarget );
820 	}
821 	else if ( nDepth == 1 ) {
822 		ByteString sDeliverTarget(
823 			"# \n"
824 			"# deliver target to handle\n"
825 			"# project dependencies\n"
826 			"# \n\n"
827 			"TG_DELIVER : $(RC_SUBDIRS)\n"
828 			"\t$(DELIVER)\n"
829 		);
830 		aMakefile.WriteLine( sDeliverTarget );
831 	}
832 
833 	if ( bMakefileMk ) {
834 		ByteString sInclude(
835 			"# \n"
836 			"# local makefile\n"
837 			"# \n"
838 			"\n"
839 			".INCLUDE : makefile.mk\n"
840 		);
841 
842 		if ( nDepth != 1 )
843 			sInclude += ByteString(
844 				"\n"
845 				"all_rc_target: ALLTAR\n"
846 			);
847 
848 		aMakefile.WriteLine( sInclude );
849 	}
850 
851 	ByteString sComment(
852 		"# \n"
853 		"# single directory targets for\n"
854 		"# dependency handling between directories\n"
855 		"# \n"
856 	);
857 	aMakefile.WriteLine( sComment );
858 
859 	for ( sal_uIntPtr i = 0; i < pSubDirectories->Count(); i++ ) {
860 		ByteString sTarget(
861 			(( SourceDirectory * )pSubDirectories->GetObject( i ))->
862 			GetTarget()
863 		);
864 		if ( sTarget.Len())
865 			aMakefile.WriteLine( sTarget );
866 	}
867 
868 	ByteString sFooter(
869 		"\n"
870 	);
871 	if ( !bMakefileMk ) {
872 		sFooter += ByteString(
873 			"# \n"
874 			"# central target makefile\n"
875 			"# \n"
876 			"\n"
877 		);
878 		if ( nDepth != 0 ) {
879 			sFooter += ByteString(
880 				".INCLUDE : target.mk\n"
881 			);
882 		}
883 		else {
884 			sFooter += ByteString(
885 				".IF \"$(checkout)\"==\"\"\n"
886 				".INCLUDE : target.mk\n"
887 				".ENDIF\t#\"$(checkout)\"==\"\"\n"
888 			);
889 		}
890 	}
891 	sFooter += ByteString(
892 		"\n"
893 		"#*************************************************************************\n"
894 	);
895 	aMakefile.WriteLine( sFooter );
896 
897 	aMakefile.Close();
898 
899 	fprintf( stdout, "\n" );
900 
901 	sal_Bool bSuccess = sal_True;
902 	if ( bAllChilds )
903 		for ( sal_uIntPtr k = 0; k < pSubDirectories->Count(); k++ )
904 			if  ( !(( SourceDirectory * ) pSubDirectories->GetObject( k ))->
905 				CreateRecursiveMakefile( sal_True ))
906 				bSuccess = sal_False;
907 
908 	return bSuccess;
909 }
910 
911 //
912 // class SourceDirectoryList
913 //
914 
915 /*****************************************************************************/
~SourceDirectoryList()916 SourceDirectoryList::~SourceDirectoryList()
917 /*****************************************************************************/
918 {
919 	for ( sal_uIntPtr i = 0; i < Count(); i++ )
920 		delete GetObject( i );
921 }
922 
923 /*****************************************************************************/
Search(const ByteString & rDirectoryName)924 SourceDirectory *SourceDirectoryList::Search(
925 	const ByteString &rDirectoryName )
926 /*****************************************************************************/
927 {
928 	sal_uIntPtr nPos = IsString( ( ByteString * ) (&rDirectoryName) );
929 	if ( nPos != LIST_ENTRY_NOTFOUND )
930 		return ( SourceDirectory * ) GetObject( nPos );
931 
932 	return NULL;
933 }
934 
935 
936