commands: add linker options
This commit is contained in:
@@ -8,3 +8,8 @@ export const optFlag = (flag: string, opt: string | undefined) => undefList(opt,
|
||||
* Generate a switch flag, like "--rebuild", "--nobuild"
|
||||
*/
|
||||
export const optSwitch = (flag: string, opt: boolean | undefined) => undefList(opt, opt => opt ? [flag] : [])
|
||||
|
||||
export const optMultiFlag = (flag: string, opt: string[] | undefined) =>
|
||||
undefList(
|
||||
opt,
|
||||
opt => opt.flatMap(name => [flag, name]))
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { optFlag, optSwitch, undefList } from "./common";
|
||||
import { optFlag, optMultiFlag, optSwitch, undefList } from "./common";
|
||||
|
||||
export interface GeneralOptions {
|
||||
output?: string;
|
||||
output?: string
|
||||
|
||||
sysroot?: string
|
||||
|
||||
outputKind?: "exe" | "object" | "assembly" | "preprocessed"
|
||||
}
|
||||
@@ -20,7 +22,28 @@ export function generalCommand(options: GeneralOptions) {
|
||||
case "preprocessed":
|
||||
return ["-E"]
|
||||
}
|
||||
})
|
||||
}),
|
||||
...optFlag("--sysroot", options.sysroot),
|
||||
]
|
||||
}
|
||||
|
||||
interface LinkerOptions {
|
||||
/**
|
||||
* Directory searched for "-l"
|
||||
*/
|
||||
searchDirs?: string[];
|
||||
|
||||
/**
|
||||
* -l libraries.
|
||||
* Static library dependecies must be sorted in topologic order.
|
||||
*/
|
||||
libraries?: string[];
|
||||
}
|
||||
|
||||
export function linkerCommand(options: LinkerOptions) {
|
||||
return [
|
||||
...optMultiFlag("-L", options.searchDirs),
|
||||
...optMultiFlag("-l", options.libraries),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -30,7 +53,7 @@ export interface PreprocessorOptions {
|
||||
|
||||
export function preprocessorCommand(options: PreprocessorOptions) {
|
||||
return [
|
||||
...undefList(options.includeDirs, dirs => dirs.flatMap(name => ["-I", name]))
|
||||
...optMultiFlag("-I", options.includeDirs),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -61,8 +84,8 @@ export interface ExtractOptions {
|
||||
|
||||
export function extractCommand(options: ExtractOptions): string[] {
|
||||
return [
|
||||
...undefList(options.func, func => func.flatMap(name => ["--func", name])),
|
||||
...undefList(options.bb, bb => bb.flatMap(name => ["--bb", name])),
|
||||
...optMultiFlag("--func", options.func),
|
||||
...optMultiFlag("--bb", options.bb),
|
||||
...optFlag("-o", options.output),
|
||||
...optSwitch("-S", options.asm),
|
||||
...undefList(options.input, input => [input])
|
||||
|
||||
Reference in New Issue
Block a user