blob: 1f7bd82bf2cf15cd8762c2b2bd501407b5911251 [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() {
7 ar = "ar"
8 cc = "cc"
9 cxx = "c++"
10}
11
halcanary19a97202016-08-03 15:08:04 -070012config("no_rtti") {
13 cflags_cc = [ "-fno-rtti" ]
14}
15
mtklein7fbfbbe2016-07-21 12:25:45 -070016config("default") {
17 cflags = [
18 "-g",
19 "-fstrict-aliasing",
20 "-fPIC",
mtklein8796ff12016-07-27 14:59:08 -070021 "-fvisibility=hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070022
23 "-Werror",
24 "-Wall",
25 "-Wextra",
26 "-Winit-self",
27 "-Wpointer-arith",
28 "-Wsign-compare",
29 "-Wvla",
30
31 "-Wno-deprecated-declarations",
32 "-Wno-unused-parameter",
33 ]
34 cflags_cc = [
35 "-std=c++11",
36 "-fno-exceptions",
mtklein7fbfbbe2016-07-21 12:25:45 -070037 "-fno-threadsafe-statics",
mtklein8796ff12016-07-27 14:59:08 -070038 "-fvisibility-inlines-hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070039
40 "-Wnon-virtual-dtor",
41 ]
42}
43
44config("release") {
45 cflags = [ "-Os" ]
46 defines = [ "NDEBUG" ]
47}
48
49config("executable") {
50 if (is_mac) {
51 ldflags = [ "-Wl,-rpath,@loader_path/." ]
52 } else if (is_linux) {
53 ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
54 }
55}
56
mtkleind434b012016-08-10 07:30:58 -070057pool("link_pool") {
58 depth = 0 #unlimited
59}
60
mtklein7fbfbbe2016-07-21 12:25:45 -070061toolchain("gcc_like") {
62 lib_switch = "-l"
63 lib_dir_switch = "-L"
64
65 tool("cc") {
66 depfile = "{{output}}.d"
67 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
68 depsformat = "gcc"
69 outputs = [
70 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
71 ]
mtkleinf05c2c22016-07-28 11:42:34 -070072 description = "$cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070073 }
74
75 tool("cxx") {
76 depfile = "{{output}}.d"
77 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
78 depsformat = "gcc"
79 outputs = [
80 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
81 ]
mtkleinf05c2c22016-07-28 11:42:34 -070082 description = "$cxx ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070083 }
84
85 tool("asm") {
86 depfile = "{{output}}.d"
87 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
88 depsformat = "gcc"
89 outputs = [
90 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
91 ]
mtkleinf05c2c22016-07-28 11:42:34 -070092 description = "$cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070093 }
94
95 tool("alink") {
96 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
97 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -070098 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -070099 ]
100 default_output_extension = ".a"
101 output_prefix = "lib"
mtkleinf05c2c22016-07-28 11:42:34 -0700102 description = "$ar {{output}} ..."
mtklein7fbfbbe2016-07-21 12:25:45 -0700103 }
104
105 tool("solink") {
106 soname = "{{target_output_name}}{{output_extension}}"
107
108 rpath = "-Wl,-soname,$soname"
109 if (is_mac) {
110 rpath = "-Wl,-install_name,@rpath/$soname"
111 }
112
113 command = "$cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
114 outputs = [
115 "{{root_out_dir}}/$soname",
116 ]
117 output_prefix = "lib"
118 default_output_extension = ".so"
mtkleinf05c2c22016-07-28 11:42:34 -0700119 description = "$cxx -shared ... -o {{output}}"
mtkleind434b012016-08-10 07:30:58 -0700120 pool = ":link_pool"
mtklein7fbfbbe2016-07-21 12:25:45 -0700121 }
122
123 tool("link") {
124 command = "$cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
125 outputs = [
126 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
127 ]
mtkleinf05c2c22016-07-28 11:42:34 -0700128 description = "$cxx ... -o {{output}}"
mtkleind434b012016-08-10 07:30:58 -0700129 pool = ":link_pool"
mtklein7fbfbbe2016-07-21 12:25:45 -0700130 }
131
132 tool("stamp") {
133 command = "touch {{output}}"
134 }
135
136 tool("copy") {
137 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
138 }
139}