added command line, added basic character
This commit is contained in:
11
fpc/Makefile
11
fpc/Makefile
@@ -2,13 +2,22 @@ TIER_FILES := ../tier0/lib.cpp ../tier0/mem.cpp ../tier0/platform.cpp ../tier1/u
|
||||
FPC_FILES := main.cpp library/runner.cpp library/helper.cpp library/c.cpp library/ld.cpp library/target.cpp
|
||||
CC = clang
|
||||
OUTPUT_DIR = fpc
|
||||
CCFLAGS = -I../public -Ipublic -lc -lstdc++
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CCFLAGS += -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -std=c++11 -Wl,-export_dynamic
|
||||
endif
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
CCFLAGS += -rdynamic
|
||||
endif
|
||||
|
||||
recompile: ../build/tools
|
||||
./fpc build
|
||||
mv fpc_temp fpc
|
||||
|
||||
install: $(FPC_FILES) ../build/tools
|
||||
$(CC) -g -rdynamic $(TIER_FILES) $(FPC_FILES) -I../public -Ipublic -lc -lstdc++ -o $(OUTPUT_DIR)
|
||||
$(CC) -g $(TIER_FILES) $(FPC_FILES) $(CCFLAGS) -o $(OUTPUT_DIR)
|
||||
./fpc build
|
||||
mv fpc_temp fpc
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include "c.h"
|
||||
#include "filesystem.h"
|
||||
#include "helper.h"
|
||||
#include "target.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "libgen.h"
|
||||
#include "ctype.h"
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
@@ -19,18 +23,46 @@ CLDProject CCProject::Compile()
|
||||
unsigned int hash = GenerateProjectHash();
|
||||
for (auto &file: files)
|
||||
{
|
||||
V_printf(" CC %s\n", file.GetString());
|
||||
CUtlString szOutputFile = CUtlString("%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), IFileSystem2::OwnDirectory(), file.GetString());
|
||||
CUtlString szOutputDir;
|
||||
CUtlVector<CUtlString> args;
|
||||
V_printf(" CC %s\n", file.GetString());
|
||||
CUtlString szTarget = "";
|
||||
if (m_target.cpu == TARGET_CPU_AMD64)
|
||||
{
|
||||
if (m_target.kernel == TARGET_KERNEL_WINDOWS)
|
||||
{
|
||||
szTarget = "x86_64-pc-windows-gnu";
|
||||
}
|
||||
if (m_target.kernel == TARGET_KERNEL_LINUX)
|
||||
{
|
||||
szTarget = "x86_64-unknown-linux-gnu";
|
||||
}
|
||||
if (m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
szTarget = "x86_64-apple-darwin";
|
||||
}
|
||||
};
|
||||
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",
|
||||
szTarget,
|
||||
"-g",
|
||||
"-c",
|
||||
"-o",
|
||||
szOutputFile,
|
||||
file,
|
||||
};
|
||||
if (!strcmp(Plat_GetExtension(file),"cpp"))
|
||||
args.AppendTail("-std=c++17");
|
||||
else
|
||||
args.AppendTail("-std=c99");
|
||||
|
||||
if (m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
args.AppendTail("-isysroot");
|
||||
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk");
|
||||
}
|
||||
if (bFPIC)
|
||||
args.AppendTail("-fPIC");
|
||||
if (bFPIE)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "libgen.h"
|
||||
#include "target.h"
|
||||
|
||||
CUtlString CLDProject::Link( void )
|
||||
{
|
||||
@@ -15,7 +16,10 @@ CUtlString CLDProject::Link( void )
|
||||
szFileName = CUtlString("lib%s.a", m_szName.GetString());
|
||||
break;
|
||||
case ELINK_DYNAMIC_LIBRARY:
|
||||
szFileName = CUtlString("lib%s.so", m_szName.GetString());
|
||||
if (m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
szFileName = CUtlString("lib%s.dylib", m_szName.GetString());
|
||||
if (m_target.kernel == TARGET_KERNEL_LINUX)
|
||||
szFileName = CUtlString("lib%s.so", m_szName.GetString());
|
||||
break;
|
||||
}
|
||||
CUtlString szOutputFile = CUtlString("%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, hash, m_szName.GetString(), szFileName.GetString());
|
||||
@@ -59,12 +63,23 @@ CUtlString CLDProject::Link( void )
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
args = {
|
||||
"-rdynamic",
|
||||
"-o",
|
||||
szOutputFile,
|
||||
};
|
||||
if (m_target.kernel == TARGET_KERNEL_LINUX)
|
||||
{
|
||||
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);
|
||||
for (auto lib: libraries)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "tier1/utlvector.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/wait.h"
|
||||
#include "tier1/commandline.h"
|
||||
int IRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
@@ -14,10 +15,16 @@ int IRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
CUtlVector<const char*> execargs;
|
||||
execargs.AppendTail(szName);
|
||||
if (ICommandLine::CheckParam("-fpcdebug"))
|
||||
V_printf("%s",szName.GetString());
|
||||
for (auto &arg: args)
|
||||
{
|
||||
execargs.AppendTail(arg);
|
||||
if (ICommandLine::CheckParam("-fpcdebug"))
|
||||
V_printf(" %s",arg.GetString());
|
||||
}
|
||||
if (ICommandLine::CheckParam("-fpcdebug"))
|
||||
V_printf("\n");
|
||||
execargs.AppendTail(0);
|
||||
execvp(szName, (char *const*)execargs.GetData());
|
||||
}
|
||||
|
||||
@@ -1,16 +1,34 @@
|
||||
#include "target.h"
|
||||
#include <god/build.h>
|
||||
#include "tier1/commandline.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
Target_t Target_t::DefaultTarget()
|
||||
{
|
||||
CUtlString szDevice = ICommandLine::ParamValue("-device");
|
||||
CUtlString szOS = ICommandLine::ParamValue("-os");
|
||||
CUtlString szArch = ICommandLine::ParamValue("-arch");
|
||||
|
||||
ETargetKernel kernel =
|
||||
#if defined(__linux__)
|
||||
TARGET_KERNEL_LINUX
|
||||
#elif defined(__APPLE__)
|
||||
TARGET_KERNEL_DARWIN
|
||||
#endif
|
||||
;
|
||||
ETargetCPU cpu = TARGET_CPU_AMD64;
|
||||
|
||||
if ( szOS == "windows" )
|
||||
kernel = TARGET_KERNEL_WINDOWS;
|
||||
else if ( szOS == "linux" )
|
||||
kernel = TARGET_KERNEL_LINUX;
|
||||
else if ( szOS == "macos" )
|
||||
kernel = TARGET_KERNEL_DARWIN;
|
||||
else if ( szOS != 0 )
|
||||
V_printf("Unknown OS: %s\n", szOS.GetString());
|
||||
|
||||
return {
|
||||
.kernel = TARGET_KERNEL_LINUX,
|
||||
#ifdef __x86_64__
|
||||
.cpu = TARGET_CPU_AMD64,
|
||||
#endif
|
||||
#ifdef __x86__
|
||||
.cpu = TARGET_CPU_I386,
|
||||
#endif
|
||||
.kernel = kernel,
|
||||
.cpu = cpu,
|
||||
.optimization = TARGET_DEBUG,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,27 @@ struct C_Macro_t
|
||||
CUtlString szValue;
|
||||
};
|
||||
|
||||
enum ECVersion
|
||||
{
|
||||
CVERSION_89,
|
||||
CVERSION_99 = 0,
|
||||
CVERSION_11,
|
||||
CVERSION_17,
|
||||
CVERSION_23,
|
||||
CVERSION_2Y,
|
||||
};
|
||||
|
||||
enum ECPPVersion
|
||||
{
|
||||
CPPVERSION_98 = 1,
|
||||
CPPVERSION_11 = 0,
|
||||
CPPVERSION_14 = 2,
|
||||
CPPVERSION_17 = 3,
|
||||
CPPVERSION_20 = 4,
|
||||
CPPVERSION_23 = 5,
|
||||
CPPVERSION_2C = 6,
|
||||
};
|
||||
|
||||
class CCProject : public CProject
|
||||
{
|
||||
public:
|
||||
@@ -24,6 +45,8 @@ public:
|
||||
bool bFPIE;
|
||||
bool bFPIC;
|
||||
bool bDebug = m_target.optimization == TARGET_DEBUG;
|
||||
ECVersion cVersion;
|
||||
ECPPVersion cppVersion;
|
||||
CLDProject Compile();
|
||||
static void GenerateCompileCommands();
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ enum ETargetKernel
|
||||
{
|
||||
TARGET_KERNEL_LINUX,
|
||||
TARGET_KERNEL_WINDOWS,
|
||||
TARGET_KERNEL_DARWIN,
|
||||
};
|
||||
|
||||
enum ETargetCPU
|
||||
|
||||
Reference in New Issue
Block a user