using awk inside makefiles

Got bitten by this early in the morning. When using awk inside a makefile, many of awk’s built-in variables ($0..n, $NF, $FS, etc) disappear because make substitutes the dollar sign and first letter out into a (presumably) undefined value, leaving you with a mess that doesn’t work. 😛

After a little time with google, it transpires that the solution is to use two dollar signs, which make doesn’t interpolate, leaving you with a working script and leaving me with only this horror to content with (some formatting changes made so wordpress renders correctly) 🙂

find src -type f
  | awk -F "/"
  '{ print substr($$0, 0, index($$0, $$NF) - 1) }'
  | sort -u
  | awk -v cwd=$(CWD) '{ 
  print "{""\""$$0"*\",[\ndebug_info,\n{outdir, "
  "\"""ebin""\"""}\n
    {i,"cwd"/include}\n]""}." }' >> Emakefile
Advertisements

, ,

  1. #1 by ruckuus on April 28, 2009 - 5:43 am

    Thanks for this post, I have been facing the same problem with you and it’s now solved!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: