         throw "unknown template type: #{input.type}"
 
   generateTargets: ->
+    groupSubs = {}
+    for rule in @rootMist.rules
+      for input in rule.src.inputs
+        if input.type is 'group'
+          (groupSubs[input.value] = groupSubs[input.value] || []).push rule
+
     for rule in @rootMist.rules
       for input in rule.src.inputs
         switch input.type
           when 'glob'
             results = Globber.performGlob input.value, @rootDir
             for result in results
-              @processInput rule, result
+              @processInput rule, result, null, groupSubs
           when 'group' then break
           else
             throw "unknown input type: #{input.type}"
 
-  processInput: (rule, input, group)->
+  processInput: (rule, input, group, groupSubs = {})->
     return if input of rule.targets
 
     processor = (fn)->

      rule.targets = {}

  emitGroupOutput: (group, output)->
    console.log "\x1b[31m", group, output, "\x1b[0m"
    (@groupRefs[group] = @groupRefs[group] || []).push output
    console.log "\x1b[33m", @groupRefs, "\x1b[0m"

  ###
  # Generates templates for dependencies and outputs

      outputs: rule.templates.outputs.map processor
      auxOutputs: rule.templates.auxOutputs.map processor

    for k, a of rule.targets[input]
      rule.targets[input][k] = a.flatten()

    for group in rule.src.groups
      for output in rule.targets[input].outputs
        (@groupRefs[group] = @groupRefs[group] || []).push output
        if group of groupSubs
          for rule in groupSubs[group]
            @processInput rule, output, group, groupSubs

###
# Make sure to always include `$1` in the replacement
