diff options
author | Ayke van Laethem <[email protected]> | 2018-11-25 18:05:29 +0100 |
---|---|---|
committer | Ayke van Laethem <[email protected]> | 2018-12-10 15:38:01 +0100 |
commit | dea660b21c9dff3122d975028a167c9998e3cc3f (patch) | |
tree | 7bf870780225b6ba268815f13fd092782252dd42 /main.go | |
parent | e10d05c74fca049207a89939581cea1087457423 (diff) | |
download | tinygo-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.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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 |