#include "helper.h"
#include "c.h"
#include "ld.h"
#include "tier1/utlstring.h"

CUtlVector<CUtlString> launcher_CompiledFiles = {
	"launcher/launcher.cpp",
};

int launcher_build()
{
	CCProject compileProject = {};
	CLDProject ldProject = {};

	compileProject.m_szName = "launcher";
	compileProject.files = launcher_CompiledFiles;
	compileProject.includeDirectories = all_IncludeDirectories;
	compileProject.bFPIC = true;
	if (bStaticBuild)
	{
		compileProject.macros.AppendTail((C_Macro_t){"STATIC_BUILD","1"});
	}
	ldProject = compileProject.Compile();
	ldProject.linkType = ELINK_EXECUTABLE;

	if (bStaticBuild)
	{
		ldProject.objects.AppendTail((CObject){tier0_lib});
		ldProject.objects.AppendTail((CObject){tier1_lib});
		ldProject.objects.AppendTail((CObject){rapier_lib});
		ldProject.objects.AppendTail((CObject){engine_lib});
		ldProject.objects.AppendTail((CObject){server_lib});
		ldProject.objects.AppendTail((CObject){client_lib});
		if (Target_t::DefaultTarget().kernel == TARGET_KERNEL_IOS)
		{
			ldProject.objects.AppendTail((CObject){"external/ios/libMoltenVK.a"});
			ldProject.frameworks.AppendTail("SDL3");
			ldProject.frameworks.AppendTail("CoreFoundation");
			ldProject.frameworks.AppendTail("CoreGraphics");
			ldProject.frameworks.AppendTail("IOSurface");
			ldProject.frameworks.AppendTail("Metal");
			ldProject.frameworks.AppendTail("Foundation");
			ldProject.frameworks.AppendTail("QuartzCore");
			ldProject.frameworks.AppendTail("UIKit");
			ldProject.frameworkDirectories.AppendTail("external/ios");
		};
	};

	CUtlString outputProject = ldProject.Link();
	IFileSystem2::MakeDirectory(CUtlString("%s/bin",szOutputDir.GetString()));
	IFileSystem2::CopyFile(CUtlString("%s/bin/funnygame", szOutputDir.GetString()), outputProject);

	return 0;
};
DECLARE_BUILD_STAGE(launcher, launcher_build);
