title: Makefile: Reading/splitting an array
body: <p>Say you had the following directory structure:</p>
  
  <pre><code># directory structure
  ├── GIT-REPO
  │   ├── dev
  │   ├── production
  │   ├── mgmt
  </code></pre>
  
  <p>I'm looking for a way in a Makefile to find the environment based on what directory it is living in.  I found a way to do this in bash with the following:</p>
  
  <pre><code>DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &amp;&amp; pwd)"                                                                    
  IFS='/' read -r -a DIR_ARRAY &lt;&lt;&lt; "$DIR"                                                                         
  GIT_REPO=some-repo                                                                                            
  
  for ((i=0; i &lt; ${#DIR_ARRAY[@]}; i++)) do                                                                            
      if [ "${DIR_ARRAY[$i]}" = "$GIT_REPO" ] ; then                                                                   
          echo ${DIR_ARRAY[$i+1]}                                                                                      
      fi                                                                                                               
  done
  </code></pre>
  
  <p>But I'm having a hard time translating this into a Makefile.  Each of these environment directories will have a Makefile as well as subdirectories.  I want to be able to dynamically look up what environment it is under by finding the name of the directory to the right of the $GIT_REPO directory.</p>