From e50c6f1af14182ae349cbfdb36e9991c8183eabe Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 7 Oct 2018 22:48:33 +0200 Subject: [PATCH] main: generate binary files when compiling to .bin --- main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 529b19b3..55f412fc 100644 --- a/main.go +++ b/main.go @@ -146,10 +146,15 @@ func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA, debug } } - if strings.HasSuffix(outpath, ".hex") { - // Get an Intel .hex file from the .elf file. - tmppath = filepath.Join(dir, "main.hex") - cmd := exec.Command(spec.Objcopy, "-O", "ihex", executable, tmppath) + ext := filepath.Ext(outpath) + if ext == ".hex" || ext == ".bin" { + // Get an Intel .hex file or .bin file from the .elf file. + tmppath = filepath.Join(dir, "main"+ext) + format := map[string]string{ + ".hex": "ihex", + ".bin": "binary", + }[ext] + cmd := exec.Command(spec.Objcopy, "-O", format, executable, tmppath) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err = cmd.Run()