parameters: (rules, output_dir, spec, sources, options, actions_to_add)
docstring: Generate an external makefile to do a set of rules.
  
    Arguments:
      rules: the list of rules to include
      output_dir: path containing project and gyp files
      spec: project specification data
      sources: set of sources known
      options: global generator options
      actions_to_add: The list of actions we will add to.
docstring_summary: Generate an external makefile to do a set of rules.
docstring_tokens: Generate an external makefile to do a set of rules .
function: def _GenerateExternalRules(rules, output_dir, spec, sources, options, actions_to_add):
      """Generate an external makefile to do a set of rules.
  
    Arguments:
      rules: the list of rules to include
      output_dir: path containing project and gyp files
      spec: project specification data
      sources: set of sources known
      options: global generator options
      actions_to_add: The list of actions we will add to.
    """
      filename = "{}_rules{}.mk".format(spec["target_name"], options.suffix)
      mk_file = gyp.common.WriteOnDiff(os.path.join(output_dir, filename))
      # Find cygwin style versions of some paths.
      mk_file.write('OutDirCygwin:=$(shell cygpath -u "$(OutDir)")\n')
      mk_file.write('IntDirCygwin:=$(shell cygpath -u "$(IntDir)")\n')
      # Gather stuff needed to emit all: target.
      all_inputs = OrderedSet()
      all_outputs = OrderedSet()
      all_output_dirs = OrderedSet()
      first_outputs = []
      for rule in rules:
          trigger_files = _FindRuleTriggerFiles(rule, sources)
          for tf in trigger_files:
              inputs, outputs = _RuleInputsAndOutputs(rule, tf)
              all_inputs.update(OrderedSet(inputs))
              all_outputs.update(OrderedSet(outputs))
              # Only use one target from each rule as the dependency for
              # 'all' so we don't try to build each rule multiple times.
              first_outputs.append(list(outputs)[0])
              # Get the unique output directories for this rule.
              output_dirs = [os.path.split(i)[0] for i in outputs]
              for od in output_dirs:
                  all_output_dirs.add(od)
      first_outputs_cyg = [_Cygwinify(i) for i in first_outputs]
      # Write out all: target, including mkdir for each output directory.
      mk_file.write("all: %s\n" % " ".join(first_outputs_cyg))
      for od in all_output_dirs:
          if od:
              mk_file.write('\tmkdir -p `cygpath -u "%s"`\n' % od)
      mk_file.write("\n")
      # Define how each output is generated.
      for rule in rules:
          trigger_files = _FindRuleTriggerFiles(rule, sources)
          for tf in trigger_files:
              # Get all the inputs and outputs for this rule for this trigger file.
              inputs, outputs = _RuleInputsAndOutputs(rule, tf)
              inputs = [_Cygwinify(i) for i in inputs]
              outputs = [_Cygwinify(i) for i in outputs]
              # Prepare the command line for this rule.
              cmd = [_RuleExpandPath(c, tf) for c in rule["action"]]
              cmd = ['"%s"' % i for i in cmd]
              cmd = " ".join(cmd)
              # Add it to the makefile.
              mk_file.write("{}: {}\n".format(" ".join(outputs), " ".join(inputs)))
              mk_file.write("\t%s\n\n" % cmd)
      # Close up the file.
      mk_file.close()
  
      # Add makefile to list of sources.
      sources.add(filename)
      # Add a build action to call makefile.
      cmd = [
          "make",
          "OutDir=$(OutDir)",
          "IntDir=$(IntDir)",
          "-j",
          "${NUMBER_OF_PROCESSORS_PLUS_1}",
          "-f",
          filename,
      ]
      cmd = _BuildCommandLineForRuleRaw(spec, cmd, True, False, True, True)
      # Insert makefile as 0'th input, so it gets the action attached there,
      # as this is easier to understand from in the IDE.
      all_inputs = list(all_inputs)
      all_inputs.insert(0, filename)
      _AddActionStep(
          actions_to_add,
          inputs=_FixPaths(all_inputs),
          outputs=_FixPaths(all_outputs),
          description="Running external rules for %s" % spec["target_name"],
          command=cmd,
      )
function_tokens: def _GenerateExternalRules ( rules , output_dir , spec , sources , options , actions_to_add ) : filename = "{}_rules{}.mk" . format ( spec [ "target_name" ] , options . suffix ) mk_file = gyp . common . WriteOnDiff ( os . path . join ( output_dir , filename ) ) # Find cygwin style versions of some paths. mk_file . write ( 'OutDirCygwin:=$(shell cygpath -u "$(OutDir)")\n' ) mk_file . write ( 'IntDirCygwin:=$(shell cygpath -u "$(IntDir)")\n' ) # Gather stuff needed to emit all: target. all_inputs = OrderedSet ( ) all_outputs = OrderedSet ( ) all_output_dirs = OrderedSet ( ) first_outputs = [ ] for rule in rules : trigger_files = _FindRuleTriggerFiles ( rule , sources ) for tf in trigger_files : inputs , outputs = _RuleInputsAndOutputs ( rule , tf ) all_inputs . update ( OrderedSet ( inputs ) ) all_outputs . update ( OrderedSet ( outputs ) ) # Only use one target from each rule as the dependency for # 'all' so we don't try to build each rule multiple times. first_outputs . append ( list ( outputs ) [ 0 ] ) # Get the unique output directories for this rule. output_dirs = [ os . path . split ( i ) [ 0 ] for i in outputs ] for od in output_dirs : all_output_dirs . add ( od ) first_outputs_cyg = [ _Cygwinify ( i ) for i in first_outputs ] # Write out all: target, including mkdir for each output directory. mk_file . write ( "all: %s\n" % " " . join ( first_outputs_cyg ) ) for od in all_output_dirs : if od : mk_file . write ( '\tmkdir -p `cygpath -u "%s"`\n' % od ) mk_file . write ( "\n" ) # Define how each output is generated. for rule in rules : trigger_files = _FindRuleTriggerFiles ( rule , sources ) for tf in trigger_files : # Get all the inputs and outputs for this rule for this trigger file. inputs , outputs = _RuleInputsAndOutputs ( rule , tf ) inputs = [ _Cygwinify ( i ) for i in inputs ] outputs = [ _Cygwinify ( i ) for i in outputs ] # Prepare the command line for this rule. cmd = [ _RuleExpandPath ( c , tf ) for c in rule [ "action" ] ] cmd = [ '"%s"' % i for i in cmd ] cmd = " " . join ( cmd ) # Add it to the makefile. mk_file . write ( "{}: {}\n" . format ( " " . join ( outputs ) , " " . join ( inputs ) ) ) mk_file . write ( "\t%s\n\n" % cmd ) # Close up the file. mk_file . close ( ) # Add makefile to list of sources. sources . add ( filename ) # Add a build action to call makefile. cmd = [ "make" , "OutDir=$(OutDir)" , "IntDir=$(IntDir)" , "-j" , "${NUMBER_OF_PROCESSORS_PLUS_1}" , "-f" , filename , ] cmd = _BuildCommandLineForRuleRaw ( spec , cmd , True , False , True , True ) # Insert makefile as 0'th input, so it gets the action attached there, # as this is easier to understand from in the IDE. all_inputs = list ( all_inputs ) all_inputs . insert ( 0 , filename ) _AddActionStep ( actions_to_add , inputs = _FixPaths ( all_inputs ) , outputs = _FixPaths ( all_outputs ) , description = "Running external rules for %s" % spec [ "target_name" ] , command = cmd , )