Generate .bin file when project gets built.
diff --git a/cli/compiler.go b/cli/compiler.go
index 893abd8..edc1096 100644
--- a/cli/compiler.go
+++ b/cli/compiler.go
@@ -39,6 +39,7 @@
arPath string
odPath string
osPath string
+ ocPath string
ldFlags string
ldResolveCircularDeps bool
ldMapFile bool
@@ -75,6 +76,7 @@
c.arPath = v.GetString("compiler.path.archive")
c.odPath = v.GetString("compiler.path.objdump")
c.osPath = v.GetString("compiler.path.objsize")
+ c.ocPath = v.GetString("compiler.path.objcopy")
cflags := v.GetStringSlice("compiler.flags." + cDef)
for _, flag := range cflags {
@@ -252,14 +254,14 @@
return objList
}
-func (c *Compiler) CompileBinary(binFile string, options map[string]bool,
+func (c *Compiler) CompileBinary(dstFile string, options map[string]bool,
objFiles string) error {
objList := c.getObjFiles(objFiles)
- log.Printf("[INFO] Compiling Binary %s with object files %s", binFile,
+ log.Printf("[INFO] Compiling Binary %s with object files %s", dstFile,
objList)
- cmd := c.ccPath + " -o " + binFile + " " + c.ldFlags + " " + c.Cflags
+ cmd := c.ccPath + " -o " + dstFile + " " + c.ldFlags + " " + c.Cflags
if c.ldResolveCircularDeps {
cmd += " -Wl,--start-group -lc " + objList + " -Wl,--end-group "
} else {
@@ -270,7 +272,7 @@
cmd += " -T " + c.LinkerScript
}
if checkBoolMap(options, "mapFile") {
- cmd += " -Wl,-Map=" + binFile + ".map"
+ cmd += " -Wl,-Map=" + dstFile + ".map"
}
_, err := ShellCommand(cmd)
@@ -279,7 +281,7 @@
}
if checkBoolMap(options, "listFile") {
- listFile := binFile + ".lst"
+ listFile := dstFile + ".lst"
// if list file exists, remove it
if NodeExist(listFile) {
if err := os.RemoveAll(listFile); err != nil {
@@ -287,7 +289,7 @@
}
}
- cmd = c.odPath + " -wxdS " + binFile + " >> " + listFile
+ cmd = c.odPath + " -wxdS " + dstFile + " >> " + listFile
_, err := ShellCommand(cmd)
if err != nil {
// XXX: gobjdump appears to always crash. Until we get that sorted
@@ -297,15 +299,24 @@
sects := []string{".text", ".rodata", ".data"}
for _, sect := range sects {
- cmd = c.odPath + " -s -j " + sect + " " + binFile + " >> " + listFile
+ cmd = c.odPath + " -s -j " + sect + " " + dstFile + " >> " + listFile
ShellCommand(cmd)
}
- cmd = c.osPath + " " + binFile + " >> " + listFile
+ cmd = c.osPath + " " + dstFile + " >> " + listFile
+ }
+
+ if checkBoolMap(options, "binFile") {
+ binFile := dstFile + ".bin"
+ cmd = c.ocPath + " -R .bss -R .bss.core -R .bss.core.nz -O binary " +
+ dstFile + " " + binFile
+ _, err := ShellCommand(cmd)
+ if err != nil {
+ return err
+ }
}
return nil
-
}
func (c *Compiler) CompileElf(binFile string, options map[string]bool,
diff --git a/cli/project.go b/cli/project.go
index c508600..47d2810 100644
--- a/cli/project.go
+++ b/cli/project.go
@@ -321,9 +321,9 @@
log.Printf("[DEBUG] Compiling a binary %s from libs %s", binDir+p.Name,
strings.Join(libs, " "))
- err = c.CompileElf(binDir+p.Name,
- map[string]bool{"mapFile": c.ldMapFile,
- "listFile": true}, strings.Join(libs, " "))
+ options := map[string]bool{"mapFile": c.ldMapFile,
+ "listFile": true, "binFile": true}
+ err = c.CompileElf(binDir+p.Name, options, strings.Join(libs, " "))
if err != nil {
return err
}