added compile_commands.json
This commit is contained in:
12
fpc/Makefile
12
fpc/Makefile
@@ -4,10 +4,16 @@ FPC_FILES := main.cpp library/runner.cpp library/helper.cpp library/c.cpp librar
|
||||
CC = clang
|
||||
OUTPUT_DIR = fpc
|
||||
|
||||
install:
|
||||
recompile:
|
||||
./fpc build
|
||||
mv fpc_temp fpc
|
||||
cp fpc ../build/tools/fpc
|
||||
|
||||
../build/tools:
|
||||
mkdir -p ../build/tools
|
||||
|
||||
minimal: $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) ../build/tools
|
||||
$(CC) -g -rdynamic $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) -I../public -Ipublic -lc -lstdc++ -o $(OUTPUT_DIR)
|
||||
install: $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) ../build/tools
|
||||
$(CC) -g -rdynamic $(TIER0_FILES) $(TIER1_FILES) $(FPC_FILES) -I../public -Ipublic -lc -lstdc++ -o $(OUTPUT_DIR)
|
||||
./fpc build
|
||||
mv fpc_temp fpc
|
||||
cp fpc ../build/tools/fpc
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "public/c.h"
|
||||
#include "public/ld.h"
|
||||
#include "public/c.h"
|
||||
#include "public/helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "signal.h"
|
||||
|
||||
@@ -37,9 +36,10 @@ int build_fpc()
|
||||
compileProject.includeDirectories = g_IncludeDirectories;
|
||||
ldProject = compileProject.Compile();
|
||||
|
||||
ldProject.Link();
|
||||
CUtlString outputProject = ldProject.Link();
|
||||
|
||||
IFileSystem2::MakeDirectory("../build/tools");
|
||||
IFileSystem2::CopyFile("fpc_temp", outputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "helper.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "libgen.h"
|
||||
#include <cstdio>
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
@@ -54,9 +55,33 @@ CLDProject CCProject::Compile()
|
||||
proj.objects.AppendTail((CObject){szOutputFile});
|
||||
|
||||
ClangFile_t cfile = {};
|
||||
cfile.m_szName = m_szName;
|
||||
cfile.m_szName = file;
|
||||
cfile.m_szArguments = args;
|
||||
g_clangFiles.AppendTail(cfile);
|
||||
}
|
||||
return proj;
|
||||
}
|
||||
|
||||
void CCProject::GenerateCompileCommands()
|
||||
{
|
||||
FILE* f = V_fopen("compile_commands.json", "w");
|
||||
V_fprintf(f, "[\n");
|
||||
uint32_t i = 0;
|
||||
for (auto &file: g_clangFiles)
|
||||
{
|
||||
V_fprintf(f, "\t{\n");
|
||||
V_fprintf(f, "\t\t\"arguments\": [\n");
|
||||
V_fprintf(f, "\t\t\t\"clang\",\n");
|
||||
for (auto &arg: file.m_szArguments)
|
||||
V_fprintf(f, "\t\t\t\"%s\",\n",arg.GetString());
|
||||
|
||||
V_fseek(f, -2, SEEK_CUR);
|
||||
V_fprintf(f, "\n\t\t],\n");
|
||||
V_fprintf(f, "\t\t\"file\": \"%s\",\n", file.m_szName.GetString());
|
||||
V_fprintf(f, "\t\t\"directory\": \"%s\"\n", IFileSystem2::OwnDirectory());
|
||||
V_fprintf(f, "\t},\n");
|
||||
};
|
||||
V_fseek(f, -2, SEEK_CUR);
|
||||
V_fprintf(f, "\n]\n");
|
||||
V_fclose(f);
|
||||
};
|
||||
|
||||
@@ -23,11 +23,25 @@ unsigned int CProject::GenerateProjectHash( void )
|
||||
|
||||
static char path[1024];
|
||||
static ssize_t pathSize = readlink("/proc/self/exe", path, sizeof(path) - 1);
|
||||
static char* pathDir = dirname(path);
|
||||
char *szPathDir = dirname(path);
|
||||
char *szBuildDir = 0;
|
||||
char *IFileSystem2::OwnDirectory()
|
||||
{
|
||||
return pathDir;
|
||||
return szPathDir;
|
||||
};
|
||||
char *IFileSystem2::BuildDirectory()
|
||||
{
|
||||
return szBuildDir;
|
||||
};
|
||||
|
||||
void IFileSystem2::CopyFile( const char *szDestination, const char *szOrigin )
|
||||
{
|
||||
CUtlVector<CUtlString> args = {
|
||||
CUtlString(szOrigin),
|
||||
CUtlString(szDestination),
|
||||
};
|
||||
IRunner::Run("cp", args);
|
||||
}
|
||||
|
||||
void IFileSystem2::MakeDirectory( const char *psz )
|
||||
{
|
||||
|
||||
33
fpc/main.cpp
33
fpc/main.cpp
@@ -1,3 +1,4 @@
|
||||
#include "public/c.h"
|
||||
#include "public/helper.h"
|
||||
#include "public/ld.h"
|
||||
#include "tier0/platform.h"
|
||||
@@ -5,13 +6,18 @@
|
||||
#include "c.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "signal.h"
|
||||
#include "libgen.h"
|
||||
|
||||
CUtlString owndir;
|
||||
int build()
|
||||
{
|
||||
|
||||
extern char *szBuildDir;
|
||||
|
||||
CCProject compileScriptProject = {};
|
||||
compileScriptProject.m_szName = "build";
|
||||
compileScriptProject.files = {"build.cpp"};
|
||||
compileScriptProject.includeDirectories = {"public","../public"};
|
||||
compileScriptProject.includeDirectories = {CUtlString("%s/public",IFileSystem2::OwnDirectory()),CUtlString("%s/public", IFileSystem2::BuildDirectory()), CUtlString("%s/../public",IFileSystem2::OwnDirectory()),CUtlString("%s/../public", IFileSystem2::BuildDirectory())};
|
||||
compileScriptProject.bFPIC = true;
|
||||
CLDProject linkScriptProject = compileScriptProject.Compile();
|
||||
linkScriptProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
@@ -22,6 +28,7 @@ int build()
|
||||
build->m_pMainFn();
|
||||
};
|
||||
Plat_UnloadLibrary(scriptDLL);
|
||||
CCProject::GenerateCompileCommands();
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -42,7 +49,28 @@ void IEngine_Signal(int sig)
|
||||
};
|
||||
|
||||
int main(int c, char **v)
|
||||
{
|
||||
{
|
||||
CUtlString buildcppDir = IFileSystem2::OwnDirectory();
|
||||
owndir = buildcppDir;
|
||||
char *szBuildcppDir = buildcppDir.GetString();
|
||||
findbuild:
|
||||
FILE* file = V_fopen("build.cpp", "rb");
|
||||
if (!file)
|
||||
{
|
||||
dirname(szBuildcppDir);
|
||||
if (buildcppDir=="/")
|
||||
{
|
||||
V_printf("build.cpp not found\n");
|
||||
return 0;
|
||||
}
|
||||
chdir(szBuildcppDir);
|
||||
goto findbuild;
|
||||
} else {
|
||||
V_fclose(file);
|
||||
}
|
||||
extern char *szBuildDir;
|
||||
szBuildDir = szBuildcppDir;
|
||||
|
||||
#ifdef __linux
|
||||
signal(SIGHUP, IEngine_Signal);
|
||||
signal(SIGINT, IEngine_Signal);
|
||||
@@ -54,7 +82,6 @@ int main(int c, char **v)
|
||||
signal(SIGFPE, IEngine_Signal);
|
||||
signal(SIGSEGV, IEngine_Signal);
|
||||
signal(SIGTERM, IEngine_Signal);
|
||||
V_printf("cool\n");
|
||||
#endif
|
||||
ICommandLine::CreateCommandLine(c, v);
|
||||
if (ICommandLine::CheckParam("build"))
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
bool bFPIE;
|
||||
bool bFPIC;
|
||||
CLDProject Compile();
|
||||
static void GenerateCompileCommands();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@ interface IFileSystem2
|
||||
{
|
||||
public:
|
||||
static char *OwnDirectory();
|
||||
static char *BuildDirectory();
|
||||
static void MakeDirectory( const char *psz );
|
||||
static void CopyFile( const char *szDestination, const char *szOrigin );
|
||||
static void CopyDirectory( const char *szDestination, const char *szOrigin );
|
||||
|
||||
Reference in New Issue
Block a user