brought back functionality from previous builds but now cross-platform
This commit is contained in:
@@ -22,12 +22,19 @@ CLDProject CCProject::Compile()
|
||||
proj.m_szName = m_szName;
|
||||
unsigned int hash = GenerateProjectHash();
|
||||
for (auto &file: files)
|
||||
{
|
||||
CUtlString szTarget = m_target.GetTriplet();
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, m_szName.GetString(), IFileSystem2::BuildDirectory(), file.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
IFileSystem2::MakeDirectory(szOutputDir);
|
||||
}
|
||||
for (auto &file: files)
|
||||
{
|
||||
CUtlVector<CUtlString> args;
|
||||
V_printf(" CC %s\n", file.GetString());
|
||||
CUtlString szTarget = m_target.GetTriplet();
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, m_szName.GetString(), IFileSystem2::BuildDirectory(), file.GetString());
|
||||
CUtlString szOutputDir;
|
||||
|
||||
args = {
|
||||
"-target",
|
||||
@@ -40,6 +47,8 @@ CLDProject CCProject::Compile()
|
||||
};
|
||||
if (!strcmp(Plat_GetExtension(file),"cpp"))
|
||||
args.AppendTail("-std=c++17");
|
||||
else if (!strcmp(Plat_GetExtension(file),"mm"))
|
||||
;
|
||||
else
|
||||
args.AppendTail("-std=c99");
|
||||
|
||||
@@ -76,9 +85,6 @@ CLDProject CCProject::Compile()
|
||||
}
|
||||
if (!IFileSystem2::ShouldRecompile(file, szOutputFile))
|
||||
goto skipcompile;
|
||||
szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
IFileSystem2::MakeDirectory(szOutputDir);
|
||||
IRunner::Run("clang", args);
|
||||
|
||||
skipcompile:
|
||||
|
||||
@@ -51,6 +51,7 @@ void IFileSystem2::CopyFile( const char *szDestination, const char *szOrigin )
|
||||
CUtlString(szDestination),
|
||||
};
|
||||
IRunner::Run("cp", args);
|
||||
IRunner::Wait();
|
||||
}
|
||||
void IFileSystem2::CopyDirectory( const char *szDestination, const char *szOrigin )
|
||||
{
|
||||
@@ -60,6 +61,7 @@ void IFileSystem2::CopyDirectory( const char *szDestination, const char *szOrigi
|
||||
CUtlString(szDestination),
|
||||
};
|
||||
IRunner::Run("cp", args);
|
||||
IRunner::Wait();
|
||||
}
|
||||
|
||||
void IFileSystem2::MakeDirectory( const char *psz )
|
||||
@@ -69,6 +71,7 @@ void IFileSystem2::MakeDirectory( const char *psz )
|
||||
CUtlString(psz),
|
||||
};
|
||||
IRunner::Run("mkdir", args);
|
||||
IRunner::Wait();
|
||||
};
|
||||
|
||||
bool IFileSystem2::ShouldRecompile(const char *szSource, const char *szOutput)
|
||||
|
||||
@@ -10,7 +10,10 @@ CUtlString CLDProject::Link( void )
|
||||
switch(linkType)
|
||||
{
|
||||
case ELINK_EXECUTABLE:
|
||||
szFileName = CUtlString("%s", m_szName.GetString());
|
||||
if (m_target.kernel == TARGET_KERNEL_WINDOWS)
|
||||
szFileName = CUtlString("%s.exe", m_szName.GetString());
|
||||
else
|
||||
szFileName = CUtlString("%s", m_szName.GetString());
|
||||
break;
|
||||
case ELINK_STATIC_LIBRARY:
|
||||
szFileName = CUtlString("lib%s.a", m_szName.GetString());
|
||||
@@ -50,6 +53,7 @@ CUtlString CLDProject::Link( void )
|
||||
for (auto object: objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
IRunner::Run("ar", args);
|
||||
IRunner::Wait();
|
||||
} else {
|
||||
V_printf(" LINK %s\n", m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
@@ -70,10 +74,18 @@ CUtlString CLDProject::Link( void )
|
||||
"-target",
|
||||
m_target.GetTriplet(),
|
||||
};
|
||||
if (m_target.kernel == TARGET_KERNEL_WINDOWS)
|
||||
{
|
||||
args.AppendTail("-fuse-ld=lld");
|
||||
args.AppendTail("-Wl,--whole-archive");
|
||||
}
|
||||
if (m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
args.AppendTail("-isysroot");
|
||||
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk");
|
||||
args.AppendTail("-Wl,-export_dynamic");
|
||||
args.AppendTail("-undefined");
|
||||
args.AppendTail("dynamic_lookup");
|
||||
}
|
||||
if (m_target.kernel == TARGET_KERNEL_IOS)
|
||||
{
|
||||
@@ -89,18 +101,16 @@ CUtlString CLDProject::Link( void )
|
||||
{
|
||||
args.AppendTail("-rdynamic");
|
||||
}
|
||||
if (m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
args.AppendTail("-Wl,-export_dynamic");
|
||||
args.AppendTail("-undefined");
|
||||
args.AppendTail("dynamic_lookup");
|
||||
}
|
||||
if (linkType == ELINK_DYNAMIC_LIBRARY)
|
||||
{
|
||||
args.AppendTail("-shared");
|
||||
}
|
||||
for (auto object: objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
if (m_target.kernel == TARGET_KERNEL_WINDOWS)
|
||||
{
|
||||
args.AppendTail("-Wl,--no-whole-archive");
|
||||
}
|
||||
for (auto lib: libraries)
|
||||
{
|
||||
args.AppendTail("-l");
|
||||
@@ -116,7 +126,9 @@ CUtlString CLDProject::Link( void )
|
||||
args.AppendTail("-framework");
|
||||
args.AppendTail(framework);
|
||||
}
|
||||
|
||||
IRunner::Run("clang++", args);
|
||||
IRunner::Wait();
|
||||
}
|
||||
compiled:
|
||||
return szOutputFile;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "unistd.h"
|
||||
#include "sys/wait.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<pid_t> g_processes;
|
||||
int IRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
@@ -26,10 +28,13 @@ int IRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
if (ICommandLine::CheckParam("-fpcdebug"))
|
||||
V_printf("\n");
|
||||
execargs.AppendTail(0);
|
||||
execvp(szName, (char *const*)execargs.GetData());
|
||||
if ( execvp(szName, (char *const*)execargs.GetData()) == -1 )
|
||||
{
|
||||
V_printf("Failed to launch %s\n",szName.GetString());
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
/* parent */
|
||||
wait(NULL);
|
||||
g_processes.AppendTail(pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -49,10 +54,14 @@ int IRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlStrin
|
||||
}
|
||||
execargs.AppendTail(0);
|
||||
chdir(szDirectory.GetString());
|
||||
execvp(szName, (char *const*)execargs.GetData());
|
||||
if ( execvp(szName, (char *const*)execargs.GetData()) == -1 )
|
||||
{
|
||||
V_printf("Failed to launch %s\n",szName.GetString());
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
g_processes.AppendTail(pid);
|
||||
/* parent */
|
||||
wait(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,3 +70,13 @@ int IRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlStrin
|
||||
|
||||
}
|
||||
|
||||
int IRunner::Wait( void )
|
||||
{
|
||||
for (auto &process: g_processes)
|
||||
{
|
||||
int status;
|
||||
pid_t wpid = waitpid(process, &status, 0);
|
||||
}
|
||||
g_processes = {};
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
static int Run( CUtlString szName, CUtlVector<CUtlString>& args );
|
||||
static int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args );
|
||||
static int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment );
|
||||
static int Wait( void );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user