]>
git.saurik.com Git - wxWidgets.git/blob - utils/makegen/makegen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils/makegen/makegen.cpp
3 // Purpose: a tool to generate the makefiles for samples
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #error "This is a console mode program and must be linked with wxBase."
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 #include <wx/string.h>
30 #include <wx/textfile.h>
31 #include <wx/datetime.h>
33 // ----------------------------------------------------------------------------
34 // the application class
35 // ----------------------------------------------------------------------------
37 class MakeGenApp
: public wxApp
40 virtual bool OnInit();
45 void Usage(); // give the usage message
47 bool GenerateMakefile(const wxString
& filename
);
49 wxString m_sampleName
, // the name of the sample
50 m_dirname
, // directory with the template files
51 m_outputDir
; // directory to output files to
54 IMPLEMENT_APP(MakeGenApp
);
56 // ============================================================================
58 // ============================================================================
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 void MakeGenApp::Usage()
66 wxLogError(_T("Usage: %s [-o output_dir] sample_name"), argv
[0]);
69 bool MakeGenApp::GenerateMakefile(const wxString
& filename
)
71 wxTextFile
fileIn(m_dirname
+ filename
);
74 wxLogError(_T("Makefile '%s' couldn't be generated."), filename
.c_str());
79 wxFFile
fileOut(m_outputDir
+ filename
, "w");
80 if ( !fileOut
.IsOpened() )
82 wxLogError(_T("Makefile '%s' couldn't be generated."), filename
.c_str());
87 size_t count
= fileIn
.GetLineCount();
88 for ( size_t n
= 0; n
< count
; n
++ )
90 wxString line
= fileIn
[n
];
92 line
.Replace(_T("#DATE"), wxDateTime::Now().FormatISODate());
93 line
.Replace(_T("#NAME"), m_sampleName
);
95 fileOut
.Write(line
+ _T('\n'));
101 bool MakeGenApp::OnInit()
103 // parse the cmd line
104 if ( (argc
== 1) || (argc
== 3) ||
105 (argv
[1][0] == _T('-') && argv
[1][1] != _T('o')) ||
106 (argc
== 2 && argv
[1][0] == _T('-')) )
113 m_sampleName
= argv
[1];
114 if ( m_sampleName
[0u] == _T('-') )
116 m_outputDir
= argv
[2];
117 if ( !wxEndsWithPathSeparator(m_outputDir
) )
119 m_outputDir
+= _T('/');
122 m_sampleName
= argv
[3];
128 int MakeGenApp::OnRun()
130 m_dirname
= wxGetenv(_T("MAKEGEN_PATH"));
133 m_dirname
= wxGetCwd();
136 if ( !wxEndsWithPathSeparator(m_dirname
) )
138 m_dirname
+= _T('/');
141 m_dirname
+= _T("templates");
143 wxDir
dir(m_dirname
);
145 m_dirname
+= _T('/');
147 if ( !dir
.IsOpened() )
149 wxLogError(_T("Aborting generating the makefiles."));
156 bool cont
= dir
.GetFirst(&filename
, _T("?akefile.*"), wxDIR_FILES
);
161 if ( !GenerateMakefile(filename
) )
163 wxLogError(_T("Error during makefile generation, aborting."));
168 cont
= dir
.GetNext(&filename
);
173 wxLogVerbose(_T("Successfully generated %u makefiles in '%s'."),
174 n
, m_outputDir
.c_str());
178 wxLogWarning(_T("No makefiles found: either set MAKEGEN_PATH variable "
179 "or run the program from its directory"));