~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to wrappers/AnalyticalFunctionCompiler/src/CreateLibrary.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-11-18 06:32:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118063222-pa0qncclrerrqkg2
Tags: 0.12.2-1
* New upstream release
* Bug fix: "New upstream release available (0.12.2)", thanks to Jerome
  Robert (Closes: #506005).
* Applied patch by J. Robert.
* debian/control: build-depends on libxml2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//                                               -*- C++ -*-
2
 
/**
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.
7
 
 *
8
 
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
9
 
 *
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.
14
 
 *
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.
19
 
 *
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
23
 
 *
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 $
27
 
 */
28
 
#include <string>
29
 
#include <sstream>
30
 
#include <iostream>
31
 
#include <list>
32
 
#include <fstream>
33
 
#include <iomanip>
34
 
#include "config.h"
35
 
#include "AnalyticalFunctionCompiler.hxx"
36
 
 
37
 
namespace AnalyticalFunctionCompiler
38
 
{
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()
42
 
  {
43
 
    std::ostringstream instructionStream;
44
 
 
45
 
    instructionStream << "echo \"Compilation step:\" > /tmp/msg1 && echo >> /tmp/msg1 && ";
46
 
 
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()) )
53
 
      {
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);
61
 
      }
62
 
    else
63
 
      {
64
 
        system("rm /tmp/msg1 /tmp/msg2");
65
 
      }
66
 
  } // AnalyticalFunctionCompiler::createLibrary
67
 
} // namespace AnalyticalFunctionCompiler