mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Rename PUFFS to WUFFS, part 3 of N
This commit is contained in:
1 parent
0cea46531b
commit
7a6a598d1e
17 files changed
+4
-4
No files matched your search
@@ -0,0 +1,134 @@
|
||||
// Copyright 2017 The Puffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
cf "github.com/google/wuffs/cmd/commonflags"
|
||||
)
|
||||
|
||||
func doGenlib(args []string) error {
|
||||
flags := flag.FlagSet{}
|
||||
ccompilersFlag := flags.String("ccompilers", cf.CcompilersDefault, cf.CcompilersUsage)
|
||||
dstdirFlag := flags.String("dstdir", "", "directory containing the object files ")
|
||||
srcdirFlag := flags.String("srcdir", "", "directory containing the C source files")
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
args = flags.Args()
|
||||
|
||||
if *dstdirFlag == "" {
|
||||
return fmt.Errorf("empty -dstdir flag")
|
||||
}
|
||||
if *srcdirFlag == "" {
|
||||
return fmt.Errorf("empty -srcdir flag")
|
||||
}
|
||||
|
||||
for _, cc := range strings.Split(*ccompilersFlag, ",") {
|
||||
cc = strings.TrimSpace(cc)
|
||||
if cc == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, dynamism := range []string{"static", "dynamic"} {
|
||||
outDir := filepath.Join(*dstdirFlag, cc+"-"+dynamism)
|
||||
if err := os.MkdirAll(outDir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := genObj(outDir, *srcdirFlag, cc, dynamism, args); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := genLib(outDir, cc, dynamism, args); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: are these extensions correct for non-Linux?
|
||||
var (
|
||||
objExtensions = map[string]string{
|
||||
"dynamic": ".lo",
|
||||
"static": ".o",
|
||||
}
|
||||
libExtensions = map[string]string{
|
||||
"dynamic": ".so",
|
||||
"static": ".a",
|
||||
}
|
||||
)
|
||||
|
||||
func genObj(outDir string, inDir string, cc string, dynamism string, filenames []string) error {
|
||||
for _, filename := range filenames {
|
||||
in := filepath.Join(inDir, filename+".c")
|
||||
out := genlibOutFilename(outDir, dynamism, filename)
|
||||
|
||||
args := []string(nil)
|
||||
args = append(args, "-O3", "-std=c99")
|
||||
if dynamism == "dynamic" {
|
||||
args = append(args, "-fPIC", "-DPIC")
|
||||
}
|
||||
args = append(args, "-c", "-o", out, in)
|
||||
|
||||
cmd := exec.Command(cc, args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("genlib: %s\n", out)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func genLib(outDir string, cc string, dynamism string, filenames []string) error {
|
||||
args := []string(nil)
|
||||
switch dynamism {
|
||||
case "dynamic":
|
||||
// TODO: add a "-Wl,-soname,libpuffs.so.1.2.3" argument?
|
||||
args = append(args, "-shared", "-fPIC", "-o")
|
||||
case "static":
|
||||
cc = "ar"
|
||||
args = append(args, "rc")
|
||||
}
|
||||
out := filepath.Join(outDir, "libpuffs"+libExtensions[dynamism])
|
||||
args = append(args, out)
|
||||
|
||||
for _, filename := range filenames {
|
||||
args = append(args, genlibOutFilename(outDir, dynamism, filename))
|
||||
}
|
||||
|
||||
cmd := exec.Command(cc, args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("genlib: %s\n", out)
|
||||
return nil
|
||||
}
|
||||
|
||||
func genlibOutFilename(outDir string, dynamism string, filename string) string {
|
||||
filename = strings.Replace(filename, "/", "-", -1)
|
||||
filename = strings.Replace(filename, "\\", "-", -1)
|
||||
filename = filepath.Join(outDir, filename+objExtensions[dynamism])
|
||||
return filename
|
||||
}
|
||||
Reference in new issue
Block a user