aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorRon Evans <[email protected]>2018-12-11 10:37:27 +0100
committerAyke van Laethem <[email protected]>2018-12-13 20:10:27 +0100
commitcb648d8ae1755028deda4143db2fa61419327d8a (patch)
tree69bd338050fd1e4bb8e39ddeda0e4edc638a4d12 /main.go
parent8734732d0c125101a2d5b317b0627ef2a4ba7d43 (diff)
downloadtinygo-cb648d8ae1755028deda4143db2fa61419327d8a.tar.gz
tinygo-cb648d8ae1755028deda4143db2fa61419327d8a.zip
compiler: pass -cflags and -ldflags to tinygo CLI command
Signed-off-by: Ron Evans <[email protected]>
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/main.go b/main.go
index c1a311f24..fb0d72438 100644
--- a/main.go
+++ b/main.go
@@ -34,6 +34,8 @@ type BuildConfig struct {
debug bool
printSizes string
initInterp bool
+ cFlags []string
+ ldFlags []string
}
// Helper function for Compiler object.
@@ -41,10 +43,16 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
if config.gc == "" && spec.GC != "" {
config.gc = spec.GC
}
+
+ // Append command line passed CFlags and LDFlags
+ spec.CFlags = append(spec.CFlags, config.cFlags...)
+ spec.LDFlags = append(spec.LDFlags, config.ldFlags...)
+
compilerConfig := compiler.Config{
Triple: spec.Triple,
GC: config.gc,
CFlags: spec.CFlags,
+ LDFlags: spec.LDFlags,
Debug: config.debug,
DumpSSA: config.dumpSSA,
RootDir: sourceDir(),
@@ -497,6 +505,8 @@ func main() {
ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug")
initInterp := flag.Bool("initinterp", true, "enable/disable partial evaluator of generated IR")
port := flag.String("port", "/dev/ttyACM0", "flash port")
+ cFlags := flag.String("cflags", "", "additional cflags for compiler")
+ ldFlags := flag.String("ldflags", "", "additional ldflags for linker")
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "No command-line arguments supplied.")
@@ -516,6 +526,14 @@ func main() {
initInterp: *initInterp,
}
+ if *cFlags != "" {
+ config.cFlags = strings.Split(*cFlags, " ")
+ }
+
+ if *ldFlags != "" {
+ config.ldFlags = strings.Split(*ldFlags, " ")
+ }
+
os.Setenv("CC", "clang -target="+*target)
switch command {