16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Development Tools<br />

Make looks at <strong>the</strong> date stamps on your files, <strong>the</strong>n does what is necessary to create an up-to-date version.<br />

Makefile format:<br />

target: prerequisite-list<br />

construction-commands<br />

Increases of <strong>the</strong> modularity of programs means that a project may have to cope <strong>with</strong> a large number of files:<br />

- file-to-file dependencies<br />

- make creates <strong>the</strong> finished program by recompiling only those portions directly of indirectly affected by <strong>the</strong><br />

change<br />

- find <strong>the</strong> target in <strong>the</strong> description file<br />

- ensure that all files on which <strong>the</strong> target depends, exists and are up to date<br />

- create target file if any of <strong>the</strong> generators have been modified more recently than <strong>the</strong> target<br />

Commands in <strong>the</strong> rule will be performed whenever "main.o" is needed and "main.c" or "win.h" have been updated<br />

since "main.o" was last rebuilt.<br />

/* main.c ---------------------------*/<br />

#include "win.h"<br />

...<br />

/* win.c ----------------------------*/<br />

#include "win.h"<br />

...<br />

/* kit.c ----------------------------*/<br />

#include "kit.h" #include "win.h"<br />

...<br />

# makefile --------------------------<br />

prog: main.o win.a kit.a<br />

cc -o prog main.a win.a kit.a #link<br />

main.a: main.c win.h<br />

cc -c main.c<br />

win.o: win.c win.h<br />

cc -c win.c -1curses<br />

# compile<br />

# compile in library<br />

kit.a: kit.c kit.h win.h<br />

cc -DDEBUG -c kit.c<br />

# compile <strong>with</strong> debug<br />

# -----------------------------------<br />

$ make kit.o # recompiles kit.a if any of kit.c, kit.h or win.h has been changed<br />

$ make prog # rebuilds (compiles) any of object files required to build "prog " and <strong>the</strong>n link <strong>the</strong>se files<br />

$ make # same as "make prog" (1st rule)<br />

$ make -n prog # show commands only (not performed)<br />

$ make -ffile.mk # use file.mk instead of Makefile<br />

Dependency Tree<br />

main.c<br />

win.c<br />

win.h<br />

main.o<br />

win.o<br />

prog<br />

kit.c<br />

kit.o<br />

kit.h<br />

# Makefile ----------------------------------------<br />

BASE = /staff/neville<br />

CC<br />

= cc<br />

52

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!