From 9c45a03a59b6ed9d69b501848d0d65e0712958d9 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 16 Jun 2024 16:28:22 +0800 Subject: [PATCH] compiler: add GCC common options generator --- compiler.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/compiler.ts b/compiler.ts index e4c2220..b2bc5a9 100644 --- a/compiler.ts +++ b/compiler.ts @@ -93,6 +93,35 @@ export async function extract(options: ExtractOptions) { return exitcode } +export interface GeneralOptions { + output?: string; + + outputKind?: "exe" | "object" | "assembly" | "preprocessed" +} + +export function generalCommand(options: GeneralOptions) { + return [ + ...(options.output ? ["-o", options.output] : []), + ...(options.outputKind ? { + exe: [], + object: ["-c"], + assembly: ["-S"], + preprocessed: ["-E"] + }[options.outputKind] : []) + ] +} + +export interface PreprocessorOptions { + includeDirs?: string[]; +} + +export function preprocessorCommand(options: PreprocessorOptions) { + return [ + ...((options.includeDirs ?? []).flatMap(name => ["-I", name])) + ] +} + + /** * Links objects into an executable using specified environment variables and paths.