title: Compile file only if specific subdir changes with GNU Make
body: <p>I have a set of files in a structure like this:</p>
  <pre><code>-src
     -SubDir1
       -file1.c
       -file2.h
      -file3.c
     -SubDir2
       -file1.c
      -file2.c
     -SubDir3
       -file1.c
      -file2.c
  -outDir
  
  </code></pre>
  <p>I compile the files from each subdir with a script that generates a custom output file (.out). I have created a makefile that produces the .out file for each Subdir when any .c file changes in any subdir. The problem is that this will compile all the subdir, as I have created a rule that makes the .out files depend on all the .c files.</p>
  <p>Is there a clever way to create a custom rule that makes each .out file only depend on the files of each subdir? Also the .out file should be in a new directory. Below you will find the makefile I have created</p>
  <pre><code>#Recursive wild card for all the subdirs
  rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
  
  SRCS_DIR=src
  SRCS_SUBDIRS= $(wildcard $(SRCS_DIR)/*/)
  FILES := $(call rwildcard,$(SRCS_DIR)/,*)
  
  #Get each subdir name 
  SUBDIRS_NAMES=$(subst $(SRCS_DIR)/,,$(SRCS_SUBDIRS)) 
  
  #Output file has the name of each subdir with .out extension
  OUTPUT_FILES=$(subst /,.out,$(SUBDIRS_NAMES))
  
  Process_Outputs: $(OUTPUT_FILES)
      CustomProcess $@
      
  /outDir/$(OUTPUT_FILES):$(FILES)
      myCustomScript $@
  </code></pre>