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 (
|
|
|
|
"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",
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
"--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2017-11-30 22:31:26 +01:00
|
|
|
windowsClangCflags = append(ClangFilterUnknownCflags(windowsCflags), []string{}...)
|
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
|
|
|
}
|
|
|
|
|
2018-08-08 19:28:12 +02:00
|
|
|
windowsClangCppflags = []string{}
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2018-08-08 19:28:12 +02:00
|
|
|
windowsX86ClangCppflags = []string{}
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2018-08-08 19:28:12 +02:00
|
|
|
windowsX8664ClangCppflags = []string{}
|
2017-11-30 22:31:26 +01:00
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
windowsLdflags = []string{
|
|
|
|
"--enable-stdcall-fixup",
|
2018-08-30 21:37:56 +02:00
|
|
|
"-Wl,--dynamicbase",
|
|
|
|
"-Wl,--nxcompat",
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2018-04-17 23:16:05 +02:00
|
|
|
windowsClangLdflags = append(ClangFilterUnknownCflags(windowsLdflags), []string{}...)
|
|
|
|
windowsClangLldflags = ClangFilterUnknownLldflags(windowsClangLdflags)
|
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",
|
2016-02-04 08:16:33 +01:00
|
|
|
}
|
2017-11-30 22:31:26 +01:00
|
|
|
windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{
|
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",
|
|
|
|
}...)
|
2018-04-17 23:16:05 +02:00
|
|
|
windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)
|
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",
|
2016-02-04 08:16:33 +01:00
|
|
|
}
|
2017-11-30 22:31:26 +01:00
|
|
|
windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{
|
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",
|
|
|
|
}...)
|
2018-04-17 23:16:05 +02:00
|
|
|
windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags)
|
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
|
|
|
|
2017-11-30 22:31:26 +01:00
|
|
|
pctx.StaticVariable("WindowsClangCflags", strings.Join(windowsClangCflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsClangLdflags", strings.Join(windowsClangLdflags, " "))
|
2018-04-17 23:16:05 +02:00
|
|
|
pctx.StaticVariable("WindowsClangLldflags", strings.Join(windowsClangLldflags, " "))
|
2017-11-30 22:31:26 +01:00
|
|
|
pctx.StaticVariable("WindowsClangCppflags", strings.Join(windowsClangCppflags, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("WindowsX86ClangCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(windowsX86Cflags), " "))
|
|
|
|
pctx.StaticVariable("WindowsX8664ClangCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(windowsX8664Cflags), " "))
|
|
|
|
pctx.StaticVariable("WindowsX86ClangLdflags", strings.Join(windowsX86ClangLdflags, " "))
|
2018-04-17 23:16:05 +02:00
|
|
|
pctx.StaticVariable("WindowsX86ClangLldflags", strings.Join(windowsX86ClangLldflags, " "))
|
2017-11-30 22:31:26 +01:00
|
|
|
pctx.StaticVariable("WindowsX8664ClangLdflags", strings.Join(windowsX8664ClangLdflags, " "))
|
2018-04-17 23:16:05 +02:00
|
|
|
pctx.StaticVariable("WindowsX8664ClangLldflags", strings.Join(windowsX8664ClangLldflags, " "))
|
2017-11-30 22:31:26 +01:00
|
|
|
pctx.StaticVariable("WindowsX86ClangCppflags", strings.Join(windowsX86ClangCppflags, " "))
|
|
|
|
pctx.StaticVariable("WindowsX8664ClangCppflags", strings.Join(windowsX8664ClangCppflags, " "))
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (t *toolchainWindows) GccRoot() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.WindowsGccRoot}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindows) GccTriple() string {
|
2016-07-29 22:44:28 +02:00
|
|
|
return "${config.WindowsGccTriple}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindows) GccVersion() string {
|
2015-12-07 21:30:44 +01:00
|
|
|
return windowsGccVersion
|
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-09-09 10:15:26 +02:00
|
|
|
func (t *toolchainWindowsX86) WindresFlags() string {
|
|
|
|
return "-F pe-i386"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindowsX8664) WindresFlags() string {
|
|
|
|
return "-F pe-x86-64"
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindowsX86) ClangCflags() string {
|
|
|
|
return "${config.WindowsClangCflags} ${config.WindowsX86ClangCflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindowsX8664) ClangCflags() string {
|
|
|
|
return "${config.WindowsClangCflags} ${config.WindowsX8664ClangCflags}"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainWindowsX86) ClangCppflags() string {
|
|
|
|
return "${config.WindowsClangCppflags} ${config.WindowsX86ClangCppflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:31:26 +01:00
|
|
|
func (t *toolchainWindowsX8664) ClangCppflags() string {
|
|
|
|
return "${config.WindowsClangCppflags} ${config.WindowsX8664ClangCppflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:31:26 +01:00
|
|
|
func (t *toolchainWindowsX86) ClangLdflags() string {
|
|
|
|
return "${config.WindowsClangLdflags} ${config.WindowsX86ClangLdflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2018-04-03 20:33:34 +02:00
|
|
|
func (t *toolchainWindowsX86) ClangLldflags() string {
|
2018-04-17 23:16:05 +02:00
|
|
|
return "${config.WindowsClangLldflags} ${config.WindowsX86ClangLldflags}"
|
2018-04-03 20:33:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 22:31:26 +01:00
|
|
|
func (t *toolchainWindowsX8664) ClangLdflags() string {
|
|
|
|
return "${config.WindowsClangLdflags} ${config.WindowsX8664ClangLdflags}"
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
|
|
|
|
2018-04-03 20:33:34 +02:00
|
|
|
func (t *toolchainWindowsX8664) ClangLldflags() string {
|
2018-04-17 23:16:05 +02:00
|
|
|
return "${config.WindowsClangLldflags} ${config.WindowsX8664ClangLldflags}"
|
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
|
|
|
}
|