blob: 26e80f8dfc45f9e1ab6cfb95116d6967a8c58d5f [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++"
mtklein8079ba62016-08-16 09:31:16 -070010
11 extra_cflags = ""
12 extra_cflags_c = ""
13 extra_cflags_cc = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070014}
15
halcanary19a97202016-08-03 15:08:04 -070016config("no_rtti") {
17 cflags_cc = [ "-fno-rtti" ]
18}
19
mtklein7fbfbbe2016-07-21 12:25:45 -070020config("default") {
21 cflags = [
22 "-g",
23 "-fstrict-aliasing",
24 "-fPIC",
mtklein8796ff12016-07-27 14:59:08 -070025 "-fvisibility=hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070026
27 "-Werror",
28 "-Wall",
29 "-Wextra",
30 "-Winit-self",
31 "-Wpointer-arith",
32 "-Wsign-compare",
33 "-Wvla",
34
35 "-Wno-deprecated-declarations",
36 "-Wno-unused-parameter",
37 ]
38 cflags_cc = [
39 "-std=c++11",
40 "-fno-exceptions",
mtklein7fbfbbe2016-07-21 12:25:45 -070041 "-fno-threadsafe-statics",
mtklein8796ff12016-07-27 14:59:08 -070042 "-fvisibility-inlines-hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070043
44 "-Wnon-virtual-dtor",
45 ]
46}
47
48config("release") {
49 cflags = [ "-Os" ]
50 defines = [ "NDEBUG" ]
51}
52
53config("executable") {
54 if (is_mac) {
55 ldflags = [ "-Wl,-rpath,@loader_path/." ]
56 } else if (is_linux) {
57 ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
58 }
59}
60
mtkleind434b012016-08-10 07:30:58 -070061pool("link_pool") {
62 depth = 0 #unlimited
63}
64
mtklein7fbfbbe2016-07-21 12:25:45 -070065toolchain("gcc_like") {
66 lib_switch = "-l"
67 lib_dir_switch = "-L"
68
69 tool("cc") {
70 depfile = "{{output}}.d"
mtklein8079ba62016-08-16 09:31:16 -070071 command = "$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 -070072 depsformat = "gcc"
73 outputs = [
74 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
75 ]
mtkleinf05c2c22016-07-28 11:42:34 -070076 description = "$cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070077 }
78
79 tool("cxx") {
80 depfile = "{{output}}.d"
mtklein8079ba62016-08-16 09:31:16 -070081 command = "$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 -070082 depsformat = "gcc"
83 outputs = [
84 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
85 ]
mtkleinf05c2c22016-07-28 11:42:34 -070086 description = "$cxx ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070087 }
88
89 tool("asm") {
90 depfile = "{{output}}.d"
91 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
92 depsformat = "gcc"
93 outputs = [
94 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
95 ]
mtkleinf05c2c22016-07-28 11:42:34 -070096 description = "$cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070097 }
98
99 tool("alink") {
100 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
101 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -0700102 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -0700103 ]
104 default_output_extension = ".a"
105 output_prefix = "lib"
mtkleinf05c2c22016-07-28 11:42:34 -0700106 description = "$ar {{output}} ..."
mtklein7fbfbbe2016-07-21 12:25:45 -0700107 }
108
109 tool("solink") {
110 soname = "{{target_output_name}}{{output_extension}}"
111
112 rpath = "-Wl,-soname,$soname"
113 if (is_mac) {
114 rpath = "-Wl,-install_name,@rpath/$soname"
115 }
116
117 command = "$cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
118 outputs = [
119 "{{root_out_dir}}/$soname",
120 ]
121 output_prefix = "lib"
122 default_output_extension = ".so"
mtkleinf05c2c22016-07-28 11:42:34 -0700123 description = "$cxx -shared ... -o {{output}}"
mtkleind434b012016-08-10 07:30:58 -0700124 pool = ":link_pool"
mtklein7fbfbbe2016-07-21 12:25:45 -0700125 }
126
127 tool("link") {
128 command = "$cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
129 outputs = [
130 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
131 ]
mtkleinf05c2c22016-07-28 11:42:34 -0700132 description = "$cxx ... -o {{output}}"
mtkleind434b012016-08-10 07:30:58 -0700133 pool = ":link_pool"
mtklein7fbfbbe2016-07-21 12:25:45 -0700134 }
135
136 tool("stamp") {
137 command = "touch {{output}}"
138 }
139
140 tool("copy") {
141 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
142 }
143}