Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/lang/compilation.h

Go to the documentation of this file.
00001 //  Copyright (C) 2001--2002  Petter Urkedal (petter.urkedal@matfys.lth.se)
00002 //
00003 //  This file is free software; you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation; either version 2 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  This file is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with this program; if not, write to the Free Software
00015 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 //  As a special exception, you may use this file as part of a free
00018 //  software library without restriction.  Specifically, if other files
00019 //  instantiate templates or use macros or inline functions from this
00020 //  file, or you compile this file and link it with other files to
00021 //  produce an executable, this file does not by itself cause the
00022 //  resulting executable to be covered by the GNU General Public
00023 //  License.  This exception does not however invalidate any other
00024 //  reasons why the executable file might be covered by the GNU General
00025 //  Public License.
00026 //
00027 //  $Id: compilation.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00028 
00029 //  !! Experimental.  Interface may change !!
00030 
00031 #ifndef MORE_LANG_COMPILATION_H
00032 #define MORE_LANG_COMPILATION_H
00033 
00034 #include <string>
00035 #include <list>
00036 #include <map>
00037 #include <more/io/fwd.h>
00038 
00039 namespace more {
00040 namespace lang {
00041 
00042   /** An enum type to identify a programming language. */
00043   enum lang_t
00044   {
00045       // NB. Sync with lang_info in compilation.cc.
00046 
00047       lang_undefined,
00048 
00049       // These are supported by compilation.
00050       lang_c,           // C
00051       lang_cxx,         // C++
00052 
00053       // The following are not used here (at least yet).
00054       lang_scheme,      // Scheme
00055       lang_java,        // Java
00056       lang_shell,       // Bourne shell or bash
00057       lang_perl,        // Perl
00058       lang_f77,         // FORTRAN 77
00059       lang_f90,         // FORTRAN 90
00060       // ... extend if needed
00061 
00062       lang_end
00063   };
00064 
00065   std::string language_name(lang_t lang);
00066 
00067   std::string header_file_name(std::string const& bname, lang_t lang,
00068                                std::string const& dir = ".");
00069   std::string source_file_name(std::string const& bname, lang_t lang,
00070                                std::string const& dir = ".");
00071   std::string c_header_file_name(std::string const& bname,
00072                                  std::string const& dir = ".");
00073   std::string cxx_header_file_name(std::string const& bname,
00074                                    std::string const& dir = ".");
00075   std::string c_source_file_name(std::string const& bname,
00076                                  std::string const& dir = ".");
00077   std::string cxx_source_file_name(std::string const& bname,
00078                                    std::string const& dir = ".");
00079   std::string ltobject_file_name(std::string const& bname,
00080                                  std::string const& dir = ".");
00081   std::string program_file_name(std::string const& bname,
00082                                 std::string const& dir = ".");
00083   std::string library_file_name(std::string const& bname,
00084                                 std::string const& dir = ".");
00085   std::string dlopen_file_name(std::string const& bname,
00086                                std::string const& dir = ".");
00087 
00088   /** The state of a C/C++ compilation and linkage. */
00089   struct compilation
00090   {
00091       enum target_type
00092       {
00093           target_none, target_program,
00094           target_library, target_library_dlopen
00095       };
00096       typedef unsigned long version_type;
00097 
00098     private:
00099       struct source_entry
00100       {
00101           source_entry() {}
00102           source_entry(lang_t lang, double t, bool rebuild_p)
00103               : m_lang(lang), m_version(t), m_rebuild_p(rebuild_p) {}
00104           void sync(io::syncstream&);
00105 
00106           lang_t m_lang;
00107           double m_version;
00108           bool m_rebuild_p;
00109       };
00110       typedef std::map<std::string, source_entry> source_entry_container;
00111       typedef source_entry_container::iterator source_entry_iterator;
00112       typedef source_entry_container::const_iterator source_entry_const_iterator;
00113 
00114     public:
00115       compilation(std::string const& srcdir,
00116                   std::string const& builddir);
00117 
00118       compilation(std::string const& srcdir,
00119                   std::string const& builddir,
00120                   std::string const& includedir,
00121                   std::string const& libdir);
00122 
00123       // Directories
00124       std::string const& src_dir() const { return m_srcdir; }
00125       std::string const& build_dir() const { return m_builddir; }
00126       std::string const& include_dir() const { return m_includedir; }
00127       std::string const& lib_dir() const { return m_libdir; }
00128 
00129       // Insert Sources
00130 //       std::string insert_cxx_header(std::string const& bname);
00131 //       std::string insert_c_header(std::string const& bname);
00132 
00133       std::string insert_header(std::string const& bname, lang_t lang);
00134 
00135 //       std::string insert_cxx_source(std::string const& bname);
00136 //       std::string insert_c_source(std::string const& bname);
00137 
00138       /** Insert a C or C++ source file.  \a version is the time or
00139           version of the file.  The file will be compiled if the there
00140           is no file with this name already, and recompiled if the
00141           version is newer than that of the existing file.  Use \c
00142           version==0 to never rebuild.  Returns the full path to the
00143           file, or an empty string if the file shall not be
00144           (re)compiled. */
00145       std::string insert_source(std::string const& bname, lang_t lang,
00146                                 version_type version);
00147       /** Insert a C or C++ source file.  Same as the overloaded
00148           function, except this will always assume the inserted file
00149           is new and rebuild. */
00150       std::string insert_source(std::string const& bname, lang_t lang);
00151 
00152       std::string insert_libadd(std::string const& bname);
00153 
00154       // Insert Flags
00155       void append_cppflags(std::string const& cppflags);
00156       void append_cflags(std::string const& cxxflags);
00157       void append_cxxflags(std::string const& cflags);
00158       void append_ldflags(std::string const& ldflags);
00159 
00160       // Set Target
00161       void set_target_program(std::string const& bname);
00162       void set_target_library(std::string const& bname, bool module_p);
00163 
00164       // Get Target Names
00165       std::string program_file_name() const { return m_target; }
00166       std::string library_file_name() const { return m_target; }
00167 
00168       // Take Action
00169       bool make_all();
00170       bool make_install();
00171 
00172       // Versioning
00173       void set_interface_added() { m_interface_added = 1; }
00174       void set_interface_changed() { m_interface_changed = 1; }
00175 
00176     private:
00177       bool check_cache();
00178 
00179       bool libtool(std::string const& cmd, char const* mode);
00180       bool libtool_compile(std::string const& cmd)
00181       {
00182           return libtool(cmd, "compile");
00183       }
00184       bool libtool_link(std::string const& cmd)
00185       {
00186           return libtool(cmd, "link");
00187       }
00188 
00189       void sync_state(io::syncstream&);
00190 
00191       typedef std::list<std::string> string_list;
00192 
00193       std::string m_srcdir;
00194       std::string m_builddir;
00195       std::string m_includedir;
00196       std::string m_libdir;
00197 
00198       // bnames of sources
00199 //       string_list m_c_headers;
00200 //       string_list m_cxx_headers;
00201       string_list m_headers;
00202       source_entry_container m_sources;
00203 //       string_list m_c_sources;
00204 //       string_list m_cxx_sources;
00205 
00206       std::string m_cppflags;
00207       std::string m_cflags;
00208       std::string m_cxxflags;
00209       std::string m_ldflags;
00210 
00211       target_type m_target_type;
00212       std::string m_target; // full names sans directory
00213       std::string m_target_bname;
00214 
00215       int m_so_version_scheme;
00216       static int const s_so_version_scheme_none = 0;    // don't use versions
00217       static int const s_so_version_scheme_libtool = 1; // libtool logic
00218       static int const s_so_version_scheme_max = 1;
00219       int m_so_version_current; // MSB
00220       int m_so_version_revision;
00221       int m_so_version_age;
00222       unsigned int m_interface_added : 1;
00223       unsigned int m_interface_changed : 1;
00224   };
00225 
00226 }}
00227 
00228 #endif

Generated on Sat Sep 7 19:11:17 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.