Help Files: Fortran77: Make





     HELP                      Sep. 15, 1984                  F77/MAKE



          Make - A System for Program Development and Maintenance

     The UNIX utility 'make' is a program development tool that great-
     ly enhances the construction and maintenance of moderate to large
     programs in any language.

     'Make' is used to find out which  object  files  that  a  program
     depends on are out of date, and to have them automatically recom-
     piled.  To use 'make', you must describe the dependencies  within
     the program in a file called 'makefile' or 'Makefile'.  Here is a
     simple 'Makefile' for a program 'prog' which  is  made  from  the
     source in 'main.f', 'sub1.f' and 'sub2.f':

             prog:   main.o sub1.o sub2.o
                     f77 main.o sub1.o sub2.o -o prog

     The first line describes the target, 'prog', and gives  the  name
     of  the  three object files it depends on.  The second line tells
     how to create the target file once the files it depends on are up
     to date.

     'Make' requires that the target file name MUST  start  in  column
     one and the next line MUST start with a tab (control-I), not with
     blanks.

     To use this makefile, type: 'make'.  Then 'make' will check  that
     the  three  object  files  exist  and  are  more  recent than the
     corresponding source files; e.g. if 'main.f' was last changed  on
     April  20,  5:02 and 'main.o' was last changed on April 20, 4:58,
     then 'make' will recompile 'main.f' to generate  an  up  to  date
     'main.o'.   If however, 'main.o' is more recent than 'main.f', it
     will not be recompiled.

     Once the three files named on the first  line  are  up  to  date,
     'make'  checks whether any of them are newer than 'prog'.  If so,
     it executes the next line to generate a new  version  of  'prog';
     otherwise, it stops and reports 'prog' is up to date.

     For this example, typing 'make' when the object files do not  ex-
     ist results in:

             f77    -c main.f
             main.f:
                MAIN:
             f77    -c sub1.f
             sub1.f:
                sub1:
             f77    -c sub2.f
             sub2.f:
                sub2:
             f77 main.o sub1.o sub2.o  -o doit
             Loading prog ...

     If you type 'make' again:

             `prog' is up to date.

     If you now edit 'main.f' and then type 'make':

             f77    -c main.f
             main.f:
                MAIN:
             f77 main.o sub1.o sub2.o  -o doit
             Loading prog ...

     'Make' only performs those steps that are needed to  keep  'prog'
     up  to  date.  To see what 'make' would do without actually doing
     it, type 'make -n'.

     Here is a more advanced 'Makefile'.  FFLAGS is a  special  string
     known  to  'make' in which you can specify f77 compilation flags;
     here '-g' is specified to save the symbol table for use with  the
     symbolic  debugger.   OBJECTS and SOURCES are defined as lists of
     file names.

             FFLAGS = -g
             OBJECTS = main.o sub1.o sub2.o sub3.o sub4.o sub5.o
             SOURCES = main.f sub1.f sub2.f sub3.f sub4.f sub5.f

             prog:   $(OBJECTS)
                     f77 -g $(OBJECTS) -o prog  -lf77plot

             main.o sub1.o:          common_a.inc
             sub2.o sub3.o sub4.o:   common_b.inc

             #       to print all the source on the line printer
             print: ; pr common_a.inc common_b.inc $(SOURCES) | lpr

             #       to remove all the object files and core dumps
             remove: ; rm -f $(OBJECTS) core

     The linking line specifies the '-g' flag because FFLAGS  is  used
     automatically   only   for   compilations.    It  also  specifies
     '-lf77plot' for the f77 graphics interface library (see  "man  3f
     plot").  The next two lines specify additional dependencies; both
     'main.o' and 'sub1.o' depend on the file 'common_a.inc' and three
     object  files  depend  on 'common_b.inc'.  These two files define
     common blocks and are included via the 'include'  statement  (see
     "help f77 style").  Now if 'common_a.inc' is changed, 'make' will
     automatically   recompile   'main.o'   and   'sub1.o',   and   if
     'common_b.inc' is changed, the three object files depending on it
     will be recompiled.

     The last lines define two new targets, 'print' and  'remove'.   A
     name is designated as a target by appearing on a line starting in
     column one.  The default when you type  'make'  is  to  make  the
     first  target.   Thus typing 'make' is equivalent to typing 'make
     prog'.  You can also type 'make print' which will cause  all  the
     source  files to be printed or 'make remove' to remove disk files
     to save space.

     For more online information on 'make', see "man make".  For  more
     extensive  written  documentation, see "A Guide for VAX UNIX For-
     tran Users" and "Make - A Program for Maintaining  Computer  Pro-
     grams".


Comments to decf@euler.berkeley.edu
© 1998 UC Regents