3
* @file CreateLibrary.cxx
4
* @brief Implementation of the method AnalyticalFunctionCompiler::CreateLibrary(),
5
* which attempts to compile the library associated to the external code.
6
* the needed external code.
8
* (C) Copyright 2005-2007 EDF-EADS-Phimeca
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License.
15
* This library is distributed in the hope that it will be useful
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
* @author: $LastChangedBy: dutka $
25
* @date: $LastChangedDate: 2008-06-26 13:50:17 +0200 (jeu, 26 jun 2008) $
26
* Id: $Id: CreateLibrary.cxx 862 2008-06-26 11:50:17Z dutka $
35
#include "AnalyticalFunctionCompiler.hxx"
37
namespace AnalyticalFunctionCompiler
39
/** Generate the binary version of the plugin */
40
/** Need a cleaner implementation! It should produce an autotooled package for the external code, then use it to produce the external code */
41
void AnalyticalFunctionCompiler::createLibrary()
43
std::ostringstream instructionStream;
45
instructionStream << "echo \"Compilation step:\" > /tmp/msg1 && echo >> /tmp/msg1 && ";
47
std::ostringstream commandStream;
48
commandStream << "g++ -I" << OT_INCLUDE_PATH << " " << path_ << name_ << ".cxx -shared -o " << path_ << name_ << ".so -L" << OT_LIB_PATH << "/" << OT_LIB_NAME << " -lOT ";
49
std::string command(commandStream.str());
50
instructionStream << command << " &> /tmp/msg2";
51
std::string compileInstruction(instructionStream.str());
52
if ( system(compileInstruction.c_str()) )
54
std::ostringstream errorStream;
55
errorStream << "echo > /tmp/msg3 && echo \"Formula:\" >> /tmp/msg3 && echo >> /tmp/msg3 && echo \"" << formula_ << "\" >> /tmp/msg3 && echo > /tmp/msg4 && echo \"Source code:\" >> /tmp/msg4 && echo >> /tmp/msg4 && cat /tmp/msg1 /tmp/msg2 /tmp/msg3 /tmp/msg4 " << path_ << name_ << ".cxx > /tmp/msg && rm /tmp/msg1 /tmp/msg2 /tmp/msg3 /tmp/msg4";
56
std::string errorMessage(errorStream.str());
57
system(errorMessage.c_str());
58
system("cat /tmp/msg");
59
std::cout << std::endl << "Compilation command was: " << command << std::endl;
60
exit(BAD_COMPILATION);
64
system("rm /tmp/msg1 /tmp/msg2");
66
} // AnalyticalFunctionCompiler::createLibrary
67
} // namespace AnalyticalFunctionCompiler