mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
umk: CCJ support
git-svn-id: svn://ultimatepp.org/upp/trunk@15987 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
1f2cefbb78
commit
2e0a930119
8 changed files with 341 additions and 27 deletions
|
|
@ -91,6 +91,7 @@ public:
|
|||
void Clean();
|
||||
void RebuildAll();
|
||||
void SaveMakeFile(const String& fn, bool exporting);
|
||||
void SaveCCJ(const String& fn, bool exporting);
|
||||
|
||||
MakeBuild();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,16 @@ String BrcToC(CParser& binscript, String basedir);
|
|||
|
||||
Vector<String> SvnInfo(const String& package);
|
||||
|
||||
String MakeIdent(const char *name);
|
||||
|
||||
struct CppBuilder : Builder {
|
||||
virtual String GetTargetExt() const;
|
||||
virtual void CleanPackage(const String& package, const String& outdir);
|
||||
|
||||
const Workspace& wspc;
|
||||
Time targettime;
|
||||
Vector<String> CFLAGS;
|
||||
Vector<String> CXXFLAGS;
|
||||
|
||||
String GetSharedLibPath(const String& package) const;
|
||||
int AllocSlot();
|
||||
|
|
@ -57,6 +61,9 @@ struct CppBuilder : Builder {
|
|||
const Vector<String>& all_uses, const Vector<String>& all_libraries,
|
||||
const Index<String>& common_config, bool exporting);
|
||||
|
||||
virtual void AddCCJ(MakeFile& mfinfo, String package,
|
||||
const Index<String>& common_config, bool exporting, bool last_ws);
|
||||
|
||||
CppBuilder() : wspc(GetIdeWorkspace()) {}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ file
|
|||
Builders.h options(BUILDER_OPTION) PCH,
|
||||
CppBuilder.cpp,
|
||||
MakeFile.cpp,
|
||||
CCJ.cpp,
|
||||
coff.h,
|
||||
Builders readonly separator,
|
||||
GccBuilder.cpp,
|
||||
|
|
|
|||
272
uppsrc/ide/Builders/CCJ.cpp
Normal file
272
uppsrc/ide/Builders/CCJ.cpp
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
#include "Builders.h"
|
||||
|
||||
inline
|
||||
String SString(const String& s) {
|
||||
if (s.Find(' ') >= 0)
|
||||
return "\"" << s << "\"";
|
||||
return s;
|
||||
}
|
||||
|
||||
inline
|
||||
String SAppend(String l, const String& r) {
|
||||
return l << SString(r);
|
||||
}
|
||||
|
||||
void CppBuilder::AddCCJ(
|
||||
MakeFile& makefile,
|
||||
String package,
|
||||
const Index<String>& common_config,
|
||||
bool exporting,
|
||||
bool last_ws)
|
||||
{
|
||||
const char* eol = "\n";
|
||||
const char* tab = "\t";
|
||||
|
||||
String packagepath = PackagePath(package);
|
||||
Package pkg;
|
||||
pkg.Load(packagepath);
|
||||
String packagedir = GetFileFolder(packagepath);
|
||||
Vector<String> src = GetUppDirs();
|
||||
for(int i = 0; i < src.GetCount(); i++)
|
||||
src[i] = UnixPath(src[i]);
|
||||
|
||||
bool main = HasFlag("MAIN");
|
||||
bool is_shared = HasFlag("SO");
|
||||
bool libout = !main && !HasFlag("NOLIB");
|
||||
bool win32 = HasFlag("WIN32");
|
||||
|
||||
String pack_ident = MakeIdent(package);
|
||||
Vector<String> macdef;
|
||||
String objext = (HasFlag("MSC") || HasFlag("EVC") ? ".obj" : ".o");
|
||||
|
||||
macdef.Append(Macro);
|
||||
|
||||
Vector<String> x(config.GetKeys(), 1);
|
||||
Sort(x);
|
||||
for(int i = 0; i < x.GetCount(); i++) {
|
||||
if(common_config.Find(x[i]) < 0) {
|
||||
String str;
|
||||
str << "-Dflag" << x[i];
|
||||
macdef << str;
|
||||
}
|
||||
x[i] = InitCaps(x[i]);
|
||||
}
|
||||
|
||||
makefile.outdir << outdir << "/";
|
||||
|
||||
if(main) {
|
||||
Vector<String> flags;
|
||||
if(HasFlag("DEBUG"))
|
||||
flags << "-D_DEBUG" << debug_options;
|
||||
else
|
||||
flags << release_options;
|
||||
if(HasFlag("DEBUG_MINIMAL"))
|
||||
flags << "-ggdb" << "-g1";
|
||||
if(HasFlag("DEBUG_FULL"))
|
||||
flags << "-ggdb" << "-g2";
|
||||
if(is_shared && !win32)
|
||||
flags << "-fPIC";
|
||||
flags.Append(GatherV(pkg.option, config.GetKeys()));
|
||||
|
||||
CFLAGS = clone(flags);
|
||||
CXXFLAGS = pick(flags);
|
||||
|
||||
CFLAGS << c_options;
|
||||
CXXFLAGS << cpp_options;
|
||||
}
|
||||
|
||||
// String cmplr = Sys("which " + compiler);
|
||||
// cmplr.TrimEnd("\n");
|
||||
String cmplr = compiler;
|
||||
|
||||
const String inc_outdir = SAppend("-I", makefile.outdir);
|
||||
for(int count = pkg.GetCount(), last = count - 1, i = 0; i < count; i++)
|
||||
if(!pkg[i].separator) {
|
||||
String gop = Gather(pkg[i].option, config.GetKeys());
|
||||
String fn = SourcePath(package, pkg[i]);
|
||||
String ext = ToLower(GetFileExt(fn));
|
||||
bool isc = ext == ".c";
|
||||
const bool ish = ext == ".h";
|
||||
const bool isrc = (ext == ".rc" && HasFlag("WIN32"));
|
||||
const bool iscpp = (ext == ".cpp" || ext == ".cc" || ext == ".cxx");
|
||||
const bool ishpp = (ext == ".hpp" || ext == ".hh" || ext == ".hxx");
|
||||
const bool isicpp = (ext == ".icpp");
|
||||
if(ext == ".brc") {
|
||||
isc = true;
|
||||
fn << "c";
|
||||
}
|
||||
if(isc || ish || isrc || iscpp || ishpp || isicpp) {
|
||||
String outfile;
|
||||
const String srcfile = SString(fn);
|
||||
outfile << makefile.outdir << AdjustMakePath(GetFileTitle(fn));
|
||||
if (isrc)
|
||||
outfile << "_rc";
|
||||
else if (ish || ishpp)
|
||||
outfile << "_hpp";
|
||||
else
|
||||
outfile << "_cpp";
|
||||
outfile << objext;
|
||||
outfile = SString(outfile);
|
||||
|
||||
#if 0
|
||||
Json j;
|
||||
JsonArray ja;
|
||||
ja << cmplr;
|
||||
ja << "-c";
|
||||
ja << "-x";
|
||||
if (isc)
|
||||
ja << "c" << CFLAGS;
|
||||
else
|
||||
ja << "c++" << CXXFLAGS;
|
||||
ja << CINC ;
|
||||
ja << inc_outdir;
|
||||
ja << macdef;
|
||||
// ja << gop; // ???
|
||||
ja << srcfile << "-o" << outfile;
|
||||
// j("arguments", ja)("directory", GetFileFolder(fn))("file", GetFileName(fn));
|
||||
// j("arguments", ja)("directory", GetFileFolder(fn))("file", fn);
|
||||
j("arguments", ja)("directory", SString(GetFileFolder(fn)))("file", srcfile);
|
||||
makefile.rules << tab << j;
|
||||
if (i == last && last_ws)
|
||||
makefile.rules << eol;
|
||||
else
|
||||
makefile.rules << "," << eol;
|
||||
#else
|
||||
Json j;
|
||||
String ja;
|
||||
ja << cmplr;
|
||||
ja << " -c";
|
||||
ja << " -x";
|
||||
if (isc)
|
||||
ja << " c " << Join(CFLAGS, " ");
|
||||
else
|
||||
ja << " c++ " << Join(CXXFLAGS, " ");
|
||||
MergeWith(ja, " ", Join(CINC, " "));
|
||||
MergeWith(ja, " ", inc_outdir);
|
||||
MergeWith(ja, " ", Join(macdef, " "));
|
||||
ja << ' ' << srcfile << " -o" << outfile;
|
||||
j("command", ja)("directory", SString(GetFileFolder(fn)))("file", srcfile);
|
||||
makefile.rules << tab << j;
|
||||
if (i == last && last_ws)
|
||||
makefile.rules << eol;
|
||||
else
|
||||
makefile.rules << "," << eol;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MakeBuild::SaveCCJ(const String& fn, bool exporting)
|
||||
{
|
||||
const char* eol = "\n";
|
||||
const char* tab = "\t";
|
||||
|
||||
BeginBuilding(true);
|
||||
|
||||
VectorMap<String, String> bm = GetMethodVars(method);
|
||||
Host host;
|
||||
CreateHost(host, false, false);
|
||||
One<Builder> b = CreateBuilder(&host);
|
||||
|
||||
if(!b)
|
||||
return;
|
||||
|
||||
const TargetMode& tm = GetTargetMode();
|
||||
|
||||
String makefile;
|
||||
|
||||
Vector<String> uppdirs = GetUppDirs();
|
||||
String uppout = exporting ? GetVar("OUTPUT") : ".cache/upp.out";
|
||||
|
||||
Index<String> allconfig = PackageConfig(GetIdeWorkspace(), 0, bm, mainconfigparam, host, *b);
|
||||
bool win32 = allconfig.Find("WIN32") >= 0;
|
||||
|
||||
Workspace wspc;
|
||||
wspc.Scan(GetMain(), allconfig.GetKeys());
|
||||
|
||||
Index<String> pkg_config;
|
||||
for(int i = 0; i < wspc.GetCount(); i++) {
|
||||
Index<String> modconfig = PackageConfig(wspc, i, bm, mainconfigparam, host, *b);
|
||||
PkgConfig(wspc, modconfig, pkg_config);
|
||||
if(i)
|
||||
for(int a = allconfig.GetCount(); --a >= 0;)
|
||||
if(modconfig.Find(allconfig[a]) < 0)
|
||||
allconfig.Remove(a);
|
||||
}
|
||||
|
||||
makefile << "[" << eol;
|
||||
|
||||
Index<String> oi;
|
||||
if(!exporting)
|
||||
for(int i = 0; i < uppdirs.GetCount(); i++) {
|
||||
String s;
|
||||
s << "-I" << uppdirs[i];
|
||||
oi.FindAdd(s);
|
||||
}
|
||||
|
||||
for(const String& s: pkg_config) {
|
||||
String str;
|
||||
String out;
|
||||
str << "pkg-config --cflags " << s;
|
||||
if (Sys(str, out) < 0)
|
||||
continue;
|
||||
out.TrimEnd("\n");
|
||||
if (out.IsEmpty())
|
||||
continue;
|
||||
Vector<String> l = Split(out, ' ');
|
||||
for(const String& s1: l)
|
||||
oi.FindAdd(s1);
|
||||
}
|
||||
|
||||
Vector<String> includes = SplitDirs(bm.Get("INCLUDE",""));
|
||||
for(int i = 0; i < includes.GetCount(); i++) {
|
||||
String str;
|
||||
str << SAppend("-I", includes[i]);
|
||||
oi.FindAdd(str);
|
||||
}
|
||||
|
||||
for (const String& s: allconfig) {
|
||||
String str;
|
||||
str << "-Dflag" << s;
|
||||
b->Macro << str;
|
||||
}
|
||||
|
||||
String UPPOUT("-I");
|
||||
if (exporting)
|
||||
UPPOUT << "_out/";
|
||||
else
|
||||
UPPOUT << GetMakePath(AdjustMakePath(AppendFileName(uppout, "")), win32);
|
||||
oi.FindAdd(pick(UPPOUT));
|
||||
|
||||
b->CINC.Append(oi.PickKeys());
|
||||
|
||||
String config, rules;
|
||||
|
||||
for(int count = wspc.GetCount(), last = count - 1, i = 0; i < count; i++) {
|
||||
const String package = wspc[i];
|
||||
b->config = PackageConfig(wspc, i, bm, mainconfigparam, host, *b);
|
||||
b->version = tm.version;
|
||||
b->method = method;
|
||||
b->outdir = OutDir(b->config, package, bm);
|
||||
MakeFile mf;
|
||||
b->AddCCJ(mf, package, allconfig, exporting, i == last);
|
||||
config << mf.config;
|
||||
rules << mf.rules;
|
||||
if(i == 0) // main package
|
||||
b->SaveBuildInfo(package);
|
||||
}
|
||||
|
||||
makefile
|
||||
<< config
|
||||
<< rules
|
||||
<< "]"
|
||||
;
|
||||
|
||||
bool sv = ::SaveFile(fn, makefile);
|
||||
if(!exporting) {
|
||||
if(sv)
|
||||
PutConsole(NFormat("%s(1): compile_commands.json generation complete", fn));
|
||||
else
|
||||
PutConsole(NFormat("%s: error writing compile_commands.json", fn));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include "Builders.h"
|
||||
|
||||
static String MakeIdent(const char *name)
|
||||
String MakeIdent(const char *name)
|
||||
{
|
||||
String out;
|
||||
for(; *name; name++)
|
||||
|
|
@ -222,6 +222,17 @@ void CppBuilder::AddMakeFile(MakeFile& makefile, String package,
|
|||
*/
|
||||
}
|
||||
|
||||
JsonArray& operator<<(JsonArray& array, const Vector<String>& v) {
|
||||
for (const String& s: v)
|
||||
array << s;
|
||||
return array;
|
||||
}
|
||||
|
||||
Vector<String>& operator<<(Vector<String>& array, const Vector<String>& v) {
|
||||
array.Append(v);
|
||||
return array;
|
||||
}
|
||||
|
||||
Point CppBuilder::ExtractVersion() const
|
||||
{
|
||||
Point v = Point(Null, Null);
|
||||
|
|
|
|||
|
|
@ -291,6 +291,7 @@ struct CustomStep {
|
|||
|
||||
Vector<String> Combine(const Vector<String>& conf, const char *flags);
|
||||
String Gather(const Array<OptItem>& set, const Vector<String>& conf, bool nospace = false);
|
||||
Vector<String> GatherV(const Array<OptItem>& set, const Vector<String>& conf);
|
||||
|
||||
bool HasFlag(const Vector<String>& conf, const char *flag);
|
||||
|
||||
|
|
@ -456,6 +457,8 @@ struct Builder {
|
|||
FileTime start_time;
|
||||
|
||||
Index<String> pkg_config; // names of packages for pkg-config
|
||||
Vector<String> CINC;
|
||||
Vector<String> Macro;
|
||||
|
||||
VectorMap<String, int> tmpfilei; // for naming automatic response files
|
||||
|
||||
|
|
@ -474,7 +477,10 @@ struct Builder {
|
|||
virtual void AddMakeFile(MakeFile& mfinfo, String package,
|
||||
const Vector<String>& all_uses, const Vector<String>& all_libraries,
|
||||
const Index<String>& common_config, bool exporting) {}
|
||||
virtual void AddCCJ(MakeFile& mfinfo, String package,
|
||||
const Index<String>& common_config, bool exporting, bool last_ws) {}
|
||||
virtual String GetTargetExt() const = 0;
|
||||
virtual void SaveBuildInfo(const String& package) {}
|
||||
|
||||
Builder() { doall = false; main_conf = false; }
|
||||
virtual ~Builder() {}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,14 @@ String Gather(const Array<OptItem>& set, const Vector<String>& conf, bool nospac
|
|||
return s;
|
||||
}
|
||||
|
||||
Vector<String> GatherV(const Array<OptItem>& set, const Vector<String>& conf) {
|
||||
Vector<String> s;
|
||||
for(int i = 0; i < set.GetCount(); i++)
|
||||
if(MatchWhen(set[i].when, conf))
|
||||
s << set[i].text;
|
||||
return s;
|
||||
}
|
||||
|
||||
int GetType(const Vector<String>& conf, const char *flags) {
|
||||
Vector<String> f = SplitFlags(flags);
|
||||
int q = FLAG_UNDEFINED;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ CONSOLE_APP_MAIN
|
|||
ide.makefile_svn_revision = false;
|
||||
bool clean = false;
|
||||
bool makefile = false;
|
||||
bool ccfile = false;
|
||||
bool deletedir = true;
|
||||
int exporting = 0;
|
||||
bool run = false;
|
||||
|
|
@ -107,6 +108,7 @@ CONSOLE_APP_MAIN
|
|||
case 'X': exporting = 2; break;
|
||||
case 'k': deletedir = false; break;
|
||||
case 'u': ide.use_target = true; break;
|
||||
case 'j': ccfile = true; break;
|
||||
case 'M': {
|
||||
makefile = true;
|
||||
if(s[1] == '=') {
|
||||
|
|
@ -232,6 +234,12 @@ CONSOLE_APP_MAIN
|
|||
|
||||
ide.method = m;
|
||||
|
||||
if(ccfile) {
|
||||
ide.SaveCCJ(GetFileDirectory(PackagePath(ide.main)) + "compile_commands.json", false);
|
||||
SetExitCode(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if(clean)
|
||||
ide.Clean();
|
||||
if(exporting) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue