made it work with new fpc
This commit is contained in:
2
.fpccfg
Normal file
2
.fpccfg
Normal file
@@ -0,0 +1,2 @@
|
||||
[wasm32-unknown-wasi]
|
||||
sysroot = "/home/kotofyt/Downloads/wasi-sysroot-29.0/"
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -28,3 +28,6 @@
|
||||
[submodule "external/xtool"]
|
||||
path = external/xtool
|
||||
url = https://github.com/xtool-org/xtool.git
|
||||
[submodule "external/funnystdlib"]
|
||||
path = external/funnystdlib
|
||||
url = https://github.com/KoT3isGood/funnystdlib.git
|
||||
|
||||
@@ -1,640 +0,0 @@
|
||||
#include "appleauth/iauth.h"
|
||||
#include "tier2/fileformats/plist.h"
|
||||
#include "http/http.h"
|
||||
#include "openssl/srp.h"
|
||||
#include "openssl/evp.h"
|
||||
#include "openssl/sha.h"
|
||||
#include "tier0/rand.h"
|
||||
|
||||
IHTTPClientManager *g_pHttpClientMgr = NULL;
|
||||
static int base64_decode(const char *b64, unsigned char *pOut) {
|
||||
int len = strlen(b64);
|
||||
if (pOut == NULL)
|
||||
return (len*3)/4;
|
||||
int out_len = EVP_DecodeBlock(pOut,
|
||||
(const unsigned char *)b64,
|
||||
len);
|
||||
if (out_len < 0)
|
||||
return -1;
|
||||
|
||||
while (len > 0 && b64[len - 1] == '=') {
|
||||
out_len--;
|
||||
len--;
|
||||
}
|
||||
|
||||
return out_len;
|
||||
}
|
||||
|
||||
// autogenerated
|
||||
#define APPLE_LOCAL_USER "e2e70285da39596ef06153b9c4e1e5dc8d2f983bc5cd63f5b1e292207060d931"
|
||||
#define APPLE_HTTP_HEADER \
|
||||
{ \
|
||||
{"X-Apple-I-Client-Time", "2026-1-9T12:00:00"}, \
|
||||
{"X-Apple-Locale", "en_US"}, \
|
||||
{"X-Apple-I-TimeZone", "Europe/Kyiv"}, \
|
||||
{"X-Mme-Client-Info", "<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>"}, \
|
||||
{"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, \
|
||||
{"X-Apple-I-MD-LU", APPLE_LOCAL_USER}, \
|
||||
{"X-Apple-I-MD-M", "0"}, \
|
||||
{"X-Apple-I-SRL-NO", "0"}, \
|
||||
{"X-Mme-Device-Id", "0"}, \
|
||||
{"Content-Type", "text/x-xml-plist"}, \
|
||||
{"Accept", "*/*"}, \
|
||||
};
|
||||
|
||||
#define N2048 "AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B855F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773BCA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB694B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73"
|
||||
#define G2048 "2"
|
||||
enum EPasswordType
|
||||
{
|
||||
PASSWORD_TYPE_S2K,
|
||||
PASSWORD_TYPE_S2K_FO,
|
||||
};
|
||||
|
||||
class CAppleAuth: public IAppleAuth
|
||||
{
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual void Shutdown() override;
|
||||
virtual void LaunchLoginDaemon() override;
|
||||
virtual EAppleAuthDaemonStatus GetStatus() override;
|
||||
virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) override;
|
||||
virtual EAppleAuthStatus Submit2FA( const char *szCode ) override;
|
||||
virtual CUtlString EncryptPassword( const char *szPassword, CUtlString szSalt, uint32_t uIters, EPasswordType eType );
|
||||
void ComputeM1( unsigned char M1[SHA256_DIGEST_LENGTH], const BIGNUM *N, const BIGNUM *g, const char *username, const char *password, const unsigned char *salt, size_t salt_len, const BIGNUM *A, const BIGNUM *B, const BIGNUM *a );
|
||||
|
||||
CUtlString FetchADIPB();
|
||||
void FetchHeaders( CUtlString szAdiPb );
|
||||
|
||||
IHTTPClient *m_pANIClient;
|
||||
IHTTPClient *m_pGrandSlamClient;
|
||||
|
||||
CUtlString m_szProvisionStart = "/grandslam/MidService/startMachineProvisioning";
|
||||
CUtlString m_szProvisionFinish = "/grandslam/MidService/finishMachineProvisioning";
|
||||
IJSONObject *pHeader;
|
||||
|
||||
CUtlString m_szAppleIMD;
|
||||
CUtlString m_szAppleIMDM;
|
||||
CUtlString m_szAppleIMDRINFO;
|
||||
|
||||
};
|
||||
|
||||
CUtlString CAppleAuth::FetchADIPB()
|
||||
{
|
||||
|
||||
CUtlString szProvisionExpectedInputRaw = NULL;
|
||||
IJSONObject *pObject = NULL;
|
||||
IJSONObject *pPlistObject = NULL;
|
||||
CUtlString szProvisionExpectedInput = NULL;
|
||||
CUtlString szAdiPb = NULL;
|
||||
|
||||
m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL);
|
||||
|
||||
{
|
||||
HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER;
|
||||
HTTPHeader_t header = {
|
||||
sizeof(params)/sizeof(HTTPHeaderParam_t),
|
||||
params,
|
||||
};
|
||||
m_pGrandSlamClient->Get("/grandslam/GsService2/lookup", &header);
|
||||
HTTPResponse_t r = m_pGrandSlamClient->GetResponse();
|
||||
if ( r.m_uCode != 200 )
|
||||
{
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_pANIClient->WebSocket_Connect("/v3/provisioning_session") )
|
||||
Plat_FatalErrorFunc("Failed to init AppleAuth websocket\n");
|
||||
|
||||
// Getting adipb
|
||||
while ( ( szProvisionExpectedInputRaw = m_pANIClient->WebSocket_RecvText() ) != NULL )
|
||||
{
|
||||
pObject = JSONManager()->ReadString(szProvisionExpectedInputRaw);
|
||||
szProvisionExpectedInput = pObject->GetValue("result")->GetStringValue();
|
||||
V_printf("%s\n",szProvisionExpectedInput.GetString());
|
||||
if ( szProvisionExpectedInput == "GiveIdentifier" )
|
||||
{
|
||||
m_pANIClient->WebSocket_SendText("{\"identifier\": \"" APPLE_LOCAL_USER "\"}");
|
||||
continue;
|
||||
}
|
||||
if ( szProvisionExpectedInput == "GiveStartProvisioningData" )
|
||||
{
|
||||
const char *plist =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
|
||||
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
"\t<key>Header</key>\n"
|
||||
"\t<dict/>\n"
|
||||
"\t<key>Request</key>\n"
|
||||
"\t<dict/>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n";
|
||||
|
||||
HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER;
|
||||
HTTPHeader_t header = {
|
||||
sizeof(params)/sizeof(HTTPHeaderParam_t),
|
||||
params,
|
||||
};
|
||||
m_pGrandSlamClient->Post(m_szProvisionStart, &header, V_strlen(plist), plist);
|
||||
HTTPResponse_t r = m_pGrandSlamClient->GetResponse();
|
||||
if ( r.m_uCode != 200 )
|
||||
{
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
return NULL;
|
||||
}
|
||||
IJSONObject *pObject = PropertyListManager()->ReadString(r.m_message);
|
||||
CUtlString spim = pObject->GetValue("Response")->GetObject()->GetValue("spim")->GetStringValue();
|
||||
m_pANIClient->WebSocket_SendText(CUtlString("{\"spim\": \"%s\"}", spim.GetString()));
|
||||
|
||||
continue;
|
||||
}
|
||||
if ( szProvisionExpectedInput == "GiveEndProvisioningData" )
|
||||
{
|
||||
CUtlString cpim = pObject->GetValue("cpim")->GetStringValue();
|
||||
|
||||
CUtlString plist = CUtlString(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
|
||||
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
"\t<key>Header</key>\n"
|
||||
"\t<dict/>\n"
|
||||
"\t<key>Request</key>\n"
|
||||
"\t<dict>\n"
|
||||
"\t<key>cpim</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t</dict>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n", cpim.GetString());
|
||||
|
||||
HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER;
|
||||
HTTPHeader_t header = {
|
||||
sizeof(params)/sizeof(HTTPHeaderParam_t),
|
||||
params,
|
||||
};
|
||||
m_pGrandSlamClient->Post(m_szProvisionFinish, &header, V_strlen(plist), plist);
|
||||
HTTPResponse_t r = m_pGrandSlamClient->GetResponse();
|
||||
if ( r.m_uCode != 200 )
|
||||
{
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
return NULL;
|
||||
}
|
||||
IJSONObject *pObject = PropertyListManager()->ReadString(r.m_message);
|
||||
CUtlString tk = pObject->GetValue("Response")->GetObject()->GetValue("tk")->GetStringValue();
|
||||
CUtlString ptm = pObject->GetValue("Response")->GetObject()->GetValue("ptm")->GetStringValue();
|
||||
|
||||
V_printf("%s\n",CUtlString("{\"tk\": \"%s\", \"ptm\": \"%s\"}", tk.GetString(), ptm.GetString()).GetString());
|
||||
m_pANIClient->WebSocket_SendText(CUtlString("{\"tk\": \"%s\", \"ptm\": \"%s\"}", tk.GetString(), ptm.GetString()));
|
||||
|
||||
continue;
|
||||
}
|
||||
if ( szProvisionExpectedInput == "ProvisioningSuccess" )
|
||||
{
|
||||
szAdiPb = pObject->GetValue("adi_pb")->GetStringValue();
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
break;
|
||||
}
|
||||
if ( szProvisionExpectedInput == "Timeout" )
|
||||
{
|
||||
break;
|
||||
}
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
return NULL;
|
||||
}
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
return szAdiPb;
|
||||
}
|
||||
void CAppleAuth::FetchHeaders( CUtlString szAdiPb )
|
||||
{
|
||||
// Get header
|
||||
HTTPHeaderParam_t params[] = {
|
||||
"Content-Type", "application/json",
|
||||
};
|
||||
HTTPHeader_t header = {
|
||||
sizeof(params)/sizeof(HTTPHeaderParam_t),
|
||||
params,
|
||||
};
|
||||
m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL);
|
||||
CUtlString szPostData = CUtlString("{\"identifier\": \"" APPLE_LOCAL_USER "\", \"adi_pb\": \"%s\"}", szAdiPb.GetString());
|
||||
V_printf("%s\n",szPostData.GetString());
|
||||
m_pANIClient->Post("/v3/get_headers", &header, V_strlen(szPostData), szPostData);
|
||||
HTTPResponse_t r = m_pANIClient->GetResponse();
|
||||
V_printf("%i\n",r.m_uCode);
|
||||
if ( r.m_uCode == 200 )
|
||||
{
|
||||
V_printf("%s\n",r.m_message.GetMemory());
|
||||
pHeader = JSONManager()->ReadString(r.m_message);
|
||||
m_szAppleIMD = pHeader->GetValue("X-Apple-I-MD")->GetStringValue();
|
||||
m_szAppleIMDM = pHeader->GetValue("X-Apple-I-MD-M")->GetStringValue();
|
||||
m_szAppleIMDRINFO = pHeader->GetValue("X-Apple-I-MD-RINFO")->GetStringValue();
|
||||
JSONManager()->FreeObject(pHeader);
|
||||
}
|
||||
g_pHttpClientMgr->Disconnect(m_pANIClient);
|
||||
}
|
||||
|
||||
void CAppleAuth::Init()
|
||||
{
|
||||
CreateInterfaceFn fnHttpFactory = Sys_GetFactory("funnyhttp");
|
||||
|
||||
g_pHttpClientMgr = (IHTTPClientManager*)fnHttpFactory(HTTP_CLIENT_INTERFACE_VERSION, NULL);
|
||||
|
||||
m_pGrandSlamClient = g_pHttpClientMgr->Connect("gsa.apple.com", true, NULL);
|
||||
|
||||
CUtlString szAdiPb = FetchADIPB();
|
||||
FetchHeaders(szAdiPb);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CAppleAuth::Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CAppleAuth::LaunchLoginDaemon()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
EAppleAuthDaemonStatus CAppleAuth::GetStatus()
|
||||
{
|
||||
return APPLE_AUTH_DAEMON_NOT_LOGGED_IN;
|
||||
}
|
||||
|
||||
|
||||
EAppleAuthStatus CAppleAuth::SubmitLoginData( const char *szEmail, const char *szPassword )
|
||||
{
|
||||
const char *pszUser = szEmail;
|
||||
const char *pszPass = szPassword;
|
||||
|
||||
BIGNUM* pN = BN_new();
|
||||
BIGNUM* pG = BN_new();
|
||||
BIGNUM* pa = BN_new();
|
||||
BIGNUM* pA = BN_new();
|
||||
BN_CTX *pbnCtx = BN_CTX_new();
|
||||
|
||||
SHA256_CTX pSha;
|
||||
unsigned char pK[SHA256_DIGEST_LENGTH];
|
||||
BN_hex2bn(&pN, N2048);
|
||||
BN_hex2bn(&pG, G2048);
|
||||
CUtlBuffer<unsigned char> bN;
|
||||
CUtlBuffer<unsigned char> bG;
|
||||
bN = CUtlBuffer<unsigned char>(BN_num_bytes(pN));
|
||||
bG = CUtlBuffer<unsigned char>(BN_num_bytes(pG));
|
||||
BN_bn2bin(pN, bN.GetMemory());
|
||||
SHA256_Init(&pSha);
|
||||
SHA256_Update(&pSha, bN.GetMemory(), bN.GetSize());
|
||||
SHA256_Update(&pSha, bG.GetMemory(), bG.GetSize());
|
||||
SHA256_Final(pK, &pSha);
|
||||
|
||||
BN_rand(pa, 256, 0, 0);
|
||||
BN_set_flags(pa, BN_FLG_CONSTTIME);
|
||||
BN_mod_exp(pA, pG, pa, pN, pbnCtx);
|
||||
|
||||
char *pszA = BN_bn2hex(pA);
|
||||
|
||||
CUtlString plist = CUtlString(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
|
||||
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
"\t<key>Header</key>\n"
|
||||
"\t<dict>\n"
|
||||
"\t<key>Version</key>\n"
|
||||
"\t<string>1.0.1</string>\n"
|
||||
"\t</dict>\n"
|
||||
|
||||
"\t<key>Request</key>\n"
|
||||
"\t<dict>\n"
|
||||
|
||||
"\t<key>A2k</key>\n"
|
||||
"\t<data>%s</data>\n"
|
||||
|
||||
"\t<key>ps</key>\n"
|
||||
"\t<array><string>s2k</string><string>s2k_fo</string></array>\n"
|
||||
|
||||
"\t<key>u</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
|
||||
"\t<key>o</key>\n"
|
||||
"\t<string>init</string>\n"
|
||||
|
||||
"\t<key>cpd</key>\n"
|
||||
"\t<dict>\n"
|
||||
|
||||
"\t<key>X-Apple-I-Client-Time</key>\n"
|
||||
"\t<string>2026-1-9T12:00:00Z</string>\n"
|
||||
"\t<key>X-Apple-I-MD</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t<key>X-Apple-I-MD-LU</key>\n"
|
||||
"\t<string>" APPLE_LOCAL_USER "</string>\n"
|
||||
"\t<key>X-Apple-I-MD-M</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t<key>X-Apple-I-MD-RINFO</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t<key>X-Mme-Client-Info</key>\n"
|
||||
"\t<string><MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)></string>\n"
|
||||
"\t<key>X-Apple-I-SRL-NO</key>\n"
|
||||
"\t<string>0</string>\n"
|
||||
|
||||
|
||||
"\t<key>bootstrap</key>\n"
|
||||
"\t<trur/>\n"
|
||||
|
||||
"\t<key>icscrec</key>\n"
|
||||
"\t<true/>\n"
|
||||
|
||||
|
||||
"\t<key>pbe</key>\n"
|
||||
"\t<false/>\n"
|
||||
|
||||
"\t<key>prkgen</key>\n"
|
||||
"\t<true/>\n"
|
||||
|
||||
"\t<key>svct</key>\n"
|
||||
"\t<string>iCloud</string>\n"
|
||||
|
||||
"\t<key>loc</key>\n"
|
||||
"\t<string>en_US</string>\n"
|
||||
|
||||
"\t</dict>\n"
|
||||
|
||||
"\t</dict>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n", pszA, szEmail, m_szAppleIMD.GetString(), m_szAppleIMDM.GetString(), m_szAppleIMDRINFO.GetString());
|
||||
HTTPHeaderParam_t params[] = {
|
||||
{"Content-Type", "text/x-xml-plist"},
|
||||
{"Accept", "*/*"},
|
||||
{"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, \
|
||||
{"X-Mme-Client-Info", "<MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>"}, \
|
||||
};
|
||||
HTTPHeader_t header = {
|
||||
sizeof(params)/sizeof(HTTPHeaderParam_t),
|
||||
params,
|
||||
};
|
||||
V_printf("%s\n",plist.GetString());
|
||||
m_pGrandSlamClient->Post("/grandslam/GsService2", &header, plist.GetLenght(), plist);
|
||||
HTTPResponse_t stResponse = m_pGrandSlamClient->GetResponse();
|
||||
V_printf("%i %i\n", stResponse.m_uCode, stResponse.m_bIsComplete);
|
||||
if (stResponse.m_uCode != 200)
|
||||
return APPLE_AUTH_FAILURE;
|
||||
V_printf("%s\n",stResponse.m_message.GetMemory());
|
||||
IJSONObject *pObject = PropertyListManager()->ReadString(stResponse.m_message);
|
||||
IJSONObject *pResponse = pObject->GetValue("Response")->GetObject();
|
||||
CUtlString szEncryptedPassword = EncryptPassword(szPassword, pResponse->GetValue("s")->GetStringValue(), pResponse->GetValue("i")->GetNumberValue(), PASSWORD_TYPE_S2K);
|
||||
const char *szSalt = pResponse->GetValue("s")->GetStringValue();
|
||||
const char *szB = pResponse->GetValue("B")->GetStringValue();
|
||||
unsigned char salt[32];
|
||||
int iSaltLen = base64_decode(szSalt, salt);
|
||||
|
||||
int iBLen = base64_decode(szB, NULL);
|
||||
CUtlBuffer<unsigned char> BBuffer = CUtlBuffer<unsigned char>(iBLen);
|
||||
iBLen = base64_decode(szB, BBuffer.GetMemory());
|
||||
BIGNUM *pB = BN_bin2bn(BBuffer.GetMemory(), BBuffer.GetSize(), NULL);
|
||||
unsigned char M1[SHA256_DIGEST_LENGTH];
|
||||
ComputeM1(M1, pN, pG, szEmail, szPassword, salt, iSaltLen, pA, pB, pa);
|
||||
|
||||
CUtlString szM1 = {};
|
||||
for ( int i = 0; i < SHA256_DIGEST_LENGTH; i++ )
|
||||
{
|
||||
szM1.AppendTail(CUtlString("%02x", M1[i]));
|
||||
}
|
||||
|
||||
plist = CUtlString(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
|
||||
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
"\t<key>Header</key>\n"
|
||||
"\t<dict>\n"
|
||||
"\t<key>Version</key>\n"
|
||||
"\t<string>1.0.1</string>\n"
|
||||
"\t</dict>\n"
|
||||
|
||||
"\t<key>Request</key>\n"
|
||||
"\t<dict>\n"
|
||||
|
||||
"\t<key>M1</key>\n"
|
||||
"\t<data>%s</data>\n"
|
||||
|
||||
"\t<key>c</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
|
||||
"\t<key>ps</key>\n"
|
||||
"\t<array><string>s2k</string><string>s2k_fo</string></array>\n"
|
||||
|
||||
"\t<key>u</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
|
||||
"\t<key>o</key>\n"
|
||||
"\t<string>complete</string>\n"
|
||||
|
||||
"\t<key>cpd</key>\n"
|
||||
"\t<dict>\n"
|
||||
|
||||
"\t<key>X-Apple-I-Client-Time</key>\n"
|
||||
"\t<string>2026-1-9T12:00:00Z</string>\n"
|
||||
"\t<key>X-Apple-I-MD</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t<key>X-Apple-I-MD-LU</key>\n"
|
||||
"\t<string>" APPLE_LOCAL_USER "</string>\n"
|
||||
"\t<key>X-Apple-I-MD-M</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t<key>X-Apple-I-MD-RINFO</key>\n"
|
||||
"\t<string>%s</string>\n"
|
||||
"\t<key>X-Mme-Client-Info</key>\n"
|
||||
"\t<string><MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)></string>\n"
|
||||
"\t<key>X-Apple-I-SRL-NO</key>\n"
|
||||
"\t<string>0</string>\n"
|
||||
|
||||
|
||||
"\t<key>bootstrap</key>\n"
|
||||
"\t<trur/>\n"
|
||||
|
||||
"\t<key>icscrec</key>\n"
|
||||
"\t<true/>\n"
|
||||
|
||||
|
||||
"\t<key>pbe</key>\n"
|
||||
"\t<false/>\n"
|
||||
|
||||
"\t<key>prkgen</key>\n"
|
||||
"\t<true/>\n"
|
||||
|
||||
"\t<key>svct</key>\n"
|
||||
"\t<string>iCloud</string>\n"
|
||||
|
||||
"\t<key>loc</key>\n"
|
||||
"\t<string>en_US</string>\n"
|
||||
|
||||
"\t</dict>\n"
|
||||
|
||||
"\t</dict>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n", szM1.GetString(), pResponse->GetValue("c")->GetStringValue(), szEmail, m_szAppleIMD.GetString(), m_szAppleIMDM.GetString(), m_szAppleIMDRINFO.GetString());
|
||||
V_printf("%s\n", plist.GetString());
|
||||
m_pGrandSlamClient->Post("/grandslam/GsService2", &header, plist.GetLenght(), plist);
|
||||
stResponse = m_pGrandSlamClient->GetResponse();
|
||||
V_printf("%i %i\n", stResponse.m_uCode, stResponse.m_bIsComplete);
|
||||
if (stResponse.m_uCode != 200)
|
||||
return APPLE_AUTH_FAILURE;
|
||||
V_printf("%s\n", stResponse.m_message.GetMemory());
|
||||
|
||||
g_pHttpClientMgr->Disconnect(m_pGrandSlamClient);
|
||||
|
||||
|
||||
OPENSSL_free(pszA);
|
||||
return APPLE_AUTH_SUCCESS;
|
||||
}
|
||||
|
||||
static void hash_bn_pad(unsigned char out[SHA256_DIGEST_LENGTH], const BIGNUM *bn)
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
int len = BN_num_bytes(bn);
|
||||
BN_bn2bin(bn, buf + (256 - len));
|
||||
|
||||
SHA256(buf, 256, out);
|
||||
}
|
||||
|
||||
void CAppleAuth::ComputeM1(
|
||||
unsigned char M1[SHA256_DIGEST_LENGTH],
|
||||
const BIGNUM *N,
|
||||
const BIGNUM *g,
|
||||
const char *username,
|
||||
const char *password,
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const BIGNUM *A,
|
||||
const BIGNUM *B,
|
||||
const BIGNUM *a
|
||||
)
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
unsigned char HN[SHA256_DIGEST_LENGTH], Hg[SHA256_DIGEST_LENGTH], HNxorg[SHA256_DIGEST_LENGTH];
|
||||
unsigned char HI[SHA256_DIGEST_LENGTH];
|
||||
|
||||
/* H(N) xor H(g) */
|
||||
hash_bn_pad(HN, N);
|
||||
hash_bn_pad(Hg, g);
|
||||
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
|
||||
HNxorg[i] = HN[i] ^ Hg[i];
|
||||
|
||||
/* H(I) */
|
||||
SHA256((const unsigned char *)username, strlen(username), HI);
|
||||
|
||||
/* x = H(s || H(I ":" P)) */
|
||||
unsigned char inner_hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, (const unsigned char *)username, strlen(username));
|
||||
SHA256_Update(&ctx, (const unsigned char *)":", 1);
|
||||
SHA256_Update(&ctx, (const unsigned char *)password, strlen(password));
|
||||
SHA256_Final(inner_hash, &ctx);
|
||||
|
||||
unsigned char x_hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, salt, salt_len);
|
||||
SHA256_Update(&ctx, inner_hash, SHA256_DIGEST_LENGTH);
|
||||
SHA256_Final(x_hash, &ctx);
|
||||
|
||||
BIGNUM *x = BN_bin2bn(x_hash, SHA256_DIGEST_LENGTH, NULL);
|
||||
|
||||
/* k = H(N || g) */
|
||||
unsigned char k_hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_Init(&ctx);
|
||||
unsigned char bufN[256], bufg[256];
|
||||
memset(bufN, 0, 256); BN_bn2bin(N, bufN + (256 - BN_num_bytes(N)));
|
||||
memset(bufg, 0, 256); BN_bn2bin(g, bufg + (256 - BN_num_bytes(g)));
|
||||
SHA256_Update(&ctx, bufN, 256);
|
||||
SHA256_Update(&ctx, bufg, 256);
|
||||
SHA256_Final(k_hash, &ctx);
|
||||
BIGNUM *k = BN_bin2bn(k_hash, SHA256_DIGEST_LENGTH, NULL);
|
||||
|
||||
/* u = H(A || B) */
|
||||
unsigned char bufA[256], bufB[256], u_hash[SHA256_DIGEST_LENGTH];
|
||||
memset(bufA, 0, 256); BN_bn2bin(A, bufA + (256 - BN_num_bytes(A)));
|
||||
memset(bufB, 0, 256); BN_bn2bin(B, bufB + (256 - BN_num_bytes(B)));
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, bufA, 256);
|
||||
SHA256_Update(&ctx, bufB, 256);
|
||||
SHA256_Final(u_hash, &ctx);
|
||||
BIGNUM *u = BN_bin2bn(u_hash, SHA256_DIGEST_LENGTH, NULL);
|
||||
|
||||
/* S = (B - k * g^x)^(a + u * x) mod N */
|
||||
BN_CTX *bn_ctx = BN_CTX_new();
|
||||
BIGNUM *gx = BN_new(), *kgx = BN_new(), *B_sub = BN_new();
|
||||
BIGNUM *ux = BN_new(), *exp = BN_new(), *S = BN_new();
|
||||
|
||||
BN_mod_exp(gx, g, x, N, bn_ctx); /* g^x mod N */
|
||||
BN_mod_mul(kgx, k, gx, N, bn_ctx); /* k * g^x mod N */
|
||||
BN_mod_sub(B_sub, B, kgx, N, bn_ctx); /* B - k*g^x mod N */
|
||||
BN_mul(ux, u, x, bn_ctx); /* u*x */
|
||||
BN_add(exp, a, ux); /* a + u*x */
|
||||
BN_mod_exp(S, B_sub, exp, N, bn_ctx); /* S */
|
||||
|
||||
/* K = H(S) */
|
||||
unsigned char S_bytes[256];
|
||||
memset(S_bytes, 0, 256);
|
||||
BN_bn2bin(S, S_bytes + (256 - BN_num_bytes(S)));
|
||||
unsigned char K[SHA256_DIGEST_LENGTH];
|
||||
SHA256(S_bytes, 256, K);
|
||||
|
||||
/* Compute M1 */
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, HNxorg, SHA256_DIGEST_LENGTH);
|
||||
SHA256_Update(&ctx, HI, SHA256_DIGEST_LENGTH);
|
||||
SHA256_Update(&ctx, salt, salt_len);
|
||||
SHA256_Update(&ctx, bufA, 256);
|
||||
SHA256_Update(&ctx, bufB, 256);
|
||||
SHA256_Update(&ctx, K, SHA256_DIGEST_LENGTH);
|
||||
SHA256_Final(M1, &ctx);
|
||||
|
||||
/* Cleanup */
|
||||
BN_free(x); BN_free(k); BN_free(u);
|
||||
BN_free(gx); BN_free(kgx); BN_free(B_sub); BN_free(ux); BN_free(exp); BN_free(S);
|
||||
BN_CTX_free(bn_ctx);
|
||||
}
|
||||
|
||||
EAppleAuthStatus CAppleAuth::Submit2FA( const char *szCode )
|
||||
{
|
||||
|
||||
}
|
||||
CUtlString CAppleAuth::EncryptPassword( const char *szPassword, CUtlString szSalt, uint32_t uIters, EPasswordType eType )
|
||||
{
|
||||
|
||||
unsigned char hashedPassword[SHA256_DIGEST_LENGTH];
|
||||
CUtlString szHashedPasswordHex = "";
|
||||
unsigned char encryptedPassword[32];
|
||||
CUtlString szEncryptedPasswordHex = "";
|
||||
unsigned char salt[32];
|
||||
int iSaltLen = base64_decode(szSalt, salt);
|
||||
|
||||
if ( eType == PASSWORD_TYPE_S2K )
|
||||
{
|
||||
for ( int i = 0; i < SHA256_DIGEST_LENGTH; i++ )
|
||||
{
|
||||
szHashedPasswordHex.AppendTail(CUtlString("%02x", hashedPassword[i]));
|
||||
}
|
||||
PKCS5_PBKDF2_HMAC(szHashedPasswordHex, szHashedPasswordHex.GetLenght(), salt, iSaltLen, uIters, EVP_sha256(), 32, encryptedPassword);
|
||||
};
|
||||
for ( int i = 0; i < SHA256_DIGEST_LENGTH; i++ )
|
||||
{
|
||||
szEncryptedPasswordHex.AppendTail(CUtlString("%02x", encryptedPassword[i]));
|
||||
}
|
||||
V_printf("%s\n",szEncryptedPasswordHex.GetString());
|
||||
return szEncryptedPasswordHex;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static CAppleAuth s_appleAuth;
|
||||
EXPOSE_INTERFACE_GLOBALVAR(CAppleAuth, IAppleAuth, APPLE_AUTH_INTERFACE_VERSION, s_appleAuth);
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(http, "../http/build.cpp")
|
||||
|
||||
DECLARE_BUILD_STAGE(appleauth)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "appleauth";
|
||||
compileProject.files = {
|
||||
"auth.cpp"
|
||||
};
|
||||
compileProject.includeDirectories = {"../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")});
|
||||
ldProject.libraries = {
|
||||
"crypto",
|
||||
};
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
CUtlString szOutputProject = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_OBJECT("appleauth", szOutputProject)
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
#include "asmrigs/as.h"
|
||||
#include "tier2/tokenizer.h"
|
||||
#include "asmrigs/tokenparser.h"
|
||||
|
||||
struct ObjectHeader_t
|
||||
{
|
||||
uint8_t m_magic[4];
|
||||
uint32_t m_uSymbolCount;
|
||||
uint32_t m_uDatasCount;
|
||||
};
|
||||
|
||||
enum EDataFlags: uint32_t
|
||||
{
|
||||
DATA_TYPE_DECLARE,
|
||||
DATA_TYPE_USED,
|
||||
};
|
||||
|
||||
struct Data_t
|
||||
{
|
||||
uint64_t m_uDataSize;
|
||||
uint64_t m_uDataOffsetSize;
|
||||
};
|
||||
|
||||
struct Symbol_t
|
||||
{
|
||||
uint32_t m_uName;
|
||||
uint32_t m_uData;
|
||||
EDataFlags m_eDataFlags;
|
||||
};
|
||||
|
||||
enum EInstruction: uint8_t
|
||||
{
|
||||
I_NOP = 0,
|
||||
|
||||
I_PUSH = 3,
|
||||
I_POP = 4,
|
||||
|
||||
I_CMP = 5,
|
||||
|
||||
I_JUMP = 6,
|
||||
I_JZ = 7,
|
||||
I_JNZ = 8,
|
||||
I_JG = 9,
|
||||
I_JGE = 10,
|
||||
I_JLE = 11,
|
||||
|
||||
I_LOAD = 12,
|
||||
I_STORE = 13,
|
||||
I_LOADPTR = 14,
|
||||
I_STOREPTR = 15,
|
||||
I_LOADLIT = 16,
|
||||
|
||||
I_JSR = 20,
|
||||
I_RET = 21,
|
||||
};
|
||||
|
||||
CUtlBuffer<uint8_t> Assemble( const char *szAssembly, AsOptions_t stOptions )
|
||||
{
|
||||
CUtlVector<CUtlString> externalFunctions;
|
||||
CUtlVector<CUtlString> publicFunctions;
|
||||
CUtlVector<CUtlString> labels;
|
||||
CUtlVector<Token_t> tokens = Tokenize(szAssembly);
|
||||
Token_t *pTokens = tokens.GetData();
|
||||
for ( int i = 0; i < tokens.GetSize()-2; )
|
||||
{
|
||||
if ( !tokens[i].m_bIsQuoted && tokens[i].m_szValue == "/" )
|
||||
if ( !tokens[i+1].m_bIsQuoted && tokens[i+1].m_szValue == "/" )
|
||||
if ( !tokens[i+2].m_bIsQuoted && tokens[i+2].m_szValue == "/" )
|
||||
{
|
||||
tokens.RemoveAt(i, 3);
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
};
|
||||
CTokenParser parser;
|
||||
parser.m_pTokens = tokens.GetData();
|
||||
parser.m_pTokensEnd = tokens.GetData()+tokens.GetSize();
|
||||
parser.m_pCurrentToken = tokens.GetData()-1;
|
||||
parser.Continue();
|
||||
|
||||
CUtlVector<uint8_t> commandStream;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (parser.IsEOF())
|
||||
break;
|
||||
CUtlString szCommand = parser.PeekToken();
|
||||
parser.Continue();
|
||||
if ( szCommand == "extrn" )
|
||||
{
|
||||
externalFunctions.AppendTail(parser.PeekToken());
|
||||
parser.Continue();
|
||||
continue;
|
||||
}
|
||||
if ( szCommand == "public" )
|
||||
{
|
||||
publicFunctions.AppendTail(parser.PeekToken());
|
||||
parser.Continue();
|
||||
continue;
|
||||
}
|
||||
if ( szCommand == "store" )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( szCommand == "load" )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( szCommand == "jsr" )
|
||||
{
|
||||
commandStream.AppendTail(I_JSR);
|
||||
continue;
|
||||
}
|
||||
if ( szCommand == "ret" )
|
||||
{
|
||||
commandStream.AppendTail(I_RET);
|
||||
continue;
|
||||
}
|
||||
if (parser.IsEOF())
|
||||
break;
|
||||
if (!V_strcmp(parser.PeekToken(), ":"))
|
||||
{
|
||||
parser.Continue();
|
||||
labels.AppendTail("");
|
||||
}
|
||||
else
|
||||
{
|
||||
V_printf("%s is not a valid instuction or label\n", szCommand.GetString());
|
||||
}
|
||||
}
|
||||
return {};
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "asmrigs/tokenparser.h"
|
||||
#include "asmrigs/as.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
CommandLine()->CreateCommandLine(argc, argv);
|
||||
|
||||
CreateInterfaceFn filesystemFactory = Sys_GetFactory("filesystem_std");
|
||||
filesystem = (IFileSystem*)filesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
|
||||
IFileHandle *pFile = filesystem->Open(argv[1], FILEMODE_READ);
|
||||
const char *szFileContents = filesystem->ReadString(pFile);
|
||||
filesystem->Close(pFile);
|
||||
|
||||
Assemble(szFileContents, {});
|
||||
return 0;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef BRB_H
|
||||
#define BRB_H
|
||||
|
||||
#include "tier2/tokenizer.h"
|
||||
#include "tier3/lexer.h"
|
||||
|
||||
|
||||
abstract_class IBGenerator
|
||||
{
|
||||
public:
|
||||
virtual void AddExternSymbol( const char *szName ) = 0;
|
||||
virtual void DefineFunction( const char *szName ) = 0;
|
||||
virtual void Load( uint8_t uRegister, int iValue ) = 0;
|
||||
virtual void Return() = 0;
|
||||
virtual CUtlString GetAssembly() = 0;
|
||||
};
|
||||
|
||||
#define B_GENERATOR_INTERFACE_VERSION "BGenerator001"
|
||||
|
||||
#endif
|
||||
@@ -1,395 +0,0 @@
|
||||
#include "brb.h"
|
||||
#include "asmrigs/tokenparser.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
|
||||
IBGenerator *g_pGenerator;
|
||||
|
||||
class CBGenerator: public IBGenerator
|
||||
{
|
||||
public:
|
||||
virtual void AddExternSymbol( const char *szName ) override;
|
||||
virtual void DefineFunction( const char *szName ) override;
|
||||
virtual CUtlString GetAssembly() override;
|
||||
CUtlVector<CUtlString> m_externalSymbols;
|
||||
CUtlString m_szAssembly;
|
||||
};
|
||||
EXPOSE_INTERFACE(CBGenerator, IBGenerator, B_GENERATOR_INTERFACE_VERSION);
|
||||
|
||||
void CBGenerator::AddExternSymbol( const char *szName )
|
||||
{
|
||||
m_externalSymbols.AppendTail(szName);
|
||||
}
|
||||
|
||||
void CBGenerator::DefineFunction( const char *szName )
|
||||
{
|
||||
m_szAssembly.AppendTail(CUtlString("public %s\n", szName));
|
||||
m_szAssembly.AppendTail(CUtlString("%s:\n", szName));
|
||||
}
|
||||
|
||||
CUtlString CBGenerator::GetAssembly()
|
||||
{
|
||||
return m_szAssembly;
|
||||
}
|
||||
|
||||
void CompileErrorExpectedToken( Token_t *pToken, const char *szToken )
|
||||
{
|
||||
if (pToken->m_bIsQuoted)
|
||||
V_printf("%d:%d: expected %s but got string literal\n", pToken->m_iLine, pToken->m_iCharacter, szToken);
|
||||
else
|
||||
V_printf("%d:%d: expected %s but got %s\n", pToken->m_iLine, pToken->m_iCharacter, szToken, pToken->m_szValue.GetString());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void CompileErrorUnexpectedToken( Token_t *pToken )
|
||||
{
|
||||
if (pToken->m_bIsQuoted)
|
||||
V_printf("%d:%d: unexpected string literal\n", pToken->m_iLine, pToken->m_iCharacter );
|
||||
else
|
||||
V_printf("%d:%d: unexpected %s\n", pToken->m_iLine, pToken->m_iCharacter, pToken->m_szValue.GetString());
|
||||
exit(1);
|
||||
}
|
||||
void CompileErrorGotRValue( Token_t *pToken )
|
||||
{
|
||||
V_printf("%d:%d: got rvalue when expected lvalue\n", pToken->m_iLine, pToken->m_iCharacter );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
enum EBValueType
|
||||
{
|
||||
EBVALUE_TYPE_UNKNOWN,
|
||||
EBVALUE_TYPE_INT_LITERAL,
|
||||
EBVALUE_TYPE_VARIABLE,
|
||||
};
|
||||
|
||||
struct BValue_t
|
||||
{
|
||||
enum EBValueType m_eType;
|
||||
int m_iLiteral;
|
||||
const char *m_szVarName;
|
||||
};
|
||||
|
||||
enum EBValueNodeOp
|
||||
{
|
||||
EBVALUE_OP_NOTHING,
|
||||
EBVALUE_OP_VALUE,
|
||||
EBVALUE_OP_READ_PTR,
|
||||
EBVALUE_OP_GET_PTR,
|
||||
EBVALUE_OP_ADD,
|
||||
EBVALUE_OP_SUB,
|
||||
EBVALUE_OP_MUL,
|
||||
EBVALUE_OP_DIV,
|
||||
EBVALUE_OP_PARENTHESIS,
|
||||
EBVALUE_OP_NEG,
|
||||
EBVALUE_OP_NOT,
|
||||
};
|
||||
|
||||
struct Node_t
|
||||
{
|
||||
BValue_t m_value;
|
||||
struct Node_t *m_pLeftValue;
|
||||
struct Node_t *m_pRightValue;
|
||||
EBValueNodeOp m_eOp;
|
||||
};
|
||||
|
||||
struct ScopeVariable_t
|
||||
{
|
||||
const char *szName;
|
||||
};
|
||||
|
||||
|
||||
BValue_t ParseVar( CTokenParser *pParser )
|
||||
{
|
||||
const char *szToken = pParser->PeekToken();
|
||||
|
||||
if (V_isdigit(szToken[0]))
|
||||
{
|
||||
pParser->Continue();
|
||||
return {EBVALUE_TYPE_INT_LITERAL, atoi(szToken)};
|
||||
}
|
||||
pParser->Continue();
|
||||
return {EBVALUE_TYPE_VARIABLE, 0, szToken};
|
||||
};
|
||||
Node_t *ParseExpr( CTokenParser *pParser );
|
||||
void ParseRValue( CTokenParser *pParser );
|
||||
Node_t *ParsePrimary( CTokenParser *pParser )
|
||||
{
|
||||
Node_t *pNode;
|
||||
if (pParser->IsToken("("))
|
||||
{
|
||||
pParser->Continue();
|
||||
pNode = ParseExpr(pParser);
|
||||
if (!pParser->IsToken(")"))
|
||||
CompileErrorExpectedToken(pParser->m_pCurrentToken, ")");
|
||||
pParser->Continue();
|
||||
goto lvalue;
|
||||
}
|
||||
pNode = new Node_t();
|
||||
pNode->m_eOp = EBVALUE_OP_VALUE;
|
||||
pNode->m_value = ParseVar( pParser );
|
||||
lvalue:
|
||||
if (pParser->IsToken("="))
|
||||
{
|
||||
if (pNode->m_eOp == EBVALUE_OP_VALUE)
|
||||
{
|
||||
if ( pNode->m_value.m_eType == EBVALUE_TYPE_VARIABLE )
|
||||
goto confirmedlvalue;
|
||||
};
|
||||
CompileErrorGotRValue(pParser->m_pCurrentToken);
|
||||
confirmedlvalue:
|
||||
pParser->Continue();
|
||||
ParseRValue(pParser);
|
||||
};
|
||||
|
||||
return pNode;
|
||||
}
|
||||
Node_t *ParseUnary( CTokenParser *pParser )
|
||||
{
|
||||
return ParsePrimary(pParser);
|
||||
}
|
||||
Node_t *ParseTerm( CTokenParser *pParser )
|
||||
{
|
||||
Node_t *pNode;
|
||||
Node_t *pNewNode;
|
||||
|
||||
EBValueNodeOp eOp = EBVALUE_OP_NOTHING;
|
||||
pNode = new Node_t();
|
||||
for (;;)
|
||||
{
|
||||
if (pParser->IsToken("*"))
|
||||
{
|
||||
pParser->Continue();
|
||||
eOp = EBVALUE_OP_MUL;
|
||||
}
|
||||
else if (pParser->IsToken("/"))
|
||||
{
|
||||
pParser->Continue();
|
||||
eOp = EBVALUE_OP_DIV;
|
||||
}
|
||||
else
|
||||
{
|
||||
pNode->m_eOp = eOp;
|
||||
if (pNode->m_pLeftValue == NULL)
|
||||
pNode->m_pLeftValue = ParseUnary(pParser);
|
||||
else
|
||||
{
|
||||
if (eOp == EBVALUE_OP_NOTHING)
|
||||
break;
|
||||
eOp = EBVALUE_OP_NOTHING;
|
||||
pNode->m_pRightValue = ParseUnary(pParser);
|
||||
pNewNode = new Node_t();
|
||||
pNewNode->m_pLeftValue = pNode;
|
||||
pNode = pNewNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pNode->m_pRightValue == NULL)
|
||||
{
|
||||
pNewNode = pNode->m_pLeftValue;
|
||||
delete pNode;
|
||||
return pNewNode;
|
||||
}
|
||||
return pNode;
|
||||
}
|
||||
|
||||
Node_t *ParseExpr( CTokenParser *pParser )
|
||||
{
|
||||
Node_t *pNode;
|
||||
Node_t *pNewNode;
|
||||
|
||||
EBValueNodeOp eOp = EBVALUE_OP_NOTHING;
|
||||
pNode = new Node_t();
|
||||
for (;;)
|
||||
{
|
||||
if (pParser->IsToken("+"))
|
||||
{
|
||||
pParser->Continue();
|
||||
eOp = EBVALUE_OP_ADD;
|
||||
}
|
||||
else if (pParser->IsToken("-"))
|
||||
{
|
||||
pParser->Continue();
|
||||
eOp = EBVALUE_OP_SUB;
|
||||
}
|
||||
else
|
||||
{
|
||||
pNode->m_eOp = eOp;
|
||||
if (pNode->m_pLeftValue == NULL)
|
||||
pNode->m_pLeftValue = ParseTerm(pParser);
|
||||
else
|
||||
{
|
||||
if (eOp == EBVALUE_OP_NOTHING)
|
||||
break;
|
||||
eOp = EBVALUE_OP_NOTHING;
|
||||
pNode->m_pRightValue = ParseTerm(pParser);
|
||||
pNewNode = new Node_t();
|
||||
pNewNode->m_pLeftValue = pNode;
|
||||
pNode = pNewNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pNode->m_pRightValue == NULL)
|
||||
{
|
||||
pNewNode = pNode->m_pLeftValue;
|
||||
delete pNode;
|
||||
return pNewNode;
|
||||
}
|
||||
return pNode;
|
||||
}
|
||||
|
||||
void PrintExpr( Node_t *pNode )
|
||||
{
|
||||
if ( pNode->m_eOp == EBVALUE_OP_VALUE )
|
||||
{
|
||||
switch ( pNode->m_value.m_eType )
|
||||
{
|
||||
case EBVALUE_TYPE_INT_LITERAL:
|
||||
V_printf("%i\n", pNode->m_value.m_iLiteral);
|
||||
break;
|
||||
case EBVALUE_TYPE_VARIABLE:
|
||||
V_printf("%s\n", pNode->m_value.m_szVarName);
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
if (pNode->m_pLeftValue)
|
||||
PrintExpr(pNode->m_pLeftValue);
|
||||
if (pNode->m_pRightValue)
|
||||
PrintExpr(pNode->m_pRightValue);
|
||||
if (pNode->m_eOp == EBVALUE_OP_ADD)
|
||||
V_printf("+\n");
|
||||
if (pNode->m_eOp == EBVALUE_OP_SUB)
|
||||
V_printf("-\n");
|
||||
if (pNode->m_eOp == EBVALUE_OP_MUL)
|
||||
V_printf("*\n");
|
||||
if (pNode->m_eOp == EBVALUE_OP_DIV)
|
||||
V_printf("/\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ParseRValue( CTokenParser *pParser )
|
||||
{
|
||||
PrintExpr(ParseExpr( pParser ));
|
||||
}
|
||||
|
||||
void ParseStatement( CTokenParser *pParser )
|
||||
{
|
||||
if (pParser->IsToken("return"))
|
||||
{
|
||||
pParser->Continue();
|
||||
ParseRValue( pParser );
|
||||
if (!pParser->IsToken(";"))
|
||||
CompileErrorExpectedToken(pParser->m_pCurrentToken, ";");
|
||||
V_printf(" ret\n");
|
||||
pParser->Continue();
|
||||
}
|
||||
else if (pParser->IsToken("extrn"))
|
||||
{
|
||||
pParser->Continue();
|
||||
for (;;)
|
||||
{
|
||||
const char *szName = pParser->PeekToken();
|
||||
pParser->Continue();
|
||||
if (pParser->IsToken(","))
|
||||
{
|
||||
pParser->Continue();
|
||||
continue;
|
||||
}
|
||||
if (pParser->IsToken(";"))
|
||||
{
|
||||
pParser->Continue();
|
||||
break;
|
||||
}
|
||||
CompileErrorUnexpectedToken(pParser->m_pCurrentToken);
|
||||
};
|
||||
}
|
||||
else if (pParser->IsToken("auto"))
|
||||
{
|
||||
pParser->Continue();
|
||||
for (;;)
|
||||
{
|
||||
const char *szName = pParser->PeekToken();
|
||||
pParser->Continue();
|
||||
if (pParser->IsToken(","))
|
||||
{
|
||||
pParser->Continue();
|
||||
continue;
|
||||
}
|
||||
if (pParser->IsToken(";"))
|
||||
{
|
||||
pParser->Continue();
|
||||
break;
|
||||
}
|
||||
CompileErrorUnexpectedToken(pParser->m_pCurrentToken);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
ParseRValue(pParser);
|
||||
if (!pParser->IsToken(";"))
|
||||
CompileErrorExpectedToken(pParser->m_pCurrentToken, ";");
|
||||
pParser->Continue();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void ParseGlobal( CTokenParser *pParser )
|
||||
{
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (pParser->IsEOF())
|
||||
break;
|
||||
const char *szObjectName = pParser->PeekToken();
|
||||
pParser->Continue();
|
||||
|
||||
if (pParser->IsToken("("))
|
||||
{
|
||||
pParser->Continue();
|
||||
if (!pParser->IsToken(")"))
|
||||
CompileErrorExpectedToken(pParser->m_pCurrentToken, ")");
|
||||
pParser->Continue();
|
||||
g_pGenerator->DefineFunction(szObjectName);
|
||||
|
||||
if (!pParser->IsToken("{"))
|
||||
CompileErrorExpectedToken(pParser->m_pCurrentToken, "{");
|
||||
pParser->Continue();
|
||||
while (!pParser->IsToken("}"))
|
||||
{
|
||||
ParseStatement( pParser );
|
||||
}
|
||||
pParser->Continue();
|
||||
}
|
||||
else
|
||||
{
|
||||
CompileErrorExpectedToken(pParser->m_pCurrentToken, "(");
|
||||
}
|
||||
}
|
||||
V_printf("%s\n", g_pGenerator->GetAssembly().GetString());
|
||||
};
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
CommandLine()->CreateCommandLine(argc, argv);
|
||||
|
||||
CreateInterfaceFn filesystemFactory = Sys_GetFactory("filesystem_std");
|
||||
filesystem = (IFileSystem*)filesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
|
||||
IFileHandle *pFile = filesystem->Open(argv[1], FILEMODE_READ);
|
||||
const char *szFileContents = filesystem->ReadString(pFile);
|
||||
filesystem->Close(pFile);
|
||||
|
||||
g_pGenerator = (IBGenerator*)CreateInterface(B_GENERATOR_INTERFACE_VERSION, NULL);
|
||||
|
||||
|
||||
CUtlVector<Token_t> tokens = Tokenize(szFileContents);
|
||||
CTokenParser parser;
|
||||
parser.m_pTokens = tokens.GetData();
|
||||
parser.m_pTokensEnd = tokens.GetData()+tokens.GetSize();
|
||||
parser.m_pCurrentToken = tokens.GetData()-1;
|
||||
parser.Continue();
|
||||
ParseGlobal(&parser);
|
||||
|
||||
V_free((void*)szFileContents);
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(fs, "../stdfilesystems/build.cpp")
|
||||
|
||||
|
||||
DECLARE_BUILD_STAGE(libbras)
|
||||
{
|
||||
CProject_t stProject = {};
|
||||
LinkProject_t stLink = {};
|
||||
CUtlString szBuiltFile = {};
|
||||
|
||||
stProject.m_szName = "bras";
|
||||
stProject.files = {
|
||||
"as/as.cpp",
|
||||
};
|
||||
stProject.includeDirectories = {
|
||||
"../public"
|
||||
};
|
||||
|
||||
stLink = ccompiler->Compile(&stProject);
|
||||
stLink.linkType = ELINK_STATIC_LIBRARY;
|
||||
stLink.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||
GET_PROJECT_LIBRARY(tier1, "tier1"),
|
||||
GET_PROJECT_LIBRARY(tier2, "tier2"),
|
||||
};
|
||||
szBuiltFile = linker->Link(&stLink);
|
||||
ADD_OUTPUT_OBJECT("bras", szBuiltFile);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(bras)
|
||||
{
|
||||
CProject_t stProject = {};
|
||||
LinkProject_t stLink = {};
|
||||
CUtlString szBuiltFile = {};
|
||||
|
||||
stProject.m_szName = "bras";
|
||||
stProject.files = {
|
||||
"as/main.cpp",
|
||||
};
|
||||
stProject.includeDirectories = {
|
||||
"../public"
|
||||
};
|
||||
|
||||
stLink = ccompiler->Compile(&stProject);
|
||||
stLink.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY(libbras, "bras"),
|
||||
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||
GET_PROJECT_LIBRARY(tier1, "tier1"),
|
||||
GET_PROJECT_LIBRARY(tier2, "tier2"),
|
||||
};
|
||||
szBuiltFile = linker->Link(&stLink);
|
||||
ADD_OUTPUT_OBJECT("bras", szBuiltFile);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(brb)
|
||||
{
|
||||
CProject_t stProject = {};
|
||||
LinkProject_t stLink = {};
|
||||
CUtlString szBuiltFile = {};
|
||||
|
||||
stProject.m_szName = "bc";
|
||||
stProject.files = {
|
||||
"brb/main.cpp",
|
||||
};
|
||||
stProject.includeDirectories = {
|
||||
"../public"
|
||||
};
|
||||
|
||||
stLink = ccompiler->Compile(&stProject);
|
||||
stLink.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY(libbras, "bras"),
|
||||
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||
GET_PROJECT_LIBRARY(tier1, "tier1"),
|
||||
GET_PROJECT_LIBRARY(tier2, "tier2"),
|
||||
};
|
||||
szBuiltFile = linker->Link(&stLink);
|
||||
ADD_OUTPUT_OBJECT("bc", szBuiltFile);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(install)
|
||||
{
|
||||
CUtlString szBuildOutput = CUtlString("build/%s", Target_t::DefaultTarget().GetTriplet().GetString());
|
||||
filesystem2->MakeDirectory(szBuildOutput);
|
||||
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_OBJECT(brb, "bc"));
|
||||
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_OBJECT(bras, "bras"));
|
||||
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_LIBRARY(tier0, "tier0"));
|
||||
filesystem2->CopyFile(szBuildOutput, GET_PROJECT_LIBRARY(filesystem_std, "fs"));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
public min
|
||||
min:
|
||||
pop b
|
||||
pop c
|
||||
min a, b, c
|
||||
ret
|
||||
|
||||
public max
|
||||
max:
|
||||
pop b
|
||||
pop c
|
||||
max a, b, c
|
||||
ret
|
||||
|
||||
public abs
|
||||
abs:
|
||||
pop b
|
||||
abs a, b, c
|
||||
ret
|
||||
|
||||
public sign
|
||||
sign:
|
||||
pop b
|
||||
sign a, b
|
||||
ret
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
_tick()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
public _tick
|
||||
_tick:
|
||||
ret
|
||||
@@ -1,5 +0,0 @@
|
||||
_tick()
|
||||
{
|
||||
extrn a;
|
||||
a = 30;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
public _tick
|
||||
_tick:
|
||||
ret
|
||||
@@ -1,5 +0,0 @@
|
||||
_tick()
|
||||
{
|
||||
extrn a;
|
||||
a = 1 + 2 * 3 * ( 4 + 5 );
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
main()
|
||||
{
|
||||
extrn something;
|
||||
auto a, b;
|
||||
a = 10;
|
||||
b = a + 5;
|
||||
return b;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
add(a,b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
return add(2,3);
|
||||
}
|
||||
96
build.cpp
96
build.cpp
@@ -2,88 +2,26 @@
|
||||
#include "helper.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
|
||||
CUtlVector<CUtlString> all_IncludeDirectories = {
|
||||
"public",
|
||||
"external",
|
||||
"external/Vulkan-Headers/include",
|
||||
"external/Vulkan-Utility-Libraries/include",
|
||||
"external/volk",
|
||||
"external/cglm/include",
|
||||
"external/stb",
|
||||
"external/SDL/include",
|
||||
"external/steamworks/public",
|
||||
"external/GameNetworkingSockets/include",
|
||||
};
|
||||
|
||||
auto szTarget = Target_t::DefaultTarget().GetTriplet();
|
||||
auto szOutputDir = CUtlString("build/funnygame/%s/game",szTarget.GetString());
|
||||
auto szOutputDir = CUtlString("build/funnygame/%s/game", szTarget.GetString());
|
||||
|
||||
bool bStaticBuild = false;
|
||||
bool bSteam = false;
|
||||
CUtlString steam_lib;
|
||||
ADD_DEPENDENCY_BUILD_FILE(launcher, "launcher/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(engine, "engine/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(ms, "materialsystem/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(fs, "external/funnystdlib/stdfilesystems/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, "external/funnystdlib/tier0/build.cpp");
|
||||
|
||||
extern "C" void Preinit()
|
||||
DECLARE_BUILD_STAGE(install)
|
||||
{
|
||||
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS || Target_t::DefaultTarget().kernel == TARGET_KERNEL_WINDOWS)
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(launcher, "launcher"));
|
||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(engine, "engine"));
|
||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(MaterialSystem, "MaterialSystem"));
|
||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(RenderSystemVulkan, "RenderSystemVulkan"));
|
||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(tier0, "tier0"));
|
||||
filesystem2->CopyFile(szOutputDir, GET_PROJECT_OBJECT(filesystem_std, "fs"));
|
||||
if (Target_t::DefaultTarget().kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||
{
|
||||
bStaticBuild = true;
|
||||
}
|
||||
|
||||
if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS || Target_t::DefaultTarget().kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
all_IncludeDirectories.AppendTail("external/metal-cpp");
|
||||
} else {
|
||||
all_IncludeDirectories.AppendTail("external/Vulkan-Headers/include");
|
||||
all_IncludeDirectories.AppendTail("external/VulkanMemoryAllocator/include");
|
||||
}
|
||||
switch ( Target_t::DefaultTarget().kernel )
|
||||
{
|
||||
case TARGET_KERNEL_WINDOWS:
|
||||
bSteam = true;
|
||||
steam_lib = "external/steamworks/redistributable_bin/win64/steam_api64.dll";
|
||||
break;
|
||||
case TARGET_KERNEL_LINUX:
|
||||
bSteam = true;
|
||||
steam_lib = "external/steamworks/redistributable_bin/linux64/libsteam_api.so";
|
||||
break;
|
||||
case TARGET_KERNEL_DARWIN:
|
||||
bSteam = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (bSteam)
|
||||
{
|
||||
if (bStaticBuild)
|
||||
{
|
||||
filesystem2->MakeDirectory(CUtlString("%s/bin", szOutputDir.GetString()));
|
||||
filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), steam_lib);
|
||||
} else
|
||||
{
|
||||
filesystem2->MakeDirectory(CUtlString("%s/bin", szOutputDir.GetString()));
|
||||
filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), steam_lib);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CUtlString tier0_lib;
|
||||
CUtlString engine_lib;
|
||||
CUtlString server_lib;
|
||||
CUtlString client_lib;
|
||||
|
||||
#include "tier0/__build.cpp"
|
||||
#include "tier1/__build.cpp"
|
||||
#include "tier2/__build.cpp"
|
||||
|
||||
#include "game/server/__build.cpp"
|
||||
#include "game/client/__build.cpp"
|
||||
|
||||
#include "materialsystem/__build.cpp"
|
||||
|
||||
#include "rapier/__build.cpp"
|
||||
#include "engine/__build.cpp"
|
||||
#include "shadercompiler/__build.cpp"
|
||||
|
||||
#include "launcher/__build.cpp"
|
||||
#include "funnyassets/__build.cpp"
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> engine_CompiledFiles = {
|
||||
"engine/engine.cpp",
|
||||
@@ -27,10 +26,11 @@ DECLARE_BUILD_STAGE(engine)
|
||||
|
||||
compileProject.m_szName = "engine";
|
||||
compileProject.files = engine_CompiledFiles;
|
||||
compileProject.includeDirectories = all_IncludeDirectories;
|
||||
compileProject.includeDirectories = {"public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
|
||||
/*
|
||||
if (bStaticBuild)
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
else
|
||||
@@ -41,20 +41,25 @@ DECLARE_BUILD_STAGE(engine)
|
||||
ldProject.objects.AppendTail((Object_t){material_lib});
|
||||
if (bSteam)
|
||||
ldProject.objects.AppendTail((Object_t){steam_lib});
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
}
|
||||
*/
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
|
||||
ldProject.libraries = engine_Libraries;
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
CUtlString szOutputDir = linker->Link(&ldProject);
|
||||
|
||||
/*
|
||||
if (!bStaticBuild)
|
||||
{
|
||||
*/
|
||||
filesystem2->MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString()));
|
||||
filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), outputProject);
|
||||
filesystem2->CopyFile(CUtlString("%s/bin", szOutputDir.GetString()), szOutputDir);
|
||||
/*
|
||||
} else {
|
||||
engine_lib = outputProject;
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -2,15 +2,20 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
ADD_DEPENDENCY_BUILD_FILE(MaterialSystem, "../materialsystem/")
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/");
|
||||
#define FUNNYSTDLIB "../external/funnystdlib/"
|
||||
ADD_DEPENDENCY_BUILD_FILE(MaterialSystem, "../materialsystem/build.cpp")
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
|
||||
|
||||
DECLARE_BUILD_STAGE(engine)
|
||||
{
|
||||
bool bUsesSDL = true;
|
||||
if (Target_t::DefaultTarget().cpu == TARGET_CPU_WASM32)
|
||||
{
|
||||
bUsesSDL = false;
|
||||
}
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
@@ -19,14 +24,16 @@ DECLARE_BUILD_STAGE(engine)
|
||||
"engine.cpp",
|
||||
"cvar.cpp",
|
||||
|
||||
"gamewindow_sdl.cpp",
|
||||
|
||||
"sv_dll.cpp",
|
||||
"cl_dll.cpp",
|
||||
};
|
||||
if (bUsesSDL)
|
||||
compileProject.files.AppendTail("gamewindow_sdl.cpp");
|
||||
|
||||
compileProject.includeDirectories = {
|
||||
"../public",
|
||||
"../external/SDL/include",
|
||||
FUNNYSTDLIB"public",
|
||||
};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
@@ -34,12 +41,29 @@ DECLARE_BUILD_STAGE(engine)
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
ldProject.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY("tier1", "tier1"),
|
||||
GET_PROJECT_LIBRARY("tier2", "tier2"),
|
||||
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||
};
|
||||
ldProject.libraries = {
|
||||
"SDL3"
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")});
|
||||
|
||||
if (bUsesSDL)
|
||||
ldProject.libraries.AppendTail("SDL3");
|
||||
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||
{
|
||||
ldProject.libraryDirectories = {"../external/windows"};
|
||||
ldProject.libraries.AppendTail("winpthread-1");
|
||||
ldProject.libraries.AppendTail("winmm");
|
||||
ldProject.libraries.AppendTail("ole32");
|
||||
ldProject.libraries.AppendTail("gdi32");
|
||||
ldProject.libraries.AppendTail("oleaut32");
|
||||
ldProject.libraries.AppendTail("setupapi");
|
||||
ldProject.libraries.AppendTail("imm32");
|
||||
ldProject.libraries.AppendTail("version");
|
||||
ldProject.libraries.AppendTail("shell32");
|
||||
ldProject.libraries.AppendTail("uuid");
|
||||
|
||||
};
|
||||
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_OBJECT("engine", outputProject)
|
||||
|
||||
@@ -3,22 +3,26 @@
|
||||
#include "igamewindow.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/commandline.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier0/mem.h"
|
||||
#include "sv_dll.h"
|
||||
|
||||
IRenderContext *g_pRenderContext;
|
||||
IFileSystem *filesystem;
|
||||
|
||||
extern "C" void FunnyMain( int argc, char **argv )
|
||||
{
|
||||
CommandLine()->CreateCommandLine(argc, argv);
|
||||
|
||||
void *pFilesystem = Plat_LoadLibrary("libfilesystem.so");
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem);
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std");
|
||||
|
||||
filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
filesystem->Init();
|
||||
|
||||
gamewindow->Init();
|
||||
g_pMaterialSystem->Init();
|
||||
CreateInterfaceFn pMaterialSystemFactory = Sys_GetFactory("MaterialSystem");
|
||||
CreateInterfaceFn pRenderSystemFactory = Sys_GetFactory("RenderSystemVulkan");
|
||||
g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL);
|
||||
g_pRenderContext->Init();
|
||||
|
||||
ServerGameDLL()->Init();
|
||||
|
||||
@@ -43,26 +47,25 @@ extern "C" void FunnyMain( int argc, char **argv )
|
||||
|
||||
pCameraInfoBuffer = g_pRenderContext->CreateConstantBuffer(64);
|
||||
|
||||
/*
|
||||
pShader = g_pRenderContext->CreateShader("funnygame/core/shaders/flat.shader_c");
|
||||
pMaterial = g_pRenderContext->CreateMaterial(pShader);
|
||||
pMaterial->PSSetConstantsBuffer(0, pCameraInfoBuffer);
|
||||
*/
|
||||
|
||||
pOutputImage = g_pRenderContext->CreateRenderTarget(
|
||||
g_pRenderContext->GetNewOutputImageWidth(),
|
||||
g_pRenderContext->GetNewOutputImageHeight(),
|
||||
1280,
|
||||
720,
|
||||
IMAGE_FORMAT_RGBA8_UNORM,
|
||||
MULTISAMPLE_TYPE_NONE);
|
||||
|
||||
IRenderCommandList *pCommandList = g_pRenderContext->CreateCommandList();
|
||||
pCommandList->StartRecording();
|
||||
pCommandList->SetRenderTarget(0, pOutputImage);
|
||||
pCommandList->SetMaterial(pMaterial);
|
||||
pCommandList->SetVertexBuffer(0, pVertices);
|
||||
pCommandList->DrawPrimitives(3, 0, 1, 0);
|
||||
pCommandList->SetClearColor(0, 1,0,0,0);
|
||||
pCommandList->EndRecording();
|
||||
|
||||
for (;;) {
|
||||
gamewindow->UpdateWindow();
|
||||
/*
|
||||
if (g_pRenderContext->BIsOutputImageOutdated())
|
||||
{
|
||||
@@ -77,11 +80,7 @@ extern "C" void FunnyMain( int argc, char **argv )
|
||||
*/
|
||||
|
||||
g_pRenderContext->SubmitCommandList(pCommandList);
|
||||
|
||||
g_pRenderContext->SetOutputImage(pOutputImage);
|
||||
|
||||
gamewindow->UpdateWindow();
|
||||
Materials()->Frame(0);
|
||||
g_pRenderContext->Frame(0);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -36,9 +36,9 @@ void CGameManager::Init()
|
||||
CUtlString sz;
|
||||
|
||||
pFile = filesystem->Open("game.ini", FILEMODE_READ);
|
||||
szData = CUtlBuffer<char>(pFile->Size());
|
||||
pFile->Read(szData.GetMemory(), szData.GetSize());
|
||||
pFile->Close();
|
||||
szData = CUtlBuffer<char>(filesystem->Size(pFile));
|
||||
filesystem->Read(pFile, szData.GetMemory(), szData.GetSize());
|
||||
filesystem->Close(pFile);
|
||||
|
||||
g_pGameParameters= INIManager()->ReadString(szData);
|
||||
pMainGame = g_pGameParameters->GetSection("MainGame");
|
||||
|
||||
@@ -17,48 +17,22 @@ class CSDLGameWindow: public IGameWindow
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual void Shutdown() override;
|
||||
virtual void UpdateWindow() override;
|
||||
virtual void Tick( float fDelta ) override;
|
||||
virtual void Frame( float fDelta ) override;
|
||||
virtual uint32_t GetRenderWidth() override;
|
||||
virtual uint32_t GetRenderHeight() override;
|
||||
|
||||
// Rendering info
|
||||
virtual void SetRenderImage( IImage *pImage ) override;
|
||||
virtual bool BIsRenderResolutionUpdated() override;
|
||||
virtual void GetRenderWidth() override;
|
||||
virtual void GetRenderHeight() override;
|
||||
|
||||
// Vulkan stuff
|
||||
virtual int GetVulkanInstanceExtensionCount() override;
|
||||
virtual const char **GetVulkanInstanceExtensions() override;
|
||||
|
||||
virtual void CreateVulkanSurface( void *pInstance, void *pDevice ) override;
|
||||
virtual void DestroyVulkanSurface( void *pInstance, void *pDevice ) override;
|
||||
|
||||
virtual void *GetVulkanSurface() override;
|
||||
virtual void *GetVulkanFence( int iFrame ) override;
|
||||
virtual void *GetVulkanDrawSemaphore( int iFrame ) override;
|
||||
virtual void *GetVulkanPresentSemaphore( int iFrame ) override;
|
||||
virtual IImage *GetVulkanSwapchainImage( int iFrame ) override;
|
||||
virtual void *CreateVulkanSurface( void *pInstance ) override;
|
||||
virtual void DestroyVulkanSurface( void *pInstance ) override;
|
||||
private:
|
||||
|
||||
VkSurfaceKHR m_hSurface;
|
||||
SDL_Window *m_pWindow;
|
||||
EGraphicsAPI m_ePreferredGraphicsAPI;
|
||||
|
||||
uint32_t m_uRenderWidth;
|
||||
uint32_t m_uRenderHeight;
|
||||
bool m_bIsRenderResolutionUpdated;
|
||||
|
||||
void *m_pVulkanSurface;
|
||||
CUtlVector<IImage*> m_vulkanImages;
|
||||
void *m_pVulkanFences[VULKAN_FRAMES_IN_FLIGHT];
|
||||
void *m_pVulkanPresentSemaphores[VULKAN_FRAMES_IN_FLIGHT];
|
||||
};
|
||||
|
||||
CSDLGameWindow g_sdlGameWindow;
|
||||
IGameWindow *gamewindow = &g_sdlGameWindow;
|
||||
|
||||
|
||||
void CSDLGameWindow::Init()
|
||||
{
|
||||
m_ePreferredGraphicsAPI = GRAPHICS_API_VULKAN;
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD))
|
||||
Plat_FatalErrorFunc("SDL_Init: %s\n", SDL_GetError());
|
||||
|
||||
@@ -72,18 +46,14 @@ void CSDLGameWindow::Shutdown()
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindow::UpdateWindow()
|
||||
void CSDLGameWindow::Frame( float fDelta )
|
||||
{
|
||||
SDL_Event event;
|
||||
m_bIsRenderResolutionUpdated = false;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
m_bIsRenderResolutionUpdated = true;
|
||||
m_uRenderWidth = event.window.data1;
|
||||
m_uRenderWidth = event.window.data2;
|
||||
break;
|
||||
case SDL_EVENT_QUIT:
|
||||
SDL_Quit();
|
||||
@@ -94,46 +64,92 @@ void CSDLGameWindow::UpdateWindow()
|
||||
}
|
||||
}
|
||||
}
|
||||
EGraphicsAPI CSDLGameWindow::GetGraphicsAPI()
|
||||
void CSDLGameWindow::Tick( float fDelta )
|
||||
{
|
||||
return GRAPHICS_API_VULKAN;
|
||||
|
||||
};
|
||||
|
||||
uint32_t CSDLGameWindow::GetRenderWidth()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CSDLGameWindow::GetVulkanInstanceExtensionCount()
|
||||
uint32_t CSDLGameWindow::GetRenderHeight()
|
||||
{
|
||||
if ( m_ePreferredGraphicsAPI != GRAPHICS_API_VULKAN )
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void *CSDLGameWindow::CreateVulkanSurface( void *pInstance )
|
||||
{
|
||||
SDL_Vulkan_CreateSurface(m_pWindow, (VkInstance)pInstance, NULL, (VkSurfaceKHR*)&m_hSurface);
|
||||
return (void*)m_hSurface;
|
||||
}
|
||||
|
||||
void CSDLGameWindow::DestroyVulkanSurface( void *pInstance )
|
||||
{
|
||||
SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_hSurface, NULL);
|
||||
}
|
||||
|
||||
class CSDLGameWindowManager: public IGameWindowManager
|
||||
{
|
||||
|
||||
virtual void Init() override;
|
||||
virtual void Tick( float fDelta ) override;
|
||||
virtual void Frame( float fDelta ) override;
|
||||
virtual void Shutdown() override;
|
||||
|
||||
virtual IGameWindow *CreateWindow() override;
|
||||
virtual void DestroyWindow( IGameWindow* pWindow ) override;
|
||||
|
||||
virtual int GetVulkanInstanceExtensionCount() override;
|
||||
virtual const char **GetVulkanInstanceExtensions() override;
|
||||
};
|
||||
|
||||
void CSDLGameWindowManager::Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::Tick( float fDelta )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::Frame( float fDelta )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
IGameWindow *CSDLGameWindowManager::CreateWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSDLGameWindowManager::DestroyWindow( IGameWindow* pWindow )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int CSDLGameWindowManager::GetVulkanInstanceExtensionCount()
|
||||
{
|
||||
uint32_t nCount;
|
||||
SDL_Vulkan_GetInstanceExtensions(&nCount);
|
||||
|
||||
return nCount;
|
||||
}
|
||||
|
||||
const char **CSDLGameWindow::GetVulkanInstanceExtensions()
|
||||
const char **CSDLGameWindowManager::GetVulkanInstanceExtensions()
|
||||
{
|
||||
if ( m_ePreferredGraphicsAPI != GRAPHICS_API_VULKAN )
|
||||
return 0;
|
||||
|
||||
uint32_t nCount;
|
||||
return (const char **)SDL_Vulkan_GetInstanceExtensions(&nCount);
|
||||
}
|
||||
|
||||
void CSDLGameWindow::CreateVulkanSurface( void *pInstance )
|
||||
{
|
||||
if ( m_ePreferredGraphicsAPI != GRAPHICS_API_VULKAN )
|
||||
return;
|
||||
|
||||
SDL_Vulkan_CreateSurface(m_pWindow, (VkInstance)pInstance, NULL, (VkSurfaceKHR*)&m_pVulkanSurface);
|
||||
}
|
||||
|
||||
void CSDLGameWindow::DestroyVulkanSurface( void *pInstance )
|
||||
{
|
||||
SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_pVulkanSurface, NULL);
|
||||
}
|
||||
|
||||
void *CSDLGameWindow::GetVulkanSurface()
|
||||
{
|
||||
return m_pVulkanSurface;
|
||||
}
|
||||
|
||||
|
||||
1
external/funnystdlib
vendored
Submodule
1
external/funnystdlib
vendored
Submodule
Submodule external/funnystdlib added at 07089ffe1c
@@ -1 +0,0 @@
|
||||
[i386-unknown-linux]
|
||||
79
fpc/Makefile
79
fpc/Makefile
@@ -1,79 +0,0 @@
|
||||
# We want to build just enough to use other stuff
|
||||
TIER0_FILES := ../tier0/lib.cpp ../tier0/mem.cpp ../tier0/platform.cpp ../tier0/commandline.cpp ../tier0/rand.cpp
|
||||
TIER1_FILES := ../tier1/utlbuffer.cpp ../tier1/interface.cpp ../tier1/utlstring.cpp ../tier1/utlvector.cpp ../tier1/utlmap.cpp
|
||||
TIER2_FILES := ../tier2/filesystem.cpp ../tier2/fileformats/ini.cpp ../tier2/tokenizer.cpp ../tier2/fileformats/json.cpp
|
||||
FILESYSTEM_FILES := ../stdfilesystems/filesystem_libc.cpp
|
||||
TIER1_OBJS := $(TIER1_FILES:.cpp=.o)
|
||||
TIER2_OBJS := $(TIER2_FILES:.cpp=.o)
|
||||
FPC_FILES := library/helper.cpp library/target.cpp library/builder.cpp library/runner.cpp library/c.cpp library/ld.cpp library/clang/c.cpp library/clang/ld.cpp
|
||||
CC = clang++
|
||||
|
||||
ifneq ($(FPC_ARCH),)
|
||||
ifneq ($(FPC_OS),)
|
||||
ifneq ($(FPC_ABI),)
|
||||
REAL_TARGET := -target $(FPC_ARCH)-$(FPC_OS)-$(FPC_ABI) -DFPC_ARCH=\"$(FPC_ARCH)\" -DFPC_OS=\"$(FPC_OS)\" -DFPC_ABI=\"$(FPC_ABI)\"
|
||||
else
|
||||
REAL_TARGET := -target $(FPC_ARCH)-$(FPC_OS) -DFPC_ARCH=\"$(FPC_ARCH)\" -DFPC_OS=\"$(FPC_OS)\"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
CCFLAGS = $(REAL_TARGET) -g -I../public -Ipublic
|
||||
|
||||
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)
|
||||
endif
|
||||
|
||||
recompile: ../build/tools/fpc
|
||||
build/fpc build
|
||||
|
||||
install: ../build/tools/fpc build/libfpcbuild.a build/libfpc.so build/libtier0.so build/libtier1.a build/libtier2.a build/libfilesystem_std.so install_temp builddir
|
||||
$(CC) -fPIC main.cpp library/helper.cpp library/target.cpp library/builder.cpp -lc -lstdc++ $(CCFLAGS) -o build/fpc -ltier0 -Lbuild build/libtier1.a build/libtier2.a -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN'
|
||||
build/fpc build -fpcdebug
|
||||
mv build/fpc_temp build/fpc
|
||||
mv build/libfpc_temp.so build/libfpc.so
|
||||
build/fpc build -fpcdebug
|
||||
mv build/fpc_temp build/fpc
|
||||
mv build/libfpc_temp.so build/libfpc.so
|
||||
|
||||
build/libtier0.so: $(TIER0_FILES) builddir
|
||||
$(CC) $(CCFLAGS) -fPIC -shared -o build/libtier0.so $(TIER0_FILES)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) $(CCFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
build/libtier1.a: $(TIER1_OBJS) builddir build/libtier0.so
|
||||
ar rcs build/libtier1.a $(TIER1_OBJS)
|
||||
|
||||
build/libtier2.a: $(TIER2_OBJS) builddir build/libtier1.a
|
||||
ar rcs build/libtier2.a $(TIER2_OBJS)
|
||||
|
||||
build/libfilesystem_std.so: $(FILESYSTEM_FILES) build/libtier1.a build/libtier0.so builddir
|
||||
$(CC) $(CCFLAGS) -fPIC -shared -o build/libfilesystem_std.so $(FILESYSTEM_FILES) build/libtier1.a -ltier0 -Lbuild
|
||||
|
||||
build/libfpcbuild.a: buildfile/interfaces.o builddir
|
||||
ar rcs build/libfpcbuild.a buildfile/interfaces.o
|
||||
|
||||
build/libfpc.so: $(FPC_FILES) builddir build/libfpcbuild.a build/libtier1.a build/libtier2.a
|
||||
$(CC) $(CCFLAGS) $(FPC_FILES) library/libfpc.cpp -fPIC -shared -o build/libfpc.so build/libtier1.a build/libtier2.a
|
||||
|
||||
builddir:
|
||||
mkdir -p build
|
||||
|
||||
../build/tools/fpc:
|
||||
mkdir -p ../build/tools/fpc
|
||||
|
||||
install_fpc: ../build/tools/fpc
|
||||
cp -r build/* ../build/tools/fpc
|
||||
|
||||
install_temp: builddir
|
||||
cp -r public build
|
||||
cp -r ../public/tier0 build/public
|
||||
cp -r ../public/tier1 build/public
|
||||
cp -r ../public/tier2 build/public
|
||||
|
||||
auto: install install_fpc
|
||||
|
||||
34
fpc/README
34
fpc/README
@@ -1,34 +0,0 @@
|
||||
funny project compiler
|
||||
|
||||
fpc is a simple project manager written in C++ without usage of STL.
|
||||
Instead it uses C++ files for building stuff with quite simple API.
|
||||
It also generates compile_commands.json.
|
||||
|
||||
basics cheat sheet
|
||||
|
||||
With this toolset it should be sufficient enough to build any simple application.
|
||||
|
||||
DECLARE_BUILD_STAGE( stage_name, function ) - Declares build stage
|
||||
|
||||
CProject - compiler output base;
|
||||
CShaderProject - shader compiler output base (NOT IMPLEMENTED)
|
||||
|
||||
CCProject - C, C++, Objective-C, Objective-C++ compiler
|
||||
CLDProject - linker
|
||||
|
||||
IFileSystem2 - simple filesystem for creating, deleting and copying stuff
|
||||
|
||||
usage parameters cheat sheet
|
||||
|
||||
-os - sets target kernel
|
||||
windows
|
||||
linux
|
||||
macos
|
||||
ios
|
||||
android
|
||||
|
||||
-arch - sets target arch
|
||||
x86_64
|
||||
aarch64
|
||||
|
||||
-fpcdebug - shows shell command used to run the command
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "swift.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, "../../tier1/build.cpp");
|
||||
|
||||
DECLARE_BUILD_STAGE(xtool)
|
||||
{
|
||||
if (!linker->IsLibraryExists("swiftCore"))
|
||||
{
|
||||
V_printf("Swift is not installed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
CUtlString outputProject = CUtlString("fpcxtool/.build/%s/debug/libfpcxtool.so",Target_t::HostTarget().GetTriplet().GetString());
|
||||
V_printf("SWIFT %s\n", outputProject.GetString());
|
||||
|
||||
CUtlVector<CUtlString> args = {"build"};
|
||||
runner->Run("swift","fpcxtool", args);
|
||||
runner->Wait();
|
||||
|
||||
ADD_OUTPUT_OBJECT("xtool", outputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(xtool_cpp)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
CUtlString szOutputProject = "";
|
||||
|
||||
compileProject.m_szName = "xtool";
|
||||
compileProject.files = {
|
||||
"fpcxtool/fpcxtool.cpp"
|
||||
};
|
||||
compileProject.includeDirectories = {"../public","../../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(xtool, "xtool")});
|
||||
ldProject.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY(tier1, "tier1"),
|
||||
};
|
||||
|
||||
szOutputProject = linker->Link(&ldProject);
|
||||
ADD_OUTPUT_OBJECT("xtool", szOutputProject);
|
||||
return 0;
|
||||
}
|
||||
160
fpc/build.cpp
160
fpc/build.cpp
@@ -1,160 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(tier2, "../tier2/build.cpp");
|
||||
ADD_DEPENDENCY_BUILD_FILE(appleauth, "../appleauth/build.cpp");
|
||||
|
||||
|
||||
CUtlVector<CUtlString> g_fpcFiles = {
|
||||
|
||||
"main.cpp",
|
||||
"library/helper.cpp",
|
||||
"library/target.cpp",
|
||||
"library/builder.cpp",
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> g_libFpcFiles = {
|
||||
"library/libfpc.cpp",
|
||||
"library/helper.cpp",
|
||||
"library/target.cpp",
|
||||
"library/builder.cpp",
|
||||
"library/runner.cpp",
|
||||
"library/winerunner.cpp",
|
||||
"library/deploy.cpp",
|
||||
|
||||
"library/c.cpp",
|
||||
"library/ld.cpp",
|
||||
"library/swift.cpp",
|
||||
|
||||
"library/android/apktool.cpp",
|
||||
"library/apple/appletool.cpp",
|
||||
|
||||
"library/clang/c.cpp",
|
||||
"library/clang/ld.cpp",
|
||||
|
||||
"library/windows/c.cpp",
|
||||
"library/windows/ld.cpp",
|
||||
|
||||
"library/apple/swift.cpp",
|
||||
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> g_IncludeDirectories = {
|
||||
"public",
|
||||
"../public",
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(libfpcbuild)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "fpcbuild";
|
||||
compileProject.files = g_libFpcFiles;
|
||||
compileProject.includeDirectories = g_IncludeDirectories;
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
|
||||
|
||||
ADD_OUTPUT_OBJECT("fpcbuild", outputProject)
|
||||
|
||||
return 0;
|
||||
}
|
||||
DECLARE_BUILD_STAGE(libfpc)
|
||||
{
|
||||
if (linker->IsLibraryExists("clang"))
|
||||
g_libFpcFiles.AppendTail("library/clang/c_libclang.cpp");
|
||||
else
|
||||
V_printf("Warning: to support included files libclang must be installed.\n");
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "fpc";
|
||||
compileProject.files = g_libFpcFiles;
|
||||
compileProject.includeDirectories = g_IncludeDirectories;
|
||||
compileProject.bFPIC = true;
|
||||
compileProject.macros = {
|
||||
{"FPC_ARCH", CUtlString("\"%s\"",Target_t::StringFromCPU(compileProject.m_target.cpu))},
|
||||
{"FPC_OS", CUtlString("\"%s\"",Target_t::StringFromKernel(compileProject.m_target.kernel))},
|
||||
{"FPC_ABI", CUtlString("\"%s\"",Target_t::StringFromABI(compileProject.m_target.abi))},
|
||||
};
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
ldProject.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||
GET_PROJECT_LIBRARY(tier1, "tier1"),
|
||||
GET_PROJECT_LIBRARY(tier2, "tier2"),
|
||||
};
|
||||
|
||||
if (linker->IsLibraryExists("clang"))
|
||||
ldProject.libraries.AppendTail("clang");
|
||||
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
|
||||
|
||||
ADD_OUTPUT_OBJECT("fpc", outputProject)
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
DECLARE_BUILD_STAGE(fpc)
|
||||
{
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "fpc";
|
||||
compileProject.files = g_fpcFiles;
|
||||
compileProject.bFPIC = true;
|
||||
compileProject.includeDirectories = g_IncludeDirectories;
|
||||
compileProject.macros = {
|
||||
{"FPC_ARCH", CUtlString("\"%s\"",Target_t::StringFromCPU(compileProject.m_target.cpu))},
|
||||
{"FPC_OS", CUtlString("\"%s\"",Target_t::StringFromKernel(compileProject.m_target.kernel))},
|
||||
{"FPC_ABI", CUtlString("\"%s\"",Target_t::StringFromABI(compileProject.m_target.abi))},
|
||||
};
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.libraryObjects = {
|
||||
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||
GET_PROJECT_LIBRARY(tier1, "tier1"),
|
||||
GET_PROJECT_LIBRARY(tier2, "tier2"),
|
||||
};
|
||||
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
|
||||
|
||||
ADD_OUTPUT_OBJECT("fpc", outputProject);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
DECLARE_BUILD_STAGE(install)
|
||||
{
|
||||
CUtlString szExe = GET_PROJECT_LIBRARY(fpc, "fpc");
|
||||
CUtlString szLibFpc = GET_PROJECT_LIBRARY(libfpc, "fpc");
|
||||
CUtlString szTier0 = GET_PROJECT_LIBRARY(tier0, "tier0");
|
||||
CUtlString szTier1 = GET_PROJECT_LIBRARY(tier1, "tier1");
|
||||
CUtlString szTier2 = GET_PROJECT_LIBRARY(tier2, "tier2");
|
||||
CUtlString szHttp = GET_PROJECT_LIBRARY(funnyhttp, "funnyhttp");
|
||||
CUtlString szAppleAuth = GET_PROJECT_LIBRARY(appleauth, "appleauth");
|
||||
|
||||
filesystem2->CopyFile("build/fpc_temp", szExe);
|
||||
filesystem2->CopyFile("build/libfpc_temp.so", szLibFpc);
|
||||
filesystem2->CopyFile("build", szHttp);
|
||||
filesystem2->CopyFile("build", szAppleAuth);
|
||||
|
||||
/*
|
||||
filesystem2->CopyFile("build/libtier1.a", szTier1);
|
||||
filesystem2->CopyFile("build/libtier2.a", szTier2);
|
||||
filesystem2->CopyFile("build/libtier0_temp.so", szTier0);
|
||||
*/
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
#include "tier1/interface.h"
|
||||
#include "helper.h"
|
||||
|
||||
static BuildFileInfo_t buildfileinfo = {};
|
||||
CBuildStage *g_pCurrentStage = NULL;
|
||||
GetProjectObjectFn g_pfnGetProjectObject = NULL;
|
||||
|
||||
BuildFileInfo_t *GetBuildFileInfo()
|
||||
{
|
||||
return &buildfileinfo;
|
||||
}
|
||||
|
||||
|
||||
CBuildStage::CBuildStage( const char *psz, int(*pMainFn)() )
|
||||
{
|
||||
m_psz = psz;
|
||||
m_pMainFn = pMainFn;
|
||||
if (psz == 0 || pMainFn == 0)
|
||||
Plat_FatalErrorFunc("Name and function pointer must be set\n");
|
||||
|
||||
GetBuildFileInfo()->m_stages.AppendTail(this);
|
||||
};
|
||||
|
||||
CBuildDependentFile::CBuildDependentFile( const char *psz )
|
||||
{
|
||||
// TODO: This doesn't affect recursion, which is bad
|
||||
|
||||
GetBuildFileInfo()->m_dependantFiles.AppendTail(psz);
|
||||
}
|
||||
|
||||
CUtlString FPC_GetProjectObject( const char *szName, const char *szObjectName )
|
||||
{
|
||||
CUtlString szOutputString;
|
||||
szOutputString = g_pfnGetProjectObject(szName, szObjectName);
|
||||
return szOutputString;
|
||||
}
|
||||
|
||||
|
||||
EXPOSE_INTERFACE_GLOBALVAR(BuildFileInfo_t, BuildFileInfo_t, BUILD_FILE_INFO_INTERFACE_VERSION, buildfileinfo);
|
||||
EXPOSE_INTERFACE_GLOBALVAR(CBuildStage, CBuildStage, BUILD_CURRENT_STAGE_INTERFACE_VERSION, g_pCurrentStage);
|
||||
EXPOSE_INTERFACE_GLOBALVAR(GetProjectObjectFn, GetProjectObjectFn, BUILD_GET_PROJECT_OBJECT_INTERFACE_VERSION, g_pfnGetProjectObject);
|
||||
57
fpc/external/build.cpp
vendored
57
fpc/external/build.cpp
vendored
@@ -1,57 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
|
||||
DECLARE_BUILD_STAGE(zsign)
|
||||
{
|
||||
if (!filesystem)
|
||||
{
|
||||
void *pFilesystem = Plat_LoadLibrary("libfilesystem_std.so");
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem);
|
||||
|
||||
filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
}
|
||||
IDirectoryHandle *pDir = filesystem->OpenDir("zsign");
|
||||
if (!pDir)
|
||||
return 0;
|
||||
filesystem->CloseDir(pDir);
|
||||
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
CUtlString szOutputProject = "";
|
||||
|
||||
compileProject.m_szName = "zsign";
|
||||
compileProject.m_target = Target_t::HostTarget();
|
||||
compileProject.bFPIC = true;
|
||||
compileProject.files = {
|
||||
"zsign/src/common/archive.cpp",
|
||||
"zsign/src/common/base64.cpp",
|
||||
"zsign/src/common/fs.cpp",
|
||||
"zsign/src/common/json.cpp",
|
||||
"zsign/src/common/log.cpp",
|
||||
"zsign/src/common/sha.cpp",
|
||||
"zsign/src/common/timer.cpp",
|
||||
"zsign/src/common/util.cpp",
|
||||
"zsign/src/archo.cpp",
|
||||
"zsign/src/bundle.cpp",
|
||||
"zsign/src/macho.cpp",
|
||||
"zsign/src/openssl.cpp",
|
||||
"zsign/src/signing.cpp",
|
||||
"zsign/src/zsign.cpp",
|
||||
};
|
||||
compileProject.includeDirectories = {
|
||||
"zsign/src/common",
|
||||
"zsign/src",
|
||||
};
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
|
||||
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
szOutputProject = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_OBJECT("zsign", szOutputProject);
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
fpc/external/zsign
vendored
1
fpc/external/zsign
vendored
Submodule fpc/external/zsign deleted from cb49b1d34e
@@ -1,207 +0,0 @@
|
||||
#include "apktool.h"
|
||||
#include "helper.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "runner.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
void AndroidManifest_t::SetPackageVersion( CUtlString szVersion )
|
||||
{
|
||||
m_szVersion = szVersion;
|
||||
}
|
||||
|
||||
void AndroidManifest_t::SetPackageBuild( uint64_t nBuild )
|
||||
{
|
||||
m_nBuild = nBuild;
|
||||
}
|
||||
|
||||
void AndroidManifest_t::SetPackageID( CUtlString szPackageID )
|
||||
{
|
||||
m_szPackageID = szPackageID;
|
||||
}
|
||||
|
||||
void AndroidManifest_t::SetPackageName( CUtlString szPackageName )
|
||||
{
|
||||
m_szPackageName = szPackageName;
|
||||
}
|
||||
|
||||
void AndroidManifest_t::SetTargetSDKVersion( uint64_t nTargetVersion )
|
||||
{
|
||||
m_nTargetVersion = nTargetVersion;
|
||||
}
|
||||
|
||||
void AndroidManifest_t::SetMinSDKVersion( uint64_t nMinVersion )
|
||||
{
|
||||
m_nMinVersion = nMinVersion;
|
||||
}
|
||||
|
||||
void AndroidManifest_t::AddUserFeature( CUtlString szName, bool bIsRequired, uint64_t nVersion )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AndroidManifest_t::AddUserLibrary( CUtlString szPath )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CUtlString AndroidManifest_t::BuildManifest()
|
||||
{
|
||||
CPUProject_t project = {};
|
||||
project.m_szName = m_szPackageName;
|
||||
unsigned int hash = project.GenerateProjectHash();
|
||||
CUtlString szOutputDir = CUtlString("%s/android/%u_%s/",FPC_TEMPORAL_DIRNAME, hash, m_szPackageID.GetString());
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
filesystem2->MakeDirectory(CUtlString("%s/res", szOutputDir.GetString()));
|
||||
|
||||
CUtlString szAndroidManifestPath = CUtlString("%s/AndroidManifest.xml", szOutputDir.GetString());
|
||||
FILE *pAndroidManifest = V_fopen(szAndroidManifestPath, "wb");
|
||||
|
||||
V_fprintf(pAndroidManifest, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
V_fprintf(pAndroidManifest, "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"%s\">\n", m_szPackageID.GetString());
|
||||
V_fprintf(pAndroidManifest, "<uses-sdk android:minSdkVersion=\"%lu\" android:targetSdkVersion=\"%lu\" />\n",m_nMinVersion, m_nTargetVersion);
|
||||
V_fprintf(pAndroidManifest, "<application android:label=\"%s\" android:hasCode=\"false\" android:debuggable=\"true\">\n", m_szPackageName.GetString());
|
||||
V_fprintf(pAndroidManifest, "<activity android:name=\"android.app.NativeActivity\" android:label=\"%s\" android:exported=\"true\">\n", m_szPackageName.GetString());
|
||||
V_fprintf(pAndroidManifest, "<meta-data android:name=\"android.app.lib_name\" android:value=\"native-app\" />\n");
|
||||
V_fprintf(pAndroidManifest, "<intent-filter>\n");
|
||||
V_fprintf(pAndroidManifest, "<action android:name=\"android.intent.action.MAIN\" />\n");
|
||||
V_fprintf(pAndroidManifest, "<category android:name=\"android.intent.category.LAUNCHER\" />\n");
|
||||
V_fprintf(pAndroidManifest, "</intent-filter>\n");
|
||||
V_fprintf(pAndroidManifest, "</activity>\n");
|
||||
V_fprintf(pAndroidManifest, "</application>\n");
|
||||
V_fprintf(pAndroidManifest, "</manifest>\n");
|
||||
|
||||
V_fclose(pAndroidManifest);
|
||||
return szOutputDir;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CAPKTool : public IAPKTool
|
||||
{
|
||||
public:
|
||||
virtual CUtlString BuildPackage( AndroidManifest_t manifest, CUtlString szManifestDir ) override;
|
||||
virtual CUtlString SignPackage( const char *szApk, LegalInfo_t *pLegalInfo, const char *szAlias, const char *szStorePassword, const char *szKeyPassword ) override;
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
CUtlString CAPKTool::BuildPackage( AndroidManifest_t manifest, CUtlString szManifestDir )
|
||||
{
|
||||
|
||||
V_printf(" APKTOOL %s\n", manifest.m_szPackageID.GetString());
|
||||
|
||||
IINISection *pSection = NULL;
|
||||
const char *szBuildTools;
|
||||
pSection = g_pConfig->GetSection("Android_Build_Tools");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("build_tools are required for this target");
|
||||
szBuildTools = pSection->GetStringValue("path");
|
||||
CUtlVector<CUtlString> args = {
|
||||
"package",
|
||||
"-f",
|
||||
"-M",
|
||||
"AndroidManifest.xml",
|
||||
"-S",
|
||||
"res",
|
||||
"-I",
|
||||
CUtlString("%s/../../platforms/android-%lu/android.jar", szBuildTools, manifest.m_nTargetVersion),
|
||||
"-F",
|
||||
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
|
||||
};
|
||||
runner->Run(CUtlString("%s/aapt",szBuildTools),szManifestDir,args);
|
||||
runner->Wait();
|
||||
|
||||
args = {
|
||||
"-u",
|
||||
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
|
||||
"lib/x86_64/libnative-app.so",
|
||||
};
|
||||
runner->Run("zip",szManifestDir, args);
|
||||
runner->Wait();
|
||||
|
||||
args = {
|
||||
"-f",
|
||||
"-v",
|
||||
"4",
|
||||
CUtlString("%s.unaligned.apk", manifest.m_szPackageID.GetString()),
|
||||
CUtlString("%s.apk", manifest.m_szPackageID.GetString()),
|
||||
};
|
||||
runner->Run(CUtlString("%s/zipalign",szBuildTools),szManifestDir,args);
|
||||
runner->Wait();
|
||||
|
||||
return CUtlString("%s/%s.apk",szManifestDir.GetString(), manifest.m_szPackageID.GetString());
|
||||
}
|
||||
|
||||
CUtlString CAPKTool::SignPackage( const char *szApk, LegalInfo_t *pLegalInfo, const char *szAlias, const char *szStorePassword, const char *szKeyPassword )
|
||||
{
|
||||
V_printf(" APKSIGN %s\n", szApk );
|
||||
CUtlString szOutput = CUtlString("%s.signed", szApk);
|
||||
LegalInfo_t stLegalInfo = {};
|
||||
CUtlVector<CUtlString> args = {};
|
||||
|
||||
CPUProject_t project = {};
|
||||
project.m_szName = szAlias;
|
||||
unsigned int hash = project.GenerateProjectHash();
|
||||
CUtlString szOutputDir = CUtlString("%s/android/%u_%s/",FPC_TEMPORAL_DIRNAME, hash, szAlias);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
CUtlString szKeystoreDir = CUtlString("%s/%s.jks",szOutputDir.GetString(),szAlias);
|
||||
CUtlString szDname = "";
|
||||
|
||||
IINISection *pSection = NULL;
|
||||
const char *szBuildTools;
|
||||
pSection = g_pConfig->GetSection("Android_Build_Tools");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("build_tools are required for this target");
|
||||
szBuildTools = pSection->GetStringValue("path");
|
||||
|
||||
// We need to have a name at least
|
||||
stLegalInfo.FirstName = "Gordon";
|
||||
stLegalInfo.LastName = "Freeman";
|
||||
|
||||
if (pLegalInfo != NULL)
|
||||
stLegalInfo = *pLegalInfo;
|
||||
|
||||
if (!stLegalInfo.FirstName)
|
||||
Plat_FatalErrorFunc("First name wasn't provided\n");
|
||||
if (!stLegalInfo.LastName)
|
||||
Plat_FatalErrorFunc("Last name wasn't provided\n");
|
||||
szDname.AppendTail(CUtlString("CN=%s %s", stLegalInfo.FirstName, stLegalInfo.LastName));
|
||||
|
||||
args = {
|
||||
"-genkeypair",
|
||||
"-keystore", szKeystoreDir,
|
||||
"-alias", szAlias,
|
||||
"-keyalg", "RSA",
|
||||
"-keysize", "2048",
|
||||
"-validity", "10000",
|
||||
"-storepass", szStorePassword,
|
||||
"-keypass", szKeyPassword,
|
||||
"-dname", szDname,
|
||||
};
|
||||
runner->Run("keytool", args);
|
||||
runner->Wait();
|
||||
|
||||
args = {
|
||||
"sign",
|
||||
"--ks", szKeystoreDir,
|
||||
"--ks-key-alias", szAlias,
|
||||
"--ks-pass", CUtlString("pass:%s",szStorePassword),
|
||||
"--key-pass", CUtlString("pass:%s",szKeyPassword),
|
||||
szApk,
|
||||
};
|
||||
runner->Run(CUtlString("%s/apksigner",szBuildTools), args);
|
||||
runner->Wait();
|
||||
|
||||
return szApk;
|
||||
};
|
||||
|
||||
IAPKTool *APKTool()
|
||||
{
|
||||
static CAPKTool s_apktool = {};
|
||||
return &s_apktool;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "signtool.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
|
||||
class CAndroidSignTool : public ISignTool
|
||||
{
|
||||
public:
|
||||
virtual void SignFile( CUtlString szFile ) override;
|
||||
virtual void SignDirectory( CUtlString szDirectory ) override;
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CAndroidSignTool, ISignTool, ANDROID_SIGN_TOOL_INTERFACE_NAME);
|
||||
|
||||
void CAndroidSignTool::SignFile( CUtlString szFile )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CAndroidSignTool::SignDirectory( CUtlString szDirectory )
|
||||
{
|
||||
V_printf("Android doesn't support signing of directories\n");
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
#include "appletool.h"
|
||||
#include "helper.h"
|
||||
#include "runner.h"
|
||||
#include "appleauth/iauth.h"
|
||||
|
||||
void AppleManifest_t::SetPackageID( CUtlString szPackageID )
|
||||
{
|
||||
m_szPackageID = szPackageID;
|
||||
}
|
||||
|
||||
void AppleManifest_t::SetPackageName( CUtlString szPackageName )
|
||||
{
|
||||
m_szPackageName = szPackageName;
|
||||
}
|
||||
|
||||
void AppleManifest_t::SetPackageExecutable( CUtlString szPackageExecutable )
|
||||
{
|
||||
m_szPackageExecutable = szPackageExecutable;
|
||||
}
|
||||
|
||||
CUtlString AppleManifest_t::BuildManifest()
|
||||
{
|
||||
CPUProject_t project = {};
|
||||
project.m_szName = m_szPackageName;
|
||||
unsigned int hash = project.GenerateProjectHash();
|
||||
CUtlString szOutputDir = CUtlString("%s/apple/%u_%s/app/",FPC_TEMPORAL_DIRNAME, hash, m_szPackageID.GetString());
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
filesystem2->CopyFile(szOutputDir, m_szPackageExecutable);
|
||||
CUtlString szInfoPlist = CUtlString("%s/Info.plist", szOutputDir.GetString());
|
||||
FILE *pInfoPlistFile = V_fopen(szInfoPlist, "wb");
|
||||
|
||||
V_fprintf(pInfoPlistFile, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
V_fprintf(pInfoPlistFile, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
|
||||
V_fprintf(pInfoPlistFile, "<plist version=\"1.0\">\n");
|
||||
V_fprintf(pInfoPlistFile, "<dict>\n");
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundleIdentifier</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>%s</string>\n", m_szPackageID.GetString());
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundleName</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>%s</string>\n", m_szPackageName.GetString());
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundleDisplayName</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>%s</string>\n", m_szPackageName.GetString());
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundleExecutable</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>%s</string>\n", m_szPackageExecutable.GetFileName().GetString());
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundlePackageType</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>APPL</string>\n");
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundleVersion</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>1.0</string>\n");
|
||||
V_fprintf(pInfoPlistFile, "<key>CFBundleShortVersionString</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<string>1.0</string>\n");
|
||||
V_fprintf(pInfoPlistFile, "<key>LSRequiresIPhoneOS</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<true/>\n");
|
||||
V_fprintf(pInfoPlistFile, "<key>UIDeviceFamily</key>\n");
|
||||
V_fprintf(pInfoPlistFile, "<array>\n");
|
||||
V_fprintf(pInfoPlistFile, "<integer>1</integer>\n");
|
||||
V_fprintf(pInfoPlistFile, "<integer>2</integer>\n");
|
||||
V_fprintf(pInfoPlistFile, "</array>\n");
|
||||
V_fprintf(pInfoPlistFile, "</dict>\n");
|
||||
|
||||
V_fclose(pInfoPlistFile);
|
||||
return szOutputDir;
|
||||
}
|
||||
|
||||
|
||||
class CAppleTool: public IAppleTool
|
||||
{
|
||||
public:
|
||||
virtual CUtlString BuildPackage( AppleManifest_t manifest, CUtlString szManifestDir ) override;
|
||||
virtual CUtlString SignPackage( const char *szIpa, const char *szPassword ) override;
|
||||
};
|
||||
|
||||
CUtlString CAppleTool::BuildPackage( AppleManifest_t manifest, CUtlString szManifestDir )
|
||||
{
|
||||
CUtlVector<CUtlString> args = {};
|
||||
args = {
|
||||
"-r",
|
||||
CUtlString("../%s.ipa", manifest.m_szPackageName.GetString()),
|
||||
CUtlString("."),
|
||||
};
|
||||
runner->Run("zip",szManifestDir, args);
|
||||
runner->Wait();
|
||||
return CUtlString("../%s.ipa", manifest.m_szPackageName.GetString());
|
||||
}
|
||||
|
||||
static IAppleAuth *g_pAppleAuth;
|
||||
CUtlString CAppleTool::SignPackage( const char *szIpa, const char *szPassword )
|
||||
{
|
||||
CreateInterfaceFn fnFactory = Sys_GetFactory("appleauth");
|
||||
if (fnFactory == NULL)
|
||||
Plat_FatalErrorFunc("Couldn't get xtool\n");
|
||||
|
||||
g_pAppleAuth = (IAppleAuth*)fnFactory(APPLE_AUTH_INTERFACE_VERSION, NULL);
|
||||
g_pAppleAuth->Init();
|
||||
char *szGSAEmail = CommandLine()->ParamValue("-apple-login");
|
||||
char *szGSAPassword = CommandLine()->ParamValue("-apple-password");
|
||||
if (szGSAEmail && szGSAPassword)
|
||||
g_pAppleAuth->SubmitLoginData(szGSAEmail, szGSAPassword);
|
||||
return szIpa;
|
||||
}
|
||||
|
||||
|
||||
IAppleTool *AppleTool()
|
||||
{
|
||||
static CAppleTool s_tool;
|
||||
return &s_tool;
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
#include "swift.h"
|
||||
|
||||
class CSwiftCompiler: public ISwiftCompiler
|
||||
{
|
||||
public:
|
||||
|
||||
// Compiles all files into objects, returns linker project,
|
||||
// which can be linked into executable or library.
|
||||
//virtual LinkProject_t Compile( SwiftProject_t *pProject );
|
||||
|
||||
//virtual void GenerateLinterData() ;
|
||||
|
||||
protected:
|
||||
// Compiler internals
|
||||
|
||||
virtual CUtlVector<CUtlString> BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName ) override;
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( SwiftProject_t *pProject ) override;
|
||||
|
||||
// returns object file format, eg .obj or .o
|
||||
virtual const char *GetOutputObjectFormat() override;
|
||||
|
||||
virtual void IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue ) override;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, SwiftProject_t *pProject ) override;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, SwiftProject_t *pProject , const char *szSysroot ) override;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
|
||||
virtual void CompileFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
|
||||
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) override;
|
||||
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) override;
|
||||
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) override;
|
||||
};
|
||||
|
||||
const char *CSwiftCompiler::GetOutputObjectFormat()
|
||||
{
|
||||
return ".o";
|
||||
}
|
||||
|
||||
CUtlVector<CUtlString> CSwiftCompiler::BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName )
|
||||
{
|
||||
CUtlVector<CUtlString> cmd;
|
||||
cmd = ISwiftCompiler::BuildCommandLine(pProject, szFileName, szOutputFileName);
|
||||
cmd.AppendHead("-c");
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
const char *CSwiftCompiler::GetCompilerExecutable( SwiftProject_t *pProject )
|
||||
{
|
||||
return "swiftc";
|
||||
}
|
||||
|
||||
|
||||
void CSwiftCompiler::IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-I");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
|
||||
void CSwiftCompiler::IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CSwiftCompiler::Macro( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CSwiftCompiler::Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue )
|
||||
{
|
||||
cmd.AppendTail("-D");
|
||||
cmd.AppendTail(CUtlString("%s=%s", (char*)szName, (char*)szValue));
|
||||
}
|
||||
|
||||
void CSwiftCompiler::EnableDebugSymbols( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
cmd.AppendTail("-g");
|
||||
}
|
||||
|
||||
void CSwiftCompiler::SetTarget( CUtlVector<CUtlString> &cmd, SwiftProject_t *pProject )
|
||||
{
|
||||
cmd.AppendTail("-target");
|
||||
cmd.AppendTail(pProject->m_target.GetTriplet());
|
||||
}
|
||||
|
||||
void CSwiftCompiler::CompileFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
void CSwiftCompiler::SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-o");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
void CSwiftCompiler::EnablePIE( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
cmd.AppendTail("-fPIE");
|
||||
}
|
||||
|
||||
void CSwiftCompiler::EnablePIC( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
cmd.AppendTail("-fPIC");
|
||||
}
|
||||
void CSwiftCompiler::SetSysroot( CUtlVector<CUtlString> &cmd, SwiftProject_t *pProject, const char *szName )
|
||||
{
|
||||
if (szName != NULL)
|
||||
{
|
||||
cmd.AppendTail("--sysroot");
|
||||
cmd.AppendTail(szName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_pConfig)
|
||||
return;
|
||||
|
||||
|
||||
IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
|
||||
if (!pSection)
|
||||
return;
|
||||
|
||||
const char *szSysroot = pSection->GetStringValue("sysroot");
|
||||
if (szSysroot)
|
||||
{
|
||||
cmd.AppendTail("--sysroot");
|
||||
cmd.AppendTail(szSysroot);
|
||||
}
|
||||
}
|
||||
|
||||
EXPOSE_INTERFACE(CSwiftCompiler, ISwiftCompiler, SWIFT_COMPILER_INTERFACE_VERSION)
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
#include "builder.h"
|
||||
#include "ld.h"
|
||||
#include "c.h"
|
||||
|
||||
CUtlVector<BuildFileInfo_t> buildFileInfos = {};
|
||||
|
||||
|
||||
class CProjectBuilder : public IProjectBuilder
|
||||
{
|
||||
public:
|
||||
virtual BuildFile_t *BuildProject( const char *szProjectName, const char *szPath ) override;
|
||||
|
||||
BuildFile_t *m_pBuildFiles = NULL;
|
||||
};
|
||||
|
||||
|
||||
static CProjectBuilder s_projectBuilder;
|
||||
|
||||
EXPOSE_INTERFACE_GLOBALVAR(CProjectBuilder, IProjectBuilder, PROJECT_BUILDER_INTERFACE_NAME, s_projectBuilder)
|
||||
|
||||
IProjectBuilder *ProjectBuilder()
|
||||
{
|
||||
return &s_projectBuilder;
|
||||
};
|
||||
|
||||
CUtlString FPC_GetProjectObject( const char *szName, const char *szObjectName )
|
||||
{
|
||||
for (auto b: buildFileInfos)
|
||||
{
|
||||
for (auto s: b.m_stages)
|
||||
{
|
||||
if (strcmp(s->m_psz, szName))
|
||||
continue;
|
||||
for (auto o: s->m_outputs)
|
||||
{
|
||||
if (strcmp(o.m_szName, szObjectName))
|
||||
continue;
|
||||
|
||||
return o.m_szPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BuildFile_t *CProjectBuilder::BuildProject( const char *szProjectName, const char *szPath )
|
||||
{
|
||||
CProject_t stCompileProject = {};
|
||||
LinkProject_t stLinkProject = {};
|
||||
CUtlString szBuildLibrary;
|
||||
void *pLibrary;
|
||||
CreateInterfaceFn pBuildFactory;
|
||||
BuildFileInfo_t *pBuildFileInfo;
|
||||
BuildFileInfo_t stBuildFileInfo;
|
||||
BuildFile_t *pBuildFile = NULL;
|
||||
CBuildStage **ppExecutedBuildStage = NULL;
|
||||
GetProjectObjectFn *pfnGetProjectObject = NULL;
|
||||
CUtlString szWd = CUtlString(szPath).GetDirectory();
|
||||
|
||||
Plat_SetWorkingDir(szWd);
|
||||
|
||||
|
||||
stCompileProject.m_szName = szProjectName;
|
||||
stCompileProject.files = {
|
||||
szPath,
|
||||
};
|
||||
stCompileProject.includeDirectories = {CUtlString("%s/public",filesystem2->OwnDirectory())};
|
||||
stCompileProject.bFPIC = true;
|
||||
stCompileProject.m_target = Target_t::HostTarget();
|
||||
|
||||
stLinkProject = ccompiler->Compile(&stCompileProject);
|
||||
stLinkProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
stLinkProject.m_target = Target_t::HostTarget();
|
||||
stLinkProject.objects.AppendHead({CUtlString("%s/libfpcbuild.a",filesystem2->OwnDirectory())});
|
||||
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libfpc.so",filesystem2->OwnDirectory())});
|
||||
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libtier2.a",filesystem2->OwnDirectory())});
|
||||
stLinkProject.libraryObjects.AppendHead({CUtlString("%s/libtier1.a",filesystem2->OwnDirectory())});
|
||||
szBuildLibrary = linker->Link(&stLinkProject);
|
||||
|
||||
pLibrary = Plat_LoadLibrary(szBuildLibrary);
|
||||
if ( !pLibrary )
|
||||
return NULL;
|
||||
|
||||
pBuildFactory = Sys_GetFactory(pLibrary);
|
||||
if (!pBuildFactory)
|
||||
{
|
||||
V_printf("Failed to find CreateInterface\n");
|
||||
Plat_UnloadLibrary(szBuildLibrary);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pBuildFileInfo = (BuildFileInfo_t*)pBuildFactory(BUILD_FILE_INFO_INTERFACE_VERSION, NULL);
|
||||
ppExecutedBuildStage = (CBuildStage**)pBuildFactory(BUILD_CURRENT_STAGE_INTERFACE_VERSION, NULL);
|
||||
pfnGetProjectObject = (GetProjectObjectFn*)pBuildFactory(BUILD_GET_PROJECT_OBJECT_INTERFACE_VERSION, NULL);
|
||||
if (!pBuildFileInfo || !ppExecutedBuildStage || !pfnGetProjectObject)
|
||||
{
|
||||
V_printf("Required interfaces are not present\n");
|
||||
Plat_UnloadLibrary(szBuildLibrary);
|
||||
return NULL;
|
||||
}
|
||||
stBuildFileInfo = *pBuildFileInfo;
|
||||
buildFileInfos.AppendTail(stBuildFileInfo);
|
||||
*pfnGetProjectObject = FPC_GetProjectObject;
|
||||
for (auto a: stBuildFileInfo.m_dependantFiles)
|
||||
{
|
||||
BuildProject("something", CUtlString("%s/%s",szWd.GetString(),a));
|
||||
}
|
||||
|
||||
Plat_SetWorkingDir(szWd);
|
||||
|
||||
|
||||
for (auto &build: stBuildFileInfo.m_stages)
|
||||
{
|
||||
*ppExecutedBuildStage = build;
|
||||
build->m_pMainFn();
|
||||
for ( auto &o: build->m_outputs)
|
||||
{
|
||||
o.m_szPath.AppendHead("/");
|
||||
o.m_szPath.AppendHead(Plat_GetWorkingDir());
|
||||
};
|
||||
};
|
||||
|
||||
pBuildFile = new BuildFile_t;
|
||||
pBuildFile->m_szOutputFile = szBuildLibrary;
|
||||
pBuildFile->m_pLibrary = pLibrary;
|
||||
pBuildFile->m_pNext = m_pBuildFiles;
|
||||
m_pBuildFiles = pBuildFile;
|
||||
|
||||
|
||||
return pBuildFile;
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "target.h"
|
||||
#include <libgen.h>
|
||||
|
||||
ICCompiler *ccompiler;
|
||||
|
||||
CUtlString ICCompiler::GetOutputObjectName( CProject_t *pProject, unsigned int hash, CUtlString szFileName )
|
||||
{
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
|
||||
return CUtlString(
|
||||
"%s/%s/cc/%u_%s/%s/%s%s",
|
||||
FPC_TEMPORAL_DIRNAME,
|
||||
szTarget.GetString(),
|
||||
hash,
|
||||
pProject->m_szName.GetString(),
|
||||
filesystem2->BuildDirectory(),
|
||||
szFileName.GetString(),
|
||||
GetOutputObjectFormat());
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> ICCompiler::BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName )
|
||||
{
|
||||
|
||||
CUtlVector<CUtlString> cmd;
|
||||
|
||||
EnableDebugSymbols(cmd);
|
||||
if (pProject->bFPIC)
|
||||
EnablePIC(cmd);
|
||||
if (pProject->bFPIE)
|
||||
EnablePIE(cmd);
|
||||
SetTarget(cmd, pProject);
|
||||
SetOutputFile(cmd, szOutputFileName);
|
||||
SetSysroot(cmd, pProject, NULL);
|
||||
CompileFile(cmd, szFileName);
|
||||
for (auto ¯o: pProject->macros)
|
||||
Macro(cmd, macro.szName, macro.szValue.GetString());
|
||||
for (auto &dir: pProject->includeDirectories)
|
||||
IncludeDirectory(cmd, dir);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
LinkProject_t ICCompiler::Compile( CProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
LinkProject_t proj = {};
|
||||
proj.m_szName = pProject->m_szName;
|
||||
proj.m_target = pProject->m_target;
|
||||
proj.m_androidmanifest = pProject->m_androidmanifest;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
|
||||
|
||||
// Get output directories
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
}
|
||||
|
||||
// Run CC
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
args = BuildCommandLine(pProject, file, szOutputFile);
|
||||
if (!filesystem2->ShouldRecompile(file, szOutputFile))
|
||||
goto skipcompile;
|
||||
else
|
||||
V_printf(" CC %s\n", file.GetString());
|
||||
runner->Run(GetCompilerExecutable(pProject), args);
|
||||
skipcompile:
|
||||
proj.objects.AppendTail((Object_t){szOutputFile});
|
||||
}
|
||||
runner->Wait();
|
||||
return proj;
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "c_libclang.h"
|
||||
#include "helper.h"
|
||||
#include "obj.h"
|
||||
#include "target.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier2/fileformats/json.h"
|
||||
#include "libgen.h"
|
||||
#include "ctype.h"
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
CUtlVector<CUtlString> m_szArguments;
|
||||
};
|
||||
|
||||
class CClangCompiler : public ICCompiler
|
||||
{
|
||||
public:
|
||||
virtual LinkProject_t Compile( CProject_t *pProject ) override;
|
||||
|
||||
virtual void GenerateLinterData() override;
|
||||
protected:
|
||||
|
||||
virtual CUtlVector<CUtlString> BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) override;
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( CProject_t *pProject ) override;
|
||||
|
||||
// returns object file format, eg .obj or .o
|
||||
virtual const char *GetOutputObjectFormat() override;
|
||||
|
||||
virtual void IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue ) override;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, CProject_t *pProject ) override;
|
||||
virtual void CompileFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
|
||||
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) override;
|
||||
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) override;
|
||||
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) override;
|
||||
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject, const char *szSysroot ) override;
|
||||
};
|
||||
|
||||
const char *CClangCompiler::GetOutputObjectFormat()
|
||||
{
|
||||
return ".o";
|
||||
}
|
||||
|
||||
CUtlVector<CUtlString> CClangCompiler::BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName )
|
||||
{
|
||||
CUtlVector<CUtlString> cmd;
|
||||
cmd = ICCompiler::BuildCommandLine(pProject, szFileName, szOutputFileName);
|
||||
cmd.AppendHead("-c");
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
const char *CClangCompiler::GetCompilerExecutable( CProject_t *pProject )
|
||||
{
|
||||
return "clang";
|
||||
}
|
||||
|
||||
|
||||
void CClangCompiler::IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-I");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
|
||||
void CClangCompiler::IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CClangCompiler::Macro( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CClangCompiler::Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue )
|
||||
{
|
||||
cmd.AppendTail("-D");
|
||||
cmd.AppendTail(CUtlString("%s=%s", (char*)szName, (char*)szValue));
|
||||
}
|
||||
|
||||
void CClangCompiler::EnableDebugSymbols( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
cmd.AppendTail("-g");
|
||||
}
|
||||
|
||||
void CClangCompiler::SetTarget( CUtlVector<CUtlString> &cmd, CProject_t *pProject )
|
||||
{
|
||||
cmd.AppendTail("-target");
|
||||
cmd.AppendTail(pProject->m_target.GetTriplet());
|
||||
}
|
||||
|
||||
void CClangCompiler::CompileFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
void CClangCompiler::SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-o");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
void CClangCompiler::EnablePIE( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
cmd.AppendTail("-fPIE");
|
||||
}
|
||||
|
||||
void CClangCompiler::EnablePIC( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
cmd.AppendTail("-fPIC");
|
||||
}
|
||||
void CClangCompiler::SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject, const char *szName )
|
||||
{
|
||||
if (szName != NULL)
|
||||
{
|
||||
cmd.AppendTail("--sysroot");
|
||||
cmd.AppendTail(szName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_pConfig)
|
||||
return;
|
||||
|
||||
|
||||
IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
|
||||
if (!pSection)
|
||||
return;
|
||||
|
||||
const char *szSysroot = pSection->GetStringValue("sysroot");
|
||||
if (szSysroot)
|
||||
{
|
||||
cmd.AppendTail("--sysroot");
|
||||
cmd.AppendTail(szSysroot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXPOSE_INTERFACE(CClangCompiler, ICCompiler, CLANG_C_COMPILER_INTERFACE_NAME);
|
||||
|
||||
CUtlVector<ClangFile_t> g_clangFiles;
|
||||
IClangBackend *clangbackend = NULL;
|
||||
|
||||
LinkProject_t CClangCompiler::Compile( CProject_t *pProject )
|
||||
{
|
||||
if (!clangbackend && CommandLine()->CheckParam("-experimental_header_include"))
|
||||
clangbackend = (IClangBackend*)CreateInterface(CLANG_BACKEND_INTERFACE_NAME, NULL);
|
||||
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
LinkProject_t proj = {};
|
||||
proj.m_szName = pProject->m_szName;
|
||||
proj.m_target = pProject->m_target;
|
||||
proj.m_androidmanifest = pProject->m_androidmanifest;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
|
||||
// Get output directories
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
}
|
||||
|
||||
// Run CC
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
|
||||
bool bAreDependenciesUpdated = false;
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlVector<CUtlString> args;
|
||||
/*
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szCompiledTarget = szTarget;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion);
|
||||
}
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/cc/%u_%s/%s/%s.o",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), filesystem2->BuildDirectory(), file.GetString());
|
||||
|
||||
args = {
|
||||
"-target",
|
||||
szCompiledTarget,
|
||||
};
|
||||
*/
|
||||
|
||||
/*
|
||||
if (!strcmp(Plat_GetExtension(file),"cpp"))
|
||||
args.AppendTail("-std=c++17");
|
||||
else if (!strcmp(Plat_GetExtension(file),"mm"))
|
||||
;
|
||||
else
|
||||
args.AppendTail("-std=c99");
|
||||
*/
|
||||
|
||||
args = BuildCommandLine(pProject, file, szOutputFile);
|
||||
|
||||
/*
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
args.AppendTail("-isysroot");
|
||||
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk");
|
||||
} else if (pProject->m_target.kernel == TARGET_KERNEL_IOS)
|
||||
{
|
||||
args.AppendTail("-isysroot");
|
||||
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk");
|
||||
args.AppendTail("-miphoneos-version-min=18.0 ");
|
||||
args.AppendTail("-fembed-bitcode");
|
||||
}
|
||||
*/
|
||||
|
||||
if (!filesystem2->ShouldRecompile(file, szOutputFile))
|
||||
goto skipcompile;
|
||||
else
|
||||
V_printf(" CC %s\n", file.GetString());
|
||||
|
||||
runner->Run(GetCompilerExecutable(pProject), args);
|
||||
skipcompile:
|
||||
proj.objects.AppendTail((Object_t){szOutputFile});
|
||||
|
||||
ClangFile_t cfile = {};
|
||||
cfile.m_szName = file;
|
||||
cfile.m_szArguments = args;
|
||||
cfile.m_szArguments.AppendHead(GetCompilerExecutable(pProject));
|
||||
|
||||
g_clangFiles.AppendTail(cfile);
|
||||
}
|
||||
runner->Wait();
|
||||
return proj;
|
||||
}
|
||||
|
||||
void CClangCompiler::GenerateLinterData()
|
||||
{
|
||||
CUtlVector<IJSONValue*> jsonValues = {};
|
||||
FILE* f = V_fopen("compile_commands.json", "wb");
|
||||
for ( auto &f: g_clangFiles )
|
||||
{
|
||||
IJSONObject *pFileObject = JSONManager()->CreateObject();
|
||||
IJSONValue *pFileValue = JSONManager()->CreateValue();
|
||||
IJSONArray *pArgumentFiles = JSONManager()->CreateArray();
|
||||
IJSONValue *pArgumentsValue = JSONManager()->CreateValue();
|
||||
IJSONValue *pFileNameValue = JSONManager()->CreateValue();
|
||||
IJSONValue *pDirectoryValue = JSONManager()->CreateValue();
|
||||
CUtlVector<IJSONValue*> values;
|
||||
|
||||
for (auto &arg: f.m_szArguments)
|
||||
{
|
||||
IJSONValue *pFileValue = JSONManager()->CreateValue();
|
||||
pFileValue->SetStringValue(arg.GetString());
|
||||
values.AppendTail(pFileValue);
|
||||
}
|
||||
pArgumentFiles->SetArray(values.GetSize(), values.GetData());
|
||||
pArgumentsValue->SetArrayValue(pArgumentFiles);
|
||||
pFileNameValue->SetStringValue(f.m_szName.GetString());
|
||||
pDirectoryValue->SetStringValue(filesystem2->BuildDirectory());
|
||||
pFileObject->SetValue("arguments", pArgumentsValue);
|
||||
pFileObject->SetValue("file", pFileNameValue);
|
||||
pFileObject->SetValue("directory", pDirectoryValue);
|
||||
pFileValue->SetObjectValue(pFileObject);
|
||||
jsonValues.AppendTail(pFileValue);
|
||||
};
|
||||
IJSONArray *pArray = JSONManager()->CreateArray();
|
||||
pArray->SetArray(jsonValues.GetSize(), jsonValues.GetData());
|
||||
IJSONValue *pRoot = JSONManager()->CreateValue();
|
||||
pRoot->SetArrayValue(pArray);
|
||||
CUtlString szCommands = JSONManager()->WriteString(pRoot);
|
||||
V_fprintf(f, szCommands.GetString());
|
||||
V_fclose(f);
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
|
||||
#include "c_libclang.h"
|
||||
#include "helper.h"
|
||||
#include "tier1/interface.h"
|
||||
|
||||
#include "clang-c/Index.h"
|
||||
#include <clang-c/CXFile.h>
|
||||
#include <clang-c/CXString.h>
|
||||
|
||||
class CClangBackend: public IClangBackend
|
||||
{
|
||||
public:
|
||||
virtual bool AreFileDependenciesUpdated( CUtlString szFile, CUtlString szOutputFile, CUtlString szHashFile, CUtlVector<CUtlString> arguments ) override;
|
||||
|
||||
bool bAnyOutdated;
|
||||
CUtlString szCurrentFile;
|
||||
CUtlString szHashFile;
|
||||
|
||||
private:
|
||||
static void InclusionVisitor( CXFile included_file, CXSourceLocation *include_stack, unsigned include_len, CXClientData client_data );
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CClangBackend, IClangBackend, CLANG_BACKEND_INTERFACE_NAME);
|
||||
|
||||
bool CClangBackend::AreFileDependenciesUpdated( CUtlString szFile, CUtlString szOutputFile, CUtlString szHashFile, CUtlVector<CUtlString> arguments )
|
||||
{
|
||||
szCurrentFile = szOutputFile;
|
||||
bAnyOutdated = false;
|
||||
|
||||
CUtlVector<const char *> cArguments = {};
|
||||
for (auto &arg: arguments)
|
||||
cArguments.AppendTail(arg);
|
||||
|
||||
CXIndex index = clang_createIndex(0, 0);
|
||||
CXTranslationUnit tu;
|
||||
CXErrorCode err = clang_parseTranslationUnit2(index, szFile.GetString(), cArguments.GetData(), cArguments.GetSize(), NULL, 0, 0, &tu);
|
||||
|
||||
if (err != CXError_Success) {
|
||||
printf("clang_parseTranslationUnit2 failed with error code %d\n", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
clang_getInclusions(tu, CClangBackend::InclusionVisitor, NULL);
|
||||
|
||||
clang_disposeTranslationUnit(tu);
|
||||
clang_disposeIndex(index);
|
||||
return bAnyOutdated;
|
||||
}
|
||||
|
||||
void CClangBackend::InclusionVisitor( CXFile included_file, CXSourceLocation *include_stack, unsigned include_len, CXClientData client_data )
|
||||
{
|
||||
if (((CClangBackend*)clangbackend)->bAnyOutdated)
|
||||
return;
|
||||
CXString filename = clang_getFileName(included_file);
|
||||
|
||||
bool bUpdate =
|
||||
filesystem2->ShouldRecompile(clang_getCString(filename), ((CClangBackend*)clangbackend)->szCurrentFile);
|
||||
if (bUpdate)
|
||||
{
|
||||
((CClangBackend*)clangbackend)->bAnyOutdated = true;
|
||||
}
|
||||
|
||||
clang_disposeString(filename);
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef C_LIBCLANG_H
|
||||
#define C_LIBCLANG_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#define CLANG_BACKEND_INTERFACE_NAME "ClangBackend001"
|
||||
|
||||
abstract_class IClangBackend
|
||||
{
|
||||
public:
|
||||
virtual bool AreFileDependenciesUpdated( CUtlString szFile, CUtlString szOutputFile, CUtlString szHashFile, CUtlVector<CUtlString> arguments ) = 0;
|
||||
};
|
||||
|
||||
extern IClangBackend *clangbackend;
|
||||
|
||||
#endif
|
||||
@@ -1,413 +0,0 @@
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "libgen.h"
|
||||
#include "target.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
class CClangLinker : public ILinker
|
||||
{
|
||||
public:
|
||||
//virtual CUtlString Link( LinkProject_t *pProject ) override;
|
||||
virtual bool IsLibraryExists( CUtlString szName ) override;
|
||||
protected:
|
||||
//virtual CUtlVector<CUtlString> BuildLinkCommandLine( LinkProject_t *pProject, const char *szFileName, const char *szOutputFileName );
|
||||
//virtual CUtlVector<CUtlString> BuildArchiveCommandLine( LinkProject_t *pProject, const char *szFileName, const char *szOutputFileName );
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( LinkProject_t *pProject ) override;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject , const char *szSysroot ) override;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
|
||||
|
||||
// sets rpath
|
||||
// for windows should be ignored
|
||||
virtual void SetDefaultLibraryPaths( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
|
||||
virtual void UseStdLib( CUtlVector<CUtlString> &cmd, bool bUse ) override;
|
||||
|
||||
// windows doesn't use it as well
|
||||
virtual void UseDynamicLookup( CUtlVector<CUtlString> &cmd, bool bUse ) override;
|
||||
|
||||
// includes whole file
|
||||
virtual void UseFullFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
|
||||
// includes used stuff in a file
|
||||
virtual void UsePartialFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
|
||||
virtual void LinkFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void LinkLibraryObject( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void LinkLibrary( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void LinkLibraryPath( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
const char *CClangLinker::GetCompilerExecutable( LinkProject_t *pProject )
|
||||
{
|
||||
IINISection *pSection = NULL;
|
||||
const char *szLinker = "clang++";
|
||||
if (!g_pConfig)
|
||||
return szLinker;
|
||||
|
||||
|
||||
pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
|
||||
if (!pSection)
|
||||
return szLinker;
|
||||
|
||||
|
||||
szLinker = pSection->GetStringValue("CLANG_LINKER_INTERFACE_NAME");
|
||||
if (szLinker == NULL)
|
||||
return "clang++";
|
||||
return szLinker;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CClangLinker::SetTarget( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->linkType == ELINK_DYNAMIC_LIBRARY)
|
||||
cmd.AppendTail("-shared");
|
||||
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_IOS)
|
||||
cmd.AppendTail("-fuse-ld=lld");
|
||||
|
||||
cmd.AppendTail("-target");
|
||||
cmd.AppendTail(pProject->m_target.GetTriplet());
|
||||
}
|
||||
|
||||
void CClangLinker::SetSysroot( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject , const char *szName )
|
||||
{
|
||||
if (szName != NULL)
|
||||
{
|
||||
cmd.AppendTail("--sysroot");
|
||||
cmd.AppendTail(szName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_pConfig)
|
||||
return;
|
||||
|
||||
|
||||
IINISection *pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
|
||||
if (!pSection)
|
||||
return;
|
||||
|
||||
const char *szSysroot = pSection->GetStringValue("sysroot");
|
||||
if (szSysroot)
|
||||
{
|
||||
cmd.AppendTail("--sysroot");
|
||||
cmd.AppendTail(szSysroot);
|
||||
}
|
||||
}
|
||||
|
||||
void CClangLinker::SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-o");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
|
||||
void CClangLinker::SetDefaultLibraryPaths( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_target.kernel & TARGET_KERNEL_LINUX)
|
||||
{
|
||||
cmd.AppendTail("-Wl,--disable-new-dtags");
|
||||
cmd.AppendTail("-Wl,-rpath,$ORIGIN");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CClangLinker::UseStdLib( CUtlVector<CUtlString> &cmd, bool bUse )
|
||||
{
|
||||
if (!bUse)
|
||||
cmd.AppendTail("-nostdlib");
|
||||
}
|
||||
|
||||
|
||||
void CClangLinker::UseDynamicLookup( CUtlVector<CUtlString> &cmd, bool bUse )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CClangLinker::UseFullFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_target.kernel != TARGET_KERNEL_IOS)
|
||||
cmd.AppendTail("-Wl,--whole-archive");
|
||||
}
|
||||
|
||||
|
||||
void CClangLinker::UsePartialFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_target.kernel != TARGET_KERNEL_IOS)
|
||||
cmd.AppendTail("-Wl,--no-whole-archive");
|
||||
}
|
||||
|
||||
|
||||
void CClangLinker::LinkFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
|
||||
void CClangLinker::LinkLibraryObject( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
CUtlString szDir = CUtlString(szName).GetDirectory();
|
||||
CUtlString szFileName = CUtlString(szName).GetFileName();
|
||||
if (!V_strncmp(szFileName, "lib",3))
|
||||
szFileName.RemoveHead(3);
|
||||
if (!V_strncmp(szFileName.GetFileExtension(), "so",2))
|
||||
szFileName.RemoveTail(3);
|
||||
if (!V_strncmp(szFileName.GetFileExtension(), "a",1))
|
||||
szFileName.RemoveTail(2);
|
||||
cmd.AppendTail("-L");
|
||||
cmd.AppendTail(szDir);
|
||||
cmd.AppendTail("-l");
|
||||
cmd.AppendTail(szFileName);
|
||||
}
|
||||
|
||||
void CClangLinker::LinkLibrary( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-l");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
|
||||
void CClangLinker::LinkLibraryPath( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("-L");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
|
||||
EXPOSE_INTERFACE(CClangLinker, ILinker, CLANG_LINKER_INTERFACE_NAME);
|
||||
/*
|
||||
CUtlString CClangLinker::Link( LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
// Find a name for the file
|
||||
CUtlString szFileName;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
switch(pProject->linkType)
|
||||
{
|
||||
case ELINK_EXECUTABLE:
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS)
|
||||
szFileName = CUtlString("%s.exe", pProject->m_szName.GetString());
|
||||
else if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
szFileName = CUtlString("lib%s.so", pProject->m_szName.GetString());
|
||||
else
|
||||
szFileName = CUtlString("%s", pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_STATIC_LIBRARY:
|
||||
szFileName = CUtlString("lib%s.a", pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_DYNAMIC_LIBRARY:
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
szFileName = CUtlString("lib%s.dylib", pProject->m_szName.GetString());
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_LINUX)
|
||||
szFileName = CUtlString("lib%s.so", pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_KERNEL_DRIVER:
|
||||
Plat_FatalErrorFunc("TODO: not supported\n");
|
||||
break;
|
||||
}
|
||||
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), szFileName.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
if (pProject->linkType == ELINK_STATIC_LIBRARY)
|
||||
{
|
||||
V_printf(" AR %s\n", pProject->m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
CUtlVector<CUtlString> args;
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
args = {
|
||||
"rcs",
|
||||
szOutputFile
|
||||
};
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
runner->Run("ar", args);
|
||||
runner->Wait();
|
||||
|
||||
} else {
|
||||
V_printf(" LINK %s\n", pProject->m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
// Check if any of the files have changed
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
|
||||
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szCompiledTarget = szTarget;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion);
|
||||
}
|
||||
args = {
|
||||
"-o",
|
||||
szOutputFile,
|
||||
"-target",
|
||||
szCompiledTarget,
|
||||
};
|
||||
|
||||
// Disable stdlib
|
||||
if (pProject->bNoStdLib)
|
||||
{
|
||||
args.AppendTail("-nostdlib");
|
||||
}
|
||||
|
||||
// Sysroots
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_DARWIN)
|
||||
{
|
||||
args.AppendTail("-isysroot");
|
||||
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk");
|
||||
|
||||
// Shouldn't be here
|
||||
args.AppendTail("-Wl,-export_dynamic");
|
||||
args.AppendTail("-undefined");
|
||||
args.AppendTail("dynamic_lookup");
|
||||
}
|
||||
else if (pProject->m_target.kernel == TARGET_KERNEL_IOS)
|
||||
{
|
||||
args.AppendTail("-isysroot");
|
||||
args.AppendTail("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk");
|
||||
// Shouldn't be here ?
|
||||
args.AppendTail("-fembed-bitcode");
|
||||
args.AppendTail("-Wl,-rpath,@executable_path");
|
||||
args.AppendTail("-Wl,-all_load");
|
||||
args.AppendTail("-w");
|
||||
args.AppendTail("-miphoneos-version-min=18.0 ");
|
||||
}
|
||||
else if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
// args.AppendTail(CUtlString("--sysroot=%s/sysroot", pProject->m_target.szSysroot));
|
||||
|
||||
// Shouldn't be here ?
|
||||
args.AppendTail("-static-libstdc++");
|
||||
}
|
||||
else if (pProject->m_target.szSysroot)
|
||||
{
|
||||
// args.AppendTail(CUtlString("--sysroot=%s", pProject->m_target.szSysroot));
|
||||
}
|
||||
|
||||
// Magic for the systems
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS)
|
||||
{
|
||||
args.AppendTail("-fuse-ld=ld");
|
||||
}
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
args.AppendTail("-Wl,--disable-new-dtags");
|
||||
args.AppendTail("-Wl,-rpath,$ORIGIN");
|
||||
}
|
||||
|
||||
// Dynamic libraries
|
||||
// Android can't run executables
|
||||
if (pProject->linkType == ELINK_DYNAMIC_LIBRARY || pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
args.AppendTail("-shared");
|
||||
}
|
||||
|
||||
// All the objects
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS || pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
args.AppendTail("-Wl,--whole-archive");
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_WINDOWS || pProject->m_target.kernel == TARGET_KERNEL_LINUX || pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
args.AppendTail("-Wl,--no-whole-archive");
|
||||
for (auto object: pProject->libraryObjects)
|
||||
args.AppendTail(object);
|
||||
|
||||
// Libraries
|
||||
for (auto lib: pProject->libraries)
|
||||
{
|
||||
args.AppendTail("-l");
|
||||
args.AppendTail(lib);
|
||||
}
|
||||
for (auto lib: pProject->libraryDirectories)
|
||||
{
|
||||
args.AppendTail("-L");
|
||||
args.AppendTail(lib);
|
||||
}
|
||||
|
||||
// Apple frameworks
|
||||
for (auto &directory: pProject->frameworkDirectories)
|
||||
{
|
||||
args.AppendTail("-F");
|
||||
args.AppendTail(directory);
|
||||
}
|
||||
for (auto &framework: pProject->frameworks)
|
||||
{
|
||||
args.AppendTail("-framework");
|
||||
args.AppendTail(framework);
|
||||
}
|
||||
|
||||
IINISection *pSection = NULL;
|
||||
const char *szLinker;
|
||||
const char *szSysroot;
|
||||
if (!g_pConfig)
|
||||
goto use_default_linker;
|
||||
|
||||
|
||||
pSection = g_pConfig->GetSection(pProject->m_target.GetTriplet());
|
||||
if (!pSection)
|
||||
goto use_default_linker;
|
||||
szSysroot = pSection->GetStringValue("sysroot");
|
||||
if (szSysroot)
|
||||
{
|
||||
args.AppendTail("--sysroot");
|
||||
args.AppendTail(szSysroot);
|
||||
}
|
||||
|
||||
szLinker = pSection->GetStringValue("CLANG_LINKER_INTERFACE_NAME");
|
||||
if (szLinker)
|
||||
{
|
||||
runner->Run(szLinker, args);
|
||||
}
|
||||
|
||||
runner->Wait();
|
||||
|
||||
goto compiled;
|
||||
use_default_linker:
|
||||
runner->Run("clang++", args);
|
||||
runner->Wait();
|
||||
}
|
||||
compiled:
|
||||
return szOutputFile;
|
||||
};
|
||||
*/
|
||||
bool CClangLinker::IsLibraryExists( CUtlString szName )
|
||||
{
|
||||
szName = CUtlString("lib%s.so", szName.GetString());
|
||||
void *pLib = Plat_LoadLibrary(szName.GetString());
|
||||
if (!pLib)
|
||||
return false;
|
||||
Plat_UnloadLibrary(pLib);
|
||||
return true;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#include "deploy.h"
|
||||
|
||||
|
||||
class CDeployDeviceManager: public IDeployDeviceManager
|
||||
{
|
||||
public:
|
||||
virtual void AddDevice( IDeployDevice *pDevice ) override;
|
||||
virtual IDeployDevice *FindDeviceByName( const char *szDeviceName ) override;
|
||||
virtual const CUtlVector<IDeployDevice*> &ListDevices() override;
|
||||
private:
|
||||
CUtlVector<IDeployDevice*> m_devices;
|
||||
};
|
||||
|
||||
static CDeployDeviceManager s_deviceManager;
|
||||
|
||||
void CDeployDeviceManager::AddDevice( IDeployDevice *pDevice )
|
||||
{
|
||||
m_devices.AppendTail(pDevice);
|
||||
}
|
||||
|
||||
IDeployDevice *CDeployDeviceManager::FindDeviceByName( const char *szDeviceName )
|
||||
{
|
||||
for ( auto device: m_devices )
|
||||
{
|
||||
if ( !V_strcmp(device->GetName(), szDeviceName) )
|
||||
return device;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const CUtlVector<IDeployDevice*> &CDeployDeviceManager::ListDevices()
|
||||
{
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
|
||||
IDeployDeviceManager *DeployDeviceManager()
|
||||
{
|
||||
return &s_deviceManager;
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
#include "helper.h"
|
||||
#include "runner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "unistd.h"
|
||||
#include "libgen.h"
|
||||
#include "sys/stat.h"
|
||||
#include "tier1/interface.h"
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
unsigned int g_hashState = 102851263;
|
||||
unsigned int BaseProject_t::GenerateProjectHash( void )
|
||||
{
|
||||
unsigned int hash = 5381+g_hashState;
|
||||
int c;
|
||||
char *szName = m_szName;
|
||||
|
||||
while( (c = *szName++) )
|
||||
hash = (hash * 33) + c;
|
||||
|
||||
g_hashState = g_hashState * 1664525 + 1013904223;
|
||||
|
||||
return hash;
|
||||
};
|
||||
|
||||
static char path[1024];
|
||||
#ifdef __linux__
|
||||
static ssize_t pathSize = readlink("/proc/self/exe", path, sizeof(path) - 1);
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
static uint32_t pathSize = sizeof(path);
|
||||
static int pathResult = _NSGetExecutablePath(path, &pathSize);
|
||||
#endif
|
||||
static char *szPathDir = dirname(path);
|
||||
static char *s_szBuildDir = 0;
|
||||
EXPOSE_INTERFACE_GLOBALVAR(szBuildDir, char*, FILE_SYSTEM_2_BUILD_DIRECTORY_INTERFACE_VERSION, s_szBuildDir);
|
||||
|
||||
class CPOSIXFileSystem2: public IFileSystem2
|
||||
{
|
||||
public:
|
||||
virtual char *OwnDirectory() override;
|
||||
virtual char *BuildDirectory() override;
|
||||
virtual void MakeDirectory( const char *psz ) override;
|
||||
virtual void CopyFile( const char *szDestination, const char *szOrigin ) override;
|
||||
virtual void CopyDirectory( const char *szDestination, const char *szOrigin ) override;
|
||||
virtual bool ShouldRecompile( const char *szSource, const char *szOutput ) override;
|
||||
virtual char *GetWindowsPath( const char *szPath ) override;
|
||||
virtual char *GetPOSIXPath( const char *szPath ) override;
|
||||
};
|
||||
|
||||
char *CPOSIXFileSystem2::GetWindowsPath( const char *szPath )
|
||||
{
|
||||
char *szNewPath = (char*)V_malloc(V_strlen(szPath)+1);
|
||||
int i = 0;
|
||||
V_strcpy(szNewPath, szPath);
|
||||
while(szNewPath[i])
|
||||
{
|
||||
if (szNewPath[i] == '/')
|
||||
szNewPath[i] = '\\';
|
||||
i++;
|
||||
}
|
||||
return szNewPath;
|
||||
}
|
||||
|
||||
char *CPOSIXFileSystem2::GetPOSIXPath( const char *szPath )
|
||||
{
|
||||
char *szNewPath = (char*)V_malloc(V_strlen(szPath)+1);
|
||||
int i = 0;
|
||||
V_strcpy(szNewPath, szPath);
|
||||
while(szNewPath[i])
|
||||
{
|
||||
if (szNewPath[i] == '\\')
|
||||
szNewPath[i] = '/';
|
||||
i++;
|
||||
}
|
||||
return szNewPath;
|
||||
}
|
||||
|
||||
EXPOSE_INTERFACE(CPOSIXFileSystem2, IFileSystem2, FILE_SYSTEM_2_INTERFACE_NAME);
|
||||
IFileSystem2 *filesystem2;
|
||||
|
||||
char *CPOSIXFileSystem2::OwnDirectory()
|
||||
{
|
||||
return szPathDir;
|
||||
};
|
||||
char *CPOSIXFileSystem2::BuildDirectory()
|
||||
{
|
||||
return s_szBuildDir;
|
||||
};
|
||||
|
||||
void CPOSIXFileSystem2::CopyFile( const char *szDestination, const char *szOrigin )
|
||||
{
|
||||
CUtlVector<CUtlString> args = {
|
||||
szOrigin,
|
||||
szDestination,
|
||||
};
|
||||
runner->Run(CUtlString("cp"), args);
|
||||
runner->Wait();
|
||||
}
|
||||
void CPOSIXFileSystem2::CopyDirectory( const char *szDestination, const char *szOrigin )
|
||||
{
|
||||
CUtlVector<CUtlString> args = {
|
||||
"-r",
|
||||
szOrigin,
|
||||
szDestination,
|
||||
};
|
||||
runner->Run("cp", args);
|
||||
runner->Wait();
|
||||
}
|
||||
|
||||
void CPOSIXFileSystem2::MakeDirectory( const char *psz )
|
||||
{
|
||||
CUtlVector<CUtlString> args = {
|
||||
"-p",
|
||||
CUtlString(psz),
|
||||
};
|
||||
runner->Run("mkdir", args);
|
||||
runner->Wait();
|
||||
};
|
||||
|
||||
bool CPOSIXFileSystem2::ShouldRecompile(const char *szSource, const char *szOutput)
|
||||
{
|
||||
struct stat srcbuf;
|
||||
struct stat outbuf;
|
||||
if (stat(szSource, &srcbuf) != 0) {
|
||||
return true;
|
||||
}
|
||||
if (stat(szOutput, &outbuf) != 0) {
|
||||
return true;
|
||||
}
|
||||
return outbuf.st_mtime < srcbuf.st_mtime;
|
||||
};
|
||||
|
||||
|
||||
IINIFile *g_pConfig;
|
||||
EXPOSE_INTERFACE_GLOBALVAR(IINIFile, IINIFile, LIBFPC_CONFIG_INTERFACE_VERSION, g_pConfig);
|
||||
@@ -1,140 +0,0 @@
|
||||
#include "ld.h"
|
||||
|
||||
ILinker *linker;
|
||||
|
||||
void LinkProject_t::AddObject( Object_t object )
|
||||
{
|
||||
objects.AppendTail(object);
|
||||
};
|
||||
CUtlString ILinker::GetOutputObjectName( LinkProject_t *pProject, unsigned int hash, CUtlString szFileName )
|
||||
{
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szFileNameFormat;
|
||||
switch (pProject->linkType)
|
||||
{
|
||||
case ELINK_EXECUTABLE:
|
||||
szFileNameFormat = CUtlString(pProject->m_target.GetExecutableFileFormat(),pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_DYNAMIC_LIBRARY:
|
||||
szFileNameFormat = CUtlString(pProject->m_target.GetDynamicLibraryFileFormat(),pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_STATIC_LIBRARY:
|
||||
szFileNameFormat = CUtlString(pProject->m_target.GetStaticLibraryFileFormat(),pProject->m_szName.GetString());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return CUtlString(
|
||||
"%s/%s/ld/%u_%s/%s",
|
||||
FPC_TEMPORAL_DIRNAME,
|
||||
szTarget.GetString(),
|
||||
hash,
|
||||
pProject->m_szName.GetString(),
|
||||
szFileNameFormat.GetString());
|
||||
}
|
||||
|
||||
CUtlString ILinker::Link( LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
LinkProject_t stLinkProject = *pProject;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
stLinkProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
CUtlString szOutputFile = GetOutputObjectName(&stLinkProject, hash, NULL);
|
||||
filesystem2->MakeDirectory(szOutputFile.GetDirectory());
|
||||
|
||||
if (stLinkProject.linkType == ELINK_STATIC_LIBRARY)
|
||||
{
|
||||
CUtlVector<CUtlString> args;
|
||||
bool shouldRecompile = false;
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
|
||||
V_printf(" AR %s\n", pProject->m_szName.GetString());
|
||||
args = {
|
||||
"rcs",
|
||||
szOutputFile
|
||||
};
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
runner->Run("ar", args);
|
||||
runner->Wait();
|
||||
} else {
|
||||
bool shouldRecompile = false;
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (auto object: pProject->libraryObjects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
|
||||
V_printf(" LINK %s\n", pProject->m_szName.GetString());
|
||||
CUtlVector<CUtlString> args;
|
||||
args = BuildLinkCommandLine(pProject, szOutputFile);
|
||||
runner->Run(GetCompilerExecutable(pProject), args);
|
||||
runner->Wait();
|
||||
}
|
||||
compiled:
|
||||
return szOutputFile;
|
||||
}
|
||||
|
||||
CUtlVector<CUtlString> ILinker::BuildLinkCommandLine( LinkProject_t *pProject, const char *szOutputFileName )
|
||||
{
|
||||
CUtlVector<CUtlString> cmd;
|
||||
SetTarget(cmd, pProject);
|
||||
SetOutputFile(cmd, szOutputFileName);
|
||||
SetSysroot(cmd, pProject, NULL);
|
||||
SetDefaultLibraryPaths(cmd, pProject);
|
||||
UseFullFile(cmd, pProject);
|
||||
for (auto &o: pProject->objects)
|
||||
{
|
||||
LinkFile(cmd, o.m_szObjectFile);
|
||||
}
|
||||
UsePartialFile(cmd, pProject);
|
||||
|
||||
for (auto &o: pProject->libraryObjects)
|
||||
{
|
||||
LinkLibraryObject(cmd, o);
|
||||
};
|
||||
for (auto &o: pProject->libraries)
|
||||
{
|
||||
LinkLibrary(cmd, o);
|
||||
};
|
||||
for (auto &o: pProject->libraryDirectories)
|
||||
{
|
||||
LinkLibraryPath(cmd, o);
|
||||
};
|
||||
return cmd;
|
||||
|
||||
}
|
||||
|
||||
CUtlVector<CUtlString> ILinker::BuildArchiveCommandLine( LinkProject_t *pProject, const char *szOutputFileName )
|
||||
{
|
||||
CUtlVector<CUtlString> cmd;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "helper.h"
|
||||
#include "runner.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
|
||||
IFileSystem *filesystem;
|
||||
|
||||
void *LibFpcInit()
|
||||
{
|
||||
filesystem2 = (IFileSystem2*)CreateInterface(FILE_SYSTEM_2_INTERFACE_NAME, NULL);
|
||||
runner = (IRunner*)CreateInterface(RUNNER_INTERFACE_NAME, NULL);
|
||||
ccompiler = (ICCompiler*)CreateInterface(CLANG_C_COMPILER_INTERFACE_NAME, NULL);
|
||||
linker = (ILinker*)CreateInterface(CLANG_LINKER_INTERFACE_NAME, NULL);
|
||||
|
||||
void *pFilesystem = Plat_LoadLibrary("libfilesystem_std.so");
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem);
|
||||
filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
filesystem->Init();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EXPOSE_INTERFACE_FN(LibFpcInit, LibFpcInit, LIBFPC_INIT_INTERFACE_VERSION);
|
||||
@@ -1,105 +0,0 @@
|
||||
#include "runner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/wait.h"
|
||||
#include "tier0/commandline.h"
|
||||
|
||||
#include "winerunner.h"
|
||||
|
||||
|
||||
CUtlVector<pid_t> m_processes;
|
||||
class CPOSIXRunner: public IRunner
|
||||
{
|
||||
public:
|
||||
virtual int Run( CUtlString szName, CUtlVector<CUtlString>& args ) override;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args ) override;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment ) override;
|
||||
virtual int Wait( void ) override;
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CPOSIXRunner, IRunner, RUNNER_INTERFACE_NAME);
|
||||
IRunner *runner;
|
||||
IWineRunner *winerunner;
|
||||
|
||||
int CPOSIXRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
Plat_FatalErrorFunc("Failed to fork");
|
||||
/* child */
|
||||
if (pid == 0)
|
||||
{
|
||||
CUtlVector<const char*> execargs;
|
||||
execargs.AppendTail(szName);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("%s",szName.GetString());
|
||||
for (auto &arg: args)
|
||||
{
|
||||
execargs.AppendTail(arg);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf(" %s",arg.GetString());
|
||||
}
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("\n");
|
||||
execargs.AppendTail(0);
|
||||
if ( execvp(szName, (char *const*)execargs.GetData()) == -1 )
|
||||
{
|
||||
V_printf("Failed to launch %s\n",szName.GetString());
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
m_processes.AppendTail(pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CPOSIXRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
Plat_FatalErrorFunc("Failed to fork");
|
||||
/* child */
|
||||
if (pid == 0)
|
||||
{
|
||||
CUtlVector<const char*> execargs;
|
||||
execargs.AppendTail(szName);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("%s",szName.GetString());
|
||||
for (auto &arg: args)
|
||||
{
|
||||
execargs.AppendTail(arg);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf(" %s",arg.GetString());
|
||||
}
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("\n");
|
||||
execargs.AppendTail(0);
|
||||
chdir(szDirectory.GetString());
|
||||
if ( execvp(szName, (char *const*)execargs.GetData()) == -1 )
|
||||
{
|
||||
V_printf("Failed to launch %s\n",szName.GetString());
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
m_processes.AppendTail(pid);
|
||||
/* parent */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CPOSIXRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CPOSIXRunner::Wait( void )
|
||||
{
|
||||
for (int i = 0; i<m_processes.GetSize(); i++)
|
||||
{
|
||||
int status;
|
||||
pid_t wpid = waitpid(m_processes[i], &status, 0);
|
||||
}
|
||||
m_processes = {};
|
||||
return 0;
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
#include "swift.h"
|
||||
|
||||
CUtlString ISwiftCompiler::GetOutputObjectName( SwiftProject_t *pProject, unsigned int hash, CUtlString szFileName )
|
||||
{
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
|
||||
return CUtlString(
|
||||
"%s/%s/swift/%u_%s/%s/%s%s",
|
||||
FPC_TEMPORAL_DIRNAME,
|
||||
szTarget.GetString(),
|
||||
hash,
|
||||
pProject->m_szName.GetString(),
|
||||
filesystem2->BuildDirectory(),
|
||||
szFileName.GetString(),
|
||||
GetOutputObjectFormat());
|
||||
};
|
||||
|
||||
CUtlVector<CUtlString> ISwiftCompiler::BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName )
|
||||
{
|
||||
|
||||
CUtlVector<CUtlString> cmd;
|
||||
|
||||
EnableDebugSymbols(cmd);
|
||||
if (pProject->bFPIC)
|
||||
EnablePIC(cmd);
|
||||
if (pProject->bFPIE)
|
||||
EnablePIE(cmd);
|
||||
SetTarget(cmd, pProject);
|
||||
SetOutputFile(cmd, szOutputFileName);
|
||||
SetSysroot(cmd, pProject, NULL);
|
||||
CompileFile(cmd, szFileName);
|
||||
for (auto ¯o: pProject->macros)
|
||||
Macro(cmd, macro.szName, macro.szValue.GetString());
|
||||
for (auto &dir: pProject->includeDirectories)
|
||||
IncludeDirectory(cmd, dir);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
LinkProject_t ISwiftCompiler::Compile( SwiftProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
LinkProject_t proj = {};
|
||||
proj.m_szName = pProject->m_szName;
|
||||
proj.m_target = pProject->m_target;
|
||||
proj.m_androidmanifest = pProject->m_androidmanifest;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
|
||||
|
||||
// Get output directories
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlString szOutputDir = szOutputFile.GetDirectory();
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
}
|
||||
|
||||
// Run CC
|
||||
for (auto &file: pProject->files)
|
||||
{
|
||||
CUtlString szOutputFile = GetOutputObjectName(pProject, hash, file);
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
args = BuildCommandLine(pProject, file, szOutputFile);
|
||||
if (!filesystem2->ShouldRecompile(file, szOutputFile))
|
||||
goto skipcompile;
|
||||
else
|
||||
V_printf(" SWIFT %s\n", file.GetString());
|
||||
runner->Run(GetCompilerExecutable(pProject), args);
|
||||
skipcompile:
|
||||
proj.objects.AppendTail((Object_t){szOutputFile});
|
||||
}
|
||||
runner->Wait();
|
||||
return proj;
|
||||
}
|
||||
|
||||
ISwiftCompiler *swiftcompiler = NULL;
|
||||
@@ -1,257 +0,0 @@
|
||||
#include "target.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "sys/utsname.h"
|
||||
|
||||
// see Target_t::HostTarget
|
||||
#if defined(__i386__) && defined(POSIX)
|
||||
static utsname s_uname;
|
||||
static int s_iuNameRes = uname(&s_uname);
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Generates triplet suitable for most compilers.
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlString Target_t::GetTriplet()
|
||||
{
|
||||
CUtlString triplet = "";
|
||||
|
||||
triplet.AppendTail(StringFromCPU(cpu));
|
||||
triplet.AppendTail("-");
|
||||
triplet.AppendTail(StringFromKernel(kernel));
|
||||
|
||||
if ( abi != TARGET_ABI_UNDEFINED && abi != TARGET_ABI_DEFAULT )
|
||||
{
|
||||
triplet.AppendTail("-");
|
||||
triplet.AppendTail(StringFromABI(abi));
|
||||
}
|
||||
|
||||
|
||||
return triplet;
|
||||
}
|
||||
|
||||
const char *Target_t::GetExecutableFileFormat()
|
||||
{
|
||||
if (kernel & TARGET_KERNEL_POSIX)
|
||||
return "%s";
|
||||
|
||||
if (kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||
{
|
||||
return "%s.exe";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *Target_t::GetStaticLibraryFileFormat()
|
||||
{
|
||||
if (kernel & TARGET_KERNEL_POSIX)
|
||||
return "lib%s.a";
|
||||
|
||||
if (kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||
{
|
||||
switch(abi)
|
||||
{
|
||||
case TARGET_ABI_MSVC:
|
||||
return "%s.lib";
|
||||
default:
|
||||
return "lib%s.a";
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
const char *Target_t::GetDynamicLibraryFileFormat()
|
||||
{
|
||||
if (kernel & TARGET_KERNEL_LINUX_DEVICES)
|
||||
return "lib%s.so";
|
||||
if (kernel & TARGET_KERNEL_APPLE_DEVICES)
|
||||
return "lib%s.dylib";
|
||||
if (kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||
return "lib%s.dylib";
|
||||
return NULL;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
// Returns target on which fpc is being run
|
||||
//
|
||||
// For targets such as i386, i486, i586
|
||||
//----------------------------------------------------------------------------
|
||||
Target_t Target_t::HostTarget()
|
||||
{
|
||||
ETargetKernel kernel = TARGET_KERNEL_UNDEFINED;
|
||||
#if defined(__linux__)
|
||||
kernel = TARGET_KERNEL_LINUX;
|
||||
#elif defined(__APPLE__)
|
||||
kernel TARGET_KERNEL_DARWIN;
|
||||
#endif
|
||||
ETargetCPU cpu = TARGET_CPU_UNDEFINED;
|
||||
#if defined(__x86_64__)
|
||||
cpu = TARGET_CPU_AMD64;
|
||||
#endif
|
||||
#if defined(__i386__)
|
||||
cpu = TARGET_CPU_80386;
|
||||
#endif
|
||||
// POSIX doesn't know about these
|
||||
// use uname to get them
|
||||
#if defined(__i386__) && defined(POSIX)
|
||||
if (!V_strcmp("i486", s_uname.machine))
|
||||
cpu = TARGET_CPU_80486;
|
||||
if (!V_strcmp("i586", s_uname.machine))
|
||||
cpu = TARGET_CPU_80586;
|
||||
if (!V_strcmp("i686", s_uname.machine))
|
||||
cpu = TARGET_CPU_80686;
|
||||
#endif
|
||||
ETargetABI abi = TARGET_ABI_GNU;
|
||||
|
||||
#ifdef FPC_ARCH
|
||||
cpu = CPUFromString(FPC_ARCH);
|
||||
#endif
|
||||
#ifdef FPC_OS
|
||||
kernel = KernelFromString(FPC_OS);
|
||||
#endif
|
||||
#ifdef FPC_ABI
|
||||
abi = ABIFromString(FPC_ABI);
|
||||
#endif
|
||||
|
||||
|
||||
return {
|
||||
.kernel = kernel,
|
||||
.cpu = cpu,
|
||||
.abi = abi,
|
||||
.optimization = TARGET_DEBUG,
|
||||
};
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns default target for build, by default it will be host target
|
||||
//-----------------------------------------------------------------------------
|
||||
Target_t Target_t::DefaultTarget()
|
||||
{
|
||||
CUtlString szDevice = CommandLine()->ParamValue("-device");
|
||||
CUtlString szOS = CommandLine()->ParamValue("-os");
|
||||
CUtlString szArch = CommandLine()->ParamValue("-arch");
|
||||
CUtlString szAbi = CommandLine()->ParamValue("-abi");
|
||||
|
||||
ETargetKernel kernel = KernelFromString(szOS);
|
||||
ETargetCPU cpu = CPUFromString(szArch);
|
||||
ETargetABI abi = ABIFromString(szAbi);
|
||||
if (cpu == TARGET_CPU_UNDEFINED)
|
||||
cpu = HostTarget().cpu;
|
||||
if (kernel == TARGET_KERNEL_UNDEFINED)
|
||||
kernel = HostTarget().kernel;
|
||||
if (abi == TARGET_ABI_UNDEFINED)
|
||||
abi = HostTarget().abi;
|
||||
|
||||
|
||||
return {
|
||||
.kernel = kernel,
|
||||
.cpu = cpu,
|
||||
.abi = abi,
|
||||
.optimization = TARGET_DEBUG,
|
||||
};
|
||||
}
|
||||
const char *Target_t::StringFromCPU( ETargetCPU cpu )
|
||||
{
|
||||
if ( cpu == TARGET_CPU_AMD64 )
|
||||
return "x86_64";
|
||||
if ( cpu == TARGET_CPU_80386 )
|
||||
return "i386";
|
||||
if ( cpu == TARGET_CPU_80486 )
|
||||
return "i486";
|
||||
if ( cpu == TARGET_CPU_80586 )
|
||||
return "i586";
|
||||
if ( cpu == TARGET_CPU_80686 )
|
||||
return "i686";
|
||||
if ( cpu == TARGET_CPU_AARCH64 )
|
||||
return "aarch64";
|
||||
if ( cpu == TARGET_CPU_WASM32 )
|
||||
return "wasm32";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *Target_t::StringFromKernel( ETargetKernel kernel )
|
||||
{
|
||||
if ( kernel == TARGET_KERNEL_UNKNOWN )
|
||||
return "unknown-unknown";
|
||||
if ( kernel == TARGET_KERNEL_UNKNOWN_LINUX )
|
||||
return "unknown-linux";
|
||||
if ( kernel == TARGET_KERNEL_PC_LINUX )
|
||||
return "pc-linux";
|
||||
if ( kernel == TARGET_KERNEL_ALPINE_LINUX )
|
||||
return "alpine-linux";
|
||||
if ( kernel == TARGET_KERNEL_WINDOWS )
|
||||
return "pc-windows";
|
||||
if ( kernel == TARGET_KERNEL_DARWIN )
|
||||
return "apple-darwin";
|
||||
if ( kernel == TARGET_KERNEL_IOS )
|
||||
return "apple-ios";
|
||||
if ( kernel == TARGET_KERNEL_ANDROID )
|
||||
return "linux-android";
|
||||
if ( kernel == TARGET_KERNEL_WASI )
|
||||
return "unknown-wasi";
|
||||
if ( kernel == TARGET_KERNEL_EMSCRIPTEN )
|
||||
return "unknown-emscripten";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *Target_t::StringFromABI( ETargetABI abi )
|
||||
{
|
||||
if ( abi == TARGET_ABI_GNU )
|
||||
return "gnu";
|
||||
if ( abi == TARGET_ABI_MUSL )
|
||||
return "musl";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ETargetCPU Target_t::CPUFromString( const char *szName )
|
||||
{
|
||||
CUtlString szUtlName = szName;
|
||||
if ( szUtlName == "x86_64" )
|
||||
return TARGET_CPU_AMD64;
|
||||
else if ( szUtlName == "i386" )
|
||||
return TARGET_CPU_80386;
|
||||
else if ( szUtlName == "i486" )
|
||||
return TARGET_CPU_80486;
|
||||
else if ( szUtlName == "i586" )
|
||||
return TARGET_CPU_80586;
|
||||
else if ( szUtlName == "i686" )
|
||||
return TARGET_CPU_80686;
|
||||
else if ( szUtlName == "aarch64" )
|
||||
return TARGET_CPU_AARCH64;
|
||||
else if ( szUtlName == "wasm32" )
|
||||
return TARGET_CPU_WASM32;
|
||||
return TARGET_CPU_UNDEFINED;
|
||||
}
|
||||
|
||||
ETargetKernel Target_t::KernelFromString( const char *szName )
|
||||
{
|
||||
CUtlString szUtlName = szName;
|
||||
if ( szUtlName == "unknown" )
|
||||
return TARGET_KERNEL_UNKNOWN;
|
||||
else if ( szUtlName == "windows" )
|
||||
return TARGET_KERNEL_WINDOWS;
|
||||
else if ( szUtlName == "linux" )
|
||||
return TARGET_KERNEL_LINUX;
|
||||
else if ( szUtlName == "unknown-linux" )
|
||||
return TARGET_KERNEL_UNKNOWN_LINUX;
|
||||
else if ( szUtlName == "pc-linux" )
|
||||
return TARGET_KERNEL_PC_LINUX;
|
||||
else if ( szUtlName == "alpine-linux" )
|
||||
return TARGET_KERNEL_ALPINE_LINUX;
|
||||
else if ( szUtlName == "macos" )
|
||||
return TARGET_KERNEL_DARWIN;
|
||||
else if ( szUtlName == "ios" )
|
||||
return TARGET_KERNEL_IOS;
|
||||
else if ( szUtlName == "android" )
|
||||
return TARGET_KERNEL_ANDROID;
|
||||
return TARGET_KERNEL_UNDEFINED;
|
||||
}
|
||||
|
||||
ETargetABI Target_t::ABIFromString( const char *szName )
|
||||
{
|
||||
CUtlString szUtlName = szName;
|
||||
if ( szUtlName == "gnu" )
|
||||
return TARGET_ABI_GNU;
|
||||
else if ( szUtlName == "musl" )
|
||||
return TARGET_ABI_MUSL;
|
||||
return TARGET_ABI_UNDEFINED;
|
||||
}
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
#include "tier0/mem.h"
|
||||
#include "winerunner.h"
|
||||
#include "c.h"
|
||||
#include "helper.h"
|
||||
#include "obj.h"
|
||||
#include "target.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier0/mem.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "libgen.h"
|
||||
#include "ctype.h"
|
||||
|
||||
struct ClangFile_t
|
||||
{
|
||||
CUtlString m_szName;
|
||||
CUtlVector<CUtlString> m_szArguments;
|
||||
};
|
||||
|
||||
class CMSVCCompiler : public ICCompiler
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void GenerateLinterData() override;
|
||||
protected:
|
||||
|
||||
virtual CUtlVector<CUtlString> BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName ) override;
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( CProject_t *pProject ) override;
|
||||
|
||||
// returns object file format, eg .obj or .o
|
||||
virtual const char *GetOutputObjectFormat() override;
|
||||
|
||||
virtual void IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue ) override;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, CProject_t *pProject ) override;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject , const char *szSysroot ) override;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void CompileFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
|
||||
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) override;
|
||||
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) override;
|
||||
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) override;
|
||||
};
|
||||
|
||||
const char *CMSVCCompiler::GetOutputObjectFormat()
|
||||
{
|
||||
return ".o";
|
||||
}
|
||||
|
||||
CUtlVector<CUtlString> CMSVCCompiler::BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName )
|
||||
{
|
||||
CUtlVector<CUtlString> cmd;
|
||||
cmd = ICCompiler::BuildCommandLine(pProject, szFileName, szOutputFileName);
|
||||
cmd.AppendHead("/c");
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
const char *CMSVCCompiler::GetCompilerExecutable( CProject_t *pProject )
|
||||
{
|
||||
if (!g_pConfig)
|
||||
Plat_FatalErrorFunc(".fpccfg was not found\n");
|
||||
static IINISection *pSection = g_pConfig->GetSection("MSVC_C_COMPILER_INTERFACE_NAME");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("MSVC_C_COMPILER_INTERFACE_NAME was not found in .fpccfg\n");
|
||||
static CUtlString szExePath = pSection->GetStringValue("exe");
|
||||
return szExePath;
|
||||
}
|
||||
|
||||
|
||||
void CMSVCCompiler::IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail(CUtlString("/I%s",szName));
|
||||
}
|
||||
|
||||
void CMSVCCompiler::IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CMSVCCompiler::Macro( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
}
|
||||
|
||||
void CMSVCCompiler::Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue )
|
||||
{
|
||||
cmd.AppendTail(CUtlString("/D%s=%s", (char*)szName, (char*)szValue));
|
||||
}
|
||||
|
||||
void CMSVCCompiler::EnableDebugSymbols( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
}
|
||||
|
||||
void CMSVCCompiler::SetTarget( CUtlVector<CUtlString> &cmd, CProject_t *pProject )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCCompiler::SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject , const char *szSysroot )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCCompiler::CompileFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
void CMSVCCompiler::SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
cmd.AppendTail("/Fo");
|
||||
cmd.AppendTail(szName);
|
||||
}
|
||||
void CMSVCCompiler::EnablePIE( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
}
|
||||
|
||||
void CMSVCCompiler::EnablePIC( CUtlVector<CUtlString> &cmd )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EXPOSE_INTERFACE(CMSVCCompiler, ICCompiler, MSVC_C_COMPILER_INTERFACE_NAME);
|
||||
|
||||
void CMSVCCompiler::GenerateLinterData()
|
||||
{
|
||||
/*
|
||||
FILE* f = V_fopen("compile_commands.json", "wb");
|
||||
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");
|
||||
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", filesystem2->BuildDirectory());
|
||||
V_fprintf(f, "\t},\n");
|
||||
};
|
||||
V_fseek(f, -2, SEEK_CUR);
|
||||
V_fprintf(f, "\n]\n");
|
||||
V_fclose(f);
|
||||
*/
|
||||
};
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "libgen.h"
|
||||
#include "target.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier2/fileformats/ini.h"
|
||||
#include "winerunner.h"
|
||||
|
||||
class CMSVCLinker : public ILinker
|
||||
{
|
||||
public:
|
||||
virtual CUtlString Link( LinkProject_t *pProject ) override;
|
||||
virtual bool IsLibraryExists( CUtlString szName ) override;
|
||||
protected:
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( LinkProject_t *pProject ) override;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject , const char *szSysroot ) override;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szOutput) override;
|
||||
|
||||
|
||||
// sets rpath
|
||||
// for windows should be ignored
|
||||
virtual void SetDefaultLibraryPaths( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
|
||||
virtual void UseStdLib( CUtlVector<CUtlString> &cmd, bool bUse ) override;
|
||||
|
||||
// windows doesn't use it as well
|
||||
virtual void UseDynamicLookup( CUtlVector<CUtlString> &cmd, bool bUse ) override;
|
||||
|
||||
// includes whole file
|
||||
virtual void UseFullFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
|
||||
// includes used stuff in a file
|
||||
virtual void UsePartialFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) override;
|
||||
|
||||
virtual void LinkFile( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void LinkLibraryObject( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void LinkLibrary( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
virtual void LinkLibraryPath( CUtlVector<CUtlString> &cmd, const char *szName ) override;
|
||||
};
|
||||
|
||||
const char *CMSVCLinker::GetCompilerExecutable( LinkProject_t *pProject )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::SetTarget( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::SetSysroot( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject , const char *szSysroot )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::SetDefaultLibraryPaths( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CMSVCLinker::UseStdLib( CUtlVector<CUtlString> &cmd, bool bUse )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CMSVCLinker::UseDynamicLookup( CUtlVector<CUtlString> &cmd, bool bUse )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CMSVCLinker::UseFullFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CMSVCLinker::UsePartialFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CMSVCLinker::LinkFile( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::LinkLibraryObject( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::LinkLibrary( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMSVCLinker::LinkLibraryPath( CUtlVector<CUtlString> &cmd, const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EXPOSE_INTERFACE(CMSVCLinker, ILinker, MSVC_LINKER_INTERFACE_NAME);
|
||||
|
||||
CUtlString CMSVCLinker::Link( LinkProject_t *pProject )
|
||||
{
|
||||
if (pProject->m_szName == 0)
|
||||
{
|
||||
Plat_FatalErrorFunc("m_szName must be present\n");
|
||||
}
|
||||
|
||||
if (pProject->m_target.kernel != TARGET_KERNEL_WINDOWS)
|
||||
{
|
||||
Plat_FatalErrorFunc("target must be TARGET_KERNEL_WINDOWS\n");
|
||||
}
|
||||
|
||||
// Find a name for the file
|
||||
CUtlString szFileName;
|
||||
unsigned int hash = pProject->GenerateProjectHash();
|
||||
switch(pProject->linkType)
|
||||
{
|
||||
case ELINK_EXECUTABLE:
|
||||
szFileName = CUtlString("%s.exe", pProject->m_szName.GetString());
|
||||
case ELINK_STATIC_LIBRARY:
|
||||
szFileName = CUtlString("lib%s.a", pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_DYNAMIC_LIBRARY:
|
||||
szFileName = CUtlString("%s.dll", pProject->m_szName.GetString());
|
||||
break;
|
||||
case ELINK_KERNEL_DRIVER:
|
||||
szFileName = CUtlString("%s.sys", pProject->m_szName.GetString());
|
||||
break;
|
||||
}
|
||||
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szOutputFile = CUtlString("%s/%s/ld/%u_%s/%s",FPC_TEMPORAL_DIRNAME, szTarget.GetString(), hash, pProject->m_szName.GetString(), szFileName.GetString());
|
||||
CUtlString szOutputDir = szOutputFile;
|
||||
szOutputDir = dirname(szOutputDir);
|
||||
filesystem2->MakeDirectory(szOutputDir);
|
||||
|
||||
if (!g_pConfig)
|
||||
Plat_FatalErrorFunc(".fpccfg was not found\n");
|
||||
IINISection *pSection = g_pConfig->GetSection("MSVC_LINKER_INTERFACE_NAME");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("MSVC_LINKER_INTERFACE_NAME was not found in .fpccfg\n");
|
||||
CUtlString szExePath = pSection->GetStringValue("exe");
|
||||
if (!pSection)
|
||||
Plat_FatalErrorFunc("exe was not found in MSVC_LINKER_INTERFACE_NAME\n");
|
||||
|
||||
if (pProject->linkType == ELINK_STATIC_LIBRARY)
|
||||
{
|
||||
V_printf(" AR %s\n", pProject->m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
CUtlVector<CUtlString> args;
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
args = {
|
||||
"rcs",
|
||||
szOutputFile
|
||||
};
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
runner->Run("ar", args);
|
||||
runner->Wait();
|
||||
|
||||
} else {
|
||||
V_printf(" LINK %s\n", pProject->m_szName.GetString());
|
||||
bool shouldRecompile = false;
|
||||
CUtlVector<CUtlString> args;
|
||||
|
||||
// Check if any of the files have changed
|
||||
for (auto object: pProject->objects)
|
||||
{
|
||||
if (filesystem2->ShouldRecompile(object.m_szObjectFile,szOutputFile))
|
||||
{
|
||||
shouldRecompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldRecompile)
|
||||
goto compiled;
|
||||
|
||||
|
||||
CUtlString szTarget = pProject->m_target.GetTriplet();
|
||||
CUtlString szCompiledTarget = szTarget;
|
||||
if (pProject->m_target.kernel == TARGET_KERNEL_ANDROID)
|
||||
{
|
||||
szCompiledTarget = CUtlString("%s%u", szTarget.GetString(), pProject->m_androidmanifest.m_nTargetVersion);
|
||||
}
|
||||
|
||||
args = {
|
||||
"/nologo"
|
||||
};
|
||||
|
||||
const char *szWindowsPath = filesystem2->GetWindowsPath(szOutputFile);
|
||||
args.AppendTail(CUtlString("/out:%s", szWindowsPath));
|
||||
V_free((void*)szWindowsPath);
|
||||
|
||||
if (pProject->linkType == ELINK_KERNEL_DRIVER)
|
||||
{
|
||||
args.AppendTail("/driver");
|
||||
args.AppendTail(CUtlString("/entry:%s", pProject->szEntry));
|
||||
}
|
||||
switch (pProject->m_eWindowsSubsystem)
|
||||
{
|
||||
case WINDOWS_SUBSYSTEM_NATIVE:
|
||||
args.AppendTail("/subsystem:native");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Disable stdlib
|
||||
if (pProject->bNoStdLib)
|
||||
{
|
||||
}
|
||||
|
||||
for (auto object: pProject->objects)
|
||||
args.AppendTail(object.m_szObjectFile);
|
||||
|
||||
for (auto lib: pProject->libraries)
|
||||
{
|
||||
/*
|
||||
args.AppendTail("-l");
|
||||
args.AppendTail(lib);
|
||||
*/
|
||||
}
|
||||
|
||||
winerunner->Run(szExePath, args);
|
||||
winerunner->Wait();
|
||||
}
|
||||
compiled:
|
||||
return szOutputFile;
|
||||
};
|
||||
|
||||
bool CMSVCLinker::IsLibraryExists( CUtlString szName )
|
||||
{
|
||||
szName = CUtlString("%s.dll", szName.GetString());
|
||||
void *pLib = Plat_LoadLibrary(szName.GetString());
|
||||
if (!pLib)
|
||||
return false;
|
||||
Plat_UnloadLibrary(pLib);
|
||||
return true;
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
#include "runner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "windows.h"
|
||||
|
||||
|
||||
class CWindowsRunner: public IRunner
|
||||
{
|
||||
public:
|
||||
virtual int Run( CUtlString szName, CUtlVector<CUtlString>& args ) override;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args ) override;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment ) override;
|
||||
virtual int Wait( void ) override;
|
||||
CUtlVector<pid_t> s_processes = {};
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CWindowsRunner, IRunner, POSIX_RUNNER_INTERFACE_NAME);
|
||||
IRunner *runner;
|
||||
|
||||
int CWindowsRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
Plat_FatalErrorFunc("Failed to fork");
|
||||
/* child */
|
||||
if (pid == 0)
|
||||
{
|
||||
CUtlVector<const char*> execargs;
|
||||
execargs.AppendTail(szName);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("%s",szName.GetString());
|
||||
for (auto &arg: args)
|
||||
{
|
||||
execargs.AppendTail(arg);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf(" %s",arg.GetString());
|
||||
}
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("\n");
|
||||
execargs.AppendTail(0);
|
||||
if ( execvp(szName, (char *const*)execargs.GetData()) == -1 )
|
||||
{
|
||||
V_printf("Failed to launch %s\n",szName.GetString());
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
s_processes.AppendTail(pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CWindowsRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
Plat_FatalErrorFunc("Failed to fork");
|
||||
/* child */
|
||||
if (pid == 0)
|
||||
{
|
||||
CUtlVector<const char*> execargs;
|
||||
execargs.AppendTail(szName);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("%s",szName.GetString());
|
||||
for (auto &arg: args)
|
||||
{
|
||||
execargs.AppendTail(arg);
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf(" %s",arg.GetString());
|
||||
}
|
||||
if (CommandLine()->CheckParam("-fpcdebug"))
|
||||
V_printf("\n");
|
||||
execargs.AppendTail(0);
|
||||
chdir(szDirectory.GetString());
|
||||
if ( execvp(szName, (char *const*)execargs.GetData()) == -1 )
|
||||
{
|
||||
V_printf("Failed to launch %s\n",szName.GetString());
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
s_processes.AppendTail(pid);
|
||||
/* parent */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CWindowsRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CWindowsRunner::Wait( void )
|
||||
{
|
||||
for (auto &process: s_processes)
|
||||
{
|
||||
int status;
|
||||
pid_t wpid = waitpid(process, &status, 0);
|
||||
}
|
||||
s_processes = {};
|
||||
return 0;
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
#include "runner.h"
|
||||
#include "winerunner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/wait.h"
|
||||
#include "tier0/commandline.h"
|
||||
|
||||
class CWineRunner: public IWineRunner
|
||||
{
|
||||
public:
|
||||
CWineRunner();
|
||||
~CWineRunner();
|
||||
|
||||
virtual int Run( CUtlString szName, CUtlVector<CUtlString>& args ) override;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args ) override;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment ) override;
|
||||
virtual int Wait( void ) override;
|
||||
private:
|
||||
pid_t m_wineServerPID;
|
||||
};
|
||||
|
||||
EXPOSE_INTERFACE(CWineRunner, IWineRunner, WINE_RUNNER_INTERFACE_NAME);
|
||||
|
||||
CWineRunner::CWineRunner()
|
||||
{
|
||||
|
||||
}
|
||||
CWineRunner::~CWineRunner()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CWineRunner::Run(CUtlString szName, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
return runner->Run(szName, args);
|
||||
}
|
||||
|
||||
int CWineRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args)
|
||||
{
|
||||
CUtlVector<CUtlString> args2 = args;
|
||||
args2.AppendHead(szName);
|
||||
return runner->Run("wine", szDirectory, args2);
|
||||
}
|
||||
|
||||
int CWineRunner::Run(CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment)
|
||||
{
|
||||
CUtlVector<CUtlString> args2 = args;
|
||||
args2.AppendHead(szName);
|
||||
return runner->Run("wine", szDirectory, args2, environment);
|
||||
}
|
||||
|
||||
int CWineRunner::Wait( void )
|
||||
{
|
||||
return runner->Wait();
|
||||
};
|
||||
173
fpc/main.cpp
173
fpc/main.cpp
@@ -1,173 +0,0 @@
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/rand.h"
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier2/fileformats/ini.h"
|
||||
#include "public/c.h"
|
||||
#include "public/helper.h"
|
||||
#include "public/ld.h"
|
||||
#include "public/target.h"
|
||||
#include "runner.h"
|
||||
#include "winerunner.h"
|
||||
#include "c.h"
|
||||
#include "signal.h"
|
||||
#include "libgen.h"
|
||||
#include "builder.h"
|
||||
|
||||
CUtlString owndir;
|
||||
static char **pszBuildDir;
|
||||
|
||||
void build_tier0()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
int build()
|
||||
{
|
||||
BuildFile_t *pBuildFile = ProjectBuilder()->BuildProject("main",CUtlString("%s/build.cpp",*pszBuildDir));
|
||||
|
||||
/*
|
||||
|
||||
LinkProject_t linkScriptProject = ccompiler->Compile(&compileScriptProject);
|
||||
linkScriptProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||
linkScriptProject.m_target = Target_t::HostTarget();
|
||||
|
||||
CUtlString script = linker->Link(&linkScriptProject);
|
||||
|
||||
|
||||
void *scriptDLL = Plat_LoadLibrary(script);
|
||||
pBuildFactory = Sys_GetFactory(scriptDLL);
|
||||
|
||||
|
||||
pBuildFactory = NULL;
|
||||
pBuildFileInfo = (BuildFileInfo_t*)pBuildFactory(BUILD_FILE_INFO_INTERFACE_NAME, NULL);
|
||||
if (!pBuildFactory)
|
||||
Plat_FatalErrorFunc("Failed to find build file info interface\n");
|
||||
|
||||
auto PreinitFn = (void(*)())Plat_GetProc(scriptDLL, "Preinit");
|
||||
if (PreinitFn)
|
||||
PreinitFn();
|
||||
|
||||
for (auto &build: pBuildFileInfo->m_stages)
|
||||
{
|
||||
build->m_pMainFn();
|
||||
};
|
||||
*/
|
||||
|
||||
ccompiler->GenerateLinterData();
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
void IEngine_Signal(int sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case SIGSEGV:
|
||||
case SIGILL:
|
||||
case SIGABRT:
|
||||
Plat_Backtrace();
|
||||
Plat_FatalErrorFunc("Fault\n");
|
||||
break;
|
||||
case SIGINT:
|
||||
Plat_Exit(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
Plat_Exit(0);
|
||||
};
|
||||
|
||||
IRunner *runner;
|
||||
IWineRunner *winerunner;
|
||||
ICCompiler *ccompiler;
|
||||
ILinker *linker;
|
||||
|
||||
|
||||
int main(int c, char **v)
|
||||
{
|
||||
|
||||
char path[1024];
|
||||
|
||||
CUtlString buildcppDir = Plat_GetWorkingDir();
|
||||
owndir = buildcppDir;
|
||||
char *szBuildcppDir = buildcppDir.GetString();
|
||||
|
||||
findbuild:
|
||||
FILE* file = V_fopen("build.cpp", "rb");
|
||||
if (!file)
|
||||
{
|
||||
buildcppDir = buildcppDir.GetDirectory();
|
||||
if (buildcppDir=="/")
|
||||
{
|
||||
V_printf("build.cpp not found\n");
|
||||
return 0;
|
||||
}
|
||||
Plat_SetWorkingDir(szBuildcppDir);
|
||||
goto findbuild;
|
||||
} else {
|
||||
V_fclose(file);
|
||||
}
|
||||
|
||||
#ifdef __linux
|
||||
signal(SIGHUP, IEngine_Signal);
|
||||
signal(SIGINT, IEngine_Signal);
|
||||
signal(SIGQUIT, IEngine_Signal);
|
||||
signal(SIGILL, IEngine_Signal);
|
||||
signal(SIGTRAP, IEngine_Signal);
|
||||
signal(SIGIOT, IEngine_Signal);
|
||||
signal(SIGBUS, IEngine_Signal);
|
||||
signal(SIGFPE, IEngine_Signal);
|
||||
signal(SIGSEGV, IEngine_Signal);
|
||||
signal(SIGTERM, IEngine_Signal);
|
||||
#endif
|
||||
|
||||
|
||||
void *pLibFPC = Plat_LoadLibrary("libfpc.so");
|
||||
CreateInterfaceFn pLibFPCFactory = Sys_GetFactory(pLibFPC);
|
||||
|
||||
filesystem2 = (IFileSystem2*)pLibFPCFactory(FILE_SYSTEM_2_INTERFACE_NAME, NULL);
|
||||
pszBuildDir = (char**)pLibFPCFactory(FILE_SYSTEM_2_BUILD_DIRECTORY_INTERFACE_VERSION, NULL);
|
||||
*pszBuildDir = szBuildcppDir;
|
||||
runner = (IRunner*)pLibFPCFactory(RUNNER_INTERFACE_NAME, NULL);
|
||||
winerunner = (IWineRunner*)pLibFPCFactory(WINE_RUNNER_INTERFACE_NAME, NULL);
|
||||
ccompiler = (ICCompiler*)pLibFPCFactory(CLANG_C_COMPILER_INTERFACE_NAME, NULL);
|
||||
linker = (ILinker*)pLibFPCFactory(CLANG_LINKER_INTERFACE_NAME, NULL);
|
||||
|
||||
|
||||
|
||||
pLibFPCFactory(LIBFPC_INIT_INTERFACE_VERSION, NULL);
|
||||
|
||||
|
||||
void *pFilesystem = Plat_LoadLibrary("libfilesystem_std.so");
|
||||
CreateInterfaceFn pFilesystemFactory = Sys_GetFactory(pFilesystem);
|
||||
|
||||
filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
|
||||
filesystem->Init();
|
||||
|
||||
g_pConfig = INIManager()->ReadFile(".fpccfg");
|
||||
|
||||
IINIFile **ppConfig = (IINIFile**)pLibFPCFactory(LIBFPC_CONFIG_INTERFACE_VERSION, NULL);
|
||||
*ppConfig = g_pConfig;
|
||||
|
||||
CommandLine()->CreateCommandLine(c, v);
|
||||
Plat_InitRandom();
|
||||
|
||||
if (CommandLine()->CheckParam("-v") || CommandLine()->CheckParam("--version"))
|
||||
{
|
||||
V_printf("fpc version v1\n");
|
||||
V_printf("built " __DATE__ " " __TIME__ "\n");
|
||||
V_printf("built for %s\n", Target_t::HostTarget().GetTriplet().GetString());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (CommandLine()->CheckParam("build"))
|
||||
build();
|
||||
const char *szDeployDevice = CommandLine()->ParamValue("deploy");
|
||||
Plat_ShutdownRandom();
|
||||
return 0;
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Set Android metadata aboth the package.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef APK_TOOL_H
|
||||
#define APK_TOOL_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "legal.h"
|
||||
|
||||
struct AndroidManifest_t
|
||||
{
|
||||
public:
|
||||
void SetPackageVersion( CUtlString szVersion );
|
||||
void SetPackageBuild( uint64_t nBuild );
|
||||
void SetPackageID( CUtlString szPackageID );
|
||||
void SetPackageName( CUtlString szPackageName );
|
||||
|
||||
void SetTargetSDKVersion( uint64_t nTargetVersion );
|
||||
void SetMinSDKVersion( uint64_t nMinVersion );
|
||||
|
||||
void AddUserFeature( CUtlString szName, bool bIsRequired, uint64_t nVersion );
|
||||
void AddUserLibrary( CUtlString szPath );
|
||||
CUtlString BuildManifest();
|
||||
|
||||
CUtlString m_szPackageName;
|
||||
CUtlString m_szPackageID;
|
||||
uint64_t m_nBuild;
|
||||
CUtlString m_szVersion;
|
||||
|
||||
uint64_t m_nTargetVersion;
|
||||
uint64_t m_nMinVersion;
|
||||
};
|
||||
|
||||
abstract_class IAPKTool
|
||||
{
|
||||
public:
|
||||
virtual CUtlString BuildPackage( AndroidManifest_t manifest, CUtlString szManifestDir ) = 0;
|
||||
virtual CUtlString SignPackage( const char *szApk, LegalInfo_t *pLegalInfo, const char *szAlias, const char *szStorePassword, const char *szKeyPassword ) = 0;
|
||||
};
|
||||
|
||||
IAPKTool *APKTool();
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef Apple_TOOL_H
|
||||
#define Apple_TOOL_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "legal.h"
|
||||
|
||||
struct AppleManifest_t
|
||||
{
|
||||
public:
|
||||
void SetPackageID( CUtlString szPackageID );
|
||||
void SetPackageName( CUtlString szPackageName );
|
||||
void SetPackageExecutable( CUtlString szPackageExecutable );
|
||||
|
||||
CUtlString BuildManifest();
|
||||
|
||||
CUtlString m_szPackageName;
|
||||
CUtlString m_szPackageID;
|
||||
CUtlString m_szPackageExecutable;
|
||||
};
|
||||
|
||||
abstract_class IAppleTool
|
||||
{
|
||||
public:
|
||||
virtual CUtlString BuildPackage( AppleManifest_t manifest, CUtlString szManifestDir ) = 0;
|
||||
virtual CUtlString SignPackage( const char *szIpa, const char *szPassword ) = 0;
|
||||
};
|
||||
|
||||
|
||||
IAppleTool *AppleTool();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef BUILDER_H
|
||||
#define BUILDER_H
|
||||
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
struct BuildOutput_t
|
||||
{
|
||||
const char *m_szName;
|
||||
};
|
||||
|
||||
struct BuildOutputs_t
|
||||
{
|
||||
const char *m_szBuildStageName;
|
||||
CUtlVector<BuildOutput_t> m_buildOutputs;
|
||||
};
|
||||
|
||||
struct BuildFile_t
|
||||
{
|
||||
CUtlString m_szOutputFile;
|
||||
void *m_pLibrary;
|
||||
CUtlVector<BuildOutputs_t> m_compiledProjects;
|
||||
|
||||
struct BuildFile_t *m_pNext;
|
||||
};
|
||||
|
||||
abstract_class IProjectBuilder
|
||||
{
|
||||
public:
|
||||
virtual BuildFile_t *BuildProject( const char *szProjectName, const char *szPath ) = 0;
|
||||
};
|
||||
|
||||
IProjectBuilder *ProjectBuilder();
|
||||
|
||||
#define PROJECT_BUILDER_INTERFACE_NAME "ProjectBuilder001"
|
||||
|
||||
#endif
|
||||
128
fpc/public/c.h
128
fpc/public/c.h
@@ -1,128 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: C, C++, Objective-C and Objective-C++ compiler interface.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef C_H
|
||||
#define C_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "runner.h"
|
||||
#include "ld.h"
|
||||
#include "target.h"
|
||||
#include "helper.h"
|
||||
|
||||
struct C_Macro_t
|
||||
{
|
||||
CUtlString szName;
|
||||
CUtlString szValue;
|
||||
};
|
||||
|
||||
|
||||
// Target C version
|
||||
enum ECVersion
|
||||
{
|
||||
CVERSION_89,
|
||||
CVERSION_99 = 0,
|
||||
CVERSION_11,
|
||||
CVERSION_17,
|
||||
CVERSION_23,
|
||||
CVERSION_2Y,
|
||||
};
|
||||
|
||||
// Target C++ version
|
||||
enum ECPPVersion
|
||||
{
|
||||
CPPVERSION_98 = 0,
|
||||
CPPVERSION_11 = 1,
|
||||
CPPVERSION_14 = 2,
|
||||
CPPVERSION_17 = 3,
|
||||
CPPVERSION_20 = 4,
|
||||
CPPVERSION_23 = 5,
|
||||
CPPVERSION_2C = 6,
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// C project settings used in compilation
|
||||
// Example usage:
|
||||
// CProject_t compileProject = {};
|
||||
// LinkProject_t ldProject = {};
|
||||
//
|
||||
// compileProject.m_szName = "your project name";
|
||||
// compileProject.files = g_CompiledFiles;
|
||||
// compileProject.includeDirectories = g_IncludeDirectories;
|
||||
// ldProject = ccompiler->Compile(&compileProject);
|
||||
//----------------------------------------------------------------------------
|
||||
struct CProject_t : public CPUProject_t
|
||||
{
|
||||
public:
|
||||
// Compiled files
|
||||
CUtlVector<CUtlString> files = {};
|
||||
|
||||
// Included directories
|
||||
CUtlVector<CUtlString> includeDirectories = {};
|
||||
|
||||
// Included files
|
||||
// They are included on top of the file
|
||||
CUtlVector<CUtlString> includeFiles = {};
|
||||
|
||||
// Defined macros
|
||||
CUtlVector<C_Macro_t> macros = {};
|
||||
|
||||
// Target C version
|
||||
ECVersion cVersion;
|
||||
|
||||
// Target C++ version
|
||||
ECPPVersion cppVersion;
|
||||
};
|
||||
|
||||
// Basic interface name
|
||||
#define C_COMPILER_INTERFACE_NAME "CCompiler001"
|
||||
#define CLANG_C_COMPILER_INTERFACE_NAME "Clang" C_COMPILER_INTERFACE_NAME
|
||||
#define GNU_C_COMPILER_INTERFACE_NAME "GNU" C_COMPILER_INTERFACE_NAME
|
||||
#define MSVC_C_COMPILER_INTERFACE_NAME "MSVC" C_COMPILER_INTERFACE_NAME
|
||||
|
||||
class ICCompiler
|
||||
{
|
||||
public:
|
||||
|
||||
// Compiles all files into objects, returns linker project,
|
||||
// which can be linked into executable or library.
|
||||
virtual LinkProject_t Compile( CProject_t *pProject );
|
||||
|
||||
virtual void GenerateLinterData() = 0;
|
||||
protected:
|
||||
// Compiler internals
|
||||
|
||||
// Returns file name of the
|
||||
CUtlString GetOutputObjectName( CProject_t *pProject, unsigned int hash, CUtlString szFileName );
|
||||
|
||||
virtual CUtlVector<CUtlString> BuildCommandLine( CProject_t *pProject, const char *szFileName, const char *szOutputFileName );
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( CProject_t *pProject ) = 0;
|
||||
|
||||
// returns object file format, eg .obj or .o
|
||||
virtual const char *GetOutputObjectFormat() = 0;
|
||||
|
||||
virtual void IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue ) = 0;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, CProject_t *pProject ) = 0;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, CProject_t *pProject , const char *szSysroot ) = 0;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
|
||||
virtual void CompileFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
|
||||
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) = 0;
|
||||
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) = 0;
|
||||
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) = 0;
|
||||
|
||||
};
|
||||
|
||||
extern ICCompiler *ccompiler;
|
||||
|
||||
#endif
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef DEPLOY_H
|
||||
#define DEPLOY_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
abstract_class IDeployDevice
|
||||
{
|
||||
public:
|
||||
virtual const char *GetName() = 0;
|
||||
virtual void *Install( const char *szPath ) = 0;
|
||||
};
|
||||
|
||||
abstract_class IDeployDeviceManager
|
||||
{
|
||||
public:
|
||||
virtual void AddDevice( IDeployDevice *pDevice ) = 0;
|
||||
virtual IDeployDevice *FindDeviceByName( const char *szDeviceName ) = 0;
|
||||
virtual const CUtlVector<IDeployDevice*> &ListDevices() = 0;
|
||||
};
|
||||
|
||||
IDeployDeviceManager *DeployDeviceManager();
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,164 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Helper functions for compilers, filesystem2 and build stages.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef HELPER_H
|
||||
#define HELPER_H
|
||||
|
||||
#include "apktool.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "target.h"
|
||||
#include "tier2/fileformats/ini.h"
|
||||
#include "tier1/interface.h"
|
||||
|
||||
#define FPC_TEMPORAL_DIRNAME ".fpc"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A base for all projects
|
||||
//-----------------------------------------------------------------------------
|
||||
struct BaseProject_t
|
||||
{
|
||||
public:
|
||||
CUtlString m_szName;
|
||||
// Creates a hash for the project
|
||||
unsigned int GenerateProjectHash( void );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A base for cpu projects
|
||||
//-----------------------------------------------------------------------------
|
||||
struct CPUProject_t : public BaseProject_t
|
||||
{
|
||||
public:
|
||||
Target_t m_target = Target_t::DefaultTarget();
|
||||
|
||||
// Is compiled as position independent executable
|
||||
bool bFPIE = false;
|
||||
|
||||
// Is compiled as position independent code
|
||||
// Use for shared libraries
|
||||
bool bFPIC = false;
|
||||
|
||||
// TODO: rework manifests
|
||||
// Android manifest
|
||||
AndroidManifest_t m_androidmanifest = {};
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A base for shader projects
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShaderProject_t : public BaseProject_t
|
||||
{
|
||||
public:
|
||||
EShaderTarget m_eTarget;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// File system manager.
|
||||
//-----------------------------------------------------------------------------
|
||||
#define FILE_SYSTEM_2_INTERFACE_NAME "FileSystem2_001"
|
||||
#define FILE_SYSTEM_2_BUILD_DIRECTORY_INTERFACE_VERSION "FileSystem2BuildDirectory_001"
|
||||
|
||||
abstract_class IFileSystem2
|
||||
{
|
||||
public:
|
||||
// Returns a directory of fpc executable
|
||||
virtual char *OwnDirectory() = 0;
|
||||
|
||||
// Returns directory of build.cpp
|
||||
virtual char *BuildDirectory() = 0;
|
||||
|
||||
// Creates new directory at path
|
||||
virtual void MakeDirectory( const char *psz ) = 0;
|
||||
|
||||
// UNIX-style file copy
|
||||
virtual void CopyFile( const char *szDestination, const char *szOrigin ) = 0;
|
||||
|
||||
// UNIX-style recursive directory copy
|
||||
virtual void CopyDirectory( const char *szDestination, const char *szOrigin ) = 0;
|
||||
|
||||
// Compares timestamps of 2 files
|
||||
virtual bool ShouldRecompile( const char *szSource, const char *szOutput ) = 0;
|
||||
|
||||
virtual char *GetWindowsPath( const char *szPath ) = 0;
|
||||
virtual char *GetPOSIXPath( const char *szPath ) = 0;
|
||||
};
|
||||
|
||||
extern IFileSystem2 *filesystem2;
|
||||
|
||||
struct StageOutput_t
|
||||
{
|
||||
const char *m_szName;
|
||||
CUtlString m_szPath;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Build stage.
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBuildStage
|
||||
{
|
||||
public:
|
||||
CBuildStage( const char *psz, int(*pMainFn)() );
|
||||
const char *m_psz;
|
||||
CUtlString m_szPath;
|
||||
CUtlVector<StageOutput_t> m_outputs;
|
||||
int(*m_pMainFn)();
|
||||
};
|
||||
|
||||
|
||||
class CBuildDependentFile
|
||||
{
|
||||
public:
|
||||
CBuildDependentFile( const char *psz );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Declares new build stage.
|
||||
// example:
|
||||
// DECLARE_BUILD_STAGE(your_build_stage_name)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
//-----------------------------------------------------------------------------
|
||||
#define DECLARE_BUILD_STAGE(sz) \
|
||||
static int __build_stage_##sz(); \
|
||||
static CBuildStage __##sz##_build_stage(#sz, __build_stage_##sz); \
|
||||
static int __build_stage_##sz()
|
||||
|
||||
#define ADD_DEPENDENCY_BUILD_FILE(name, path) \
|
||||
static CBuildDependentFile __##name##DependencyFile(path);
|
||||
|
||||
#define ADD_OUTPUT_OBJECT(sz, path) \
|
||||
g_pCurrentStage->m_outputs.AppendTail((StageOutput_t){sz, path});
|
||||
|
||||
#define DEPEND_ON_PROJECT(sz) \
|
||||
|
||||
#define GET_PROJECT_LIBRARY(sz, szLib) \
|
||||
FPC_GetProjectObject(#sz, szLib)
|
||||
|
||||
|
||||
struct BuildFileInfo_t
|
||||
{
|
||||
CUtlVector<const char*> m_dependantFiles;
|
||||
CUtlVector<CBuildStage*> m_stages;
|
||||
};
|
||||
|
||||
BuildFileInfo_t *GetBuildFileInfo();
|
||||
extern CBuildStage *g_pCurrentStage;
|
||||
|
||||
CUtlString FPC_GetProjectObject( const char *szName, const char *szObjectName );
|
||||
|
||||
|
||||
#define BUILD_FILE_INFO_INTERFACE_VERSION "BuildFileInfo001"
|
||||
#define BUILD_CURRENT_STAGE_INTERFACE_VERSION "BuildCurrentStage001"
|
||||
|
||||
typedef CUtlString(*GetProjectObjectFn)( const char *szName, const char *szObjectName );
|
||||
#define BUILD_GET_PROJECT_OBJECT_INTERFACE_VERSION "GetProjectObject001"
|
||||
|
||||
#define LIBFPC_INIT_INTERFACE_VERSION "LibFPCInit001"
|
||||
|
||||
|
||||
extern IINIFile *g_pConfig;
|
||||
#define LIBFPC_CONFIG_INTERFACE_VERSION "LibFPCConfig001"
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Automatic signature generator for iOS, Android and other devices,
|
||||
// which require signed executables, files etc.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SIGN_TOOL_H
|
||||
#define SIGN_TOOL_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#define APPLE_SIGN_TOOL_INTERFACE_NAME "SignToolApple001"
|
||||
#define ANDROID_SIGN_TOOL_INTERFACE_NAME "SignToolAndroid001"
|
||||
|
||||
abstract_class ISignTool
|
||||
{
|
||||
public:
|
||||
virtual void SetSignPassword( CUtlString szPassword ) = 0;
|
||||
virtual void SignFile( CUtlString szFile ) = 0;
|
||||
virtual void SignDirectory( CUtlString szDirectory ) = 0;
|
||||
};
|
||||
|
||||
extern ISignTool *signtool_android;
|
||||
extern ISignTool *signtool_apple;
|
||||
|
||||
#endif
|
||||
135
fpc/public/ld.h
135
fpc/public/ld.h
@@ -1,135 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Linker interface.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef LD_H
|
||||
#define LD_H
|
||||
|
||||
|
||||
#include "runner.h"
|
||||
#include "helper.h"
|
||||
#include "obj.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
enum ELinkType
|
||||
{
|
||||
ELINK_EXECUTABLE,
|
||||
ELINK_DYNAMIC_LIBRARY,
|
||||
ELINK_STATIC_LIBRARY,
|
||||
|
||||
// drivers
|
||||
ELINK_KERNEL_DRIVER
|
||||
};
|
||||
|
||||
enum EWindowsSubsystem
|
||||
{
|
||||
WINDOWS_SUBSYSTEM_NATIVE,
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// C project settings used in compilation
|
||||
// Example usage:
|
||||
// CProject_t compileProject = {};
|
||||
// LinkProject_t ldProject = {};
|
||||
// CUtlString szOutputFile;
|
||||
//
|
||||
// compileProject.m_szName = "your_project_name";
|
||||
// compileProject.files = g_CompiledFiles;
|
||||
// compileProject.includeDirectories = g_IncludeDirectories;
|
||||
//
|
||||
// ldProject = ccompiler->Compile(&compileProject);
|
||||
// ldProject.linkType = ELINK_EXECUTABLE
|
||||
// szOutputFile = linker->Link(&ldProject);
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
struct LinkProject_t: public CPUProject_t
|
||||
{
|
||||
public:
|
||||
void AddObject( Object_t object );
|
||||
|
||||
// output file
|
||||
ELinkType linkType;
|
||||
|
||||
// objects, they could be libraries and compiled files
|
||||
CUtlVector<Object_t> objects = {};
|
||||
|
||||
// system libraries
|
||||
CUtlVector<CUtlString> libraries ={};
|
||||
|
||||
// directories for libraries
|
||||
CUtlVector<CUtlString> libraryDirectories = {};
|
||||
|
||||
// not used
|
||||
CUtlVector<CUtlString> libraryObjects = {};
|
||||
|
||||
// Apple framework directories
|
||||
CUtlVector<CUtlString> frameworkDirectories = {};
|
||||
|
||||
const char *szEntry = "";
|
||||
|
||||
// Disables C standart library
|
||||
bool bNoStdLib;
|
||||
|
||||
// Apple frameworks
|
||||
CUtlVector<CUtlString> frameworks = {};
|
||||
|
||||
// Windows subsystem
|
||||
EWindowsSubsystem m_eWindowsSubsystem;
|
||||
};
|
||||
|
||||
// Basic interface name
|
||||
#define LINKER_INTERFACE_NAME "Linker001"
|
||||
#define CLANG_LINKER_INTERFACE_NAME "Clang" LINKER_INTERFACE_NAME
|
||||
#define MSVC_LINKER_INTERFACE_NAME "MSVC" LINKER_INTERFACE_NAME
|
||||
|
||||
abstract_class ILinker
|
||||
{
|
||||
public:
|
||||
|
||||
// Links project
|
||||
virtual CUtlString Link( LinkProject_t *pProject );
|
||||
|
||||
virtual bool IsLibraryExists( CUtlString szName ) = 0;
|
||||
|
||||
protected:
|
||||
// Link
|
||||
// Returns file name of the
|
||||
CUtlString GetOutputObjectName( LinkProject_t *pProject, unsigned int hash, CUtlString szFileName );
|
||||
|
||||
virtual CUtlVector<CUtlString> BuildLinkCommandLine( LinkProject_t *pProject, const char *szOutputFileName );
|
||||
virtual CUtlVector<CUtlString> BuildArchiveCommandLine( LinkProject_t *pProject, const char *szOutputFileName );
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( LinkProject_t *pProject ) = 0;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) = 0;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject , const char *szSysroot ) = 0;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
|
||||
|
||||
// sets rpath
|
||||
// for windows should be ignored
|
||||
virtual void SetDefaultLibraryPaths( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) = 0;
|
||||
|
||||
virtual void UseStdLib( CUtlVector<CUtlString> &cmd, bool bUse ) = 0;
|
||||
|
||||
// windows doesn't use it as well
|
||||
virtual void UseDynamicLookup( CUtlVector<CUtlString> &cmd, bool bUse ) = 0;
|
||||
|
||||
// includes whole file
|
||||
virtual void UseFullFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) = 0;
|
||||
|
||||
// includes used stuff in a file
|
||||
virtual void UsePartialFile( CUtlVector<CUtlString> &cmd, LinkProject_t *pProject ) = 0;
|
||||
|
||||
virtual void LinkFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void LinkLibraryObject( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void LinkLibrary( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void LinkLibraryPath( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
|
||||
};
|
||||
|
||||
extern ILinker *linker;
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef LEGAL_H
|
||||
#define LEGAL_H
|
||||
|
||||
struct LegalInfo_t
|
||||
{
|
||||
const char *FirstName;
|
||||
const char *LastName;
|
||||
const char *OrganizationalUnitName;
|
||||
const char *OrganizationName;
|
||||
const char *City;
|
||||
const char *State;
|
||||
const char *CountryCode;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef LSP_H
|
||||
#define LSP_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
abstract_class IBasicLSP
|
||||
{
|
||||
virtual void GenerateConfig() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Object handler.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef OBJ_H
|
||||
#define OBJ_H
|
||||
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
struct Object_t
|
||||
{
|
||||
public:
|
||||
CUtlString m_szObjectFile;
|
||||
CUtlString m_szSourceFile;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Executable runner. It is mainly used to run compilers and linkers,
|
||||
// but can be used to run anything with given executable name
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef RUNNER_H
|
||||
#define RUNNER_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#define RUNNER_INTERFACE_NAME "Runner001"
|
||||
|
||||
abstract_class IRunner
|
||||
{
|
||||
public:
|
||||
virtual int Run( CUtlString szName, CUtlVector<CUtlString>& args ) = 0;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args ) = 0;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment ) = 0;
|
||||
virtual int Wait( void ) = 0;
|
||||
};
|
||||
|
||||
|
||||
extern IRunner *runner;
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef SIGNER_H
|
||||
#define SIGNER_H
|
||||
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier0/platform.h"
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
#ifndef SWIFT_H
|
||||
#define SWIFT_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "runner.h"
|
||||
#include "ld.h"
|
||||
#include "c.h"
|
||||
#include "target.h"
|
||||
#include "helper.h"
|
||||
|
||||
struct SwiftProject_t : public CPUProject_t
|
||||
{
|
||||
public:
|
||||
// Compiled files
|
||||
CUtlVector<CUtlString> files = {};
|
||||
|
||||
// Included directories
|
||||
CUtlVector<CUtlString> includeDirectories = {};
|
||||
|
||||
// Included files
|
||||
CUtlVector<CUtlString> includeObjcFiles = {};
|
||||
|
||||
// Stuff for embedded objc
|
||||
// Included files
|
||||
// They are included on top of the file
|
||||
CUtlVector<CUtlString> includeFiles = {};
|
||||
|
||||
// Stuff for embedded objc
|
||||
// Defined macros
|
||||
CUtlVector<C_Macro_t> macros = {};
|
||||
|
||||
// Stuff for embedded objc
|
||||
// Target C version
|
||||
ECVersion cVersion;
|
||||
|
||||
// Stuff for embedded objc
|
||||
// Target C++ version
|
||||
ECPPVersion cppVersion;
|
||||
};
|
||||
|
||||
#define SWIFT_COMPILER_INTERFACE_VERSION "SwiftCompiler001"
|
||||
|
||||
class ISwiftCompiler
|
||||
{
|
||||
public:
|
||||
|
||||
// Compiles all files into objects, returns linker project,
|
||||
// which can be linked into executable or library.
|
||||
virtual LinkProject_t Compile( SwiftProject_t *pProject );
|
||||
|
||||
//virtual void GenerateLinterData() = 0;
|
||||
protected:
|
||||
// Compiler internals
|
||||
|
||||
// Returns file name of the
|
||||
CUtlString GetOutputObjectName( SwiftProject_t *pProject, unsigned int hash, CUtlString szFileName );
|
||||
|
||||
virtual CUtlVector<CUtlString> BuildCommandLine( SwiftProject_t *pProject, const char *szFileName, const char *szOutputFileName );
|
||||
|
||||
// Returns executable which should the OS run
|
||||
virtual const char *GetCompilerExecutable( SwiftProject_t *pProject ) = 0;
|
||||
|
||||
// returns object file format, eg .obj or .o
|
||||
virtual const char *GetOutputObjectFormat() = 0;
|
||||
|
||||
virtual void IncludeDirectory( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void IncludeFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
virtual void Macro( CUtlVector<CUtlString> &cmd, const char *szName, const char *szValue ) = 0;
|
||||
|
||||
virtual void SetTarget( CUtlVector<CUtlString> &cmd, SwiftProject_t *pProject ) = 0;
|
||||
virtual void SetSysroot( CUtlVector<CUtlString> &cmd, SwiftProject_t *pProject , const char *szSysroot ) = 0;
|
||||
virtual void SetOutputFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
|
||||
virtual void CompileFile( CUtlVector<CUtlString> &cmd, const char *szName ) = 0;
|
||||
|
||||
virtual void EnableDebugSymbols( CUtlVector<CUtlString> &cmd ) = 0;
|
||||
virtual void EnablePIE( CUtlVector<CUtlString> &cmd ) = 0;
|
||||
virtual void EnablePIC( CUtlVector<CUtlString> &cmd ) = 0;
|
||||
};
|
||||
|
||||
|
||||
extern ISwiftCompiler *swiftcompiler;
|
||||
|
||||
#endif
|
||||
@@ -1,3 +0,0 @@
|
||||
#ifndef SYSROOT_FETCH_H
|
||||
#define SYSROOT_FETCH_H
|
||||
#endif
|
||||
@@ -1,94 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Target manager for compilers.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef TARGET_T
|
||||
#define TARGET_T
|
||||
|
||||
#include "tier0/commandline.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
enum ETargetKernel
|
||||
{
|
||||
TARGET_KERNEL_UNDEFINED,
|
||||
TARGET_KERNEL_UNKNOWN = 1,
|
||||
|
||||
TARGET_KERNEL_WINDOWS_DEVICES = 0x100,
|
||||
TARGET_KERNEL_WINDOWS,
|
||||
|
||||
TARGET_KERNEL_POSIX = 0x10000,
|
||||
TARGET_KERNEL_LINUX_DEVICES = TARGET_KERNEL_POSIX | 0x1000,
|
||||
TARGET_KERNEL_UNKNOWN_LINUX,
|
||||
TARGET_KERNEL_LINUX = TARGET_KERNEL_UNKNOWN_LINUX,
|
||||
TARGET_KERNEL_ALPINE_LINUX,
|
||||
TARGET_KERNEL_PC_LINUX,
|
||||
TARGET_KERNEL_ANDROID,
|
||||
TARGET_KERNEL_APPLE_DEVICES = TARGET_KERNEL_POSIX | 0x2000,
|
||||
TARGET_KERNEL_DARWIN,
|
||||
TARGET_KERNEL_IOS,
|
||||
|
||||
TARGET_KERNEL_WEB_DEVICES = 0x400,
|
||||
TARGET_KERNEL_WASI,
|
||||
TARGET_KERNEL_EMSCRIPTEN,
|
||||
};
|
||||
|
||||
enum ETargetCPU
|
||||
{
|
||||
TARGET_CPU_UNDEFINED,
|
||||
TARGET_CPU_80386,
|
||||
TARGET_CPU_80486,
|
||||
TARGET_CPU_80586,
|
||||
TARGET_CPU_80686,
|
||||
TARGET_CPU_AMD64,
|
||||
TARGET_CPU_AARCH64,
|
||||
TARGET_CPU_WASM32,
|
||||
};
|
||||
enum ETargetABI
|
||||
{
|
||||
TARGET_ABI_UNDEFINED,
|
||||
TARGET_ABI_DEFAULT,
|
||||
TARGET_ABI_GNU,
|
||||
TARGET_ABI_MUSL,
|
||||
TARGET_ABI_MSVC,
|
||||
};
|
||||
|
||||
enum ETargetOptimization
|
||||
{
|
||||
TARGET_DEBUG,
|
||||
TARGET_RELEASE_SPEED,
|
||||
TARGET_RELEASE_SIZE
|
||||
};
|
||||
|
||||
struct Target_t
|
||||
{
|
||||
ETargetKernel kernel;
|
||||
ETargetCPU cpu;
|
||||
ETargetABI abi;
|
||||
ETargetOptimization optimization;
|
||||
const char *szSysroot = CommandLine()->ParamValue("-sysroot");
|
||||
|
||||
CUtlString GetTriplet();
|
||||
const char *GetExecutableFileFormat();
|
||||
const char *GetStaticLibraryFileFormat();
|
||||
const char *GetDynamicLibraryFileFormat();
|
||||
static Target_t HostTarget();
|
||||
static Target_t DefaultTarget();
|
||||
static const char *StringFromCPU( ETargetCPU eCPU );
|
||||
static const char *StringFromKernel( ETargetKernel eKernel );
|
||||
static const char *StringFromABI( ETargetABI eABI );
|
||||
static ETargetCPU CPUFromString( const char *szName );
|
||||
static ETargetKernel KernelFromString( const char *szName );
|
||||
static ETargetABI ABIFromString( const char *szName );
|
||||
};
|
||||
|
||||
enum EShaderTarget
|
||||
{
|
||||
SHADER_TARGET_VULKAN_SPIRV,
|
||||
SHADER_TARGET_OPENGL_SPIRV,
|
||||
SHADER_TARGET_GLSL,
|
||||
SHADER_TARGET_HLSL,
|
||||
SHADER_TARGET_MSL,
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,28 +0,0 @@
|
||||
//================= Copyright kotofyt, All rights reserved ==================//
|
||||
// Purpose: Run Windows applications using Wine. On native system this will use
|
||||
// CWindowsRunner.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef WINE_RUNNER_H
|
||||
#define WINE_RUNNER_H
|
||||
|
||||
#include "runner.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#define WINE_RUNNER_INTERFACE_NAME "WineRunner001"
|
||||
|
||||
abstract_class IWineRunner: public IRunner
|
||||
{
|
||||
public:
|
||||
virtual int Run( CUtlString szName, CUtlVector<CUtlString>& args ) = 0;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args ) = 0;
|
||||
virtual int Run( CUtlString szName, CUtlString szDirectory, CUtlVector<CUtlString>& args, CUtlVector<CUtlString>& environment ) = 0;
|
||||
virtual int Wait( void ) = 0;
|
||||
};
|
||||
|
||||
|
||||
extern IWineRunner *winerunner;
|
||||
|
||||
#endif
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "helper.h"
|
||||
#include "sysroots.h"
|
||||
|
||||
DECLARE_SYSROOT_INSTALL_STAGE(xcode_install)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
[x86_64-linux-android]
|
||||
sysroot = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
|
||||
CLANG_LINKER_INTERFACE_NAME = "/home/kotofyt/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++"
|
||||
|
||||
[Android_Build_Tools]
|
||||
path = "/home/kotofyt/Android/Sdk/build-tools/36.0.0"
|
||||
@@ -1,443 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "android_native_app_glue.h"
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__))
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "threaded_app", __VA_ARGS__))
|
||||
|
||||
/* For debug builds, always enable the debug traces in this library */
|
||||
#ifndef NDEBUG
|
||||
# define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "threaded_app", __VA_ARGS__))
|
||||
#else
|
||||
# define LOGV(...) ((void)0)
|
||||
#endif
|
||||
|
||||
static void free_saved_state(struct android_app* android_app) {
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
if (android_app->savedState != NULL) {
|
||||
free(android_app->savedState);
|
||||
android_app->savedState = NULL;
|
||||
android_app->savedStateSize = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
}
|
||||
|
||||
int8_t android_app_read_cmd(struct android_app* android_app) {
|
||||
int8_t cmd;
|
||||
if (read(android_app->msgread, &cmd, sizeof(cmd)) == sizeof(cmd)) {
|
||||
switch (cmd) {
|
||||
case APP_CMD_SAVE_STATE:
|
||||
free_saved_state(android_app);
|
||||
break;
|
||||
}
|
||||
return cmd;
|
||||
} else {
|
||||
LOGE("No data on command pipe!");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void print_cur_config(struct android_app* android_app) {
|
||||
char lang[2], country[2];
|
||||
AConfiguration_getLanguage(android_app->config, lang);
|
||||
AConfiguration_getCountry(android_app->config, country);
|
||||
|
||||
LOGV("Config: mcc=%d mnc=%d lang=%c%c cnt=%c%c orien=%d touch=%d dens=%d "
|
||||
"keys=%d nav=%d keysHid=%d navHid=%d sdk=%d size=%d long=%d "
|
||||
"modetype=%d modenight=%d",
|
||||
AConfiguration_getMcc(android_app->config),
|
||||
AConfiguration_getMnc(android_app->config),
|
||||
lang[0], lang[1], country[0], country[1],
|
||||
AConfiguration_getOrientation(android_app->config),
|
||||
AConfiguration_getTouchscreen(android_app->config),
|
||||
AConfiguration_getDensity(android_app->config),
|
||||
AConfiguration_getKeyboard(android_app->config),
|
||||
AConfiguration_getNavigation(android_app->config),
|
||||
AConfiguration_getKeysHidden(android_app->config),
|
||||
AConfiguration_getNavHidden(android_app->config),
|
||||
AConfiguration_getSdkVersion(android_app->config),
|
||||
AConfiguration_getScreenSize(android_app->config),
|
||||
AConfiguration_getScreenLong(android_app->config),
|
||||
AConfiguration_getUiModeType(android_app->config),
|
||||
AConfiguration_getUiModeNight(android_app->config));
|
||||
}
|
||||
|
||||
void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd) {
|
||||
switch (cmd) {
|
||||
case APP_CMD_INPUT_CHANGED:
|
||||
LOGV("APP_CMD_INPUT_CHANGED\n");
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
if (android_app->inputQueue != NULL) {
|
||||
AInputQueue_detachLooper(android_app->inputQueue);
|
||||
}
|
||||
android_app->inputQueue = android_app->pendingInputQueue;
|
||||
if (android_app->inputQueue != NULL) {
|
||||
LOGV("Attaching input queue to looper");
|
||||
AInputQueue_attachLooper(android_app->inputQueue,
|
||||
android_app->looper, LOOPER_ID_INPUT, NULL,
|
||||
&android_app->inputPollSource);
|
||||
}
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
break;
|
||||
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
LOGV("APP_CMD_INIT_WINDOW\n");
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->window = android_app->pendingWindow;
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
break;
|
||||
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
LOGV("APP_CMD_TERM_WINDOW\n");
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
break;
|
||||
|
||||
case APP_CMD_RESUME:
|
||||
case APP_CMD_START:
|
||||
case APP_CMD_PAUSE:
|
||||
case APP_CMD_STOP:
|
||||
LOGV("activityState=%d\n", cmd);
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->activityState = cmd;
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
break;
|
||||
|
||||
case APP_CMD_CONFIG_CHANGED:
|
||||
LOGV("APP_CMD_CONFIG_CHANGED\n");
|
||||
AConfiguration_fromAssetManager(android_app->config,
|
||||
android_app->activity->assetManager);
|
||||
print_cur_config(android_app);
|
||||
break;
|
||||
|
||||
case APP_CMD_DESTROY:
|
||||
LOGV("APP_CMD_DESTROY\n");
|
||||
android_app->destroyRequested = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd) {
|
||||
switch (cmd) {
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
LOGV("APP_CMD_TERM_WINDOW\n");
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->window = NULL;
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
break;
|
||||
|
||||
case APP_CMD_SAVE_STATE:
|
||||
LOGV("APP_CMD_SAVE_STATE\n");
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->stateSaved = 1;
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
break;
|
||||
|
||||
case APP_CMD_RESUME:
|
||||
free_saved_state(android_app);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_dummy() {
|
||||
|
||||
}
|
||||
|
||||
static void android_app_destroy(struct android_app* android_app) {
|
||||
LOGV("android_app_destroy!");
|
||||
free_saved_state(android_app);
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
if (android_app->inputQueue != NULL) {
|
||||
AInputQueue_detachLooper(android_app->inputQueue);
|
||||
}
|
||||
AConfiguration_delete(android_app->config);
|
||||
android_app->destroyed = 1;
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
// Can't touch android_app object after this.
|
||||
}
|
||||
|
||||
static void process_input(struct android_app* app, struct android_poll_source* source) {
|
||||
AInputEvent* event = NULL;
|
||||
if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
|
||||
LOGV("New input event: type=%d\n", AInputEvent_getType(event));
|
||||
if (AInputQueue_preDispatchEvent(app->inputQueue, event)) {
|
||||
return;
|
||||
}
|
||||
int32_t handled = 0;
|
||||
if (app->onInputEvent != NULL) handled = app->onInputEvent(app, event);
|
||||
AInputQueue_finishEvent(app->inputQueue, event, handled);
|
||||
} else {
|
||||
LOGE("Failure reading next input event: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void process_cmd(struct android_app* app, struct android_poll_source* source) {
|
||||
int8_t cmd = android_app_read_cmd(app);
|
||||
android_app_pre_exec_cmd(app, cmd);
|
||||
if (app->onAppCmd != NULL) app->onAppCmd(app, cmd);
|
||||
android_app_post_exec_cmd(app, cmd);
|
||||
}
|
||||
|
||||
static void* android_app_entry(void* param) {
|
||||
struct android_app* android_app = (struct android_app*)param;
|
||||
|
||||
android_app->config = AConfiguration_new();
|
||||
AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager);
|
||||
|
||||
print_cur_config(android_app);
|
||||
|
||||
android_app->cmdPollSource.id = LOOPER_ID_MAIN;
|
||||
android_app->cmdPollSource.app = android_app;
|
||||
android_app->cmdPollSource.process = process_cmd;
|
||||
android_app->inputPollSource.id = LOOPER_ID_INPUT;
|
||||
android_app->inputPollSource.app = android_app;
|
||||
android_app->inputPollSource.process = process_input;
|
||||
|
||||
ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
|
||||
ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL,
|
||||
&android_app->cmdPollSource);
|
||||
android_app->looper = looper;
|
||||
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->running = 1;
|
||||
pthread_cond_broadcast(&android_app->cond);
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
|
||||
android_main(android_app);
|
||||
|
||||
android_app_destroy(android_app);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Native activity interaction (called from main thread)
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
static struct android_app* android_app_create(ANativeActivity* activity,
|
||||
void* savedState, size_t savedStateSize) {
|
||||
struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app));
|
||||
memset(android_app, 0, sizeof(struct android_app));
|
||||
android_app->activity = activity;
|
||||
|
||||
pthread_mutex_init(&android_app->mutex, NULL);
|
||||
pthread_cond_init(&android_app->cond, NULL);
|
||||
|
||||
if (savedState != NULL) {
|
||||
android_app->savedState = malloc(savedStateSize);
|
||||
android_app->savedStateSize = savedStateSize;
|
||||
memcpy(android_app->savedState, savedState, savedStateSize);
|
||||
}
|
||||
|
||||
int msgpipe[2];
|
||||
if (pipe(msgpipe)) {
|
||||
LOGE("could not create pipe: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
android_app->msgread = msgpipe[0];
|
||||
android_app->msgwrite = msgpipe[1];
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&android_app->thread, &attr, android_app_entry, android_app);
|
||||
|
||||
// Wait for thread to start.
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
while (!android_app->running) {
|
||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
|
||||
return android_app;
|
||||
}
|
||||
|
||||
static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) {
|
||||
if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) {
|
||||
LOGE("Failure writing android_app cmd: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void android_app_set_input(struct android_app* android_app, AInputQueue* inputQueue) {
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->pendingInputQueue = inputQueue;
|
||||
android_app_write_cmd(android_app, APP_CMD_INPUT_CHANGED);
|
||||
while (android_app->inputQueue != android_app->pendingInputQueue) {
|
||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
}
|
||||
|
||||
static void android_app_set_window(struct android_app* android_app, ANativeWindow* window) {
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
if (android_app->pendingWindow != NULL) {
|
||||
android_app_write_cmd(android_app, APP_CMD_TERM_WINDOW);
|
||||
}
|
||||
android_app->pendingWindow = window;
|
||||
if (window != NULL) {
|
||||
android_app_write_cmd(android_app, APP_CMD_INIT_WINDOW);
|
||||
}
|
||||
while (android_app->window != android_app->pendingWindow) {
|
||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
}
|
||||
|
||||
static void android_app_set_activity_state(struct android_app* android_app, int8_t cmd) {
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app_write_cmd(android_app, cmd);
|
||||
while (android_app->activityState != cmd) {
|
||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
}
|
||||
|
||||
static void android_app_free(struct android_app* android_app) {
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app_write_cmd(android_app, APP_CMD_DESTROY);
|
||||
while (!android_app->destroyed) {
|
||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
|
||||
close(android_app->msgread);
|
||||
close(android_app->msgwrite);
|
||||
pthread_cond_destroy(&android_app->cond);
|
||||
pthread_mutex_destroy(&android_app->mutex);
|
||||
free(android_app);
|
||||
}
|
||||
|
||||
static void onDestroy(ANativeActivity* activity) {
|
||||
LOGV("Destroy: %p\n", activity);
|
||||
android_app_free((struct android_app*)activity->instance);
|
||||
}
|
||||
|
||||
static void onStart(ANativeActivity* activity) {
|
||||
LOGV("Start: %p\n", activity);
|
||||
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_START);
|
||||
}
|
||||
|
||||
static void onResume(ANativeActivity* activity) {
|
||||
LOGV("Resume: %p\n", activity);
|
||||
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_RESUME);
|
||||
}
|
||||
|
||||
static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen) {
|
||||
struct android_app* android_app = (struct android_app*)activity->instance;
|
||||
void* savedState = NULL;
|
||||
|
||||
LOGV("SaveInstanceState: %p\n", activity);
|
||||
pthread_mutex_lock(&android_app->mutex);
|
||||
android_app->stateSaved = 0;
|
||||
android_app_write_cmd(android_app, APP_CMD_SAVE_STATE);
|
||||
while (!android_app->stateSaved) {
|
||||
pthread_cond_wait(&android_app->cond, &android_app->mutex);
|
||||
}
|
||||
|
||||
if (android_app->savedState != NULL) {
|
||||
savedState = android_app->savedState;
|
||||
*outLen = android_app->savedStateSize;
|
||||
android_app->savedState = NULL;
|
||||
android_app->savedStateSize = 0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&android_app->mutex);
|
||||
|
||||
return savedState;
|
||||
}
|
||||
|
||||
static void onPause(ANativeActivity* activity) {
|
||||
LOGV("Pause: %p\n", activity);
|
||||
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_PAUSE);
|
||||
}
|
||||
|
||||
static void onStop(ANativeActivity* activity) {
|
||||
LOGV("Stop: %p\n", activity);
|
||||
android_app_set_activity_state((struct android_app*)activity->instance, APP_CMD_STOP);
|
||||
}
|
||||
|
||||
static void onConfigurationChanged(ANativeActivity* activity) {
|
||||
struct android_app* android_app = (struct android_app*)activity->instance;
|
||||
LOGV("ConfigurationChanged: %p\n", activity);
|
||||
android_app_write_cmd(android_app, APP_CMD_CONFIG_CHANGED);
|
||||
}
|
||||
|
||||
static void onLowMemory(ANativeActivity* activity) {
|
||||
struct android_app* android_app = (struct android_app*)activity->instance;
|
||||
LOGV("LowMemory: %p\n", activity);
|
||||
android_app_write_cmd(android_app, APP_CMD_LOW_MEMORY);
|
||||
}
|
||||
|
||||
static void onWindowFocusChanged(ANativeActivity* activity, int focused) {
|
||||
LOGV("WindowFocusChanged: %p -- %d\n", activity, focused);
|
||||
android_app_write_cmd((struct android_app*)activity->instance,
|
||||
focused ? APP_CMD_GAINED_FOCUS : APP_CMD_LOST_FOCUS);
|
||||
}
|
||||
|
||||
static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) {
|
||||
LOGV("NativeWindowCreated: %p -- %p\n", activity, window);
|
||||
android_app_set_window((struct android_app*)activity->instance, window);
|
||||
}
|
||||
|
||||
static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) {
|
||||
LOGV("NativeWindowDestroyed: %p -- %p\n", activity, window);
|
||||
android_app_set_window((struct android_app*)activity->instance, NULL);
|
||||
}
|
||||
|
||||
static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) {
|
||||
LOGV("InputQueueCreated: %p -- %p\n", activity, queue);
|
||||
android_app_set_input((struct android_app*)activity->instance, queue);
|
||||
}
|
||||
|
||||
static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) {
|
||||
LOGV("InputQueueDestroyed: %p -- %p\n", activity, queue);
|
||||
android_app_set_input((struct android_app*)activity->instance, NULL);
|
||||
}
|
||||
|
||||
void ANativeActivity_onCreate(ANativeActivity* activity,
|
||||
void* savedState, size_t savedStateSize) {
|
||||
LOGV("Creating: %p\n", activity);
|
||||
activity->callbacks->onDestroy = onDestroy;
|
||||
activity->callbacks->onStart = onStart;
|
||||
activity->callbacks->onResume = onResume;
|
||||
activity->callbacks->onSaveInstanceState = onSaveInstanceState;
|
||||
activity->callbacks->onPause = onPause;
|
||||
activity->callbacks->onStop = onStop;
|
||||
activity->callbacks->onConfigurationChanged = onConfigurationChanged;
|
||||
activity->callbacks->onLowMemory = onLowMemory;
|
||||
activity->callbacks->onWindowFocusChanged = onWindowFocusChanged;
|
||||
activity->callbacks->onNativeWindowCreated = onNativeWindowCreated;
|
||||
activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
|
||||
activity->callbacks->onInputQueueCreated = onInputQueueCreated;
|
||||
activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
|
||||
|
||||
activity->instance = android_app_create(activity, savedState, savedStateSize);
|
||||
}
|
||||
@@ -1,349 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ANDROID_NATIVE_APP_GLUE_H
|
||||
#define _ANDROID_NATIVE_APP_GLUE_H
|
||||
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <android/configuration.h>
|
||||
#include <android/looper.h>
|
||||
#include <android/native_activity.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The native activity interface provided by <android/native_activity.h>
|
||||
* is based on a set of application-provided callbacks that will be called
|
||||
* by the Activity's main thread when certain events occur.
|
||||
*
|
||||
* This means that each one of this callbacks _should_ _not_ block, or they
|
||||
* risk having the system force-close the application. This programming
|
||||
* model is direct, lightweight, but constraining.
|
||||
*
|
||||
* The 'threaded_native_app' static library is used to provide a different
|
||||
* execution model where the application can implement its own main event
|
||||
* loop in a different thread instead. Here's how it works:
|
||||
*
|
||||
* 1/ The application must provide a function named "android_main()" that
|
||||
* will be called when the activity is created, in a new thread that is
|
||||
* distinct from the activity's main thread.
|
||||
*
|
||||
* 2/ android_main() receives a pointer to a valid "android_app" structure
|
||||
* that contains references to other important objects, e.g. the
|
||||
* ANativeActivity obejct instance the application is running in.
|
||||
*
|
||||
* 3/ the "android_app" object holds an ALooper instance that already
|
||||
* listens to two important things:
|
||||
*
|
||||
* - activity lifecycle events (e.g. "pause", "resume"). See APP_CMD_XXX
|
||||
* declarations below.
|
||||
*
|
||||
* - input events coming from the AInputQueue attached to the activity.
|
||||
*
|
||||
* Each of these correspond to an ALooper identifier returned by
|
||||
* ALooper_pollOnce with values of LOOPER_ID_MAIN and LOOPER_ID_INPUT,
|
||||
* respectively.
|
||||
*
|
||||
* Your application can use the same ALooper to listen to additional
|
||||
* file-descriptors. They can either be callback based, or with return
|
||||
* identifiers starting with LOOPER_ID_USER.
|
||||
*
|
||||
* 4/ Whenever you receive a LOOPER_ID_MAIN or LOOPER_ID_INPUT event,
|
||||
* the returned data will point to an android_poll_source structure. You
|
||||
* can call the process() function on it, and fill in android_app->onAppCmd
|
||||
* and android_app->onInputEvent to be called for your own processing
|
||||
* of the event.
|
||||
*
|
||||
* Alternatively, you can call the low-level functions to read and process
|
||||
* the data directly... look at the process_cmd() and process_input()
|
||||
* implementations in the glue to see how to do this.
|
||||
*
|
||||
* See the sample named "native-activity" that comes with the NDK with a
|
||||
* full usage example. Also look at the JavaDoc of NativeActivity.
|
||||
*/
|
||||
|
||||
struct android_app;
|
||||
|
||||
/**
|
||||
* Data associated with an ALooper fd that will be returned as the "outData"
|
||||
* when that source has data ready.
|
||||
*/
|
||||
struct android_poll_source {
|
||||
// The identifier of this source. May be LOOPER_ID_MAIN or
|
||||
// LOOPER_ID_INPUT.
|
||||
int32_t id;
|
||||
|
||||
// The android_app this ident is associated with.
|
||||
struct android_app* app;
|
||||
|
||||
// Function to call to perform the standard processing of data from
|
||||
// this source.
|
||||
void (*process)(struct android_app* app, struct android_poll_source* source);
|
||||
};
|
||||
|
||||
/**
|
||||
* This is the interface for the standard glue code of a threaded
|
||||
* application. In this model, the application's code is running
|
||||
* in its own thread separate from the main thread of the process.
|
||||
* It is not required that this thread be associated with the Java
|
||||
* VM, although it will need to be in order to make JNI calls any
|
||||
* Java objects.
|
||||
*/
|
||||
struct android_app {
|
||||
// The application can place a pointer to its own state object
|
||||
// here if it likes.
|
||||
void* userData;
|
||||
|
||||
// Fill this in with the function to process main app commands (APP_CMD_*)
|
||||
void (*onAppCmd)(struct android_app* app, int32_t cmd);
|
||||
|
||||
// Fill this in with the function to process input events. At this point
|
||||
// the event has already been pre-dispatched, and it will be finished upon
|
||||
// return. Return 1 if you have handled the event, 0 for any default
|
||||
// dispatching.
|
||||
int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
|
||||
|
||||
// The ANativeActivity object instance that this app is running in.
|
||||
ANativeActivity* activity;
|
||||
|
||||
// The current configuration the app is running in.
|
||||
AConfiguration* config;
|
||||
|
||||
// This is the last instance's saved state, as provided at creation time.
|
||||
// It is NULL if there was no state. You can use this as you need; the
|
||||
// memory will remain around until you call android_app_exec_cmd() for
|
||||
// APP_CMD_RESUME, at which point it will be freed and savedState set to NULL.
|
||||
// These variables should only be changed when processing a APP_CMD_SAVE_STATE,
|
||||
// at which point they will be initialized to NULL and you can malloc your
|
||||
// state and place the information here. In that case the memory will be
|
||||
// freed for you later.
|
||||
void* savedState;
|
||||
size_t savedStateSize;
|
||||
|
||||
// The ALooper associated with the app's thread.
|
||||
ALooper* looper;
|
||||
|
||||
// When non-NULL, this is the input queue from which the app will
|
||||
// receive user input events.
|
||||
AInputQueue* inputQueue;
|
||||
|
||||
// When non-NULL, this is the window surface that the app can draw in.
|
||||
ANativeWindow* window;
|
||||
|
||||
// Current content rectangle of the window; this is the area where the
|
||||
// window's content should be placed to be seen by the user.
|
||||
ARect contentRect;
|
||||
|
||||
// Current state of the app's activity. May be either APP_CMD_START,
|
||||
// APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below.
|
||||
int activityState;
|
||||
|
||||
// This is non-zero when the application's NativeActivity is being
|
||||
// destroyed and waiting for the app thread to complete.
|
||||
int destroyRequested;
|
||||
|
||||
// -------------------------------------------------
|
||||
// Below are "private" implementation of the glue code.
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
|
||||
int msgread;
|
||||
int msgwrite;
|
||||
|
||||
pthread_t thread;
|
||||
|
||||
struct android_poll_source cmdPollSource;
|
||||
struct android_poll_source inputPollSource;
|
||||
|
||||
int running;
|
||||
int stateSaved;
|
||||
int destroyed;
|
||||
int redrawNeeded;
|
||||
AInputQueue* pendingInputQueue;
|
||||
ANativeWindow* pendingWindow;
|
||||
ARect pendingContentRect;
|
||||
};
|
||||
|
||||
enum {
|
||||
/**
|
||||
* Looper data ID of commands coming from the app's main thread, which
|
||||
* is returned as an identifier from ALooper_pollOnce(). The data for this
|
||||
* identifier is a pointer to an android_poll_source structure.
|
||||
* These can be retrieved and processed with android_app_read_cmd()
|
||||
* and android_app_exec_cmd().
|
||||
*/
|
||||
LOOPER_ID_MAIN = 1,
|
||||
|
||||
/**
|
||||
* Looper data ID of events coming from the AInputQueue of the
|
||||
* application's window, which is returned as an identifier from
|
||||
* ALooper_pollOnce(). The data for this identifier is a pointer to an
|
||||
* android_poll_source structure. These can be read via the inputQueue
|
||||
* object of android_app.
|
||||
*/
|
||||
LOOPER_ID_INPUT = 2,
|
||||
|
||||
/**
|
||||
* Start of user-defined ALooper identifiers.
|
||||
*/
|
||||
LOOPER_ID_USER = 3,
|
||||
};
|
||||
|
||||
enum {
|
||||
/**
|
||||
* Command from main thread: the AInputQueue has changed. Upon processing
|
||||
* this command, android_app->inputQueue will be updated to the new queue
|
||||
* (or NULL).
|
||||
*/
|
||||
APP_CMD_INPUT_CHANGED,
|
||||
|
||||
/**
|
||||
* Command from main thread: a new ANativeWindow is ready for use. Upon
|
||||
* receiving this command, android_app->window will contain the new window
|
||||
* surface.
|
||||
*/
|
||||
APP_CMD_INIT_WINDOW,
|
||||
|
||||
/**
|
||||
* Command from main thread: the existing ANativeWindow needs to be
|
||||
* terminated. Upon receiving this command, android_app->window still
|
||||
* contains the existing window; after calling android_app_exec_cmd
|
||||
* it will be set to NULL.
|
||||
*/
|
||||
APP_CMD_TERM_WINDOW,
|
||||
|
||||
/**
|
||||
* Command from main thread: the current ANativeWindow has been resized.
|
||||
* Please redraw with its new size.
|
||||
*/
|
||||
APP_CMD_WINDOW_RESIZED,
|
||||
|
||||
/**
|
||||
* Command from main thread: the system needs that the current ANativeWindow
|
||||
* be redrawn. You should redraw the window before handing this to
|
||||
* android_app_exec_cmd() in order to avoid transient drawing glitches.
|
||||
*/
|
||||
APP_CMD_WINDOW_REDRAW_NEEDED,
|
||||
|
||||
/**
|
||||
* Command from main thread: the content area of the window has changed,
|
||||
* such as from the soft input window being shown or hidden. You can
|
||||
* find the new content rect in android_app::contentRect.
|
||||
*/
|
||||
APP_CMD_CONTENT_RECT_CHANGED,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity window has gained
|
||||
* input focus.
|
||||
*/
|
||||
APP_CMD_GAINED_FOCUS,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity window has lost
|
||||
* input focus.
|
||||
*/
|
||||
APP_CMD_LOST_FOCUS,
|
||||
|
||||
/**
|
||||
* Command from main thread: the current device configuration has changed.
|
||||
*/
|
||||
APP_CMD_CONFIG_CHANGED,
|
||||
|
||||
/**
|
||||
* Command from main thread: the system is running low on memory.
|
||||
* Try to reduce your memory use.
|
||||
*/
|
||||
APP_CMD_LOW_MEMORY,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity has been started.
|
||||
*/
|
||||
APP_CMD_START,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity has been resumed.
|
||||
*/
|
||||
APP_CMD_RESUME,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app should generate a new saved state
|
||||
* for itself, to restore from later if needed. If you have saved state,
|
||||
* allocate it with malloc and place it in android_app.savedState with
|
||||
* the size in android_app.savedStateSize. The will be freed for you
|
||||
* later.
|
||||
*/
|
||||
APP_CMD_SAVE_STATE,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity has been paused.
|
||||
*/
|
||||
APP_CMD_PAUSE,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity has been stopped.
|
||||
*/
|
||||
APP_CMD_STOP,
|
||||
|
||||
/**
|
||||
* Command from main thread: the app's activity is being destroyed,
|
||||
* and waiting for the app thread to clean up and exit before proceeding.
|
||||
*/
|
||||
APP_CMD_DESTROY,
|
||||
};
|
||||
|
||||
/**
|
||||
* Call when ALooper_pollAll() returns LOOPER_ID_MAIN, reading the next
|
||||
* app command message.
|
||||
*/
|
||||
int8_t android_app_read_cmd(struct android_app* android_app);
|
||||
|
||||
/**
|
||||
* Call with the command returned by android_app_read_cmd() to do the
|
||||
* initial pre-processing of the given command. You can perform your own
|
||||
* actions for the command after calling this function.
|
||||
*/
|
||||
void android_app_pre_exec_cmd(struct android_app* android_app, int8_t cmd);
|
||||
|
||||
/**
|
||||
* Call with the command returned by android_app_read_cmd() to do the
|
||||
* final post-processing of the given command. You must have done your own
|
||||
* actions for the command before calling this function.
|
||||
*/
|
||||
void android_app_post_exec_cmd(struct android_app* android_app, int8_t cmd);
|
||||
|
||||
/**
|
||||
* Dummy function you can call to ensure glue code isn't stripped.
|
||||
*/
|
||||
void app_dummy();
|
||||
|
||||
/**
|
||||
* This is the function that application code must implement, representing
|
||||
* the main entry to the app.
|
||||
*/
|
||||
extern void android_main(struct android_app* app);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ANDROID_NATIVE_APP_GLUE_H */
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
DECLARE_BUILD_STAGE(android_build)
|
||||
{
|
||||
AndroidManifest_t manifest = {};
|
||||
manifest.SetMinSDKVersion(21);
|
||||
manifest.SetTargetSDKVersion(35);
|
||||
manifest.SetPackageName("FPC Testing facility");
|
||||
manifest.SetPackageID("com.example.testfpc");
|
||||
CUtlString szManifestDir = manifest.BuildManifest();
|
||||
|
||||
CProject_t compileProject = {};
|
||||
compileProject.m_szName = "android_app";
|
||||
compileProject.m_androidmanifest = manifest;
|
||||
compileProject.bFPIC = true;
|
||||
compileProject.m_target = Target_t::HostTarget();
|
||||
compileProject.m_target.kernel = TARGET_KERNEL_ANDROID;
|
||||
compileProject.files = {
|
||||
"main.c",
|
||||
"android_native_app_glue.c",
|
||||
};
|
||||
LinkProject_t ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.libraries = {
|
||||
"android",
|
||||
"log",
|
||||
};
|
||||
CUtlString szOutputDir = linker->Link(&ldProject);
|
||||
filesystem2->MakeDirectory(CUtlString("%s/lib/x86_64",szManifestDir.GetString()));
|
||||
filesystem2->CopyFile(CUtlString("%s/lib/x86_64/libnative-app.so",szManifestDir.GetString()), szOutputDir);
|
||||
|
||||
CUtlString szApk = APKTool()->BuildPackage(manifest, szManifestDir);
|
||||
APKTool()->SignPackage(szApk, NULL, "mykey", "storepass", "storepass");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
|
||||
#include "android_native_app_glue.h"
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NativeApp", __VA_ARGS__))
|
||||
|
||||
// Handle lifecycle events
|
||||
static void handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
switch (cmd) {
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
LOGI("Window created");
|
||||
// You could init OpenGL/Vulkan here
|
||||
break;
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
LOGI("Window destroyed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void android_main(struct android_app* app) {
|
||||
app->onAppCmd = handle_cmd;
|
||||
|
||||
LOGI("Native app started");
|
||||
|
||||
int events;
|
||||
struct android_poll_source* source;
|
||||
|
||||
while (1) {
|
||||
LOGI("what");
|
||||
int ident;
|
||||
while ((ident = ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) {
|
||||
if (source) source->process(app, source);
|
||||
if (app->destroyRequested) {
|
||||
LOGI("App destroy requested");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,2 +0,0 @@
|
||||
[aarch64-apple-ios]
|
||||
sysroot = "/home/kotofyt/clones/yay/xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "appletool.h"
|
||||
|
||||
DECLARE_BUILD_STAGE(ios_build)
|
||||
{
|
||||
V_printf("Cool\n");
|
||||
CProject_t compileProject = {};
|
||||
compileProject.m_szName = "ios_app";
|
||||
compileProject.m_target = Target_t::HostTarget();
|
||||
compileProject.m_target.kernel = TARGET_KERNEL_IOS;
|
||||
compileProject.m_target.cpu = TARGET_CPU_AARCH64;
|
||||
compileProject.files = {
|
||||
"main.c",
|
||||
};
|
||||
LinkProject_t ldProject = ccompiler->Compile(&compileProject);
|
||||
CUtlString szOutput = linker->Link(&ldProject);
|
||||
|
||||
AppleManifest_t manifest = {};
|
||||
manifest.SetPackageName("FPC Testing facility");
|
||||
manifest.SetPackageID("com.example.testfpc");
|
||||
manifest.SetPackageExecutable(szOutput);
|
||||
CUtlString szIpa = AppleTool()->BuildPackage( manifest, manifest.BuildManifest() );
|
||||
CUtlString szPackage = AppleTool()->SignPackage(szIpa, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#include "stdio.h"
|
||||
int main()
|
||||
{
|
||||
printf("Hello, world!\n");
|
||||
return 0;
|
||||
};
|
||||
@@ -24,6 +24,7 @@ DECLARE_BUILD_STAGE(client)
|
||||
|
||||
CUtlString outputProject = linker->Link(&ldProject);
|
||||
|
||||
/*
|
||||
if (!bStaticBuild)
|
||||
{
|
||||
filesystem2->MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
|
||||
@@ -31,6 +32,7 @@ DECLARE_BUILD_STAGE(client)
|
||||
} else {
|
||||
client_lib = outputProject;
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user