2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 CompilationUnitSupportCode::CompilationUnitSupportCode ( const Project
& project
)
31 CompilationUnitSupportCode::~CompilationUnitSupportCode ()
36 CompilationUnitSupportCode::Generate ( bool verbose
)
38 for( std::map
<std::string
, Module
*>::const_iterator p
= project
.modules
.begin(); p
!= project
.modules
.end(); ++ p
)
40 GenerateForModule ( *p
->second
,
46 CompilationUnitSupportCode::GenerateForModule ( Module
& module
,
51 printf ( "\nGenerating compilation unit support code for %s",
52 module
.name
.c_str () );
55 for ( size_t i
= 0; i
< module
.non_if_data
.compilationUnits
.size () ; i
++ )
57 CompilationUnit
& compilationUnit
= *module
.non_if_data
.compilationUnits
[i
];
58 if ( compilationUnit
.GetFiles ().size () <= 1 )
60 WriteCompilationUnitFile ( module
, compilationUnit
);
65 CompilationUnitSupportCode::GetCompilationUnitFilename ( Module
& module
,
66 CompilationUnit
& compilationUnit
)
68 return NormalizeFilename ( Environment::GetIntermediatePath () + sSep
+ compilationUnit
.name
);
72 CompilationUnitSupportCode::WriteCompilationUnitFile ( Module
& module
,
73 CompilationUnit
& compilationUnit
)
78 buf
= (char*) malloc ( 512*1024 );
80 throw OutOfMemoryException ();
83 s
= s
+ sprintf ( s
, "/* This file is automatically generated. */\n" );
84 s
= s
+ sprintf ( s
, "#define ONE_COMPILATION_UNIT\n" );
86 for ( size_t i
= 0; i
< compilationUnit
.GetFiles ().size () ; i
++ )
88 const File
& file
= *compilationUnit
.GetFiles ()[i
];
89 s
= s
+ sprintf ( s
, "#include <%s/%s>\n", ChangeSeparator ( file
.file
.relative_path
, '\\', '/' ).c_str (), file
.file
.name
.c_str () );
92 s
= s
+ sprintf ( s
, "\n" );
94 FileSupportCode::WriteIfChanged ( buf
, GetCompilationUnitFilename ( module
, compilationUnit
) );