next up previous contents
Next: SUMMARY Up: . Previous: Libraries in UNIX (ar)   Contents

Maintaining large programs (make)

Large programs are often made from smaller pieces. These pieces can be very different from each other. Some may need to be compiled with a Fortran compiler and others with a different language compiler. You may also have to use certain libraries in your large programs. It can quickly become confusing as to which piece goes where, and which programs really need to be compiled after an editing session. You can either make a guess at which files to compile, or you could compile them all. If you choose the former you may miss a program; if you choose the latter you will almost certainly be wasting some time.

The make utility is designed to help you keep programs organized and save time. The basic idea behind make is to find the specified target file, make sure that all the files that it depends on are there and are up to date, and then re-create the target so that it is as up-to-date as its generators are.

In order to use the command make, you need to create a file called ``Makefile''. This file will contain all the necessary information about the source files that the final program is dependent on. When you execute the command make, it checks to see if the source files have been changed since the last time the target was created. If any of them have been changed it will recompile the changed ones, as well as those which depend on them, and the target file will be created with these new object files. It will not recompile anything that has not been affected, and (provided the Makefile is correct) it will not leave out any which need to be compiled. The basic format for make is:

make targetprogram

There can of course only be one Makefile in any given directory. However, if you wish to keep unrelated programs in the same directory, you can set up the Makefile so that more than one group can be handled by it. If you do not mention the target when you invoke make, the first file listed in the Makefile will be rebuilt. There are many, many ways to tailor make to do the things you want. To find out about fancier options see man make. For a detailed discussion on make see the ``make User's Guide'' in the ``Programmer's Overview'' manual. Here you will find, among other things, examples of Makefiles and how to use macros. If you plan to use make often, it is strongly recommended that you read it.

truein


next up previous contents
Next: SUMMARY Up: . Previous: Libraries in UNIX (ar)   Contents
h.stilmack@jach.hawaii.edu