Software Tools Makefiles Slide 2 make Overview l

  • Slides: 11
Download presentation
Software Tools Makefiles

Software Tools Makefiles

Slide 2 make Overview l The make utility helps… n. Keep track of which

Slide 2 make Overview l The make utility helps… n. Keep track of which modules of a program have been updated n. To ensure that when you compile a program you use the latest versions of all program modules.

Slide 3 The make Utility l l Large programs often have many source and

Slide 3 The make Utility l l Large programs often have many source and header files that depend on one another. After you change a file that others files depend on, you must recompile all the dependent files. n num. h For example: – Several source files – 1 header file (used by all source files) After you change the header file, each source file must be recompiled. n The header file might depend on other header files, etc. tab. h form. h size. c length. c n size. o length. o form. exe

Slide 4 The make Utility l l l Determining which modules to recompile can

Slide 4 The make Utility l l l Determining which modules to recompile can be difficult when working on large programs. The make utility automates the process. make looks at dependencies in a file named makefile in the working directory. Dependencies specify a target file depends on one or more prerequisite files. If a prerequisite file has been modified more recently than its target file, make updates the target file based on construction commands. make normally stops if it encounters an error during the construction process.

Slide 5 makefile Format The makefile format: target: prerequisite-list [TAB] construction commands l l

Slide 5 makefile Format The makefile format: target: prerequisite-list [TAB] construction commands l l The target is the name of the file that depends on the files in the prerequisite-list. The construction-commands are regular commands to the shell that usually compile and/or link the target file. The make utility executes the construction-commands when the modification time of one or more of the files in the prerequisite-list is more recent than the target file.

Slide 6 make Example 0 form. exe: size. o length. o cc –o form.

Slide 6 make Example 0 form. exe: size. o length. o cc –o form. exe size. o length. o form. exe

Slide 7 make Example 1 $ cat makefile form. exe: size. o length. o

Slide 7 make Example 1 $ cat makefile form. exe: size. o length. o cc –o form. exe size. o length. o num. h size. o size. c form. h cc –c size. c length. o: length. c form. h cc –c length. c form. h: num. h table. h cat num. h table. h > form. h tab. h form. h size. c length. c size. o length. o form. exe l The last line shows that you can put any Bourne Shell command on a construction line.

Slide 8 make Example 2 compute. h $ cat makefile # # makefile for

Slide 8 make Example 2 compute. h $ cat makefile # # makefile for compute # compute. c calc. c compute. o calc. o compute. exe: compute. o calc. o cc –o compute. exe compute. o calc. o compute. c compute. h cc –c compute. exe # the calc. o dependency is optional, and is included automatically calc. o: calc. c cc –c calc. c # delete temporary files such as. o files clean: rm *. o

Slide 9 make Example 2 $ ls –l total 22 -rw-rw----rwxrwx---rw-rw----rw-rw---- 1 1 1

Slide 9 make Example 2 $ ls –l total 22 -rw-rw----rwxrwx---rw-rw----rw-rw---- 1 1 1 1 horner horner cs cs 179 354 6337 780 49 880 311 Jan Jan 21 21 18: 20 16: 02 16: 04 18: 20 16: 04 15: 56 $ make cc –c compute. c cc –c calc. c cc –o compute. exe compute. o calc. c calc. o compute. exe compute. c compute. h compute. o makefile

Slide 10 make Example 2 (continued) l The touch utility updates the date of

Slide 10 make Example 2 (continued) l The touch utility updates the date of a file to now. $ make ‘compute. exe’ is up to date. $ touch calc. c $ make cc –c calc. c cc –o compute. exe compute. o calc. o $ touch compute. h $ make cc –c compute. c cc –o compute. exe compute. o calc. o $ make clean rm *. o $

Slide 11 Disks Usage Statistics l df display free blocks and # of files

Slide 11 Disks Usage Statistics l df display free blocks and # of files in each file system $ df / (/dev/dsk/c 0 t 0 d 0 s 0 ): 2459020 blocks 313329 files /proc (/proc ): 0 blocks 3870 files /dev/fd (fd ): 0 blocks 0 files /etc/mnttab (mnttab ): 0 blocks 0 files /var (/dev/dsk/c 0 t 0 d 0 s 3 ): 3126728 blocks 341949 files /var/run (swap ): 4512192 blocks 26131 files /cache (/dev/dsk/c 0 t 0 d 0 s 4 ): 329020 blocks 241130 files /tmp (swap ): 4512192 blocks 26131 files /home (/dev/dsk/c 0 t 0 d 0 s 7 ): 25771604 blocks 1629180 files /usr/local (/cache/. cfs_mnt_points/cssvr 12: _export_ug_sol_local_1117): 50357454 blocks 4209362 files /homes/horner (wine: /export/ ug_staff/horner): 7852022 blocks 754200 files /share (cssvr 9: /usr_local_share): 1260818 blocks 774330 files l du display disk usage statistics (in number of 512 k blocks) $ du | head -5 282. /zmodem 14. /gzip-0. 7/msdos 2. /gzip-0. 7/os 2 662. /gzip-0. 7 3626. /mail du shows disk usage of directories in 512 k blocks