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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 CompilationUnitSupportCode::CompilationUnitSupportCode ( const Project
& project
)
31 CompilationUnitSupportCode::~CompilationUnitSupportCode ()
36 CompilationUnitSupportCode::Generate ( bool verbose
)
38 for ( size_t i
= 0; i
< project
.modules
.size (); i
++ )
40 GenerateForModule ( *project
.modules
[i
],
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
.files
.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
.files
.size () ; i
++ )
88 File
& file
= *compilationUnit
.files
[i
];
89 s
= s
+ sprintf ( s
, "#include <%s>\n", ChangeSeparator ( file
.name
, '\\', '/' ).c_str () );
92 s
= s
+ sprintf ( s
, "\n" );
94 FileSupportCode::WriteIfChanged ( buf
, GetCompilationUnitFilename ( module
, compilationUnit
) );