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++" |
| 10 | } |
| 11 | |
| 12 | config("default") { |
| 13 | cflags = [ |
| 14 | "-g", |
| 15 | "-fstrict-aliasing", |
| 16 | "-fPIC", |
mtklein | 8796ff1 | 2016-07-27 14:59:08 -0700 | [diff] [blame] | 17 | "-fvisibility=hidden", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 18 | |
| 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", |
mtklein | 8796ff1 | 2016-07-27 14:59:08 -0700 | [diff] [blame] | 35 | "-fvisibility-inlines-hidden", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 36 | |
| 37 | "-Wnon-virtual-dtor", |
| 38 | ] |
| 39 | } |
| 40 | |
| 41 | config("release") { |
| 42 | cflags = [ "-Os" ] |
| 43 | defines = [ "NDEBUG" ] |
| 44 | } |
| 45 | |
| 46 | config("executable") { |
| 47 | if (is_mac) { |
| 48 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 49 | } else if (is_linux) { |
| 50 | ldflags = [ "-Wl,-rpath,\$ORIGIN" ] |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | toolchain("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 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 65 | description = "$cc ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 66 | } |
| 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 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 75 | description = "$cxx ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 76 | } |
| 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 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 85 | description = "$cc ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | tool("alink") { |
| 89 | command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" |
| 90 | outputs = [ |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame^] | 91 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 92 | ] |
| 93 | default_output_extension = ".a" |
| 94 | output_prefix = "lib" |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 95 | description = "$ar {{output}} ..." |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 96 | } |
| 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" |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 112 | description = "$cxx -shared ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 113 | } |
| 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 | ] |
mtklein | f05c2c2 | 2016-07-28 11:42:34 -0700 | [diff] [blame] | 120 | description = "$cxx ... -o {{output}}" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 121 | } |
| 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 | } |