mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 1 | # 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 | |
| 6 | declare_args() { |
| 7 | ar = "ar" |
| 8 | cc = "cc" |
| 9 | cxx = "c++" |
mtklein | 8079ba6 | 2016-08-16 09:31:16 -0700 | [diff] [blame^] | 10 | |
| 11 | extra_cflags = "" |
| 12 | extra_cflags_c = "" |
| 13 | extra_cflags_cc = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 14 | } |
| 15 | |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 16 | config("no_rtti") { |
| 17 | cflags_cc = [ "-fno-rtti" ] |
| 18 | } |
| 19 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 20 | config("default") { |
| 21 | cflags = [ |
| 22 | "-g", |
| 23 | "-fstrict-aliasing", |
| 24 | "-fPIC", |
mtklein | 8796ff1 | 2016-07-27 14:59:08 -0700 | [diff] [blame] | 25 | "-fvisibility=hidden", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 26 | |
| 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", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 41 | "-fno-threadsafe-statics", |
mtklein | 8796ff1 | 2016-07-27 14:59:08 -0700 | [diff] [blame] | 42 | "-fvisibility-inlines-hidden", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 43 | |
| 44 | "-Wnon-virtual-dtor", |
| 45 | ] |
| 46 | } |
| 47 | |
| 48 | config("release") { |
| 49 | cflags = [ "-Os" ] |
| 50 | defines = [ "NDEBUG" ] |
| 51 | } |
| 52 | |
| 53 | config("executable") { |
| 54 | if (is_mac) { |
| 55 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 56 | } else if (is_linux) { |
| 57 | ldflags = [ "-Wl,-rpath,\$ORIGIN" ] |
| 58 | } |
| 59 | } |
| 60 | |
mtklein | d434b01 | 2016-08-10 07:30:58 -0700 | [diff] [blame] | 61 | pool("link_pool") { |
| 62 | depth = 0 #unlimited |
| 63 | } |
| 64 | |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 65 | toolchain("gcc_like") { |
| 66 | lib_switch = "-l" |
| 67 | lib_dir_switch = "-L" |
| 68 | |
| 69 | tool("cc") { |
| 70 | depfile = "{{output}}.d" |
mtklein | 8079ba6 | 2016-08-16 09:31:16 -0700 | [diff] [blame^] | 71 | command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $extra_cflags $extra_cflags_c -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 72 | depsformat = "gcc" |
| 73 | outputs = [ |
| 74 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 75 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 76 | description = "$cc ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | tool("cxx") { |
| 80 | depfile = "{{output}}.d" |
mtklein | 8079ba6 | 2016-08-16 09:31:16 -0700 | [diff] [blame^] | 81 | command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $extra_cflags $extra_cflags_cc -c {{source}} -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 82 | depsformat = "gcc" |
| 83 | outputs = [ |
| 84 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 85 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 86 | description = "$cxx ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 87 | } |
| 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 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 96 | description = "$cc ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | tool("alink") { |
| 100 | command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" |
| 101 | outputs = [ |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame] | 102 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 103 | ] |
| 104 | default_output_extension = ".a" |
| 105 | output_prefix = "lib" |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 106 | description = "$ar {{output}} ..." |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 107 | } |
| 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" |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 123 | description = "$cxx -shared ... -o {{output}}" |
mtklein | d434b01 | 2016-08-10 07:30:58 -0700 | [diff] [blame] | 124 | pool = ":link_pool" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 125 | } |
| 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 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 132 | description = "$cxx ... -o {{output}}" |
mtklein | d434b01 | 2016-08-10 07:30:58 -0700 | [diff] [blame] | 133 | pool = ":link_pool" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 134 | } |
| 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 | } |