()
| 46 | } |
| 47 | |
| 48 | func (b *BuildConfig) setupEnvs() { |
| 49 | b.envBackup.backup() |
| 50 | |
| 51 | // Setup environments if defined. |
| 52 | toolchain := b.Ctx.Platform().GetToolchain() |
| 53 | if toolchain != nil { |
| 54 | toolchain.SetupEnvs() |
| 55 | } |
| 56 | |
| 57 | for _, env := range b.Envs { |
| 58 | env = strings.TrimSpace(env) |
| 59 | |
| 60 | before, after, ok := strings.Cut(env, "=") |
| 61 | if !ok { |
| 62 | color.Printf(color.Warning, "invalid environment variable `%s` and is ignored.", env) |
| 63 | continue |
| 64 | } |
| 65 | |
| 66 | key := strings.TrimSpace(before) |
| 67 | currentValue := strings.TrimSpace(after) |
| 68 | currentValue = b.expandVariables(currentValue) |
| 69 | |
| 70 | switch key { |
| 71 | case "CPATH", "LIBRARY_PATH", "PATH": |
| 72 | lastValue := filepath.ToSlash(os.Getenv(key)) |
| 73 | if strings.TrimSpace(lastValue) == "" { |
| 74 | b.envBackup.setenv(key, currentValue) |
| 75 | } else { |
| 76 | b.envBackup.setenv(key, fmt.Sprintf("%s%s%s", currentValue, string(os.PathListSeparator), lastValue)) |
| 77 | } |
| 78 | |
| 79 | case "CFLAGS", "CXXFLAGS", "LDFLAGS", "CPPFLAGS": |
| 80 | // celer can wrap CFLAGS, CXXFLAGS and CPPFLAGS automatically, so we need to remove them. |
| 81 | currentValue = strings.ReplaceAll(currentValue, "${CFLAGS}", "") |
| 82 | currentValue = strings.ReplaceAll(currentValue, "${CXXFLAGS}", "") |
| 83 | currentValue = strings.ReplaceAll(currentValue, "${CPPFLAGS}", "") |
| 84 | currentValue = strings.ReplaceAll(currentValue, "${LDFLAGS}", "") |
| 85 | |
| 86 | lastValue := filepath.ToSlash(os.Getenv(key)) |
| 87 | if strings.TrimSpace(lastValue) == "" { |
| 88 | b.envBackup.setenv(key, strings.TrimSpace(currentValue)) |
| 89 | } else { |
| 90 | b.envBackup.setenv(key, fmt.Sprintf("%s %s", lastValue, currentValue)) |
| 91 | } |
| 92 | |
| 93 | default: |
| 94 | b.envBackup.setenv(key, currentValue) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if b.buildSystem.Name() != "cmake" { |
| 99 | // This allows the bin to locate the libraries in the relative lib dir. |
| 100 | toolchain := b.Ctx.Platform().GetToolchain() |
| 101 | if strings.ToLower(toolchain.GetSystemName()) == "linux" && |
| 102 | b.buildSystem.Name() == "makefiles" { |
| 103 | b.envBackup.setenv("LDFLAGS", env.JoinSpace("-Wl,-rpath=\\$$ORIGIN/../lib", os.Getenv("LDFLAGS"))) |
| 104 | } |
| 105 |
no test coverage detected