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 | ] |
| 65 | } |
| 66 | |
| 67 | tool("cxx") { |
| 68 | depfile = "{{output}}.d" |
| 69 | command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
| 70 | depsformat = "gcc" |
| 71 | outputs = [ |
| 72 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 73 | ] |
| 74 | } |
| 75 | |
| 76 | tool("asm") { |
| 77 | depfile = "{{output}}.d" |
| 78 | command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" |
| 79 | depsformat = "gcc" |
| 80 | outputs = [ |
| 81 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 82 | ] |
| 83 | } |
| 84 | |
| 85 | tool("alink") { |
| 86 | command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}" |
| 87 | outputs = [ |
| 88 | "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 89 | ] |
| 90 | default_output_extension = ".a" |
| 91 | output_prefix = "lib" |
| 92 | } |
| 93 | |
| 94 | tool("solink") { |
| 95 | soname = "{{target_output_name}}{{output_extension}}" |
| 96 | |
| 97 | rpath = "-Wl,-soname,$soname" |
| 98 | if (is_mac) { |
| 99 | rpath = "-Wl,-install_name,@rpath/$soname" |
| 100 | } |
| 101 | |
| 102 | command = "$cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}" |
| 103 | outputs = [ |
| 104 | "{{root_out_dir}}/$soname", |
| 105 | ] |
| 106 | output_prefix = "lib" |
| 107 | default_output_extension = ".so" |
| 108 | } |
| 109 | |
| 110 | tool("link") { |
| 111 | command = "$cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}" |
| 112 | outputs = [ |
| 113 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 114 | ] |
| 115 | } |
| 116 | |
| 117 | tool("stamp") { |
| 118 | command = "touch {{output}}" |
| 119 | } |
| 120 | |
| 121 | tool("copy") { |
| 122 | command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" |
| 123 | } |
| 124 | } |