blob: 5789aef48b38e0a261e923ab0b5020778e596a50 [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
12config("default") {
13 cflags = [
14 "-g",
15 "-fstrict-aliasing",
16 "-fPIC",
mtklein8796ff12016-07-27 14:59:08 -070017 "-fvisibility=hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070018
19 "-Werror",
20 "-Wall",
21 "-Wextra",
22 "-Winit-self",
23 "-Wpointer-arith",
24 "-Wsign-compare",
25 "-Wvla",
26
27 "-Wno-deprecated-declarations",
28 "-Wno-unused-parameter",
29 ]
30 cflags_cc = [
31 "-std=c++11",
32 "-fno-exceptions",
33 "-fno-rtti",
34 "-fno-threadsafe-statics",
mtklein8796ff12016-07-27 14:59:08 -070035 "-fvisibility-inlines-hidden",
mtklein7fbfbbe2016-07-21 12:25:45 -070036
37 "-Wnon-virtual-dtor",
38 ]
39}
40
41config("release") {
42 cflags = [ "-Os" ]
43 defines = [ "NDEBUG" ]
44}
45
46config("executable") {
47 if (is_mac) {
48 ldflags = [ "-Wl,-rpath,@loader_path/." ]
49 } else if (is_linux) {
50 ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
51 }
52}
53
54toolchain("gcc_like") {
55 lib_switch = "-l"
56 lib_dir_switch = "-L"
57
58 tool("cc") {
59 depfile = "{{output}}.d"
60 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
61 depsformat = "gcc"
62 outputs = [
63 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
64 ]
mtkleinf05c2c22016-07-28 11:42:34 -070065 description = "$cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070066 }
67
68 tool("cxx") {
69 depfile = "{{output}}.d"
70 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
71 depsformat = "gcc"
72 outputs = [
73 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
74 ]
mtkleinf05c2c22016-07-28 11:42:34 -070075 description = "$cxx ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070076 }
77
78 tool("asm") {
79 depfile = "{{output}}.d"
80 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
81 depsformat = "gcc"
82 outputs = [
83 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
84 ]
mtkleinf05c2c22016-07-28 11:42:34 -070085 description = "$cc ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -070086 }
87
88 tool("alink") {
89 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
90 outputs = [
mtklein5db44aa2016-07-29 09:10:31 -070091 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
mtklein7fbfbbe2016-07-21 12:25:45 -070092 ]
93 default_output_extension = ".a"
94 output_prefix = "lib"
mtkleinf05c2c22016-07-28 11:42:34 -070095 description = "$ar {{output}} ..."
mtklein7fbfbbe2016-07-21 12:25:45 -070096 }
97
98 tool("solink") {
99 soname = "{{target_output_name}}{{output_extension}}"
100
101 rpath = "-Wl,-soname,$soname"
102 if (is_mac) {
103 rpath = "-Wl,-install_name,@rpath/$soname"
104 }
105
106 command = "$cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
107 outputs = [
108 "{{root_out_dir}}/$soname",
109 ]
110 output_prefix = "lib"
111 default_output_extension = ".so"
mtkleinf05c2c22016-07-28 11:42:34 -0700112 description = "$cxx -shared ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700113 }
114
115 tool("link") {
116 command = "$cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
117 outputs = [
118 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
119 ]
mtkleinf05c2c22016-07-28 11:42:34 -0700120 description = "$cxx ... -o {{output}}"
mtklein7fbfbbe2016-07-21 12:25:45 -0700121 }
122
123 tool("stamp") {
124 command = "touch {{output}}"
125 }
126
127 tool("copy") {
128 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
129 }
130}