summaryrefslogtreecommitdiffstats
path: root/src/tools/gputils/gputils.cpp
blob: 4fa99d1653d233a936256914b5044be45bbe9405 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org>             *
 *   Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr>           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#include "gputils.h"

#include <tqregexp.h>

#include "gputils_compile.h"
#include "gputils_config.h"
#include "devices/pic/pic/pic_memory.h"
#include "common/global/process.h"
#include "gputils_generator.h"

//----------------------------------------------------------------------------
TQString GPUtils::Base::baseExecutable(bool, Tool::OutputExecutableType) const
{
  switch (_category.type()) {
    case Tool::Category::Assembler: return "gpasm";
    case Tool::Category::Linker:    return "gplink";
    case Tool::Category::Librarian: return "gplib";
    default: break;
  }
  return TQString();
}

bool GPUtils::Base::checkExecutableResult(bool withWine, TQStringList &lines) const
{
  return ( lines.count()>0 && lines[0].startsWith(baseExecutable(withWine, Tool::OutputExecutableType::Coff)) );
}

//----------------------------------------------------------------------------
TQString GPUtils::Group::informationText() const
{
  return i18n("<a href=\"%1\">GPUtils</a> is an open-source assembler and linker suite.<br>").arg("http://gputils.sourceforge.net");
}

Tool::Group::BaseData GPUtils::Group::baseFactory(Tool::Category category) const
{
  if ( category==Tool::Category::Assembler ) return BaseData(new ::GPUtils::Base, Both);
  if ( category==Tool::Category::Linker || category==Tool::Category::Librarian ) return BaseData(new ::GPUtils::Base, ProjectOnly);
  return BaseData();
}

PURL::Directory GPUtils::Group::autodetectDirectory(Compile::DirectoryType type, const PURL::Directory &execDir, bool withWine) const
{
  switch (type.type()) {
    case Compile::DirectoryType::LinkerScript: {
      TQString exec = execDir.path() + base(Tool::Category::Linker)->baseExecutable(withWine, Tool::OutputExecutableType::Coff);
      ::Process::StringOutput process;
      process.setup(exec, "-h", withWine);
      if ( ::Process::runSynchronously(process, ::Process::Start, 1000)!=::Process::Exited ) return PURL::Directory();
      TQString s = process.sout() + process.serr();
      TQRegExp re(".*Default linker script path ([^\\n]*)\\n.*");
      if ( !re.exactMatch(s) ) return PURL::Directory();
      return PURL::Directory(re.cap(1));
    }
    case Compile::DirectoryType::Header: {
      TQString exec = execDir.path() + base(Tool::Category::Assembler)->baseExecutable(withWine, Tool::OutputExecutableType::Coff);
      ::Process::StringOutput process;
      process.setup(exec, "-h", withWine);
      if ( ::Process::runSynchronously(process, ::Process::Start, 1000)!=::Process::Exited ) return PURL::Directory();
      TQString s = process.sout() + process.serr();
      TQRegExp re(".*Default header file path ([^\\n]*)\\n.*");
      if ( !re.exactMatch(s) ) return PURL::Directory();
      return PURL::Directory(re.cap(1));
    }
    case Compile::DirectoryType::Executable:
    case Compile::DirectoryType::Library:
    case Compile::DirectoryType::Source:
    case Compile::DirectoryType::Nb_Types: break;
  }
  return PURL::Directory();
}

Compile::Process *GPUtils::Group::processFactory(const Compile::Data &data) const
{
  switch (data.category.type()) {
    case Tool::Category::Assembler:
      if (data.project) return new GPUtils::AssembleProjectFile;
      return new GPUtils::AssembleStandaloneFile;
    case Tool::Category::Linker:
      Q_ASSERT(data.project);
      return new GPUtils::LinkProject;
    case Tool::Category::Librarian:
      Q_ASSERT(data.project);
      return new GPUtils::LibraryProject;
    default: break;
  }
  Q_ASSERT(false);
  return 0;
}

Compile::Config *GPUtils::Group::configFactory(::Project *project) const
{
  return new Config(project);
}

Tool::SourceGenerator *GPUtils::Group::sourceGeneratorFactory() const
{
  return new SourceGenerator;
}