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

     1  package c
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/metux/go-metabuild/spec/target"
     7  	"github.com/metux/go-metabuild/util/compiler"
     8  )
     9  
    10  type BuilderCLibraryShared struct {
    11  	BaseCBuilder
    12  }
    13  
    14  func (b BuilderCLibraryShared) JobRun() error {
    15  	soFile := b.OutputFile()
    16  
    17  	ci := b.BuildConf.CompilerInfo(b.ForBuild(), b.CompilerLang())
    18  	cc := compiler.NewCCompiler(ci, b.TempDir())
    19  
    20  	args := compiler.CompilerArg{
    21  		Sources:    b.Sources(),
    22  		PkgImports: b.AllImports(),
    23  		Defines:    b.CDefines(),
    24  		Output:     b.OutputFile(),
    25  		Flags:      b.CFlags(),
    26  		DllName:    b.RequiredEntryStr(target.KeyName),
    27  	}
    28  
    29  	if err := cc.CompileLibraryShared(args); err != nil {
    30  		return err
    31  	}
    32  
    33  	bname := filepath.Base(soFile)
    34  
    35  	if b.InstallPkgFileAuto() {
    36  		b.WritePkgMeta(bname+".sodep", cc.BinaryInfo(soFile).DependsInfo())
    37  		b.WritePkgMeta(bname+".trigger", "activate-noawait ldconfig")
    38  	}
    39  
    40  	return nil
    41  }