blob: 547f57ebea9202a5bf9dcd43457c8e07b580c42d [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",
17
18 "-Werror",
19 "-Wall",
20 "-Wextra",
21 "-Winit-self",
22 "-Wpointer-arith",
23 "-Wsign-compare",
24 "-Wvla",
25
26 "-Wno-deprecated-declarations",
27 "-Wno-unused-parameter",
28 ]
29 cflags_cc = [
30 "-std=c++11",
31 "-fno-exceptions",
32 "-fno-rtti",
33 "-fno-threadsafe-statics",
34
35 "-Wnon-virtual-dtor",
36 ]
37}
38
39config("release") {
40 cflags = [ "-Os" ]
41 defines = [ "NDEBUG" ]
42}
43
44config("executable") {
45 if (is_mac) {
46 ldflags = [ "-Wl,-rpath,@loader_path/." ]
47 } else if (is_linux) {
48 ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
49 }
50}
51
52toolchain("gcc_like") {
53 lib_switch = "-l"
54 lib_dir_switch = "-L"
55
56 tool("cc") {
57 depfile = "{{output}}.d"
58 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
59 depsformat = "gcc"
60 outputs = [
61 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
62 ]
63 }
64
65 tool("cxx") {
66 depfile = "{{output}}.d"
67 command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
68 depsformat = "gcc"
69 outputs = [
70 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
71 ]
72 }
73
74 tool("asm") {
75 depfile = "{{output}}.d"
76 command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
77 depsformat = "gcc"
78 outputs = [
79 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
80 ]
81 }
82
83 tool("alink") {
84 command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
85 outputs = [
86 "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
87 ]
88 default_output_extension = ".a"
89 output_prefix = "lib"
90 }
91
92 tool("solink") {
93 soname = "{{target_output_name}}{{output_extension}}"
94
95 rpath = "-Wl,-soname,$soname"
96 if (is_mac) {
97 rpath = "-Wl,-install_name,@rpath/$soname"
98 }
99
100 command = "$cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
101 outputs = [
102 "{{root_out_dir}}/$soname",
103 ]
104 output_prefix = "lib"
105 default_output_extension = ".so"
106 }
107
108 tool("link") {
109 command = "$cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
110 outputs = [
111 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
112 ]
113 }
114
115 tool("stamp") {
116 command = "touch {{output}}"
117 }
118
119 tool("copy") {
120 command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
121 }
122}