aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-11-25 18:05:29 +0100
committerAyke van Laethem <[email protected]>2018-12-10 15:38:01 +0100
commitdea660b21c9dff3122d975028a167c9998e3cc3f (patch)
tree7bf870780225b6ba268815f13fd092782252dd42 /main.go
parente10d05c74fca049207a89939581cea1087457423 (diff)
downloadtinygo-dea660b21c9dff3122d975028a167c9998e3cc3f.tar.gz
tinygo-dea660b21c9dff3122d975028a167c9998e3cc3f.zip
main: compile C source files in packages
TODO: C++ etc. files
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.go b/main.go
index 77c76fb37..1bcd01c43 100644
--- a/main.go
+++ b/main.go
@@ -192,6 +192,23 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
ldflags = append(ldflags, outpath)
}
+ // Compile C files in packages.
+ for i, pkg := range c.Packages() {
+ for _, file := range pkg.CFiles {
+ path := filepath.Join(pkg.Package.Dir, file)
+ outpath := filepath.Join(dir, "pkg"+strconv.Itoa(i)+"-"+file+".o")
+ cmd := exec.Command(spec.Compiler, append(spec.CFlags, "-c", "-o", outpath, path)...)
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ cmd.Dir = sourceDir()
+ err := cmd.Run()
+ if err != nil {
+ return err
+ }
+ ldflags = append(ldflags, outpath)
+ }
+ }
+
// Link the object files together.
cmd := exec.Command(spec.Linker, ldflags...)
cmd.Stdout = os.Stdout