Makefile Debugging: A introduction to remake


shown).   Typing h gives complete help information:

mdb<0> h

  Command                  Short Name  Aliases

  ----------------------   ----------  ---------

  break *target*                  (b)  L

  cd *dir*                        (C)

  comment *text*                  (#)

  continue                        (c)

  delete breakpoint numbers..     (d)

  down [amount]                   (D)

  eval *string*                   (e)

  examine *string*                (x)

  finish                          (F)

  frame *n*                       (f)

  help [command]                  (h)  ?, ??

  info [thing]                    (i)

  next [amount]                   (n)

  print {*variable* [attrs...]}   (p)

  Print working directory         (P)

  quit [exit-status]              (q)  exit, return

  run                             (R)  restart

  set {*option*|variable} *value* (=)

  setq *variable* *value*         (")

  shell *string*                  (!)  !!

  show [thing]                    (S)

  skip                            (k)

  step [amount]                   (s)

  target                          (t)

  up [amount]                     (u)

  where                           (T)  backtrace, bt

  write [*target* [*filename*]]   (w)

Readline command line editing (emacs/vi mode) is available.

For more detailed help, type h <cmd> or consult online-documentation.


Since we are debugging the touch problem we'll just continue by single stepping with s:

mdb<0> s


foo: bar

mdb<0> s

   /home/jgc/Makefile:4 File `foo' does not exist.


foo: bar

mdb<1> s



mdb<2> s

     /home/jgc/Makefile:7       File `bar' does not exist.



mdb<3> s

    /home/jgc/Makefile:7        Must remake target `bar'.



mdb<4> s



mdb<5> s


touch -x bar


+ touch -x bar

touch: invalid option -- x

Try `touch --help' for more information.

Makefile:8: *** [bar] Error 1

#0  bar at /home/jgc/Makefile:8

#1  foo at /home/jgc/Makefile:4

#2  all at /home/jgc/Makefile:2

***Entering debugger because we encountered a fatal error.

***Exiting the debugger will exit make with exit code 1.




Whilst in the debugger I can fix the error in the Makefile and then hit R to restart.  Now things work correctly:

mdb<0> R

Changing directory to /home/jgc and restarting...

Reading makefiles...

Updating makefiles....

Updating goal targets....

 /home/jgc/Makefile:2   File `all' does not exist.


all: foo bar baz

mdb<0> c

   /home/jgc/Makefile:4 File `foo' does not exist.

     /home/jgc/Makefile:7       File `bar' does not exist.

    /home/jgc/Makefile:7        Must remake target `bar'.

+ touch bar

    /home/jgc/Makefile:7        Successfully remade target file `bar'.

  /home/jgc/Makefile:4  Must remake target `foo'.

+ touch foo

  /home/jgc/Makefile:4  Successfully remade target

About the author

John Graham-Cumming's picture John Graham-Cumming

John Graham-Cumming is Co-Founder at Electric Cloud, Inc . Prior to joining Electric Cloud, John was a Venture Consultant with Accel Partners, VP of Internet Technology at Interwoven, Inc. (IWOV), VP of Engineering at Scriptics Corporation (acquired by Interwoven), and Chief Architect at Optimal Networks, Inc. John holds BA and MA degrees in Mathematics and Computation and a Doctorate in Computer Security from Oxford University. John is the creator of the highly acclaimed open source POPFile project. He also holds two patents in network analysis and has others pending.

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, is the place to go for what is happening in software development and delivery.  Join the conversation now!