Home | History | Annotate | Download | only in gn
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "tools/gn/variables.h"
      6 
      7 namespace variables {
      8 
      9 // Built-in variables ----------------------------------------------------------
     10 
     11 const char kComponentMode[] = "component_mode";
     12 const char kComponentMode_HelpShort[] =
     13     "component_mode: [string] Specifies the meaning of the component() call.";
     14 const char kComponentMode_Help[] =
     15     "component_mode: Specifies the meaning of the component() call.\n"
     16     "\n"
     17     "  This value is looked up whenever a \"component\" target type is\n"
     18     "  encountered. The value controls whether the given target is a shared\n"
     19     "  or a static library.\n"
     20     "\n"
     21     "  The initial value will be empty, which will cause a call to\n"
     22     "  component() to throw an error. Typically this value will be set in the\n"
     23     "  build config script.\n"
     24     "\n"
     25     "Possible values:\n"
     26     "  - \"shared_library\"\n"
     27     "  - \"source_set\"\n"
     28     "  - \"static_library\"\n";
     29 
     30 const char kCpuArch[] = "cpu_arch";
     31 const char kCpuArch_HelpShort[] =
     32     "cpu_arch: [string] Current processor architecture.";
     33 const char kCpuArch_Help[] =
     34     "cpu_arch: Current processor architecture.\n"
     35     "\n"
     36     "  The initial value is based on the current architecture of the host\n"
     37     "  system. However, the build configuration can set this to any value.\n"
     38     "\n"
     39     "  This value is not used internally by GN for any purpose, so you can\n"
     40     "  set it to whatever value is relevant to your build.\n"
     41     "\n"
     42     "Possible initial values set by GN:\n"
     43     "  - \"x86\"\n"
     44     "  - \"x64\"\n"
     45     "  - \"arm\"\n";
     46 
     47 const char kCurrentToolchain[] = "current_toolchain";
     48 const char kCurrentToolchain_HelpShort[] =
     49     "current_toolchain: [string] Label of the current toolchain.";
     50 const char kCurrentToolchain_Help[] =
     51     "current_toolchain: Label of the current toolchain.\n"
     52     "\n"
     53     "  A fully-qualified label representing the current toolchain. You can\n"
     54     "  use this to make toolchain-related decisions in the build. See also\n"
     55     "  \"default_toolchain\".\n"
     56     "\n"
     57     "Example:\n"
     58     "\n"
     59     "  if (current_toolchain == \"//build:64_bit_toolchain\") {\n"
     60     "    executable(\"output_thats_64_bit_only\") {\n"
     61     "      ...\n";
     62 
     63 const char kBuildCpuArch[] = "build_cpu_arch";
     64 const char kBuildCpuArch_HelpShort[] =
     65     "build_cpu_arch: [string] The default value for the \"cpu_arch\" "
     66     "variable.";
     67 const char kBuildCpuArch_Help[] =
     68     "build_cpu_arch: The default value for the \"cpu_arch\" variable.\n"
     69     "\n"
     70     "  This value has the same definition as \"cpu_arch\" (see\n"
     71     "  \"gn help cpu_arch\") but should be treated as read-only. This is so\n"
     72     "  the build can override the \"cpu_arch\" variable for doing\n"
     73     "  cross-compiles, but can still access the host build system's CPU\n"
     74     "  architecture.\n";
     75 
     76 const char kBuildOs[] = "build_os";
     77 const char kBuildOs_HelpShort[] =
     78     "build_os: [string] The default value for the \"os\" variable.";
     79 const char kBuildOs_Help[] =
     80     "build_os: [string] The default value for the \"os\" variable.\n"
     81     "\n"
     82     "  This value has the same definition as \"os\" (see \"gn help os\") but\n"
     83     "  should be treated as read-only. This is so the build can override\n"
     84     "  the \"os\" variable for doing cross-compiles, but can still access\n"
     85     "  the host build system's operating system type.\n";
     86 
     87 const char kDefaultToolchain[] = "default_toolchain";
     88 const char kDefaultToolchain_HelpShort[] =
     89     "default_toolchain: [string] Label of the default toolchain.";
     90 const char kDefaultToolchain_Help[] =
     91     "default_toolchain: [string] Label of the default toolchain.\n"
     92     "\n"
     93     "  A fully-qualified label representing the default toolchain, which may\n"
     94     "  not necessarily be the current one (see \"current_toolchain\").\n";
     95 
     96 const char kOs[] = "os";
     97 const char kOs_HelpShort[] =
     98     "os: [string] Indicates the operating system of the current build.";
     99 const char kOs_Help[] =
    100     "os: Indicates the operating system of the current build."
    101     "\n"
    102     "  This value is set by default based on the current host operating\n"
    103     "  system. The build configuration can override the value to anything\n"
    104     "  it wants, or it can be set via the build arguments on the command\n"
    105     "  line.\n"
    106     "\n"
    107     "  If you want to know the default value without any overrides, you can\n"
    108     "  use \"default_os\" (see \"gn help default_os\").\n"
    109     "\n"
    110     "  Note that this returns the most specific value. So even though\n"
    111     "  Android and ChromeOS are both Linux, the more specific value will\n"
    112     "  be returned.\n"
    113     "\n"
    114     "Some possible values:\n"
    115     "  - \"amiga\"\n"
    116     "  - \"android\"\n"
    117     "  - \"chromeos\"\n"
    118     "  - \"ios\"\n"
    119     "  - \"linux\"\n"
    120     "  - \"mac\"\n"
    121     "  - \"win\"\n";
    122 
    123 const char kPythonPath[] = "python_path";
    124 const char kPythonPath_HelpShort[] =
    125     "python_path: [string] Absolute path of Python.";
    126 const char kPythonPath_Help[] =
    127     "python_path: Absolute path of Python.\n"
    128     "\n"
    129     "  Normally used in toolchain definitions if running some command\n"
    130     "  requires Python. You will normally not need this when invoking scripts\n"
    131     "  since GN automatically finds it for you.\n";
    132 
    133 const char kRootBuildDir[] = "root_build_dir";
    134 const char kRootBuildDir_HelpShort[] =
    135   "root_build_dir: [string] Directory where build commands are run.";
    136 const char kRootBuildDir_Help[] =
    137   "root_build_dir: [string] Directory where build commands are run.\n"
    138   "\n"
    139   "  This is the root build output directory which will be the current\n"
    140   "  directory when executing all compilers and scripts.\n"
    141   "\n"
    142   "  Most often this is used with rebase_path (see \"gn help rebase_path\")\n"
    143   "  to convert arguments to be relative to a script's current directory.\n";
    144 
    145 const char kRootGenDir[] = "root_gen_dir";
    146 const char kRootGenDir_HelpShort[] =
    147     "root_gen_dir: [string] Directory for the toolchain's generated files.";
    148 const char kRootGenDir_Help[] =
    149     "root_gen_dir: Directory for the toolchain's generated files.\n"
    150     "\n"
    151     "  Absolute path to the root of the generated output directory tree for\n"
    152     "  the current toolchain. An example value might be \"//out/Debug/gen\".\n"
    153     "  It will not have a trailing slash.\n"
    154     "\n"
    155     "  This is primarily useful for setting up include paths for generated\n"
    156     "  files. If you are passing this to a script, you will want to pass it\n"
    157     "  through to_build_path() (see \"gn help to_build_path\") to convert it\n"
    158     "  to be relative to the build directory.\n"
    159     "\n"
    160     "  See also \"target_gen_dir\" which is usually a better location for\n"
    161     "  generated files. It will be inside the root generated dir.\n";
    162 
    163 const char kRootOutDir[] = "root_out_dir";
    164 const char kRootOutDir_HelpShort[] =
    165     "root_out_dir: [string] Root directory for toolchain output files.";
    166 const char kRootOutDir_Help[] =
    167     "root_out_dir: [string] Root directory for toolchain output files.\n"
    168     "\n"
    169     "  Absolute path to the root of the output directory tree for the current\n"
    170     "  toolchain. An example value might be \"//out/Debug/gen\". It will not\n"
    171     "  have a trailing slash.\n"
    172     "\n"
    173     "  This is primarily useful for setting up script calls. If you are\n"
    174     "  passing this to a script, you will want to pass it through\n"
    175     "  to_build_path() (see \"gn help to_build_path\") to convert it\n"
    176     "  to be relative to the build directory.\n"
    177     "\n"
    178     "  See also \"target_out_dir\" which is usually a better location for\n"
    179     "  output files. It will be inside the root output dir.\n"
    180     "\n"
    181     "Example:\n"
    182     "\n"
    183     "  custom(\"myscript\") {\n"
    184     "    # Pass the output dir to the script.\n"
    185     "    args = [ \"-o\", to_build_path(root_out_dir) ]\n"
    186     "  }\n";
    187 
    188 const char kTargetGenDir[] = "target_gen_dir";
    189 const char kTargetGenDir_HelpShort[] =
    190     "target_gen_dir: [string] Directory for a target's generated files.";
    191 const char kTargetGenDir_Help[] =
    192     "target_gen_dir: Directory for a target's generated files.\n"
    193     "\n"
    194     "  Absolute path to the target's generated file directory. If your\n"
    195     "  current target is in \"//tools/doom_melon\" then this value might be\n"
    196     "  \"//out/Debug/gen/tools/doom_melon\". It will not have a trailing\n"
    197     "  slash.\n"
    198     "\n"
    199     "  This is primarily useful for setting up include paths for generated\n"
    200     "  files. If you are passing this to a script, you will want to pass it\n"
    201     "  through to_build_path() (see \"gn help to_build_path\") to convert it\n"
    202     "  to be relative to the build directory.\n"
    203     "\n"
    204     "  See also \"gn help root_gen_dir\".\n"
    205     "\n"
    206     "Example:\n"
    207     "\n"
    208     "  custom(\"myscript\") {\n"
    209     "    # Pass the generated output dir to the script.\n"
    210     "    args = [ \"-o\", to_build_path(target_gen_dir) ]\n"
    211     "  }\n";
    212 
    213 const char kTargetOutDir[] = "target_out_dir";
    214 const char kTargetOutDir_HelpShort[] =
    215     "target_out_dir: [string] Directory for target output files.";
    216 const char kTargetOutDir_Help[] =
    217     "target_out_dir: [string] Directory for target output files."
    218     "\n"
    219     "  Absolute path to the target's generated file directory. If your\n"
    220     "  current target is in \"//tools/doom_melon\" then this value might be\n"
    221     "  \"//out/Debug/obj/tools/doom_melon\". It will not have a trailing\n"
    222     "  slash.\n"
    223     "\n"
    224     "  This is primarily useful for setting up arguments for calling\n"
    225     "  scripts. If you are passing this to a script, you will want to pass it\n"
    226     "  through to_build_path() (see \"gn help to_build_path\") to convert it\n"
    227     "  to be relative to the build directory.\n"
    228     "\n"
    229     "  See also \"gn help root_out_dir\".\n"
    230     "\n"
    231     "Example:\n"
    232     "\n"
    233     "  custom(\"myscript\") {\n"
    234     "    # Pass the output dir to the script.\n"
    235     "    args = [ \"-o\", to_build_path(target_out_dir) ]\n"
    236     "  }\n";
    237 
    238 // Target variables ------------------------------------------------------------
    239 
    240 const char kAllDependentConfigs[] = "all_dependent_configs";
    241 const char kAllDependentConfigs_HelpShort[] =
    242     "all_dependent_configs: [label list] Configs to be forced on dependents.";
    243 const char kAllDependentConfigs_Help[] =
    244     "all_dependent_configs: Configs to be forced on dependents.\n"
    245     "\n"
    246     "  A list of config labels.\n"
    247     "\n"
    248     "  All targets depending on this one, and recursively, all targets\n"
    249     "  depending on those, will have the configs listed in this variable\n"
    250     "  added to them. These configs will also apply to the current target.\n"
    251     "\n"
    252     "  This addition happens in a second phase once a target and all of its\n"
    253     "  dependencies have been resolved. Therefore, a target will not see\n"
    254     "  these force-added configs in their \"configs\" variable while the\n"
    255     "  script is running, and then can not be removed. As a result, this\n"
    256     "  capability should generally only be used to add defines and include\n"
    257     "  directories necessary to compile a target's headers.\n"
    258     "\n"
    259     "  See also \"direct_dependent_configs\".\n";
    260 
    261 const char kArgs[] = "args";
    262 const char kArgs_HelpShort[] =
    263     "args: [string list] Arguments passed to a custom script.";
    264 const char kArgs_Help[] =
    265     "args: Arguments passed to a custom script.\n"
    266     "\n"
    267     "  For custom script targets, args is the list of arguments to pass\n"
    268     "  to the script. Typically you would use source expansion (see\n"
    269     "  \"gn help source_expansion\") to insert the source file names.\n"
    270     "\n"
    271     "  See also \"gn help custom\".\n";
    272 
    273 const char kCflags[] = "cflags";
    274 const char kCflags_HelpShort[] =
    275     "cflags: [string list] Flags passed to all C compiler variants.";
    276 // Avoid writing long help for each variant.
    277 #define COMMON_FLAGS_HELP \
    278     "\n"\
    279     "  Flags are never quoted. If your flag includes a string that must be\n"\
    280     "  quoted, you must do it yourself. This also means that you can\n"\
    281     "  specify more than one flag in a string if necessary (\"--foo --bar\")\n"\
    282     "  and have them be seen as separate by the tool.\n"
    283 const char kCommonCflagsHelp[] =
    284     "cflags*: Flags passed to the C compiler.\n"
    285     "\n"
    286     "  A list of strings.\n"
    287     "\n"
    288     "  \"cflags\" are passed to all invocations of the C, C++, Objective C,\n"
    289     "  and Objective C++ compilers.\n"
    290     "\n"
    291     "  To target one of these variants individually, use \"cflags_c\",\n"
    292     "  \"cflags_cc\", \"cflags_objc\", and \"cflags_objcc\", respectively.\n"
    293     "  These variant-specific versions will be appended to the \"cflags\".\n"
    294     COMMON_FLAGS_HELP;
    295 const char* kCflags_Help = kCommonCflagsHelp;
    296 
    297 const char kCflagsC[] = "cflags_c";
    298 const char kCflagsC_HelpShort[] =
    299     "cflags_c: [string list] Flags passed to the C compiler.";
    300 const char* kCflagsC_Help = kCommonCflagsHelp;
    301 
    302 const char kCflagsCC[] = "cflags_cc";
    303 const char kCflagsCC_HelpShort[] =
    304     "cflags_cc: [string list] Flags passed to the C++ compiler.";
    305 const char* kCflagsCC_Help = kCommonCflagsHelp;
    306 
    307 const char kCflagsObjC[] = "cflags_objc";
    308 const char kCflagsObjC_HelpShort[] =
    309     "cflags_objc: [string list] Flags passed to the Objective C compiler.";
    310 const char* kCflagsObjC_Help = kCommonCflagsHelp;
    311 
    312 const char kCflagsObjCC[] = "cflags_objcc";
    313 const char kCflagsObjCC_HelpShort[] =
    314     "cflags_objcc: [string list] Flags passed to the Objective C++ compiler.";
    315 const char* kCflagsObjCC_Help = kCommonCflagsHelp;
    316 
    317 const char kConfigs[] = "configs";
    318 const char kConfigs_HelpShort[] =
    319     "configs: [label list] Configs applying to this target.";
    320 const char kConfigs_Help[] =
    321     "configs: Configs applying to this target.\n"
    322     "\n"
    323     "  A list of config labels.\n"
    324     "\n"
    325     "  The include_dirs, defines, etc. in each config are appended in the\n"
    326     "  order they appear to the compile command for each file in the target.\n"
    327     "  They will appear after the include_dirs, defines, etc. that the target\n"
    328     "  sets directly.\n"
    329     "\n"
    330     "  The build configuration script will generally set up the default\n"
    331     "  configs applying to a given target type (see \"set_defaults\").\n"
    332     "  When a target is being defined, it can add to or remove from this\n"
    333     "  list.\n"
    334     "\n"
    335     "Example:\n"
    336     "  static_library(\"foo\") {\n"
    337     "    configs -= \"//build:no_rtti\"  # Don't use the default RTTI config.\n"
    338     "    configs += \":mysettings\"      # Add some of our own settings.\n"
    339     "  }\n";
    340 
    341 const char kData[] = "data";
    342 const char kData_HelpShort[] =
    343     "data: [file list] Runtime data file dependencies.";
    344 const char kData_Help[] =
    345     "data: Runtime data file dependencies.\n"
    346     "\n"
    347     "  Lists files required to run the given target. These are typically\n"
    348     "  data files.\n"
    349     "\n"
    350     "  Appearing in the \"data\" section does not imply any special handling\n"
    351     "  such as copying them to the output directory. This is just used for\n"
    352     "  declaring runtime dependencies. There currently isn't a good use for\n"
    353     "  these but it is envisioned that test data can be listed here for use\n"
    354     "  running automated tests.\n"
    355     "\n"
    356     "  See also \"gn help source_prereqs\" and \"gn help datadeps\", both of\n"
    357     "  which actually affect the build in concrete ways.\n";
    358 
    359 const char kDatadeps[] = "datadeps";
    360 const char kDatadeps_HelpShort[] =
    361     "datadeps: [label list] Non-linked dependencies.";
    362 const char kDatadeps_Help[] =
    363     "datadeps: Non-linked dependencies.\n"
    364     "\n"
    365     "  A list of target labels.\n"
    366     "\n"
    367     "  Specifies dependencies of a target that are not actually linked into\n"
    368     "  the current target. Such dependencies will built and will be available\n"
    369     "  at runtime.\n"
    370     "\n"
    371     "  This is normally used for things like plugins or helper programs that\n"
    372     "  a target needs at runtime.\n"
    373     "\n"
    374     "  See also \"gn help deps\" and \"gn help data\".\n"
    375     "\n"
    376     "Example:\n"
    377     "  executable(\"foo\") {\n"
    378     "    deps = [ \"//base\" ]\n"
    379     "    datadeps = [ \"//plugins:my_runtime_plugin\" ]\n"
    380     "  }\n";
    381 
    382 const char kDefines[] = "defines";
    383 const char kDefines_HelpShort[] =
    384     "defines: [string list] C preprocessor defines.";
    385 const char kDefines_Help[] =
    386     "defines: C preprocessor defines.\n"
    387     "\n"
    388     "  A list of strings\n"
    389     "\n"
    390     "  These strings will be passed to the C/C++ compiler as #defines. The\n"
    391     "  strings may or may not include an \"=\" to assign a value.\n"
    392     "\n"
    393     "Example:\n"
    394     "  defines = [ \"AWESOME_FEATURE\", \"LOG_LEVEL=3\" ]\n";
    395 
    396 const char kDepfile[] = "depfile";
    397 const char kDepfile_HelpShort[] =
    398     "depfile: [string] File name for input dependencies for custom targets.";
    399 const char kDepfile_Help[] =
    400     "depfile: [string] File name for input dependencies for custom targets.\n"
    401     "\n"
    402     "  If nonempty, this string specifies that the current \"custom\" target\n"
    403     "  will generate the given \".d\" file containing the dependencies of the\n"
    404     "  input. Empty or unset means that the script doesn't generate the\n"
    405     "  files.\n"
    406     "\n"
    407     "  The .d file should go in the target output directory. If you have more\n"
    408     "  than one source file that the script is being run over, you can use\n"
    409     "  the output file expansions described in \"gn help custom\" to name the\n"
    410     "  .d file according to the input."
    411     "\n"
    412     "  The format is that of a Makefile, and all of the paths should be\n"
    413     "  relative to the root build directory.\n"
    414     "\n"
    415     "Example:\n"
    416     "  custom(\"myscript_target\") {\n"
    417     "    script = \"myscript.py\"\n"
    418     "    sources = [ ... ]\n"
    419     "\n"
    420     "    # Locate the depfile in the output directory named like the\n"
    421     "    # inputs but with a \".d\" appended.\n"
    422     "    depfile = \"$relative_target_output_dir/{{source_name}}.d\"\n"
    423     "\n"
    424     "    # Say our script uses \"-o <d file>\" to indicate the depfile.\n"
    425     "    args = [ \"{{source}}\", \"-o\", depfile ]\n"
    426     "  }\n";
    427 
    428 const char kDeps[] = "deps";
    429 const char kDeps_HelpShort[] =
    430     "deps: [label list] Linked dependencies.";
    431 const char kDeps_Help[] =
    432     "deps: Linked dependencies.\n"
    433     "\n"
    434     "  A list of target labels.\n"
    435     "\n"
    436     "  Specifies dependencies of a target. Shared and dynamic libraries will\n"
    437     "  be linked into the current target. Other target types that can't be\n"
    438     "  linked (like custom scripts and groups) listed in \"deps\" will be\n"
    439     "  treated as \"datadeps\". Likewise, if the current target isn't\n"
    440     "  linkable, then all deps will be treated as \"datadeps\".\n"
    441     "\n"
    442     "  See also \"datadeps\".\n";
    443 
    444 const char kDirectDependentConfigs[] = "direct_dependent_configs";
    445 const char kDirectDependentConfigs_HelpShort[] =
    446     "direct_dependent_configs: [label list] Configs to be forced on "
    447     "dependents.";
    448 const char kDirectDependentConfigs_Help[] =
    449     "direct_dependent_configs: Configs to be forced on dependents.\n"
    450     "\n"
    451     "  A list of config labels.\n"
    452     "\n"
    453     "  Targets directly referencing this one will have the configs listed in\n"
    454     "  this variable added to them. These configs will also apply to the\n"
    455     "  current target.\n"
    456     "\n"
    457     "  This addition happens in a second phase once a target and all of its\n"
    458     "  dependencies have been resolved. Therefore, a target will not see\n"
    459     "  these force-added configs in their \"configs\" variable while the\n"
    460     "  script is running, and then can not be removed. As a result, this\n"
    461     "  capability should generally only be used to add defines and include\n"
    462     "  directories necessary to compile a target's headers.\n"
    463     "\n"
    464     "  See also \"all_dependent_configs\".\n";
    465 
    466 const char kExternal[] = "external";
    467 const char kExternal_HelpShort[] =
    468     "external: [boolean] Declares a target as externally generated.";
    469 const char kExternal_Help[] =
    470     "external: Declares a target as externally generated.\n"
    471     "\n"
    472     "  External targets are treated like normal targets as far as dependent\n"
    473     "  targets are concerned, but do not actually have their .ninja file\n"
    474     "  written to disk. This allows them to be generated by an external\n"
    475     "  program (e.g. GYP).\n"
    476     "\n"
    477     "  See also \"gn help gyp\".\n"
    478     "\n"
    479     "Example:\n"
    480     "  static_library(\"foo\") {\n"
    481     "    external = true\n"
    482     "  }\n";
    483 
    484 const char kForwardDependentConfigsFrom[] = "forward_dependent_configs_from";
    485 const char kForwardDependentConfigsFrom_HelpShort[] =
    486     "forward_dependent_configs_from: [label list] Forward dependent's configs.";
    487 const char kForwardDependentConfigsFrom_Help[] =
    488     "forward_dependent_configs_from\n"
    489     "\n"
    490     "  A list of target labels.\n"
    491     "\n"
    492     "  Exposes the direct_dependent_configs from a dependent target as\n"
    493     "  direct_dependent_configs of the current one. Each label in this list\n"
    494     "  must also be in the deps.\n"
    495     "\n"
    496     "  Sometimes you depend on a child library that exports some necessary\n"
    497     "  configuration via direct_dependent_configs. If your target in turn\n"
    498     "  exposes the child library's headers in its public headers, it might\n"
    499     "  mean that targets that depend on you won't work: they'll be seeing the\n"
    500     "  child library's code but not the necessary configuration. This list\n"
    501     "  specifies which of your deps' direct dependent configs to expose as\n"
    502     "  your own.\n"
    503     "\n"
    504     "Examples:\n"
    505     "\n"
    506     "  If we use a given library \"a\" from our public headers:\n"
    507     "\n"
    508     "    deps = [ \":a\", \":b\", ... ]\n"
    509     "    forward_dependent_configs_from = [ \":a\" ]\n"
    510     "\n"
    511     "  This example makes a \"transparent\" target that forwards a dependency\n"
    512     "  to another:\n"
    513     "\n"
    514     "    group(\"frob\") {\n"
    515     "      if (use_system_frob) {\n"
    516     "        deps = \":system_frob\"\n"
    517     "      } else {\n"
    518     "        deps = \"//third_party/fallback_frob\"\n"
    519     "      }\n"
    520     "      forward_dependent_configs_from = deps\n"
    521     "    }\n";
    522 
    523 const char kGypFile[] = "gyp_file";
    524 const char kGypFile_HelpShort[] =
    525     "gyp_file: [file name] Name of GYP file to write to in GYP mode.";
    526 const char kGypFile_Help[] =
    527     "gyp_file: Name of GYP file to write to in GYP mode.\n"
    528     "\n"
    529     "  See \"gn help gyp\" for an overview of how this works.\n"
    530     "\n"
    531     "  Tip: If all targets in a given BUILD.gn file should go in the same\n"
    532     "  GYP file, just put gyp_file = \"foo\" at the top of the file and\n"
    533     "  the variable will be in scope for all targets.\n";
    534 
    535 const char kGypHeader[] = "gyp_header";
    536 const char kGypHeader_HelpShort[] =
    537     "gyp_header: [string] Extra stuff to prepend to GYP files.";
    538 const char kGypHeader_Help[] =
    539     "gyp_header: Extra stuff to prepend to GYP files.\n"
    540     "\n"
    541     "  A Python dictionary string. This will be inserted after the initial\n"
    542     "  \"{\" in the GYP file. It is expected this is used to define the\n"
    543     "  make_global_settings.\n"
    544     "\n"
    545     "  This string should end in a comma to keep the python dictionary syntax\n"
    546     "  valid when everything is concatenated.\n";
    547 
    548 const char kHardDep[] = "hard_dep";
    549 const char kHardDep_HelpShort[] =
    550     "hard_dep: [boolean] Indicates a target should be built before dependees.";
    551 const char kHardDep_Help[] =
    552     "hard_dep: Indicates a target should be built before dependees.\n"
    553     "\n"
    554     "  Ninja's default is to assume that targets can be compiled\n"
    555     "  independently. This breaks down for generated files that are included\n"
    556     "  in other targets because Ninja doesn't know to run the generator\n"
    557     "  before compiling the source file.\n"
    558     "\n"
    559     "  Setting \"hard_dep\" to true on a target means that no sources in\n"
    560     "  targets depending directly on this one will be compiled until this\n"
    561     "  target is complete. It will introduce a Ninja implicit dependency\n"
    562     "  from those sources to this target. This flag is not transitive so\n"
    563     "  it will only affect direct dependents, which will cause problems if\n"
    564     "  a direct dependent uses this generated file in a public header that a\n"
    565     "  third target consumes. Try not to do this.\n"
    566     "\n"
    567     "  See also \"gn help source_prereqs\" which allows you to specify the\n"
    568     "  exact generated file dependency on the target consuming it.\n"
    569     "\n"
    570     "Example:\n"
    571     "  executable(\"foo\") {\n"
    572     "    # myresource will be run before any of the sources in this target\n"
    573     "    # are compiled.\n"
    574     "    deps = [ \":myresource\" ]\n"
    575     "    ...\n"
    576     "  }\n"
    577     "\n"
    578     "  custom(\"myresource\") {\n"
    579     "    hard_dep = true\n"
    580     "    script = \"my_generator.py\"\n"
    581     "    outputs = \"$target_gen_dir/myresource.h\"\n"
    582     "  }\n";
    583 
    584 const char kIncludeDirs[] = "include_dirs";
    585 const char kIncludeDirs_HelpShort[] =
    586     "include_dirs: [directory list] Additional include directories.";
    587 const char kIncludeDirs_Help[] =
    588     "include_dirs: Additional include directories.\n"
    589     "\n"
    590     "  A list of source directories.\n"
    591     "\n"
    592     "  The directories in this list will be added to the include path for\n"
    593     "  the files in the affected target.\n"
    594     "\n"
    595     "Example:\n"
    596     "  include_dirs = [ \"src/include\", \"//third_party/foo\" ]\n";
    597 
    598 const char kLdflags[] = "ldflags";
    599 const char kLdflags_HelpShort[] =
    600     "ldflags: [string list] Flags passed to the linker.";
    601 const char kLdflags_Help[] =
    602     "ldflags: Flags passed to the linker.\n"
    603     "\n"
    604     "  A list of strings.\n"
    605     "\n"
    606     "  These flags are passed on the command-line to the linker and generally\n"
    607     "  specify various linking options. Most targets will not need these and\n"
    608     "  will use \"libs\" and \"lib_dirs\" instead.\n"
    609     COMMON_FLAGS_HELP;
    610 
    611 #define COMMON_LIB_INHERITANCE_HELP \
    612     "\n" \
    613     "  libs and lib_dirs work differently than other flags in two respects.\n" \
    614     "  First, then are inherited across static library boundaries until a\n" \
    615     "  shared library or executable target is reached. Second, they are\n" \
    616     "  uniquified so each one is only passed once (the first instance of it\n" \
    617     "  will be the one used).\n" \
    618     "\n" \
    619     "  The order that libs/lib_dirs apply is:\n" \
    620     "    1. Ones set on the target itself.\n" \
    621     "    2. Ones from the configs applying to the target.\n" \
    622     "    3. Ones from deps of the target, in order (recursively following\n" \
    623     "       these rules).\n"
    624 
    625 const char kLibDirs[] = "lib_dirs";
    626 const char kLibDirs_HelpShort[] =
    627     "lib_dirs: [directory list] Additional library directories.";
    628 const char kLibDirs_Help[] =
    629     "lib_dirs: Additional library directories.\n"
    630     "\n"
    631     "  A list of directories.\n"
    632     "\n"
    633     "  Specifies additional directories passed to the linker for searching\n"
    634     "  for the required libraries. If an item is not an absolute path, it\n"
    635     "  will be treated as being relative to the current build file.\n"
    636     COMMON_LIB_INHERITANCE_HELP
    637     "\n"
    638     "Example:\n"
    639     "  lib_dirs = [ \"/usr/lib/foo\", \"lib/doom_melon\" ]\n";
    640 
    641 const char kLibs[] = "libs";
    642 const char kLibs_HelpShort[] =
    643     "libs: [string list] Additional libraries to link.";
    644 const char kLibs_Help[] =
    645     "libs: Additional libraries to link.\n"
    646     "\n"
    647     "  A list of strings.\n"
    648     "\n"
    649     "  These files will be passed to the linker, which will generally search\n"
    650     "  the library include path. Unlike a normal list of files, they will be\n"
    651     "  passed to the linker unmodified rather than being treated as file\n"
    652     "  names relative to the current build file. Generally you would set\n"
    653     "  the \"lib_dirs\" so your library is found. If you need to specify\n"
    654     "  a path, you can use \"rebase_path\" to convert a path to be relative\n"
    655     "  to the build directory.\n"
    656     "\n"
    657     "  When constructing the linker command, the \"lib_prefix\" attribute of\n"
    658     "  the linker tool in the current toolchain will be prepended to each\n"
    659     "  library. So your BUILD file should not specify the switch prefix\n"
    660     "  (like \"-l\"). On Mac, libraries ending in \".framework\" will be\n"
    661     "  special-cased: the switch \"-framework\" will be prepended instead of\n"
    662     "  the lib_prefix, and the \".framework\" suffix will be trimmed.\n"
    663     COMMON_LIB_INHERITANCE_HELP
    664     "\n"
    665     "Examples:\n"
    666     "  On Windows:\n"
    667     "    libs = [ \"ctl3d.lib\" ]\n"
    668     "  On Linux:\n"
    669     "    libs = [ \"ld\" ]\n";
    670 
    671 const char kOutputName[] = "output_name";
    672 const char kOutputName_HelpShort[] =
    673     "output_name: [string] Name for the output file other than the default.";
    674 const char kOutputName_Help[] =
    675     "output_name: Define a name for the output file other than the default.\n"
    676     "\n"
    677     "  Normally the output name of a target will be based on the target name,\n"
    678     "  so the target \"//foo/bar:bar_unittests\" will generate an output\n"
    679     "  file such as \"bar_unittests.exe\" (using Windows as an example).\n"
    680     "\n"
    681     "  Sometimes you will want an alternate name to avoid collisions or\n"
    682     "  if the internal name isn't appropriate for public distribution.\n"
    683     "\n"
    684     "  The output name should have no extension or prefixes, these will be\n"
    685     "  added using the default system rules. For example, on Linux an output\n"
    686     "  name of \"foo\" will produce a shared library \"libfoo.so\".\n"
    687     "\n"
    688     "  This variable is valid for all binary output target types.\n"
    689     "\n"
    690     "Example:\n"
    691     "  static_library(\"doom_melon\") {\n"
    692     "    output_name = \"fluffy_bunny\"\n"
    693     "  }\n";
    694 
    695 const char kOutputs[] = "outputs";
    696 const char kOutputs_HelpShort[] =
    697     "outputs: [file list] Output files for custom script and copy targets.";
    698 const char kOutputs_Help[] =
    699     "outputs: Output files for custom script and copy targets.\n"
    700     "\n"
    701     "  Outputs is valid for \"copy\" and \"custom\" target types and\n"
    702     "  indicates the resulting files. The values may contain source\n"
    703     "  expansions to generate the output names from the sources (see\n"
    704     "  \"gn help source_expansion\").\n"
    705     "\n"
    706     "  For copy targets, the outputs is the destination for the copied\n"
    707     "  file(s). For custom script targets, the outputs should be the list of\n"
    708     "  files generated by the script.\n";
    709 
    710 const char kScript[] = "script";
    711 const char kScript_HelpShort[] =
    712     "script: [file name] Script file for custom script targets.";
    713 const char kScript_Help[] =
    714     "script: Script file for custom script targets.\n"
    715     "\n"
    716     "  An absolute or buildfile-relative file name of a Python script to run\n"
    717     "  for a custom script target (see \"gn help custom\").\n";
    718 
    719 const char kSourcePrereqs[] = "source_prereqs";
    720 const char kSourcePrereqs_HelpShort[] =
    721     "source_prereqs: [file list] Additional compile-time dependencies.";
    722 const char kSourcePrereqs_Help[] =
    723     "source_prereqs: Additional compile-time dependencies.\n"
    724     "\n"
    725     "  Inputs are compile-time dependencies of the current target. This means\n"
    726     "  that all source prerequisites must be available before compiling any\n"
    727     "  of the sources.\n"
    728     "\n"
    729     "  If one of your sources #includes a generated file, that file must be\n"
    730     "  available before that source file is compiled. For subsequent builds,\n"
    731     "  the \".d\" files will list the include dependencies of each source\n"
    732     "  and Ninja can know about that dependency to make sure it's generated\n"
    733     "  before compiling your source file. However, for the first run it's\n"
    734     "  not possible for Ninja to know about this dependency.\n"
    735     "\n"
    736     "  Source prerequisites solves this problem by declaring such\n"
    737     "  dependencies. It will introduce a Ninja \"implicit\" dependency for\n"
    738     "  each source file in the target on the listed files.\n"
    739     "\n"
    740     "  For binary targets, the files in the \"source_prereqs\" should all be\n"
    741     "  listed in the \"outputs\" section of another target. There is no\n"
    742     "  reason to declare static source files as source prerequisites since\n"
    743     "  the normal include file dependency management will handle them more\n"
    744     "  efficiently anwyay.\n"
    745     "\n"
    746     "  For custom script targets that don't generate \".d\" files, the\n"
    747     "  \"source_prereqs\" section is how you can list known compile-time\n"
    748     "  dependencies your script may have.\n"
    749     "\n"
    750     "  See also \"gn help data\" and \"gn help datadeps\" (which declare\n"
    751     "  run-time rather than compile-time dependencies), and\n"
    752     "  \"gn help hard_dep\" which allows you to declare the source dependency\n"
    753     "  on the target generating a file rather than the target consuming it.\n"
    754     "\n"
    755     "Examples:\n"
    756     "  executable(\"foo\") {\n"
    757     "    sources = [ \"foo.cc\" ]\n"
    758     "    source_prereqs = [ \"$root_gen_dir/something/generated_data.h\" ]\n"
    759     "  }\n"
    760     "\n"
    761     "  custom(\"myscript\") {\n"
    762     "    script = \"domything.py\"\n"
    763     "    source_prereqs = [ \"input.data\" ]\n"
    764     "  }\n";
    765 
    766 const char kSources[] = "sources";
    767 const char kSources_HelpShort[] =
    768     "sources: [file list] Source files for a target.";
    769 const char kSources_Help[] =
    770     "sources: Source files for a target\n"
    771     "\n"
    772     "  A list of files relative to the current buildfile.\n";
    773 
    774 // -----------------------------------------------------------------------------
    775 
    776 VariableInfo::VariableInfo()
    777     : help_short(NULL),
    778       help(NULL) {
    779 }
    780 
    781 VariableInfo::VariableInfo(const char* in_help_short, const char* in_help)
    782     : help_short(in_help_short),
    783       help(in_help) {
    784 }
    785 
    786 #define INSERT_VARIABLE(var) \
    787     info_map[k##var] = VariableInfo(k##var##_HelpShort, k##var##_Help);
    788 
    789 const VariableInfoMap& GetBuiltinVariables() {
    790   static VariableInfoMap info_map;
    791   if (info_map.empty()) {
    792     INSERT_VARIABLE(BuildCpuArch)
    793     INSERT_VARIABLE(BuildOs)
    794     INSERT_VARIABLE(CpuArch)
    795     INSERT_VARIABLE(ComponentMode)
    796     INSERT_VARIABLE(CurrentToolchain)
    797     INSERT_VARIABLE(DefaultToolchain)
    798     INSERT_VARIABLE(Os)
    799     INSERT_VARIABLE(PythonPath)
    800     INSERT_VARIABLE(RootBuildDir)
    801     INSERT_VARIABLE(RootGenDir)
    802     INSERT_VARIABLE(RootOutDir)
    803     INSERT_VARIABLE(TargetGenDir)
    804     INSERT_VARIABLE(TargetOutDir)
    805   }
    806   return info_map;
    807 }
    808 
    809 const VariableInfoMap& GetTargetVariables() {
    810   static VariableInfoMap info_map;
    811   if (info_map.empty()) {
    812     INSERT_VARIABLE(AllDependentConfigs)
    813     INSERT_VARIABLE(Args)
    814     INSERT_VARIABLE(Cflags)
    815     INSERT_VARIABLE(CflagsC)
    816     INSERT_VARIABLE(CflagsCC)
    817     INSERT_VARIABLE(CflagsObjC)
    818     INSERT_VARIABLE(CflagsObjCC)
    819     INSERT_VARIABLE(Configs)
    820     INSERT_VARIABLE(Data)
    821     INSERT_VARIABLE(Datadeps)
    822     INSERT_VARIABLE(Depfile)
    823     INSERT_VARIABLE(Deps)
    824     INSERT_VARIABLE(DirectDependentConfigs)
    825     INSERT_VARIABLE(External)
    826     INSERT_VARIABLE(ForwardDependentConfigsFrom)
    827     INSERT_VARIABLE(GypFile)
    828     INSERT_VARIABLE(HardDep)
    829     INSERT_VARIABLE(IncludeDirs)
    830     INSERT_VARIABLE(Ldflags)
    831     INSERT_VARIABLE(Libs)
    832     INSERT_VARIABLE(LibDirs)
    833     INSERT_VARIABLE(OutputName)
    834     INSERT_VARIABLE(Outputs)
    835     INSERT_VARIABLE(Script)
    836     INSERT_VARIABLE(SourcePrereqs)
    837     INSERT_VARIABLE(Sources)
    838   }
    839   return info_map;
    840 }
    841 
    842 #undef INSERT_VARIABLE
    843 
    844 }  // namespace variables
    845