1 / 11

Makefiles

Software Tools. Makefiles. make Overview. The make utility helps… Keep track of which modules of a program have been updated To ensure that when you compile a program you use the latest versions of all program modules. The make Utility.

malana
Download Presentation

Makefiles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software Tools Makefiles

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

  3. The make Utility • 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. • 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. • The header file might depend on other header files, etc. num.h tab.h form.h size.c length.c size.o length.o form.exe

  4. The make Utility • 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.

  5. makefile Format • Themakefileformat: target: prerequisite-list [TAB] construction commands • Thetargetis the name of the file that depends on the files in the prerequisite-list. • Theconstruction-commandsare regular commands to the shell that usually compile and/or link the target file. • Themakeutility executes the construction-commandswhen the modification time of one or more of the files in the prerequisite-list is more recent than the target file.

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

  7. make Example 1 $ cat makefile form.exe: size.o length.o cc –o form.exe size.o length.o 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 • The last line shows that you can put any Bourne Shell command on a construction line. num.h tab.h form.h size.c length.c size.o length.o form.exe

  8. make Example 2 compute.h $ cat makefile # # makefile for compute # compute.exe: compute.o calc.o cc –o compute.exe compute.o calc.o compute.o compute.c compute.h cc –c compute.c # 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 compute.c calc.c compute.o calc.o compute.exe

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

  10. make Example 2(continued) • 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 $

  11. Disks Usage Statistics • df display free blocks and # of files in each file system $ df / (/dev/dsk/c0t0d0s0 ): 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/c0t0d0s3 ): 3126728 blocks 341949 files /var/run (swap ): 4512192 blocks 26131 files /cache (/dev/dsk/c0t0d0s4 ): 329020 blocks 241130 files /tmp (swap ): 4512192 blocks 26131 files /home (/dev/dsk/c0t0d0s7 ):25771604 blocks 1629180 files /usr/local (/cache/cache/.cfs_mnt_points/cssvr12:_export_ug_sol_local_1117):50357454 blocks 4209362 files /homes/horner (wine:/export/ug_staff/horner): 7852022 blocks 754200 files /share/share (cssvr9:/usr_local_share): 1260818 blocks 774330 files • du display disk usage statistics (in number of 512k blocks) $ du | head -5 282 ./zmodem 14 ./gzip-0.7/msdos 2 ./gzip-0.7/os2 662 ./gzip-0.7 3626 ./mail du shows disk usage of directories in 512k blocks

More Related