github.com/atrn/dcc@v0.0.0-20220806184050-4470d2553272/elf.go (about) 1 // dcc - dependency-driven C/C++ compiler front end 2 // 3 // Copyright © A.Newman 2015. 4 // 5 // This source code is released under version 2 of the GNU Public License. 6 // See the file LICENSE for details. 7 // 8 9 // +build !windows !darwin 10 11 package main 12 13 import ( 14 "fmt" 15 "os" 16 "strings" 17 ) 18 19 // ElfCreateLibrary creates a static library file using the UNIX ar 20 // program. 21 // 22 func ElfCreateLibrary(filename string, objectFiles []string) error { 23 args := append([]string{"rc", filename}, objectFiles...) 24 if Verbose { 25 fmt.Fprintln(os.Stdout, "ar", strings.Join(args, " ")) 26 } else if !Quiet { 27 fmt.Fprintln(os.Stdout, "ar", filename) 28 } 29 return Exec("ar", args, os.Stderr) 30 } 31 32 // ElfCreateDLL creates a dynamic library using the compiler, passing 33 // a -shared option. 34 // 35 func ElfCreateDLL(filename string, objectFiles []string, libraryFiles []string, linkerOptions []string, frameworks []string) error { 36 args := []string{"-shared", "-o", filename} 37 args = append(args, linkerOptions...) 38 args = append(args, objectFiles...) 39 args = append(args, libraryFiles...) 40 if Verbose { 41 fmt.Fprintln(os.Stdout, ActualCompiler.Name(), strings.Join(args, " ")) 42 } else if !Quiet { 43 fmt.Fprintln(os.Stdout, "ld", filename) 44 } 45 return Exec(ActualCompiler.Name(), args, os.Stderr) 46 }