github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/engine/builder/c/executable.go (about)

     1  package c
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/metux/go-metabuild/spec"
     7  	"github.com/metux/go-metabuild/util/compiler"
     8  )
     9  
    10  type BuilderCExecutable struct {
    11  	BaseCBuilder
    12  }
    13  
    14  func (b BuilderCExecutable) JobRun() error {
    15  	ci := b.BuildConf.CompilerInfo(b.ForBuild(), b.CompilerLang())
    16  
    17  	fn := b.OutputFile()
    18  
    19  	cc := compiler.NewCCompiler(ci, b.TempDir())
    20  	args := compiler.CompilerArg{
    21  		Sources:    b.Sources(),
    22  		PkgImports: b.AllImports(),
    23  		Defines:    b.CDefines(),
    24  		Flags:      b.CFlags(),
    25  		Output:     fn,
    26  	}
    27  
    28  	if err := cc.CompileExecutable(args); err != nil {
    29  		return err
    30  	}
    31  
    32  	if b.InstallPkgFileAuto() {
    33  		// FIXME: need to blacklist our own libs
    34  		b.WritePkgMeta(filepath.Base(fn)+".sodep", cc.BinaryInfo(fn).DependsInfo())
    35  	}
    36  
    37  	return nil
    38  }
    39  
    40  func (b BuilderCExecutable) JobPrepare(id string) error {
    41  	return nil
    42  }
    43  
    44  func MakeBuilderCExecutable(o spec.TargetObject, id string) BuilderCExecutable {
    45  	return BuilderCExecutable{MakeBaseCBuilder(o, id)}
    46  }