2015-11-25 02:53:15 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// http://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.
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
package config
|
2015-11-25 02:53:15 +01:00
|
|
|
|
|
|
|
import (
|
2022-02-16 07:48:04 +01:00
|
|
|
"path/filepath"
|
2015-11-25 02:53:15 +01:00
|
|
|
"strings"
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-11-25 02:53:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
windowsCflags = []string{
|
|
|
|
"-DUSE_MINGW",
|
|
|
|
"-DWIN32_LEAN_AND_MEAN",
|
|
|
|
"-Wno-unused-parameter",
|
|
|
|
|
|
|
|
// Workaround differences in inttypes.h between host and target.
|
|
|
|
//See bug 12708004.
|
|
|
|
"-D__STDC_FORMAT_MACROS",
|
|
|
|
"-D__STDC_CONSTANT_MACROS",
|
|
|
|
|
|
|
|
// Use C99-compliant printf functions (%zd).
|
|
|
|
"-D__USE_MINGW_ANSI_STDIO=1",
|
2018-12-04 13:36:49 +01:00
|
|
|
// Admit to using >= Windows 7. Both are needed because of <_mingw.h>.
|
|
|
|
"-D_WIN32_WINNT=0x0601",
|
|
|
|
"-DWINVER=0x0601",
|
2015-11-25 02:53:15 +01:00
|
|
|
// Get 64-bit off_t and related functions.
|
|
|
|
"-D_FILE_OFFSET_BITS=64",
|
|
|
|
|
2020-07-15 20:11:57 +02:00
|
|
|
// Don't adjust the layout of bitfields like msvc does.
|
|
|
|
"-mno-ms-bitfields",
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
"--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
windowsIncludeFlags = []string{
|
2016-07-29 22:44:28 +02:00
|
|
|
"-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include",
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
windowsCppflags = []string{}
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
windowsX86Cppflags = []string{
|
2020-09-10 02:54:32 +02:00
|
|
|
// Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj
|
|
|
|
// exception model for 32-bit.
|
|
|
|
"-fsjlj-exceptions",
|
|
|
|
}
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
windowsX8664Cppflags = []string{}
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
windowsLdflags = []string{
|
2018-08-30 21:37:56 +02:00
|
|
|
"-Wl,--dynamicbase",
|
|
|
|
"-Wl,--nxcompat",
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2021-07-15 02:03:16 +02:00
|
|
|
windowsLldflags = append(windowsLdflags, []string{
|
2020-04-08 18:11:53 +02:00
|
|
|
"-Wl,--Xlink=-Brepro", // Enable deterministic build
|
2021-07-15 02:03:16 +02:00
|
|
|
}...)
|
2016-02-04 08:16:33 +01:00
|
|
|
|
|
|
|
windowsX86Cflags = []string{
|
|
|
|
"-m32",
|
|
|
|
}
|
|
|
|
|
|
|
|
windowsX8664Cflags = []string{
|
|
|
|
"-m64",
|
|
|
|
}
|
|
|
|
|
|
|
|
windowsX86Ldflags = []string{
|
|
|
|
"-m32",
|
2017-03-14 21:36:23 +01:00
|
|
|
"-Wl,--large-address-aware",
|
2016-07-29 22:44:28 +02:00
|
|
|
"-L${WindowsGccRoot}/${WindowsGccTriple}/lib32",
|
2019-10-15 22:56:29 +02:00
|
|
|
"-static-libgcc",
|
2021-07-15 02:03:16 +02:00
|
|
|
|
2018-06-20 05:07:54 +02:00
|
|
|
"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
|
2017-11-30 22:31:26 +01:00
|
|
|
"-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
|
|
|
|
"-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32",
|
|
|
|
"-B${WindowsGccRoot}/${WindowsGccTriple}/lib32",
|
2021-07-15 02:03:16 +02:00
|
|
|
}
|
2016-02-04 08:16:33 +01:00
|
|
|
|
|
|
|
windowsX8664Ldflags = []string{
|
|
|
|
"-m64",
|
2016-07-29 22:44:28 +02:00
|
|
|
"-L${WindowsGccRoot}/${WindowsGccTriple}/lib64",
|
2018-08-30 21:37:56 +02:00
|
|
|
"-Wl,--high-entropy-va",
|
2019-10-15 22:56:29 +02:00
|
|
|
"-static-libgcc",
|
2021-07-15 02:03:16 +02:00
|
|
|
|
2018-06-20 05:07:54 +02:00
|
|
|
"-B${WindowsGccRoot}/${WindowsGccTriple}/bin",
|
2017-11-30 22:31:26 +01:00
|
|
|
"-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
|
|
|
|
"-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3",
|
|
|
|
"-B${WindowsGccRoot}/${WindowsGccTriple}/lib64",
|
2021-07-15 02:03:16 +02:00
|
|
|
}
|
2016-07-20 21:47:47 +02:00
|
|
|
|
|
|
|
windowsAvailableLibraries = addPrefix([]string{
|
|
|
|
"gdi32",
|
|
|
|
"imagehlp",
|
2017-09-09 10:42:00 +02:00
|
|
|
"iphlpapi",
|
|
|
|
"netapi32",
|
2019-01-18 18:14:08 +01:00
|
|
|
"oleaut32",
|
2016-07-20 21:47:47 +02:00
|
|
|
"ole32",
|
2019-01-18 18:14:08 +01:00
|
|
|
"opengl32",
|
2017-09-09 10:42:00 +02:00
|
|
|
"powrprof",
|
2016-07-20 21:47:47 +02:00
|
|
|
"psapi",
|
2016-09-20 23:49:33 +02:00
|
|
|
"pthread",
|
2016-07-20 21:47:47 +02:00
|
|
|
"userenv",
|
|
|
|
"uuid",
|
2016-11-22 02:31:08 +01:00
|
|
|
"version",
|
2016-07-20 21:47:47 +02:00
|
|
|
"ws2_32",
|
2019-01-18 18:14:08 +01:00
|
|
|
"windowscodecs",
|
2016-07-20 21:47:47 +02:00
|
|
|
}, "-l")
|
2015-11-25 02:53:15 +01:00
|
|
|
)
|
|
|
|
|
2015-12-07 21:30:44 +01:00
|
|
|
const (
|
|
|
|
windowsGccVersion = "4.8"
|
|
|
|
)
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func init() {
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("WindowsGccVersion", windowsGccVersion)
|
2015-11-25 02:53:15 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.SourcePathVariable("WindowsGccRoot",
|
|
|
|
"prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${WindowsGccVersion}")
|
2015-11-25 02:53:15 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("WindowsGccTriple", "x86_64-w64-mingw32")
|
2015-11-25 02:53:15 +01:00
|
|
|
|
2021-07-15 03:45:05 +02:00
|
|
|
pctx.StaticVariable("WindowsCflags", strings.Join(windowsCflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsLdflags", strings.Join(windowsLdflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsLldflags", strings.Join(windowsLldflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsCppflags", strings.Join(windowsCppflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("WindowsX86Cflags", strings.Join(windowsX86Cflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX8664Cflags", strings.Join(windowsX8664Cflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX86Ldflags", strings.Join(windowsX86Ldflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX86Lldflags", strings.Join(windowsX86Ldflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX8664Ldflags", strings.Join(windowsX8664Ldflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX8664Lldflags", strings.Join(windowsX8664Ldflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX86Cppflags", strings.Join(windowsX86Cppflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX8664Cppflags", strings.Join(windowsX8664Cppflags, " "))
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("WindowsIncludeFlags", strings.Join(windowsIncludeFlags, " "))
|
2018-11-29 16:34:32 +01:00
|
|
|
// Yasm flags
|
|
|
|
pctx.StaticVariable("WindowsX86YasmFlags", "-f win32 -m x86")
|
|
|
|
pctx.StaticVariable("WindowsX8664YasmFlags", "-f win64 -m amd64")
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainWindows struct {
|
2016-02-04 08:16:33 +01:00
|
|
|
cFlags, ldFlags string
|
2022-09-01 20:02:15 +02:00
|
|
|
toolchainBase
|
|
|
|
toolchainNoCrt
|
2016-02-04 08:16:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainWindowsX86 struct {
|
2015-11-25 02:53:15 +01:00
|
|
|
toolchain32Bit
|
2016-02-04 08:16:33 +01:00
|
|
|
toolchainWindows
|
|
|
|
}
|
2015-11-25 02:53:15 +01:00
|
|
|
|
2016-02-04 08:16:33 +01:00
|
|
|
type toolchainWindowsX8664 struct {
|
|
|
|
toolchain64Bit
|
|
|
|
toolchainWindows
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2016-02-04 08:16:33 +01:00
|
|
|
func (t *toolchainWindowsX86) Name() string {
|
2015-11-25 02:53:15 +01:00
|
|
|
return "x86"
|
|
|
|
}
|
|
|
|
|
2016-02-04 08:16:33 +01:00
|
|
|
func (t *toolchainWindowsX8664) Name() string {
|
|
|
|
return "x86_64"
|
|
|
|
}
|
|
|
|
|
2022-02-16 07:48:04 +01:00
|
|
|
func (t *toolchainWindows) ToolchainCflags() string {
|
2022-10-01 00:44:45 +02:00
|
|
|
return "-B" + filepath.Join("${config.WindowsGccRoot}", "${config.WindowsGccTriple}", "bin")
|
2022-02-16 07:48:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindows) ToolchainLdflags() string {
|
2022-10-01 00:44:45 +02:00
|
|
|
return "-B" + filepath.Join("${config.WindowsGccRoot}", "${config.WindowsGccTriple}", "bin")
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindows) IncludeFlags() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.WindowsIncludeFlags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:31:26 +01:00
|
|
|
func (t *toolchainWindowsX86) ClangTriple() string {
|
|
|
|
return "i686-windows-gnu"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindowsX8664) ClangTriple() string {
|
|
|
|
return "x86_64-pc-windows-gnu"
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX86) Cflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsCflags} ${config.WindowsX86Cflags}"
|
2017-11-30 22:31:26 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX8664) Cflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsCflags} ${config.WindowsX8664Cflags}"
|
2017-11-30 22:31:26 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX86) Cppflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsCppflags} ${config.WindowsX86Cppflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX8664) Cppflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsCppflags} ${config.WindowsX8664Cppflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX86) Ldflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsLdflags} ${config.WindowsX86Ldflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX86) Lldflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsLldflags} ${config.WindowsX86Lldflags}"
|
2018-04-03 20:33:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX8664) Ldflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsLdflags} ${config.WindowsX8664Ldflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainWindowsX8664) Lldflags() string {
|
2021-07-15 03:45:05 +02:00
|
|
|
return "${config.WindowsLldflags} ${config.WindowsX8664Lldflags}"
|
2018-04-03 20:33:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 16:34:32 +01:00
|
|
|
func (t *toolchainWindowsX86) YasmFlags() string {
|
|
|
|
return "${config.WindowsX86YasmFlags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindowsX8664) YasmFlags() string {
|
|
|
|
return "${config.WindowsX8664YasmFlags}"
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (t *toolchainWindows) ShlibSuffix() string {
|
|
|
|
return ".dll"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindows) ExecutableSuffix() string {
|
|
|
|
return ".exe"
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:47:47 +02:00
|
|
|
func (t *toolchainWindows) AvailableLibraries() []string {
|
|
|
|
return windowsAvailableLibraries
|
|
|
|
}
|
|
|
|
|
2016-11-17 10:02:25 +01:00
|
|
|
func (t *toolchainWindows) Bionic() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-02-04 08:16:33 +01:00
|
|
|
var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
|
|
|
|
var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func windowsX86ToolchainFactory(arch android.Arch) Toolchain {
|
2016-02-04 08:16:33 +01:00
|
|
|
return toolchainWindowsX86Singleton
|
|
|
|
}
|
2015-11-25 02:53:15 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
|
2016-02-04 08:16:33 +01:00
|
|
|
return toolchainWindowsX8664Singleton
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-06-02 02:09:44 +02:00
|
|
|
registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
|
|
|
|
registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|