aboutsummaryrefslogtreecommitdiffhomepage
path: root/gn/BUILD.gn
blob: 547f57ebea9202a5bf9dcd43457c8e07b580c42d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

declare_args() {
  ar = "ar"
  cc = "cc"
  cxx = "c++"
}

config("default") {
  cflags = [
    "-g",
    "-fstrict-aliasing",
    "-fPIC",

    "-Werror",
    "-Wall",
    "-Wextra",
    "-Winit-self",
    "-Wpointer-arith",
    "-Wsign-compare",
    "-Wvla",

    "-Wno-deprecated-declarations",
    "-Wno-unused-parameter",
  ]
  cflags_cc = [
    "-std=c++11",
    "-fno-exceptions",
    "-fno-rtti",
    "-fno-threadsafe-statics",

    "-Wnon-virtual-dtor",
  ]
}

config("release") {
  cflags = [ "-Os" ]
  defines = [ "NDEBUG" ]
}

config("executable") {
  if (is_mac) {
    ldflags = [ "-Wl,-rpath,@loader_path/." ]
  } else if (is_linux) {
    ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
  }
}

toolchain("gcc_like") {
  lib_switch = "-l"
  lib_dir_switch = "-L"

  tool("cc") {
    depfile = "{{output}}.d"
    command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
    depsformat = "gcc"
    outputs = [
      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
    ]
  }

  tool("cxx") {
    depfile = "{{output}}.d"
    command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
    depsformat = "gcc"
    outputs = [
      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
    ]
  }

  tool("asm") {
    depfile = "{{output}}.d"
    command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
    depsformat = "gcc"
    outputs = [
      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
    ]
  }

  tool("alink") {
    command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
    outputs = [
      "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
    ]
    default_output_extension = ".a"
    output_prefix = "lib"
  }

  tool("solink") {
    soname = "{{target_output_name}}{{output_extension}}"

    rpath = "-Wl,-soname,$soname"
    if (is_mac) {
      rpath = "-Wl,-install_name,@rpath/$soname"
    }

    command = "$cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
    outputs = [
      "{{root_out_dir}}/$soname",
    ]
    output_prefix = "lib"
    default_output_extension = ".so"
  }

  tool("link") {
    command = "$cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
    outputs = [
      "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
    ]
  }

  tool("stamp") {
    command = "touch {{output}}"
  }

  tool("copy") {
    command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
  }
}