From 39e06dd97d3808bfe96be2f0c4409c655496f969 Mon Sep 17 00:00:00 2001 From: Charlie FG Date: Mon, 23 Mar 2015 00:05:56 +0000 Subject: [PATCH] Added 'output' directive to specify final target name If specified '#qo output = filename' enables qo to link all the object files together under the filename; falls back on directory name if unspecified. --- builder.go | 1 + flagcompiler.go | 4 ++++ gcc.go | 8 ++++++-- msvc.go | 7 +++++-- scriptgen.go | 2 +- toolchain.go | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/builder.go b/builder.go index 0faab77..c9cff30 100644 --- a/builder.go +++ b/builder.go @@ -61,6 +61,7 @@ func runStage(s Stage) { func run() { percentPer = 100 / float64(nSteps) progress = 0 + oname = "" printProgress("Beginning build") for _, stage := range script { runStage(stage) diff --git a/flagcompiler.go b/flagcompiler.go index ebf7fc6..f9f9231 100644 --- a/flagcompiler.go +++ b/flagcompiler.go @@ -18,6 +18,7 @@ var cflags []string var cxxflags []string var ldflags []string var libs []string +var oname string func pkgconfig(which string, pkgs []string) []string { cmd := exec.Command("pkg-config", append([]string{which}, pkgs...)...) @@ -51,6 +52,8 @@ func parseFile(filename string) { cxxflags = append(cxxflags, parts[1:]...) case "LDFLAGS:": ldflags = append(ldflags, parts[1:]...) + case "output:": + oname = parts[1] case "pkg-config:": xcflags := pkgconfig("--cflags", parts[1:]) xlibs := pkgconfig("--libs", parts[1:]) @@ -83,6 +86,7 @@ func compileFlags() { cflags = append(cflags, strings.Fields(os.Getenv("CFLAGS"))...) cxxflags = append(cxxflags, strings.Fields(os.Getenv("CXXFLAGS"))...) ldflags = append(ldflags, strings.Fields(os.Getenv("LDFLAGS"))...) + oname = "" for _, f := range cfiles { parseFile(f) diff --git a/gcc.go b/gcc.go index 51093cd..9c63a1f 100644 --- a/gcc.go +++ b/gcc.go @@ -93,11 +93,15 @@ func (g *GCCBase) BuildRCFile(filename string, cflags []string) (stages []Stage, return stages, object } -func (g *GCCBase) Link(objects []string, ldflags []string, libs []string) *Step { +func (g *GCCBase) Link(objects []string, ldflags []string, libs []string, target string) *Step { if g.LD == "" { g.LD = g.CC } - target := targetName() + + if target == "" { + target = targetName() + } + for i := 0; i < len(libs); i++ { libs[i] = "-l" + libs[i] } diff --git a/msvc.go b/msvc.go index 951cb1e..a080223 100644 --- a/msvc.go +++ b/msvc.go @@ -98,8 +98,11 @@ func (m *MSVC) BuildRCFile(filename string, cflags []string) (stages []Stage, ob return stages, object } -func (m *MSVC) Link(objects []string, ldflags []string, libs []string) *Step { - target := targetName() +func (m *MSVC) Link(objects []string, ldflags []string, libs []string, target string) *Step { + + if target == "" { + target = targetName() + } for i := 0; i < len(libs); i++ { libs[i] = libs[i] + ".lib" } diff --git a/scriptgen.go b/scriptgen.go index 1c7e136..42a0604 100644 --- a/scriptgen.go +++ b/scriptgen.go @@ -66,7 +66,7 @@ func buildScript() { objects = append(objects, obj) } - s := toolchain.Link(objects, ldflags, libs) + s := toolchain.Link(objects, ldflags, libs, oname) script = append(script, Stage{s}) nSteps++ } diff --git a/toolchain.go b/toolchain.go index c5e5cc0..41abaae 100644 --- a/toolchain.go +++ b/toolchain.go @@ -15,7 +15,7 @@ type Toolchain interface { BuildMFile(filename string, cflags []string) (stages []Stage, object string) BuildMMFile(filename string, cflags []string) (stages []Stage, object string) BuildRCFile(filename string, cflags []string) (stages []Stage, object string) - Link(objects []string, ldflags []string, libs []string) *Step + Link(objects []string, ldflags []string, libs []string, target string) *Step } var toolchains = make(map[string]Toolchain)