title: GNU Make get the list of all files in a directory that were generated by previous rule
body: <p>I am looking for Makefile macro to get list of all files in a directory that were generated as rule1 processing and using this list for rule2 processing. </p>
  
  <p>Here's what I am trying to achieve :</p>
  
  <ul>
  <li>Rule 1: Generate source <code>.c</code> files (using xml files) and place them in <code>$(MYDIR)</code> directory.</li>
  <li>Rule 2: Get the list of all files in <code>$(MYDIR)</code> and create object files and place them in <code>$(OBJDIR)</code>.</li>
  </ul>
  
  <p>Problem is, I want to update list of files in Rule2 after Rule 1 has been processed, else list of files in <code>$(MYDIR)</code> will be empty.</p>
  
  <pre><code>all : rule_1 rule_2
  
  rule1 : $(MYDIR)/generated_source1.c $(MYDIR)/generated_source2.c
  
  $(MYDIR)/generated_source1.c:
      xsltproc generator1.xml style_generator.xsl -o $(MYDIR)/generated_source_1.c
  
  $(MYDIR)/generated_source2.c:
      xsltproc generator2.xml style_generator.xsl -o $(MYDIR)generated_source_2.c
  
  #Get list of all $(MYDIR).*c , create corresponding $(OBJDIR)/*.o list.
  SOURCES := $(wildcard $(MYDIR)/*.c)
  OBJECTS := $(notdir ${SOURCES})
  GENERATED_OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(OBJECTS))
  
  #This rule is compiling of all .c generated in rule1.
  rule2 : $(GENERATED_OBJS)
      ld -r -o $(OBJDIR)/generated_lib.o $(GENERATED_OBJS)
  
  $(OBJDIR)/%.o: $(MYDIR)/%.c
          gcc $(CFLAGS) -c -o $@ $&lt;
  </code></pre>
  
  <p><code>$(SOURCES)</code> is shown empty, but actually it should contain <code>generated_source1.c</code> and <code>generated_source2.c</code>
  I am not sure how <code>.SECONDEXPANSION</code> rule will work for my case. </p>