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.
18 #include "../../pch.h"
26 ProxyMakefile::ProxyMakefile ( const Project
& project
)
31 ProxyMakefile::~ProxyMakefile ()
36 ProxyMakefile::GenerateProxyMakefile ( const Module
& module
)
38 return module
.output
->directory
== OutputDirectory
;
42 ProxyMakefile::GenerateProxyMakefiles ( bool verbose
,
45 for ( std::map
<std::string
, Module
*>::const_iterator p
= project
.modules
.begin (); p
!= project
.modules
.end (); ++ p
)
47 Module
& module
= *p
->second
;
48 if ( !module
.enabled
)
50 if ( !GenerateProxyMakefile ( module
) )
52 GenerateProxyMakefileForModule ( module
,
59 ProxyMakefile::GeneratePathToParentDirectory ( int numberOfParentDirectories
)
62 for ( int i
= 0; i
< numberOfParentDirectories
; i
++ )
72 ProxyMakefile::GetPathToTopDirectory ( Module
& module
)
74 int numberOfDirectories
= 1;
75 string basePath
= module
.output
->relative_path
;
76 for ( size_t i
= 0; i
< basePath
.length (); i
++ )
78 if ( basePath
[i
] == cSep
)
79 numberOfDirectories
++;
81 return GeneratePathToParentDirectory ( numberOfDirectories
);
85 ProxyMakefile::GenerateProxyMakefileForModule ( Module
& module
,
94 printf ( "\nGenerating proxy makefile for %s",
95 module
.name
.c_str () );
99 string pathToTopDirectory
;
100 if ( outputTree
.length () > 0 )
102 base
= outputTree
+ sSep
+ module
.output
->relative_path
;
103 pathToTopDirectory
= working_directory
;
107 base
= module
.output
->relative_path
;
108 pathToTopDirectory
= GetPathToTopDirectory ( module
);
110 string proxyMakefile
= NormalizeFilename ( base
+ sSep
+ "GNUmakefile" );
111 string defaultTarget
= module
.name
;
113 buf
= (char*) malloc ( 10*1024 );
115 throw OutOfMemoryException ();
118 s
= s
+ sprintf ( s
, "# This file is automatically generated.\n" );
119 s
= s
+ sprintf ( s
, "\n" );
120 s
= s
+ sprintf ( s
, "TOP = %s\n", pathToTopDirectory
.c_str () );
121 s
= s
+ sprintf ( s
, "DEFAULT = %s\n", defaultTarget
.c_str () );
122 s
= s
+ sprintf ( s
, "include $(TOP)/proxy.mak\n" );
124 FileSupportCode::WriteIfChanged ( buf
, proxyMakefile
, true );