blob: da627d730498790927fcaf01e0d8088abe596136 [file] [log] [blame]
mtklein7fbfbbe2016-07-21 12:25:45 -07001# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6declare_args() {
mtklein349cece2016-08-26 08:13:04 -07007 ar = "ar"
mtklein7fbfbbe2016-07-21 12:25:45 -07008 cc = "cc"
9 cxx = "c++"
mtklein8079ba62016-08-16 09:31:16 -070010
mtklein7d6fb2c2016-08-25 14:50:44 -070011 if (is_android) {
mtklein349cece2016-08-26 08:13:04 -070012 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
mtklein7d6fb2c2016-08-25 14:50:44 -070013 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
14 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
15 }
16
mtklein8079ba62016-08-16 09:31:16 -070017 extra_cflags = ""
18 extra_cflags_c = ""
19 extra_cflags_cc = ""
mtkleincab0bb72016-08-26 13:43:19 -070020
21 compiler_prefix = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070022}
23
halcanary19a97202016-08-03 15:08:04 -070024config("no_rtti") {
25 cflags_cc = [ "-fno-rtti" ]
26}
27
mtklein7fbfbbe2016-07-21 12:25:45 -070028config("default") {
29 cflags = [
30 "-g",
31 "-fstrict-aliasing",
32 "-fPIC",
mtklein8796ff12016-07-27 14:59:08 -070033 "-fvisibility=hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070034
35 "-Werror",
36 "-Wall",
37 "-Wextra",
38 "-Winit-self",
39 "-Wpointer-arith",
40 "-Wsign-compare",
41 "-Wvla",
42
43 "-Wno-deprecated-declarations",
44 "-Wno-unused-parameter",
45 ]
46 cflags_cc = [
47 "-std=c++11",
48 "-fno-exceptions",
mtklein7fbfbbe2016-07-21 12:25:45 -070049 "-fno-threadsafe-statics",
mtklein8796ff12016-07-27 14:59:08 -070050 "-fvisibility-inlines-hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070051
52 "-Wnon-virtual-dtor",
53 ]
mtklein7d6fb2c2016-08-25 14:50:44 -070054 if (current_cpu == "arm") {
mtklein349cece2016-08-26 08:13:04 -070055 cflags += [
56 "-march=armv7-a",
57 "-mfpu=neon",
58 "-mthumb",
59 ]
60 } else if (current_cpu == "mipsel") {
61 cflags += [
62 "-march=mips32r2",
63 "-mdspr2",
64 ]
mtklein7d6fb2c2016-08-25 14:50:44 -070065 }
66
67 if (is_android) {
mtklein349cece2016-08-26 08:13:04 -070068 asmflags = [
69 "--target=$ndk_target",
70 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
71 ]
mtklein7d6fb2c2016-08-25 14:50:44 -070072 cflags += [
73 "--sysroot=$ndk/platforms/$ndk_platform",
74 "--target=$ndk_target",
mtklein349cece2016-08-26 08:13:04 -070075 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtklein7d6fb2c2016-08-25 14:50:44 -070076 ]
77 cflags_cc += [
78 "-isystem$ndk/sources/android/support/include",
79 "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include",
80 ]
81 ldflags = [
82 "--sysroot=$ndk/platforms/$ndk_platform",
83 "--target=$ndk_target",
mtklein349cece2016-08-26 08:13:04 -070084 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
mtklein7d6fb2c2016-08-25 14:50:44 -070085 "-pie",
86 ]
87 lib_dirs = [
88 "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
mtklein349cece2016-08-26 08:13:04 -070089 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
mtklein7d6fb2c2016-08-25 14:50:44 -070090 ]
91 libs = [
92 # Order matters here! Keep these three in exactly this order.
93 "c++_static",
94 "c++abi",
95 "android_support",
96 ]
mtklein349cece2016-08-26 08:13:04 -070097 if (target_cpu == "arm") {
98 libs += [ "unwind" ]
99 }
mtklein7d6fb2c2016-08-25 14:50:44 -0700100 }
101
102 if (is_linux) {
103 libs = [ "pthread" ]
104 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700105}
106
107config("release") {
108 cflags = [ "-Os" ]
109 defines = [ "NDEBUG" ]
110}
111
112config("executable") {
113 if (is_mac) {
114 ldflags = [ "-Wl,-rpath,@loader_path/." ]
115 } else if (is_linux) {
116 ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
117 }
118}
119
mtkleind434b012016-08-10 07:30:58 -0700120pool("link_pool") {
121 depth = 0 #unlimited
122}
123
mtklein7fbfbbe2016-07-21 12:25:45 -0700124toolchain("gcc_like") {
125 lib_switch = "-l"
126 lib_dir_switch = "-L"
127
128 tool("cc") {
129 depfile = "{{output}}.d"
mtkleincab0bb72016-08-26 13:43:19 -0700130 command = "$compiler_prefix $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $extra_cflags $extra_cflags_c -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700131 depsformat = "gcc"
132 outputs = [
133 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
134 ]
mtkleincab0bb72016-08-26 13:43:19 -0700135 description =
136 "$compiler_prefix $cc ... $extra_cflags $extra_cflags_c -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700137 }
138
139 tool("cxx") {
140 depfile = "{{output}}.d"
mtkleincab0bb72016-08-26 13:43:19 -0700141 command = "$compiler_prefix $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $extra_cflags $extra_cflags_cc -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700142 depsformat = "gcc"
143 outputs = [
144 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
145 ]
mtkleincab0bb72016-08-26 13:43:19 -0700146 description =
147 "$compiler_prefix $cxx ... $extra_cflags $extra_cflags_cc -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700148 }
149
150 tool("asm") {
151 depfile = "{{output}}.d"
mtkleincab0bb72016-08-26 13:43:19 -0700152 command = "$compiler_prefix $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700153 depsformat = "gcc"
154 outputs = [
155 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
156 ]
mtkleincab0bb72016-08-26 13:43:19 -0700157 description = "$compiler_prefix $cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700158 }
159
160 tool("alink") {
mtklein349cece2016-08-26 08:13:04 -0700161 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700162 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700163 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700164 ]
165 default_output_extension = ".a"
166 output_prefix = "lib"
mtklein349cece2016-08-26 08:13:04 -0700167 description = "$ar {{output}} ..."
mtklein7fbfbbe2016-07-21 12:25:45 -0700168 }
169
170 tool("solink") {
171 soname = "{{target_output_name}}{{output_extension}}"
172
173 rpath = "-Wl,-soname,$soname"
174 if (is_mac) {
175 rpath = "-Wl,-install_name,@rpath/$soname"
176 }
177
mtkleincab0bb72016-08-26 13:43:19 -0700178 command = "$compiler_prefix $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700179 outputs = [
180 "{{root_out_dir}}/$soname",
181 ]
182 output_prefix = "lib"
183 default_output_extension = ".so"
mtkleincab0bb72016-08-26 13:43:19 -0700184 description = "$compiler_prefix $cxx -shared ... -o {{output}}"
mtkleind434b012016-08-10 07:30:58 -0700185 pool = ":link_pool"
mtklein7fbfbbe2016-07-21 12:25:45 -0700186 }
187
188 tool("link") {
mtkleincab0bb72016-08-26 13:43:19 -0700189 command = "$compiler_prefix $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700190 outputs = [
191 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
192 ]
mtkleincab0bb72016-08-26 13:43:19 -0700193 description = "$compiler_prefix $cxx ... -o {{output}}"
mtkleind434b012016-08-10 07:30:58 -0700194 pool = ":link_pool"
mtklein7fbfbbe2016-07-21 12:25:45 -0700195 }
196
197 tool("stamp") {
198 command = "touch {{output}}"
199 }
200
201 tool("copy") {
202 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
203 }
204}