Makefile Debugging: A introduction to remake

[article]

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.

mdb<0>

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

mdb<0> s

(/home/jgc/Makefile:4)

foo: bar

mdb<0> s

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

(/home/jgc/Makefile:4)

foo: bar

mdb<1> s

(/home/jgc/Makefile:7)

bar:

mdb<2> s

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

(/home/jgc/Makefile:7)

bar:

mdb<3> s

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

(/home/jgc/Makefile:7)

bar:

mdb<4> s

(/home/jgc/Makefile:8)

bar:

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.

(/home/jgc/Makefile:8)

bar:

mdb<6>

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.

(/home/jgc/Makefile:2)

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

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

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