Using make and makefile

Simple example of "makefile":
----begin of file-------
OBJ = pattern.o computepts.o startupcore.o 
FFLAGS=-u 
pattern: $(OBJ) 
	f77 $(OBJ)  -lcore77  -lcore  -lsunwindow \  
	-lpixrect -o pattern 
pattern.o: pattern.f commonblock 
	f77 $(FFLAGS) -c pattern.f 
computepts.o: computepts.f commonblock 
startupcore.o: startupcore.f
-----end of file-------

make uses default rules to compile computepts.f and startupcore.f.
which could have been written as:
	f77 $(FFLAGS) -c computepts.f
	
Ensuring a consistent choice of compiling and linking options is 
critical whenever compilation and linking are done in separate steps. 
Compiling any part of a program with any of the following options 
requires linking with the same options:  

-a, -autopar, -Bx,  -fast, -G, -Lpath, -lname, -mt, -xmemalign, 
-nolib, -norunpath, -p, -pg, -xlibmopt, -xlic_lib=name, -xprofile=p

Also, a number of options require that ALL source files be compiled 
with that option. These include: 

-aligncommon, -autopar, -dx, -dalign, -dbl, -explicitpar, -f, -misalign, 
-native, -parallel, -pentium, -xarch=a, -xcache=c, -xchip=c, -xF, 
-xtarget=t, -ztext

Static linking:
For any particular unresolved reference, libraries are searched only once, 
and only for symbols that are undefined at that point in the search. 
If you list more than one library on the command line, then the libraries 
are searched in the order in which they are found on the command line. 
Place -llibrary options as follows: 
- Place the -llibrary option after any .f, .for, .F, .f95, or .o files. 
- If you call functions in libx, and they reference functions in liby, then 
  place -lx before -ly.
  
The -Ldir option adds the dir directory path to the library search list. 
The linker searches for libraries first in any directories specified by 
the -L options and then in the standard directories. 
This option is useful only if it is placed preceding the -llibrary options 
to which it applies.

Dynamic linking:

With dynamic libraries, changing the library search path and order of loading 
differs from the static case. Actual linking takes place at runtime rather 
than build time.
When building the executable file, the linker records the paths to shared 
libraries in the executable itself. These search paths can be specified 
using the -Rpath option. This is in contrast to the -Ldir option which 
indicates at buildtime where to find the library specified by a -llibrary 
option, but does not record this path into the binary executable.
The directory paths that were built in when the executable was created can 
be viewed using the dump command.
  demo% f95 program.f -R/home/proj/libs -L/home/proj/libs -lmylib 
  demo% dump  Lv a.out | grep RPATH 
  [5] RPATH /home/proj/libs:/opt/SUNWspro/lib

---> following text is the same as in file "about_libraries"
At runtime, the linker determines where to find the dynamic libraries 
that an executable needs from: 
- The value of LD_LIBRARY_PATH at runtime 
- The paths that had been specified by -R at the time the 
  executable file was built.
As noted earlier, use of LD_LIBRARY_PATH can have unexpected side-effects 
and is not recommended.

Use ldd to determine where the executable expects to find the libraries:
  demo% ldd a.out 
  	libsolib.so => /export/home/proj/libsolib.so 
  	libF77.so.4 => /opt/SUNWspro/lib/libF77.so.4 
  	libc.so.1 => /usr/lib/libc.so.1 
  	libdl.so.1 => /usr/lib/libdl.so.1

You can specify dynamic or static library binding when you compile. 
These options are actually linker options, but they are recognized 
by the compiler and passed on to the linker.  
     -Bdynamic |  -Bstatic  
Bdynamic sets the preference for shared, dynamic binding whenever possible.  
Bstatic restricts binding to static libraries only.