Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/common" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | windowsCflags = []string{ |
| 25 | "-fno-exceptions", // from build/core/combo/select.mk |
| 26 | "-Wno-multichar", // from build/core/combo/select.mk |
| 27 | |
| 28 | "-DUSE_MINGW", |
| 29 | "-DWIN32_LEAN_AND_MEAN", |
| 30 | "-Wno-unused-parameter", |
| 31 | "-m32", |
| 32 | |
| 33 | // Workaround differences in inttypes.h between host and target. |
| 34 | //See bug 12708004. |
| 35 | "-D__STDC_FORMAT_MACROS", |
| 36 | "-D__STDC_CONSTANT_MACROS", |
| 37 | |
| 38 | // Use C99-compliant printf functions (%zd). |
| 39 | "-D__USE_MINGW_ANSI_STDIO=1", |
| 40 | // Admit to using >= Win2K. Both are needed because of <_mingw.h>. |
| 41 | "-D_WIN32_WINNT=0x0500", |
| 42 | "-DWINVER=0x0500", |
| 43 | // Get 64-bit off_t and related functions. |
| 44 | "-D_FILE_OFFSET_BITS=64", |
| 45 | |
| 46 | // HOST_RELEASE_CFLAGS |
| 47 | "-O2", // from build/core/combo/select.mk |
| 48 | "-g", // from build/core/combo/select.mk |
| 49 | "-fno-strict-aliasing", // from build/core/combo/select.mk |
| 50 | } |
| 51 | |
| 52 | windowsIncludeFlags = []string{ |
| 53 | "-I${windowsGccRoot}/${windowsGccTriple}/include", |
| 54 | "-I${windowsGccRoot}/lib/gcc/${windowsGccTriple}/4.8.3/include", |
| 55 | } |
| 56 | |
| 57 | windowsLdflags = []string{ |
| 58 | "-m32", |
| 59 | "-L${windowsGccRoot}/${windowsGccTriple}", |
| 60 | "--enable-stdcall-fixup", |
| 61 | } |
| 62 | ) |
| 63 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 64 | const ( |
| 65 | windowsGccVersion = "4.8" |
| 66 | ) |
| 67 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 68 | func init() { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 69 | pctx.StaticVariable("windowsGccVersion", windowsGccVersion) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 70 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 71 | pctx.SourcePathVariable("windowsGccRoot", |
| 72 | "prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-w64-mingw32-${windowsGccVersion}") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 73 | |
| 74 | pctx.StaticVariable("windowsGccTriple", "x86_64-w64-mingw32") |
| 75 | |
| 76 | pctx.StaticVariable("windowsCflags", strings.Join(windowsCflags, " ")) |
| 77 | pctx.StaticVariable("windowsLdflags", strings.Join(windowsLdflags, " ")) |
| 78 | } |
| 79 | |
| 80 | type toolchainWindows struct { |
| 81 | toolchain32Bit |
| 82 | |
| 83 | cFlags, ldFlags string |
| 84 | } |
| 85 | |
| 86 | func (t *toolchainWindows) Name() string { |
| 87 | return "x86" |
| 88 | } |
| 89 | |
| 90 | func (t *toolchainWindows) GccRoot() string { |
| 91 | return "${windowsGccRoot}" |
| 92 | } |
| 93 | |
| 94 | func (t *toolchainWindows) GccTriple() string { |
| 95 | return "${windowsGccTriple}" |
| 96 | } |
| 97 | |
| 98 | func (t *toolchainWindows) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 99 | return windowsGccVersion |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | func (t *toolchainWindows) Cflags() string { |
| 103 | return "${windowsCflags}" |
| 104 | } |
| 105 | |
| 106 | func (t *toolchainWindows) Cppflags() string { |
| 107 | return "" |
| 108 | } |
| 109 | |
| 110 | func (t *toolchainWindows) Ldflags() string { |
| 111 | return "${windowsLdflags}" |
| 112 | } |
| 113 | |
| 114 | func (t *toolchainWindows) IncludeFlags() string { |
| 115 | return "" |
| 116 | } |
| 117 | |
| 118 | func (t *toolchainWindows) ClangSupported() bool { |
| 119 | return false |
| 120 | } |
| 121 | |
| 122 | func (t *toolchainWindows) ClangTriple() string { |
| 123 | panic("Clang is not supported under mingw") |
| 124 | } |
| 125 | |
| 126 | func (t *toolchainWindows) ClangCflags() string { |
| 127 | panic("Clang is not supported under mingw") |
| 128 | } |
| 129 | |
| 130 | func (t *toolchainWindows) ClangCppflags() string { |
| 131 | panic("Clang is not supported under mingw") |
| 132 | } |
| 133 | |
| 134 | func (t *toolchainWindows) ClangLdflags() string { |
| 135 | panic("Clang is not supported under mingw") |
| 136 | } |
| 137 | |
| 138 | func (t *toolchainWindows) ShlibSuffix() string { |
| 139 | return ".dll" |
| 140 | } |
| 141 | |
| 142 | func (t *toolchainWindows) ExecutableSuffix() string { |
| 143 | return ".exe" |
| 144 | } |
| 145 | |
| 146 | var toolchainWindowsSingleton Toolchain = &toolchainWindows{} |
| 147 | |
| 148 | func windowsToolchainFactory(arch common.Arch) Toolchain { |
| 149 | return toolchainWindowsSingleton |
| 150 | } |
| 151 | |
| 152 | func init() { |
| 153 | registerHostToolchainFactory(common.Windows, common.X86, windowsToolchainFactory) |
| 154 | } |